flags_test.go 9.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237
  1. package integration_test
  2. import (
  3. "io/ioutil"
  4. "os"
  5. "path/filepath"
  6. "strings"
  7. . "github.com/onsi/ginkgo"
  8. "github.com/onsi/ginkgo/types"
  9. . "github.com/onsi/gomega"
  10. "github.com/onsi/gomega/gexec"
  11. )
  12. var _ = Describe("Flags Specs", func() {
  13. var pathToTest string
  14. BeforeEach(func() {
  15. pathToTest = tmpPath("flags")
  16. copyIn(fixturePath("flags_tests"), pathToTest, false)
  17. })
  18. getRandomOrders := func(output string) []int {
  19. return []int{strings.Index(output, "RANDOM_A"), strings.Index(output, "RANDOM_B"), strings.Index(output, "RANDOM_C")}
  20. }
  21. It("normally passes, runs measurements, prints out noisy pendings, does not randomize tests, and honors the programmatic focus", func() {
  22. session := startGinkgo(pathToTest, "--noColor")
  23. Eventually(session).Should(gexec.Exit(types.GINKGO_FOCUS_EXIT_CODE))
  24. output := string(session.Out.Contents())
  25. Ω(output).Should(ContainSubstring("Ran 3 samples:"), "has a measurement")
  26. Ω(output).Should(ContainSubstring("11 Passed"))
  27. Ω(output).Should(ContainSubstring("0 Failed"))
  28. Ω(output).Should(ContainSubstring("1 Pending"))
  29. Ω(output).Should(ContainSubstring("3 Skipped"))
  30. Ω(output).Should(ContainSubstring("[PENDING]"))
  31. Ω(output).Should(ContainSubstring("marshmallow"))
  32. Ω(output).Should(ContainSubstring("chocolate"))
  33. Ω(output).Should(ContainSubstring("CUSTOM_FLAG: default"))
  34. Ω(output).Should(ContainSubstring("Detected Programmatic Focus - setting exit status to %d", types.GINKGO_FOCUS_EXIT_CODE))
  35. Ω(output).ShouldNot(ContainSubstring("smores"))
  36. Ω(output).ShouldNot(ContainSubstring("SLOW TEST"))
  37. Ω(output).ShouldNot(ContainSubstring("should honor -slowSpecThreshold"))
  38. orders := getRandomOrders(output)
  39. Ω(orders[0]).Should(BeNumerically("<", orders[1]))
  40. Ω(orders[1]).Should(BeNumerically("<", orders[2]))
  41. })
  42. It("should run a coverprofile when passed -cover", func() {
  43. session := startGinkgo(pathToTest, "--noColor", "--cover", "--focus=the focused set")
  44. Eventually(session).Should(gexec.Exit(0))
  45. output := string(session.Out.Contents())
  46. _, err := os.Stat(filepath.Join(pathToTest, "flags.coverprofile"))
  47. Ω(err).ShouldNot(HaveOccurred())
  48. Ω(output).Should(ContainSubstring("coverage: "))
  49. })
  50. It("should fail when there are pending tests and it is passed --failOnPending", func() {
  51. session := startGinkgo(pathToTest, "--noColor", "--failOnPending")
  52. Eventually(session).Should(gexec.Exit(1))
  53. })
  54. It("should fail if the test suite takes longer than the timeout", func() {
  55. session := startGinkgo(pathToTest, "--noColor", "--timeout=1ms")
  56. Eventually(session).Should(gexec.Exit(1))
  57. })
  58. It("should not print out pendings when --noisyPendings=false", func() {
  59. session := startGinkgo(pathToTest, "--noColor", "--noisyPendings=false")
  60. Eventually(session).Should(gexec.Exit(types.GINKGO_FOCUS_EXIT_CODE))
  61. output := string(session.Out.Contents())
  62. Ω(output).ShouldNot(ContainSubstring("[PENDING]"))
  63. Ω(output).Should(ContainSubstring("1 Pending"))
  64. })
  65. It("should override the programmatic focus when told to focus", func() {
  66. session := startGinkgo(pathToTest, "--noColor", "--focus=smores")
  67. Eventually(session).Should(gexec.Exit(0))
  68. output := string(session.Out.Contents())
  69. Ω(output).Should(ContainSubstring("marshmallow"))
  70. Ω(output).Should(ContainSubstring("chocolate"))
  71. Ω(output).Should(ContainSubstring("smores"))
  72. Ω(output).Should(ContainSubstring("3 Passed"))
  73. Ω(output).Should(ContainSubstring("0 Failed"))
  74. Ω(output).Should(ContainSubstring("0 Pending"))
  75. Ω(output).Should(ContainSubstring("12 Skipped"))
  76. })
  77. It("should override the programmatic focus when told to skip", func() {
  78. session := startGinkgo(pathToTest, "--noColor", "--skip=marshmallow|failing|flaky")
  79. Eventually(session).Should(gexec.Exit(0))
  80. output := string(session.Out.Contents())
  81. Ω(output).ShouldNot(ContainSubstring("marshmallow"))
  82. Ω(output).Should(ContainSubstring("chocolate"))
  83. Ω(output).Should(ContainSubstring("smores"))
  84. Ω(output).Should(ContainSubstring("11 Passed"))
  85. Ω(output).Should(ContainSubstring("0 Failed"))
  86. Ω(output).Should(ContainSubstring("1 Pending"))
  87. Ω(output).Should(ContainSubstring("3 Skipped"))
  88. })
  89. It("should run the race detector when told to", func() {
  90. session := startGinkgo(pathToTest, "--noColor", "--race")
  91. Eventually(session).Should(gexec.Exit(types.GINKGO_FOCUS_EXIT_CODE))
  92. output := string(session.Out.Contents())
  93. Ω(output).Should(ContainSubstring("WARNING: DATA RACE"))
  94. })
  95. It("should randomize tests when told to", func() {
  96. session := startGinkgo(pathToTest, "--noColor", "--randomizeAllSpecs", "--seed=17")
  97. Eventually(session).Should(gexec.Exit(types.GINKGO_FOCUS_EXIT_CODE))
  98. output := string(session.Out.Contents())
  99. orders := getRandomOrders(output)
  100. Ω(orders[0]).ShouldNot(BeNumerically("<", orders[1]))
  101. })
  102. It("should skip measurements when told to", func() {
  103. session := startGinkgo(pathToTest, "--skipMeasurements")
  104. Eventually(session).Should(gexec.Exit(types.GINKGO_FOCUS_EXIT_CODE))
  105. output := string(session.Out.Contents())
  106. Ω(output).ShouldNot(ContainSubstring("Ran 3 samples:"), "has a measurement")
  107. Ω(output).Should(ContainSubstring("4 Skipped"))
  108. })
  109. It("should watch for slow specs", func() {
  110. session := startGinkgo(pathToTest, "--slowSpecThreshold=0.05")
  111. Eventually(session).Should(gexec.Exit(types.GINKGO_FOCUS_EXIT_CODE))
  112. output := string(session.Out.Contents())
  113. Ω(output).Should(ContainSubstring("SLOW TEST"))
  114. Ω(output).Should(ContainSubstring("should honor -slowSpecThreshold"))
  115. })
  116. It("should pass additional arguments in", func() {
  117. session := startGinkgo(pathToTest, "--", "--customFlag=madagascar")
  118. Eventually(session).Should(gexec.Exit(types.GINKGO_FOCUS_EXIT_CODE))
  119. output := string(session.Out.Contents())
  120. Ω(output).Should(ContainSubstring("CUSTOM_FLAG: madagascar"))
  121. })
  122. It("should print out full stack traces for failures when told to", func() {
  123. session := startGinkgo(pathToTest, "--focus=a failing test", "--trace")
  124. Eventually(session).Should(gexec.Exit(1))
  125. output := string(session.Out.Contents())
  126. Ω(output).Should(ContainSubstring("Full Stack Trace"))
  127. })
  128. It("should fail fast when told to", func() {
  129. pathToTest = tmpPath("fail")
  130. copyIn(fixturePath("fail_fixture"), pathToTest, false)
  131. session := startGinkgo(pathToTest, "--failFast")
  132. Eventually(session).Should(gexec.Exit(1))
  133. output := string(session.Out.Contents())
  134. Ω(output).Should(ContainSubstring("1 Failed"))
  135. Ω(output).Should(ContainSubstring("16 Skipped"))
  136. })
  137. Context("with a flaky test", func() {
  138. It("should normally fail", func() {
  139. session := startGinkgo(pathToTest, "--focus=flaky")
  140. Eventually(session).Should(gexec.Exit(1))
  141. })
  142. It("should pass if retries are requested", func() {
  143. session := startGinkgo(pathToTest, "--focus=flaky --flakeAttempts=2")
  144. Eventually(session).Should(gexec.Exit(0))
  145. })
  146. })
  147. It("should perform a dry run when told to", func() {
  148. pathToTest = tmpPath("fail")
  149. copyIn(fixturePath("fail_fixture"), pathToTest, false)
  150. session := startGinkgo(pathToTest, "--dryRun", "-v")
  151. Eventually(session).Should(gexec.Exit(0))
  152. output := string(session.Out.Contents())
  153. Ω(output).Should(ContainSubstring("synchronous failures"))
  154. Ω(output).Should(ContainSubstring("17 Specs"))
  155. Ω(output).Should(ContainSubstring("0 Passed"))
  156. Ω(output).Should(ContainSubstring("0 Failed"))
  157. })
  158. regextest := func(regexOption string, skipOrFocus string) string {
  159. pathToTest = tmpPath("passing")
  160. copyIn(fixturePath("passing_ginkgo_tests"), pathToTest, false)
  161. session := startGinkgo(pathToTest, regexOption, "--dryRun", "-v", skipOrFocus)
  162. Eventually(session).Should(gexec.Exit(0))
  163. return string(session.Out.Contents())
  164. }
  165. It("regexScansFilePath (enabled) should skip and focus on file names", func() {
  166. output := regextest("-regexScansFilePath=true", "-skip=/passing/") // everything gets skipped (nothing runs)
  167. Ω(output).Should(ContainSubstring("0 of 4 Specs"))
  168. output = regextest("-regexScansFilePath=true", "-focus=/passing/") // everything gets focused (everything runs)
  169. Ω(output).Should(ContainSubstring("4 of 4 Specs"))
  170. })
  171. It("regexScansFilePath (disabled) should not effect normal filtering", func() {
  172. output := regextest("-regexScansFilePath=false", "-skip=/passing/") // nothing gets skipped (everything runs)
  173. Ω(output).Should(ContainSubstring("4 of 4 Specs"))
  174. output = regextest("-regexScansFilePath=false", "-focus=/passing/") // nothing gets focused (nothing runs)
  175. Ω(output).Should(ContainSubstring("0 of 4 Specs"))
  176. })
  177. It("should honor compiler flags", func() {
  178. session := startGinkgo(pathToTest, "-gcflags=-importmap 'math=math/cmplx'")
  179. Eventually(session).Should(gexec.Exit(types.GINKGO_FOCUS_EXIT_CODE))
  180. output := string(session.Out.Contents())
  181. Ω(output).Should(ContainSubstring("NaN returns complex128"))
  182. })
  183. It("should honor covermode flag", func() {
  184. session := startGinkgo(pathToTest, "--noColor", "--covermode=count", "--focus=the focused set")
  185. Eventually(session).Should(gexec.Exit(0))
  186. output := string(session.Out.Contents())
  187. Ω(output).Should(ContainSubstring("coverage: "))
  188. coverageFile := filepath.Join(pathToTest, "flags.coverprofile")
  189. _, err := os.Stat(coverageFile)
  190. Ω(err).ShouldNot(HaveOccurred())
  191. contents, err := ioutil.ReadFile(coverageFile)
  192. Ω(err).ShouldNot(HaveOccurred())
  193. Ω(contents).Should(ContainSubstring("mode: count"))
  194. })
  195. })