...

Source file src/github.com/onsi/ginkgo/v2/integration/output_interceptor_test.go

Documentation: github.com/onsi/ginkgo/v2/integration

     1  package integration_test
     2  
     3  import (
     4  	"os/exec"
     5  	"time"
     6  
     7  	. "github.com/onsi/ginkgo/v2"
     8  	. "github.com/onsi/gomega"
     9  	"github.com/onsi/gomega/gbytes"
    10  	"github.com/onsi/gomega/gexec"
    11  )
    12  
    13  var _ = Describe("OutputInterceptor", func() {
    14  	Context("exercising the edge case reported in issue #851", func() {
    15  		BeforeEach(func() {
    16  			fm.MountFixture("interceptor")
    17  
    18  			cmd := exec.Command("go", "build")
    19  			cmd.Dir = fm.PathTo("interceptor")
    20  			session, err := gexec.Start(cmd, GinkgoWriter, GinkgoWriter)
    21  			Ω(err).ShouldNot(HaveOccurred())
    22  			Eventually(session).Should(gexec.Exit(0))
    23  
    24  			Ω(fm.PathTo("interceptor", "interceptor")).Should(BeAnExistingFile())
    25  		})
    26  
    27  		It("exercises the edge case reported in issue #851 - by asserting that output interception does not hang indefinitely if a process is spawned with cmd.Stdout=os.Stdout", func() {
    28  			sess := startGinkgo(fm.PathTo("interceptor"), "--no-color")
    29  			Eventually(sess).Should(gexec.Exit(0))
    30  		})
    31  	})
    32  
    33  	Context("pausing/resuming output interception", func() {
    34  		BeforeEach(func() {
    35  			fm.MountFixture("pause_resume_interception")
    36  		})
    37  
    38  		It("can pause and resume interception", func() {
    39  			sess := startGinkgo(fm.PathTo("pause_resume_interception"), "--no-color", "--procs=2", "--json-report=report.json")
    40  			Eventually(sess).Should(gexec.Exit(0))
    41  
    42  			output := string(sess.Out.Contents())
    43  			Ω(output).Should(ContainSubstring("CAPTURED OUTPUT A\n"))
    44  			Ω(output).Should(ContainSubstring("CAPTURED OUTPUT B\n"))
    45  
    46  			Ω(output).ShouldNot(ContainSubstring("OUTPUT TO CONSOLE"))
    47  
    48  			report := fm.LoadJSONReports("pause_resume_interception", "report.json")[0]
    49  			Ω(report.SpecReports[0].CapturedStdOutErr).Should(Equal("CAPTURED OUTPUT A\nCAPTURED OUTPUT B\n"))
    50  		})
    51  	})
    52  
    53  	Context("ensuring Ginkgo does not hang when a child process does not exit: https://github.com/onsi/ginkgo/issues/1191", func() {
    54  		BeforeEach(func() {
    55  			fm.MountFixture("interceptor_sleep")
    56  		})
    57  
    58  		It("exits without hanging", func() {
    59  			sess := startGinkgo(fm.PathTo("interceptor_sleep"), "--no-color", "--procs=2")
    60  			Eventually(sess).WithTimeout(time.Second * 15).Should(gexec.Exit(0))
    61  
    62  			Ω(sess).Should(gbytes.Say("Captured StdOut/StdErr Output >>"))
    63  			Ω(sess).Should(gbytes.Say("Some STDOUT output"))
    64  			Ω(sess).Should(gbytes.Say("Some STDERR output"))
    65  			Ω(sess).Should(gbytes.Say("<< Captured StdOut/StdErr Output"))
    66  		})
    67  	})
    68  })
    69  

View as plain text