File: reporting_fixture_suite_test.go

package info (click to toggle)
golang-github-onsi-ginkgo-v2 2.22.0-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 4,060 kB
  • sloc: javascript: 59; makefile: 23; sh: 14
file content (65 lines) | stat: -rw-r--r-- 1,912 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
package reporting_fixture_test

import (
	"fmt"
	"os"
	"testing"

	. "github.com/onsi/ginkgo/v2"
	"github.com/onsi/ginkgo/v2/types"
	. "github.com/onsi/gomega"
)

func TestReportingFixture(t *testing.T) {
	RegisterFailHandler(Fail)
	RunSpecs(t, "ReportingFixture Suite")
}

var beforeEachReport, afterEachReport *os.File

var _ = ReportBeforeSuite(func(report Report) {
	f, err := os.Create(fmt.Sprintf("report-before-suite-%d.out", GinkgoParallelProcess()))
	Ω(err).ShouldNot(HaveOccurred())

	fmt.Fprintf(f, "%s - %d\n", report.SuiteDescription, report.SuiteConfig.RandomSeed)
	fmt.Fprintf(f, "%d of %d", report.PreRunStats.SpecsThatWillRun, report.PreRunStats.TotalSpecs)

	f.Close()
})

var _ = BeforeSuite(func() {
	var err error
	beforeEachReport, err = os.Create("report-before-each.out")
	Ω(err).ShouldNot(HaveOccurred())
	DeferCleanup(beforeEachReport.Close)

	afterEachReport, err = os.Create("report-after-each.out")
	Ω(err).ShouldNot(HaveOccurred())
	DeferCleanup(afterEachReport.Close)
})

var _ = ReportBeforeEach(func(report SpecReport) {
	fmt.Fprintf(beforeEachReport, "%s - %s\n", report.LeafNodeText, report.State)
})

var _ = ReportAfterEach(func(report SpecReport) {
	fmt.Fprintf(afterEachReport, "%s - %s\n", report.LeafNodeText, report.State)
})

var _ = ReportAfterSuite("my report", func(report Report) {
	f, err := os.Create("report-after-suite.out")
	Ω(err).ShouldNot(HaveOccurred())

	fmt.Fprintf(f, "%s - %d\n", report.SuiteDescription, report.SuiteConfig.RandomSeed)
	for _, specReport := range report.SpecReports {
		if specReport.LeafNodeType.Is(types.NodeTypesForSuiteLevelNodes) || specReport.LeafNodeType.Is(types.NodeTypeCleanupAfterSuite) {
			fmt.Fprintf(f, "%d: [%s] - %s\n", specReport.ParallelProcess, specReport.LeafNodeType, specReport.State)
		} else {
			fmt.Fprintf(f, "%s - %s\n", specReport.LeafNodeText, specReport.State)
		}
	}

	f.Close()

	Fail("fail!")
})