flags_test.go 6.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176
  1. package integration_test
  2. import (
  3. "os"
  4. "path/filepath"
  5. "strings"
  6. . "github.com/onsi/ginkgo"
  7. "github.com/onsi/ginkgo/types"
  8. . "github.com/onsi/gomega"
  9. "github.com/onsi/gomega/gexec"
  10. )
  11. var _ = Describe("Flags Specs", func() {
  12. var pathToTest string
  13. BeforeEach(func() {
  14. pathToTest = tmpPath("flags")
  15. copyIn("flags_tests", pathToTest)
  16. })
  17. getRandomOrders := func(output string) []int {
  18. return []int{strings.Index(output, "RANDOM_A"), strings.Index(output, "RANDOM_B"), strings.Index(output, "RANDOM_C")}
  19. }
  20. It("normally passes, runs measurements, prints out noisy pendings, does not randomize tests, and honors the programmatic focus", func() {
  21. session := startGinkgo(pathToTest, "--noColor")
  22. Eventually(session).Should(gexec.Exit(types.GINKGO_FOCUS_EXIT_CODE))
  23. output := string(session.Out.Contents())
  24. Ω(output).Should(ContainSubstring("Ran 3 samples:"), "has a measurement")
  25. Ω(output).Should(ContainSubstring("10 Passed"))
  26. Ω(output).Should(ContainSubstring("0 Failed"))
  27. Ω(output).Should(ContainSubstring("1 Pending"))
  28. Ω(output).Should(ContainSubstring("2 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).Should(ContainSubstring("Detected Programmatic Focus - setting exit status to %d", types.GINKGO_FOCUS_EXIT_CODE))
  34. Ω(output).ShouldNot(ContainSubstring("smores"))
  35. Ω(output).ShouldNot(ContainSubstring("SLOW TEST"))
  36. Ω(output).ShouldNot(ContainSubstring("should honor -slowSpecThreshold"))
  37. orders := getRandomOrders(output)
  38. Ω(orders[0]).Should(BeNumerically("<", orders[1]))
  39. Ω(orders[1]).Should(BeNumerically("<", orders[2]))
  40. })
  41. It("should run a coverprofile when passed -cover", func() {
  42. session := startGinkgo(pathToTest, "--noColor", "--cover", "--focus=the focused set")
  43. Eventually(session).Should(gexec.Exit(0))
  44. output := string(session.Out.Contents())
  45. _, err := os.Stat(filepath.Join(pathToTest, "flags.coverprofile"))
  46. Ω(err).ShouldNot(HaveOccurred())
  47. Ω(output).Should(ContainSubstring("coverage: "))
  48. })
  49. It("should fail when there are pending tests and it is passed --failOnPending", func() {
  50. session := startGinkgo(pathToTest, "--noColor", "--failOnPending")
  51. Eventually(session).Should(gexec.Exit(1))
  52. })
  53. It("should not print out pendings when --noisyPendings=false", func() {
  54. session := startGinkgo(pathToTest, "--noColor", "--noisyPendings=false")
  55. Eventually(session).Should(gexec.Exit(types.GINKGO_FOCUS_EXIT_CODE))
  56. output := string(session.Out.Contents())
  57. Ω(output).ShouldNot(ContainSubstring("[PENDING]"))
  58. Ω(output).Should(ContainSubstring("1 Pending"))
  59. })
  60. It("should override the programmatic focus when told to focus", func() {
  61. session := startGinkgo(pathToTest, "--noColor", "--focus=smores")
  62. Eventually(session).Should(gexec.Exit(0))
  63. output := string(session.Out.Contents())
  64. Ω(output).Should(ContainSubstring("marshmallow"))
  65. Ω(output).Should(ContainSubstring("chocolate"))
  66. Ω(output).Should(ContainSubstring("smores"))
  67. Ω(output).Should(ContainSubstring("3 Passed"))
  68. Ω(output).Should(ContainSubstring("0 Failed"))
  69. Ω(output).Should(ContainSubstring("0 Pending"))
  70. Ω(output).Should(ContainSubstring("10 Skipped"))
  71. })
  72. It("should override the programmatic focus when told to skip", func() {
  73. session := startGinkgo(pathToTest, "--noColor", "--skip=marshmallow|failing")
  74. Eventually(session).Should(gexec.Exit(0))
  75. output := string(session.Out.Contents())
  76. Ω(output).ShouldNot(ContainSubstring("marshmallow"))
  77. Ω(output).Should(ContainSubstring("chocolate"))
  78. Ω(output).Should(ContainSubstring("smores"))
  79. Ω(output).Should(ContainSubstring("10 Passed"))
  80. Ω(output).Should(ContainSubstring("0 Failed"))
  81. Ω(output).Should(ContainSubstring("1 Pending"))
  82. Ω(output).Should(ContainSubstring("2 Skipped"))
  83. })
  84. It("should run the race detector when told to", func() {
  85. session := startGinkgo(pathToTest, "--noColor", "--race")
  86. Eventually(session).Should(gexec.Exit(types.GINKGO_FOCUS_EXIT_CODE))
  87. output := string(session.Out.Contents())
  88. Ω(output).Should(ContainSubstring("WARNING: DATA RACE"))
  89. })
  90. It("should randomize tests when told to", func() {
  91. session := startGinkgo(pathToTest, "--noColor", "--randomizeAllSpecs", "--seed=21")
  92. Eventually(session).Should(gexec.Exit(types.GINKGO_FOCUS_EXIT_CODE))
  93. output := string(session.Out.Contents())
  94. orders := getRandomOrders(output)
  95. Ω(orders[0]).ShouldNot(BeNumerically("<", orders[1]))
  96. })
  97. It("should skip measurements when told to", func() {
  98. session := startGinkgo(pathToTest, "--skipMeasurements")
  99. Eventually(session).Should(gexec.Exit(types.GINKGO_FOCUS_EXIT_CODE))
  100. output := string(session.Out.Contents())
  101. Ω(output).ShouldNot(ContainSubstring("Ran 3 samples:"), "has a measurement")
  102. Ω(output).Should(ContainSubstring("3 Skipped"))
  103. })
  104. It("should watch for slow specs", func() {
  105. session := startGinkgo(pathToTest, "--slowSpecThreshold=0.05")
  106. Eventually(session).Should(gexec.Exit(types.GINKGO_FOCUS_EXIT_CODE))
  107. output := string(session.Out.Contents())
  108. Ω(output).Should(ContainSubstring("SLOW TEST"))
  109. Ω(output).Should(ContainSubstring("should honor -slowSpecThreshold"))
  110. })
  111. It("should pass additional arguments in", func() {
  112. session := startGinkgo(pathToTest, "--", "--customFlag=madagascar")
  113. Eventually(session).Should(gexec.Exit(types.GINKGO_FOCUS_EXIT_CODE))
  114. output := string(session.Out.Contents())
  115. Ω(output).Should(ContainSubstring("CUSTOM_FLAG: madagascar"))
  116. })
  117. It("should print out full stack traces for failures when told to", func() {
  118. session := startGinkgo(pathToTest, "--focus=a failing test", "--trace")
  119. Eventually(session).Should(gexec.Exit(1))
  120. output := string(session.Out.Contents())
  121. Ω(output).Should(ContainSubstring("Full Stack Trace"))
  122. })
  123. It("should fail fast when told to", func() {
  124. pathToTest = tmpPath("fail")
  125. copyIn("fail_fixture", pathToTest)
  126. session := startGinkgo(pathToTest, "--failFast")
  127. Eventually(session).Should(gexec.Exit(1))
  128. output := string(session.Out.Contents())
  129. Ω(output).Should(ContainSubstring("1 Failed"))
  130. Ω(output).Should(ContainSubstring("15 Skipped"))
  131. })
  132. It("should perform a dry run when told to", func() {
  133. pathToTest = tmpPath("fail")
  134. copyIn("fail_fixture", pathToTest)
  135. session := startGinkgo(pathToTest, "--dryRun", "-v")
  136. Eventually(session).Should(gexec.Exit(0))
  137. output := string(session.Out.Contents())
  138. Ω(output).Should(ContainSubstring("synchronous failures"))
  139. Ω(output).Should(ContainSubstring("16 Specs"))
  140. Ω(output).Should(ContainSubstring("0 Passed"))
  141. Ω(output).Should(ContainSubstring("0 Failed"))
  142. })
  143. })