1 package integration_test
2
3 import (
4 "strings"
5
6 . "github.com/onsi/ginkgo/v2"
7 . "github.com/onsi/gomega"
8 "github.com/onsi/gomega/gexec"
9 )
10
11 var _ = Describe("Flags Specs", func() {
12 BeforeEach(func() {
13 fm.MountFixture("flags")
14 })
15
16 getRandomOrders := func(output string) []int {
17 return []int{strings.Index(output, "RANDOM_A"), strings.Index(output, "RANDOM_B"), strings.Index(output, "RANDOM_C")}
18 }
19
20 It("normally passes, prints out noisy pendings, does not randomize tests, and honors the programmatic focus", func() {
21 session := startGinkgo(fm.PathTo("flags"), "--no-color")
22 Eventually(session).Should(gexec.Exit(1))
23 output := string(session.Out.Contents())
24
25 Ω(output).Should(ContainSubstring("9 Passed"))
26 Ω(output).Should(ContainSubstring("2 Failed"))
27 Ω(output).Should(ContainSubstring("1 Pending"))
28 Ω(output).Should(ContainSubstring("0 Skipped"))
29 Ω(output).Should(ContainSubstring("[PENDING]"))
30 Ω(output).Should(ContainSubstring("marshmallow"))
31 Ω(output).Should(ContainSubstring("chocolate"))
32 Ω(output).Should(ContainSubstring("CUSTOM_FLAG: default"))
33 Ω(output).ShouldNot(ContainSubstring("SLOW TEST"))
34 Ω(output).ShouldNot(ContainSubstring("should honor -slow-spec-threshold"))
35 Ω(output).ShouldNot(ContainSubstring("Full Stack Trace"))
36
37 orders := getRandomOrders(output)
38 Ω(orders[0]).Should(BeNumerically("<", orders[1]))
39 Ω(orders[1]).Should(BeNumerically("<", orders[2]))
40 })
41
42 It("should fail when there are pending tests and it is passed --fail-on-pending", func() {
43 session := startGinkgo(fm.PathTo("flags"), "--no-color", "--fail-on-pending")
44 Eventually(session).Should(gexec.Exit(1))
45 output := string(session.Out.Contents())
46 Ω(output).Should(ContainSubstring("Detected pending specs and --fail-on-pending is set"))
47 })
48
49 It("should run the race detector when told to", Label("slow"), func() {
50 if !raceDetectorSupported() {
51 Skip("race detection is not supported")
52 }
53 session := startGinkgo(fm.PathTo("flags"), "--no-color", "--race")
54 Eventually(session).Should(gexec.Exit(1))
55 output := string(session.Out.Contents())
56
57 Ω(output).Should(ContainSubstring("WARNING: DATA RACE"))
58 })
59
60 It("should randomize tests when told to", func() {
61 session := startGinkgo(fm.PathTo("flags"), "--no-color", "--randomize-all", "--seed=120")
62 Eventually(session).Should(gexec.Exit(1))
63 output := string(session.Out.Contents())
64
65 orders := getRandomOrders(output)
66 Ω(orders[0]).ShouldNot(BeNumerically("<", orders[1]))
67 })
68
69 It("should consistently pass in a zero seed when asked to", func() {
70 fm.MountFixture("seed")
71 session := startGinkgo(fm.PathTo("seed"), "--no-color", "--seed=0", "--nodes=2")
72 Eventually(session).Should(gexec.Exit(0))
73 })
74
75 It("should pass additional arguments in", func() {
76 session := startGinkgo(fm.PathTo("flags"), "--", "--customFlag=madagascar")
77 Eventually(session).Should(gexec.Exit(1))
78 output := string(session.Out.Contents())
79
80 Ω(output).Should(ContainSubstring("CUSTOM_FLAG: madagascar"))
81 })
82
83 It("should print out full stack traces for failures when told to", func() {
84 session := startGinkgo(fm.PathTo("flags"), "--trace")
85 Eventually(session).Should(gexec.Exit(1))
86 output := string(session.Out.Contents())
87
88 Ω(output).Should(ContainSubstring("Full Stack Trace"))
89 })
90
91 Describe("--fail-fast", func() {
92 BeforeEach(func() {
93 fm.MountFixture("fail_then_hang")
94 })
95
96 Context("when running in series", func() {
97 It("should fail fast when told to", func() {
98 session := startGinkgo(fm.PathTo("fail_then_hang"), "--fail-fast")
99 Eventually(session).Should(gexec.Exit(1))
100 output := string(session.Out.Contents())
101
102 Ω(output).Should(ContainSubstring("1 Failed"))
103 Ω(output).Should(ContainSubstring("2 Skipped"))
104 })
105 })
106
107 Context("when running in parallel", func() {
108 It("should fail fast when told to", func() {
109 session := startGinkgo(fm.PathTo("fail_then_hang"), "--fail-fast", "--procs=2")
110 Eventually(session).Should(gexec.Exit(1))
111 output := string(session.Out.Contents())
112
113 Ω(output).Should(ContainSubstring("2 Failed"))
114 Ω(output).Should(ContainSubstring("1 Skipped"))
115 })
116 })
117 })
118
119 Context("with a flaky test", func() {
120 It("should normally fail", func() {
121 session := startGinkgo(fm.PathTo("flags"), "--focus=flaky")
122 Eventually(session).Should(gexec.Exit(1))
123 })
124
125 It("should pass if retries are requested", func() {
126 session := startGinkgo(fm.PathTo("flags"), "--focus=flaky --flake-attempts=2")
127 Eventually(session).Should(gexec.Exit(0))
128 })
129 })
130
131 It("should perform a dry run when told to", func() {
132 fm.MountFixture("fail")
133 session := startGinkgo(fm.PathTo("fail"), "--dry-run", "-v")
134 Eventually(session).Should(gexec.Exit(0))
135 output := string(session.Out.Contents())
136
137 Ω(output).Should(ContainSubstring("synchronous failures"))
138 Ω(output).Should(ContainSubstring("16 Specs"))
139 Ω(output).Should(ContainSubstring("16 Passed"))
140 Ω(output).Should(ContainSubstring("0 Failed"))
141 })
142
143 It("should allow configuration overrides", func() {
144 fm.MountFixture("config_override_label_filter")
145 session := startGinkgo(fm.PathTo("config_override_label_filter"), "--label-filter=NORUN", "--no-color")
146 Eventually(session).Should(gexec.Exit(0), "Succeeds because --label-filter is overridden by the test suite itself.")
147 output := string(session.Out.Contents())
148 Ω(output).Should(ContainSubstring("2 Specs"))
149 Ω(output).Should(ContainSubstring("1 Skipped"))
150 Ω(output).Should(ContainSubstring("1 Passed"))
151 })
152
153 It("should emit node start/end events when running with --show-node-events", func() {
154 session := startGinkgo(fm.PathTo("flags"), "--no-color", "-v", "--show-node-events")
155 Eventually(session).Should(gexec.Exit(1))
156 output := string(session.Out.Contents())
157
158 Eventually(output).Should(ContainSubstring("> Enter [It] should honor -cover"))
159 Eventually(output).Should(ContainSubstring("< Exit [It] should honor -cover"))
160
161 fm.MountFixture("fail")
162 session = startGinkgo(fm.PathTo("fail"), "--no-color", "--show-node-events")
163 Eventually(session).Should(gexec.Exit(1))
164 output = string(session.Out.Contents())
165 Ω(output).Should(ContainSubstring("> Enter [It] a top level specify"))
166 Ω(output).Should(ContainSubstring("< Exit [It] a top level specify"))
167
168 session = startGinkgo(fm.PathTo("fail"), "--no-color")
169 Eventually(session).Should(gexec.Exit(1))
170 output = string(session.Out.Contents())
171 Ω(output).ShouldNot(ContainSubstring("> Enter [It] a top level specify"))
172 Ω(output).ShouldNot(ContainSubstring("< Exit [It] a top level specify"))
173 })
174 })
175
View as plain text