github.com/onsi/ginkgo@v1.16.6-0.20211118180735-4e1925ba4c95/integration/_fixtures/reporting_fixture/reporting_fixture_suite_test.go (about) 1 package reporting_fixture_test 2 3 import ( 4 "fmt" 5 "os" 6 "testing" 7 8 . "github.com/onsi/ginkgo" 9 "github.com/onsi/ginkgo/types" 10 . "github.com/onsi/gomega" 11 ) 12 13 func TestReportingFixture(t *testing.T) { 14 RegisterFailHandler(Fail) 15 RunSpecs(t, "ReportingFixture Suite") 16 } 17 18 var beforeEachReport, afterEachReport *os.File 19 20 var _ = BeforeSuite(func() { 21 var err error 22 beforeEachReport, err = os.Create("report-before-each.out") 23 Ω(err).ShouldNot(HaveOccurred()) 24 DeferCleanup(beforeEachReport.Close) 25 26 afterEachReport, err = os.Create("report-after-each.out") 27 Ω(err).ShouldNot(HaveOccurred()) 28 DeferCleanup(afterEachReport.Close) 29 }) 30 31 var _ = ReportBeforeEach(func(report SpecReport) { 32 fmt.Fprintf(beforeEachReport, "%s - %s\n", report.LeafNodeText, report.State) 33 }) 34 35 var _ = ReportAfterEach(func(report SpecReport) { 36 fmt.Fprintf(afterEachReport, "%s - %s\n", report.LeafNodeText, report.State) 37 }) 38 39 var _ = ReportAfterSuite("my report", func(report Report) { 40 f, err := os.Create("report-after-suite.out") 41 Ω(err).ShouldNot(HaveOccurred()) 42 43 fmt.Fprintf(f, "%s - %d\n", report.SuiteDescription, report.SuiteConfig.RandomSeed) 44 for _, specReport := range report.SpecReports { 45 if specReport.LeafNodeType.Is(types.NodeTypesForSuiteLevelNodes) || specReport.LeafNodeType.Is(types.NodeTypeCleanupAfterSuite) { 46 fmt.Fprintf(f, "%d: [%s] - %s\n", specReport.ParallelProcess, specReport.LeafNodeType, specReport.State) 47 } else { 48 fmt.Fprintf(f, "%s - %s\n", specReport.LeafNodeText, specReport.State) 49 } 50 } 51 52 f.Close() 53 54 Fail("fail!") 55 })