PartTracker.tests.cpp 7.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253
  1. /*
  2. * Created by Phil on 1/10/2015.
  3. * Copyright 2015 Two Blue Cubes Ltd
  4. *
  5. * Distributed under the Boost Software License, Version 1.0. (See accompanying
  6. * file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
  7. */
  8. #include "internal/catch_suppress_warnings.h"
  9. #include "internal/catch_test_case_tracker.h"
  10. #include "catch.hpp"
  11. using namespace Catch;
  12. namespace {
  13. Catch::TestCaseTracking::NameAndLocation makeNAL( std::string const& name ) {
  14. return Catch::TestCaseTracking::NameAndLocation( name, Catch::SourceLineInfo("",0) );
  15. }
  16. }
  17. TEST_CASE( "Tracker" ) {
  18. TrackerContext ctx;
  19. ctx.startRun();
  20. ctx.startCycle();
  21. ITracker& testCase = SectionTracker::acquire( ctx, makeNAL( "Testcase" ) );
  22. REQUIRE( testCase.isOpen() );
  23. ITracker& s1 = SectionTracker::acquire( ctx, makeNAL( "S1" ) );
  24. REQUIRE( s1.isOpen() );
  25. SECTION( "successfully close one section" ) {
  26. s1.close();
  27. REQUIRE( s1.isSuccessfullyCompleted() );
  28. REQUIRE( testCase.isComplete() == false );
  29. testCase.close();
  30. REQUIRE( ctx.completedCycle() );
  31. REQUIRE( testCase.isSuccessfullyCompleted() );
  32. }
  33. SECTION( "fail one section" ) {
  34. s1.fail();
  35. REQUIRE( s1.isComplete() );
  36. REQUIRE( s1.isSuccessfullyCompleted() == false );
  37. REQUIRE( testCase.isComplete() == false );
  38. testCase.close();
  39. REQUIRE( ctx.completedCycle() );
  40. REQUIRE( testCase.isSuccessfullyCompleted() == false );
  41. SECTION( "re-enter after failed section" ) {
  42. ctx.startCycle();
  43. ITracker& testCase2 = SectionTracker::acquire( ctx, makeNAL( "Testcase" ) );
  44. REQUIRE( testCase2.isOpen() );
  45. ITracker& s1b = SectionTracker::acquire( ctx, makeNAL( "S1" ) );
  46. REQUIRE( s1b.isOpen() == false );
  47. testCase2.close();
  48. REQUIRE( ctx.completedCycle() );
  49. REQUIRE( testCase.isComplete() );
  50. REQUIRE( testCase.isSuccessfullyCompleted() );
  51. }
  52. SECTION( "re-enter after failed section and find next section" ) {
  53. ctx.startCycle();
  54. ITracker& testCase2 = SectionTracker::acquire( ctx, makeNAL( "Testcase" ) );
  55. REQUIRE( testCase2.isOpen() );
  56. ITracker& s1b = SectionTracker::acquire( ctx, makeNAL( "S1" ) );
  57. REQUIRE( s1b.isOpen() == false );
  58. ITracker& s2 = SectionTracker::acquire( ctx, makeNAL( "S2" ) );
  59. REQUIRE( s2.isOpen() );
  60. s2.close();
  61. REQUIRE( ctx.completedCycle() );
  62. testCase2.close();
  63. REQUIRE( testCase.isComplete() );
  64. REQUIRE( testCase.isSuccessfullyCompleted() );
  65. }
  66. }
  67. SECTION( "successfully close one section, then find another" ) {
  68. s1.close();
  69. ITracker& s2 = SectionTracker::acquire( ctx, makeNAL( "S2" ) );
  70. REQUIRE( s2.isOpen() == false );
  71. testCase.close();
  72. REQUIRE( testCase.isComplete() == false );
  73. SECTION( "Re-enter - skips S1 and enters S2" ) {
  74. ctx.startCycle();
  75. ITracker& testCase2 = SectionTracker::acquire( ctx, makeNAL( "Testcase" ) );
  76. REQUIRE( testCase2.isOpen() );
  77. ITracker& s1b = SectionTracker::acquire( ctx, makeNAL( "S1" ) );
  78. REQUIRE( s1b.isOpen() == false );
  79. ITracker& s2b = SectionTracker::acquire( ctx, makeNAL( "S2" ) );
  80. REQUIRE( s2b.isOpen() );
  81. REQUIRE( ctx.completedCycle() == false );
  82. SECTION ("Successfully close S2") {
  83. s2b.close();
  84. REQUIRE( ctx.completedCycle() );
  85. REQUIRE( s2b.isSuccessfullyCompleted() );
  86. REQUIRE( testCase2.isComplete() == false );
  87. testCase2.close();
  88. REQUIRE( testCase2.isSuccessfullyCompleted() );
  89. }
  90. SECTION ("fail S2") {
  91. s2b.fail();
  92. REQUIRE( ctx.completedCycle() );
  93. REQUIRE( s2b.isComplete() );
  94. REQUIRE( s2b.isSuccessfullyCompleted() == false );
  95. testCase2.close();
  96. REQUIRE( testCase2.isSuccessfullyCompleted() == false );
  97. // Need a final cycle
  98. ctx.startCycle();
  99. ITracker& testCase3 = SectionTracker::acquire( ctx, makeNAL( "Testcase" ) );
  100. REQUIRE( testCase3.isOpen() );
  101. ITracker& s1c = SectionTracker::acquire( ctx, makeNAL( "S1" ) );
  102. REQUIRE( s1c.isOpen() == false );
  103. ITracker& s2c = SectionTracker::acquire( ctx, makeNAL( "S2" ) );
  104. REQUIRE( s2c.isOpen() == false );
  105. testCase3.close();
  106. REQUIRE( testCase3.isSuccessfullyCompleted() );
  107. }
  108. }
  109. }
  110. SECTION( "open a nested section" ) {
  111. ITracker& s2 = SectionTracker::acquire( ctx, makeNAL( "S2" ) );
  112. REQUIRE( s2.isOpen() );
  113. s2.close();
  114. REQUIRE( s2.isComplete() );
  115. REQUIRE( s1.isComplete() == false );
  116. s1.close();
  117. REQUIRE( s1.isComplete() );
  118. REQUIRE( testCase.isComplete() == false );
  119. testCase.close();
  120. REQUIRE( testCase.isComplete() );
  121. }
  122. }
  123. static bool previouslyRun = false;
  124. static bool previouslyRunNested = false;
  125. TEST_CASE( "#1394", "[.][approvals][tracker]" ) {
  126. // -- Don't re-run after specified section is done
  127. REQUIRE(previouslyRun == false);
  128. SECTION( "RunSection" ) {
  129. previouslyRun = true;
  130. }
  131. SECTION( "SkipSection" ) {
  132. // cause an error if this section is called because it shouldn't be
  133. REQUIRE(1 == 0);
  134. }
  135. }
  136. TEST_CASE( "#1394 nested", "[.][approvals][tracker]" ) {
  137. REQUIRE(previouslyRunNested == false);
  138. SECTION( "NestedRunSection" ) {
  139. SECTION( "s1" ) {
  140. previouslyRunNested = true;
  141. }
  142. }
  143. SECTION( "NestedSkipSection" ) {
  144. // cause an error if this section is called because it shouldn't be
  145. REQUIRE(1 == 0);
  146. }
  147. }
  148. // Selecting a "not last" section inside a test case via -c "section" would
  149. // previously only run the first subsection, instead of running all of them.
  150. // This allows us to check that `"#1670 regression check" -c A` leads to
  151. // 2 successful assertions.
  152. TEST_CASE("#1670 regression check", "[.approvals][tracker]") {
  153. SECTION("A") {
  154. SECTION("1") SUCCEED();
  155. SECTION("2") SUCCEED();
  156. }
  157. SECTION("B") {
  158. SECTION("1") SUCCEED();
  159. SECTION("2") SUCCEED();
  160. }
  161. }
  162. // #1938 required a rework on how generator tracking works, so that `GENERATE`
  163. // supports being sandwiched between two `SECTION`s. The following tests check
  164. // various other scenarios through checking output in approval tests.
  165. TEST_CASE("#1938 - GENERATE after a section", "[.][regression][generators]") {
  166. SECTION("A") {
  167. SUCCEED("A");
  168. }
  169. auto m = GENERATE(1, 2, 3);
  170. SECTION("B") {
  171. REQUIRE(m);
  172. }
  173. }
  174. TEST_CASE("#1938 - flat generate", "[.][regression][generators]") {
  175. auto m = GENERATE(1, 2, 3);
  176. REQUIRE(m);
  177. }
  178. TEST_CASE("#1938 - nested generate", "[.][regression][generators]") {
  179. auto m = GENERATE(1, 2, 3);
  180. auto n = GENERATE(1, 2, 3);
  181. REQUIRE(m);
  182. REQUIRE(n);
  183. }
  184. TEST_CASE("#1938 - mixed sections and generates", "[.][regression][generators]") {
  185. auto i = GENERATE(1, 2);
  186. SECTION("A") {
  187. SUCCEED("A");
  188. }
  189. auto j = GENERATE(3, 4);
  190. SECTION("B") {
  191. SUCCEED("B");
  192. }
  193. auto k = GENERATE(5, 6);
  194. CAPTURE(i, j, k);
  195. SUCCEED();
  196. }
  197. TEST_CASE("#1938 - Section followed by flat generate", "[.][regression][generators]") {
  198. SECTION("A") {
  199. REQUIRE(1);
  200. }
  201. auto m = GENERATE(2, 3);
  202. REQUIRE(m);
  203. }