CmdLine.tests.cpp 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582
  1. /*
  2. * Created by Phil on 13/5/2013.
  3. * Copyright 2014 Two Blue Cubes Ltd. All rights reserved.
  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 "catch.hpp"
  9. #include "internal/catch_test_spec_parser.h"
  10. #include "internal/catch_config.hpp"
  11. #include "internal/catch_commandline.h"
  12. #ifdef __clang__
  13. # pragma clang diagnostic ignored "-Wc++98-compat"
  14. #endif
  15. inline Catch::TestCase fakeTestCase(const char* name, const char* desc = "") { return Catch::makeTestCase(nullptr, "", { name, desc }, CATCH_INTERNAL_LINEINFO); }
  16. TEST_CASE( "Parse test names and tags", "[command-line][test-spec]" ) {
  17. using Catch::parseTestSpec;
  18. using Catch::TestSpec;
  19. Catch::TestCase tcA = fakeTestCase( "a" );
  20. Catch::TestCase tcB = fakeTestCase( "b", "[one][x]" );
  21. Catch::TestCase tcC = fakeTestCase( "longer name with spaces", "[two][three][.][x]" );
  22. Catch::TestCase tcD = fakeTestCase( "zlonger name with spacesz" );
  23. SECTION( "Empty test spec should have no filters" ) {
  24. TestSpec spec;
  25. CHECK( spec.hasFilters() == false );
  26. CHECK( spec.matches( tcA ) == false );
  27. CHECK( spec.matches( tcB ) == false );
  28. }
  29. SECTION( "Test spec from empty string should have no filters" ) {
  30. TestSpec spec = parseTestSpec( "" );
  31. CHECK( spec.hasFilters() == false );
  32. CHECK( spec.matches(tcA ) == false );
  33. CHECK( spec.matches( tcB ) == false );
  34. }
  35. SECTION( "Test spec from just a comma should have no filters" ) {
  36. TestSpec spec = parseTestSpec( "," );
  37. CHECK( spec.hasFilters() == false );
  38. CHECK( spec.matches( tcA ) == false );
  39. CHECK( spec.matches( tcB ) == false );
  40. }
  41. SECTION( "Test spec from name should have one filter" ) {
  42. TestSpec spec = parseTestSpec( "b" );
  43. CHECK( spec.hasFilters() == true );
  44. CHECK( spec.matches( tcA ) == false );
  45. CHECK( spec.matches( tcB ) == true );
  46. }
  47. SECTION( "Test spec from quoted name should have one filter" ) {
  48. TestSpec spec = parseTestSpec( "\"b\"" );
  49. CHECK( spec.hasFilters() == true );
  50. CHECK( spec.matches( tcA ) == false );
  51. CHECK( spec.matches( tcB ) == true );
  52. }
  53. SECTION( "Test spec from name should have one filter" ) {
  54. TestSpec spec = parseTestSpec( "b" );
  55. CHECK( spec.hasFilters() == true );
  56. CHECK( spec.matches( tcA ) == false );
  57. CHECK( spec.matches( tcB ) == true );
  58. CHECK( spec.matches( tcC ) == false );
  59. }
  60. SECTION( "Wildcard at the start" ) {
  61. TestSpec spec = parseTestSpec( "*spaces" );
  62. CHECK( spec.hasFilters() == true );
  63. CHECK( spec.matches( tcA ) == false );
  64. CHECK( spec.matches( tcB ) == false );
  65. CHECK( spec.matches( tcC ) == true );
  66. CHECK( spec.matches( tcD ) == false );
  67. CHECK( parseTestSpec( "*a" ).matches( tcA ) == true );
  68. }
  69. SECTION( "Wildcard at the end" ) {
  70. TestSpec spec = parseTestSpec( "long*" );
  71. CHECK( spec.hasFilters() == true );
  72. CHECK( spec.matches( tcA ) == false );
  73. CHECK( spec.matches( tcB ) == false );
  74. CHECK( spec.matches( tcC ) == true );
  75. CHECK( spec.matches( tcD ) == false );
  76. CHECK( parseTestSpec( "a*" ).matches( tcA ) == true );
  77. }
  78. SECTION( "Wildcard at both ends" ) {
  79. TestSpec spec = parseTestSpec( "*name*" );
  80. CHECK( spec.hasFilters() == true );
  81. CHECK( spec.matches( tcA ) == false );
  82. CHECK( spec.matches( tcB ) == false );
  83. CHECK( spec.matches( tcC ) == true );
  84. CHECK( spec.matches( tcD ) == true );
  85. CHECK( parseTestSpec( "*a*" ).matches( tcA ) == true );
  86. }
  87. SECTION( "Redundant wildcard at the start" ) {
  88. TestSpec spec = parseTestSpec( "*a" );
  89. CHECK( spec.hasFilters() == true );
  90. CHECK( spec.matches( tcA ) == true );
  91. CHECK( spec.matches( tcB ) == false );
  92. }
  93. SECTION( "Redundant wildcard at the end" ) {
  94. TestSpec spec = parseTestSpec( "a*" );
  95. CHECK( spec.hasFilters() == true );
  96. CHECK( spec.matches( tcA ) == true );
  97. CHECK( spec.matches( tcB ) == false );
  98. }
  99. SECTION( "Redundant wildcard at both ends" ) {
  100. TestSpec spec = parseTestSpec( "*a*" );
  101. CHECK( spec.hasFilters() == true );
  102. CHECK( spec.matches( tcA ) == true );
  103. CHECK( spec.matches( tcB ) == false );
  104. }
  105. SECTION( "Wildcard at both ends, redundant at start" ) {
  106. TestSpec spec = parseTestSpec( "*longer*" );
  107. CHECK( spec.hasFilters() == true );
  108. CHECK( spec.matches( tcA ) == false );
  109. CHECK( spec.matches( tcB ) == false );
  110. CHECK( spec.matches( tcC ) == true );
  111. CHECK( spec.matches( tcD ) == true );
  112. }
  113. SECTION( "Just wildcard" ) {
  114. TestSpec spec = parseTestSpec( "*" );
  115. CHECK( spec.hasFilters() == true );
  116. CHECK( spec.matches( tcA ) == true );
  117. CHECK( spec.matches( tcB ) == true );
  118. CHECK( spec.matches( tcC ) == true );
  119. CHECK( spec.matches( tcD ) == true );
  120. }
  121. SECTION( "Single tag" ) {
  122. TestSpec spec = parseTestSpec( "[one]" );
  123. CHECK( spec.hasFilters() == true );
  124. CHECK( spec.matches( tcA ) == false );
  125. CHECK( spec.matches( tcB ) == true );
  126. CHECK( spec.matches( tcC ) == false );
  127. }
  128. SECTION( "Single tag, two matches" ) {
  129. TestSpec spec = parseTestSpec( "[x]" );
  130. CHECK( spec.hasFilters() == true );
  131. CHECK( spec.matches( tcA ) == false );
  132. CHECK( spec.matches( tcB ) == true );
  133. CHECK( spec.matches( tcC ) == true );
  134. }
  135. SECTION( "Two tags" ) {
  136. TestSpec spec = parseTestSpec( "[two][x]" );
  137. CHECK( spec.hasFilters() == true );
  138. CHECK( spec.matches( tcA ) == false );
  139. CHECK( spec.matches( tcB ) == false );
  140. CHECK( spec.matches( tcC ) == true );
  141. }
  142. SECTION( "Two tags, spare separated" ) {
  143. TestSpec spec = parseTestSpec( "[two] [x]" );
  144. CHECK( spec.hasFilters() == true );
  145. CHECK( spec.matches( tcA ) == false );
  146. CHECK( spec.matches( tcB ) == false );
  147. CHECK( spec.matches( tcC ) == true );
  148. }
  149. SECTION( "Wildcarded name and tag" ) {
  150. TestSpec spec = parseTestSpec( "*name*[x]" );
  151. CHECK( spec.hasFilters() == true );
  152. CHECK( spec.matches( tcA ) == false );
  153. CHECK( spec.matches( tcB ) == false );
  154. CHECK( spec.matches( tcC ) == true );
  155. CHECK( spec.matches( tcD ) == false );
  156. }
  157. SECTION( "Single tag exclusion" ) {
  158. TestSpec spec = parseTestSpec( "~[one]" );
  159. CHECK( spec.hasFilters() == true );
  160. CHECK( spec.matches( tcA ) == true );
  161. CHECK( spec.matches( tcB ) == false );
  162. CHECK( spec.matches( tcC ) == true );
  163. }
  164. SECTION( "One tag exclusion and one tag inclusion" ) {
  165. TestSpec spec = parseTestSpec( "~[two][x]" );
  166. CHECK( spec.hasFilters() == true );
  167. CHECK( spec.matches( tcA ) == false );
  168. CHECK( spec.matches( tcB ) == true );
  169. CHECK( spec.matches( tcC ) == false );
  170. }
  171. SECTION( "One tag exclusion and one wldcarded name inclusion" ) {
  172. TestSpec spec = parseTestSpec( "~[two]*name*" );
  173. CHECK( spec.hasFilters() == true );
  174. CHECK( spec.matches( tcA ) == false );
  175. CHECK( spec.matches( tcB ) == false );
  176. CHECK( spec.matches( tcC ) == false );
  177. CHECK( spec.matches( tcD ) == true );
  178. }
  179. SECTION( "One tag exclusion, using exclude:, and one wldcarded name inclusion" ) {
  180. TestSpec spec = parseTestSpec( "exclude:[two]*name*" );
  181. CHECK( spec.hasFilters() == true );
  182. CHECK( spec.matches( tcA ) == false );
  183. CHECK( spec.matches( tcB ) == false );
  184. CHECK( spec.matches( tcC ) == false );
  185. CHECK( spec.matches( tcD ) == true );
  186. }
  187. SECTION( "name exclusion" ) {
  188. TestSpec spec = parseTestSpec( "~b" );
  189. CHECK( spec.hasFilters() == true );
  190. CHECK( spec.matches( tcA ) == true );
  191. CHECK( spec.matches( tcB ) == false );
  192. CHECK( spec.matches( tcC ) == true );
  193. CHECK( spec.matches( tcD ) == true );
  194. }
  195. SECTION( "wildcarded name exclusion" ) {
  196. TestSpec spec = parseTestSpec( "~*name*" );
  197. CHECK( spec.hasFilters() == true );
  198. CHECK( spec.matches( tcA ) == true );
  199. CHECK( spec.matches( tcB ) == true );
  200. CHECK( spec.matches( tcC ) == false );
  201. CHECK( spec.matches( tcD ) == false );
  202. }
  203. SECTION( "wildcarded name exclusion with tag inclusion" ) {
  204. TestSpec spec = parseTestSpec( "~*name*,[three]" );
  205. CHECK( spec.hasFilters() == true );
  206. CHECK( spec.matches( tcA ) == true );
  207. CHECK( spec.matches( tcB ) == true );
  208. CHECK( spec.matches( tcC ) == true );
  209. CHECK( spec.matches( tcD ) == false );
  210. }
  211. SECTION( "wildcarded name exclusion, using exclude:, with tag inclusion" ) {
  212. TestSpec spec = parseTestSpec( "exclude:*name*,[three]" );
  213. CHECK( spec.hasFilters() == true );
  214. CHECK( spec.matches( tcA ) == true );
  215. CHECK( spec.matches( tcB ) == true );
  216. CHECK( spec.matches( tcC ) == true );
  217. CHECK( spec.matches( tcD ) == false );
  218. }
  219. SECTION( "two wildcarded names" ) {
  220. TestSpec spec = parseTestSpec( "\"longer*\"\"*spaces\"" );
  221. CHECK( spec.hasFilters() == true );
  222. CHECK( spec.matches( tcA ) == false );
  223. CHECK( spec.matches( tcB ) == false );
  224. CHECK( spec.matches( tcC ) == true );
  225. CHECK( spec.matches( tcD ) == false );
  226. }
  227. SECTION( "empty tag" ) {
  228. TestSpec spec = parseTestSpec( "[]" );
  229. CHECK( spec.hasFilters() == false );
  230. CHECK( spec.matches( tcA ) == false );
  231. CHECK( spec.matches( tcB ) == false );
  232. CHECK( spec.matches( tcC ) == false );
  233. CHECK( spec.matches( tcD ) == false );
  234. }
  235. SECTION( "empty quoted name" ) {
  236. TestSpec spec = parseTestSpec( "\"\"" );
  237. CHECK( spec.hasFilters() == false );
  238. CHECK( spec.matches( tcA ) == false );
  239. CHECK( spec.matches( tcB ) == false );
  240. CHECK( spec.matches( tcC ) == false );
  241. CHECK( spec.matches( tcD ) == false );
  242. }
  243. SECTION( "quoted string followed by tag exclusion" ) {
  244. TestSpec spec = parseTestSpec( "\"*name*\"~[.]" );
  245. CHECK( spec.hasFilters() == true );
  246. CHECK( spec.matches( tcA ) == false );
  247. CHECK( spec.matches( tcB ) == false );
  248. CHECK( spec.matches( tcC ) == false );
  249. CHECK( spec.matches( tcD ) == true );
  250. }
  251. SECTION( "Leading and trailing spaces in test spec" ) {
  252. TestSpec spec = parseTestSpec( "\" aardvark \"" );
  253. CHECK( spec.matches( fakeTestCase( " aardvark " ) ) );
  254. CHECK( spec.matches( fakeTestCase( " aardvark" ) ) );
  255. CHECK( spec.matches( fakeTestCase( " aardvark " ) ) );
  256. CHECK( spec.matches( fakeTestCase( "aardvark " ) ) );
  257. CHECK( spec.matches( fakeTestCase( "aardvark" ) ) );
  258. }
  259. SECTION( "Leading and trailing spaces in test name" ) {
  260. TestSpec spec = parseTestSpec( "aardvark" );
  261. CHECK( spec.matches( fakeTestCase( " aardvark " ) ) );
  262. CHECK( spec.matches( fakeTestCase( " aardvark" ) ) );
  263. CHECK( spec.matches( fakeTestCase( " aardvark " ) ) );
  264. CHECK( spec.matches( fakeTestCase( "aardvark " ) ) );
  265. CHECK( spec.matches( fakeTestCase( "aardvark" ) ) );
  266. }
  267. SECTION("Shortened hide tags are split apart when parsing") {
  268. TestSpec spec = parseTestSpec("[.foo]");
  269. CHECK(spec.matches(fakeTestCase("hidden and foo", "[.][foo]")));
  270. CHECK_FALSE(spec.matches(fakeTestCase("only foo", "[foo]")));
  271. }
  272. SECTION("Shortened hide tags also properly handle exclusion") {
  273. TestSpec spec = parseTestSpec("~[.foo]");
  274. CHECK_FALSE(spec.matches(fakeTestCase("hidden and foo", "[.][foo]")));
  275. CHECK_FALSE(spec.matches(fakeTestCase("only foo", "[foo]")));
  276. CHECK_FALSE(spec.matches(fakeTestCase("only hidden", "[.]")));
  277. CHECK(spec.matches(fakeTestCase("neither foo nor hidden", "[bar]")));
  278. }
  279. }
  280. TEST_CASE("#1905 -- test spec parser properly clears internal state between compound tests", "[command-line][test-spec]") {
  281. using Catch::parseTestSpec;
  282. using Catch::TestSpec;
  283. // We ask for one of 2 different tests and the latter one of them has a , in name that needs escaping
  284. TestSpec spec = parseTestSpec(R"("spec . char","spec \, char")");
  285. REQUIRE(spec.matches(fakeTestCase("spec . char")));
  286. REQUIRE(spec.matches(fakeTestCase("spec , char")));
  287. REQUIRE_FALSE(spec.matches(fakeTestCase(R"(spec \, char)")));
  288. }
  289. TEST_CASE("#1912 -- test spec parser handles escaping", "[command-line][test-spec]") {
  290. using Catch::parseTestSpec;
  291. using Catch::TestSpec;
  292. SECTION("Various parentheses") {
  293. TestSpec spec = parseTestSpec(R"(spec {a} char,spec \[a] char)");
  294. REQUIRE(spec.matches(fakeTestCase(R"(spec {a} char)")));
  295. REQUIRE(spec.matches(fakeTestCase(R"(spec [a] char)")));
  296. REQUIRE_FALSE(spec.matches(fakeTestCase("differs but has similar tag", "[a]")));
  297. }
  298. SECTION("backslash in test name") {
  299. TestSpec spec = parseTestSpec(R"(spec \\ char)");
  300. REQUIRE(spec.matches(fakeTestCase(R"(spec \ char)")));
  301. }
  302. }
  303. TEST_CASE( "Process can be configured on command line", "[config][command-line]" ) {
  304. #ifndef CATCH_CONFIG_DISABLE_MATCHERS
  305. using namespace Catch::Matchers;
  306. #endif
  307. Catch::ConfigData config;
  308. auto cli = Catch::makeCommandLineParser(config);
  309. SECTION("empty args don't cause a crash") {
  310. auto result = cli.parse({""});
  311. CHECK(result);
  312. CHECK(config.processName == "");
  313. }
  314. SECTION("default - no arguments") {
  315. auto result = cli.parse({"test"});
  316. CHECK(result);
  317. CHECK(config.processName == "test");
  318. CHECK(config.shouldDebugBreak == false);
  319. CHECK(config.abortAfter == -1);
  320. CHECK(config.noThrow == false);
  321. CHECK(config.reporterName == "console");
  322. Catch::Config cfg(config);
  323. CHECK_FALSE(cfg.hasTestFilters());
  324. }
  325. SECTION("test lists") {
  326. SECTION("Specify one test case using") {
  327. auto result = cli.parse({"test", "test1"});
  328. CHECK(result);
  329. Catch::Config cfg(config);
  330. REQUIRE(cfg.hasTestFilters());
  331. REQUIRE(cfg.testSpec().matches(fakeTestCase("notIncluded")) == false);
  332. REQUIRE(cfg.testSpec().matches(fakeTestCase("test1")));
  333. }
  334. SECTION("Specify one test case exclusion using exclude:") {
  335. auto result = cli.parse({"test", "exclude:test1"});
  336. CHECK(result);
  337. Catch::Config cfg(config);
  338. REQUIRE(cfg.hasTestFilters());
  339. REQUIRE(cfg.testSpec().matches(fakeTestCase("test1")) == false);
  340. REQUIRE(cfg.testSpec().matches(fakeTestCase("alwaysIncluded")));
  341. }
  342. SECTION("Specify one test case exclusion using ~") {
  343. auto result = cli.parse({"test", "~test1"});
  344. CHECK(result);
  345. Catch::Config cfg(config);
  346. REQUIRE(cfg.hasTestFilters());
  347. REQUIRE(cfg.testSpec().matches(fakeTestCase("test1")) == false);
  348. REQUIRE(cfg.testSpec().matches(fakeTestCase("alwaysIncluded")));
  349. }
  350. }
  351. SECTION("reporter") {
  352. SECTION("-r/console") {
  353. CHECK(cli.parse({"test", "-r", "console"}));
  354. REQUIRE(config.reporterName == "console");
  355. }
  356. SECTION("-r/xml") {
  357. CHECK(cli.parse({"test", "-r", "xml"}));
  358. REQUIRE(config.reporterName == "xml");
  359. }
  360. SECTION("--reporter/junit") {
  361. CHECK(cli.parse({"test", "--reporter", "junit"}));
  362. REQUIRE(config.reporterName == "junit");
  363. }
  364. SECTION("Only one reporter is accepted") {
  365. REQUIRE_FALSE(cli.parse({ "test", "-r", "xml", "-r", "junit" }));
  366. }
  367. SECTION("must match one of the available ones") {
  368. auto result = cli.parse({"test", "--reporter", "unsupported"});
  369. CHECK(!result);
  370. #ifndef CATCH_CONFIG_DISABLE_MATCHERS
  371. REQUIRE_THAT(result.errorMessage(), Contains("Unrecognized reporter"));
  372. #endif
  373. }
  374. }
  375. SECTION("debugger") {
  376. SECTION("-b") {
  377. CHECK(cli.parse({"test", "-b"}));
  378. REQUIRE(config.shouldDebugBreak == true);
  379. }
  380. SECTION("--break") {
  381. CHECK(cli.parse({"test", "--break"}));
  382. REQUIRE(config.shouldDebugBreak);
  383. }
  384. }
  385. SECTION("abort") {
  386. SECTION("-a aborts after first failure") {
  387. CHECK(cli.parse({"test", "-a"}));
  388. REQUIRE(config.abortAfter == 1);
  389. }
  390. SECTION("-x 2 aborts after two failures") {
  391. CHECK(cli.parse({"test", "-x", "2"}));
  392. REQUIRE(config.abortAfter == 2);
  393. }
  394. SECTION("-x must be numeric") {
  395. auto result = cli.parse({"test", "-x", "oops"});
  396. CHECK(!result);
  397. #ifndef CATCH_CONFIG_DISABLE_MATCHERS
  398. REQUIRE_THAT(result.errorMessage(), Contains("convert") && Contains("oops"));
  399. #endif
  400. }
  401. SECTION("wait-for-keypress") {
  402. SECTION("Accepted options") {
  403. using tuple_type = std::tuple<char const*, Catch::WaitForKeypress::When>;
  404. auto input = GENERATE(table<char const*, Catch::WaitForKeypress::When>({
  405. tuple_type{"never", Catch::WaitForKeypress::Never},
  406. tuple_type{"start", Catch::WaitForKeypress::BeforeStart},
  407. tuple_type{"exit", Catch::WaitForKeypress::BeforeExit},
  408. tuple_type{"both", Catch::WaitForKeypress::BeforeStartAndExit},
  409. }));
  410. CHECK(cli.parse({"test", "--wait-for-keypress", std::get<0>(input)}));
  411. REQUIRE(config.waitForKeypress == std::get<1>(input));
  412. }
  413. SECTION("invalid options are reported") {
  414. auto result = cli.parse({"test", "--wait-for-keypress", "sometimes"});
  415. CHECK(!result);
  416. #ifndef CATCH_CONFIG_DISABLE_MATCHERS
  417. REQUIRE_THAT(result.errorMessage(), Contains("never") && Contains("both"));
  418. #endif
  419. }
  420. }
  421. }
  422. SECTION("nothrow") {
  423. SECTION("-e") {
  424. CHECK(cli.parse({"test", "-e"}));
  425. REQUIRE(config.noThrow);
  426. }
  427. SECTION("--nothrow") {
  428. CHECK(cli.parse({"test", "--nothrow"}));
  429. REQUIRE(config.noThrow);
  430. }
  431. }
  432. SECTION("output filename") {
  433. SECTION("-o filename") {
  434. CHECK(cli.parse({"test", "-o", "filename.ext"}));
  435. REQUIRE(config.outputFilename == "filename.ext");
  436. }
  437. SECTION("--out") {
  438. CHECK(cli.parse({"test", "--out", "filename.ext"}));
  439. REQUIRE(config.outputFilename == "filename.ext");
  440. }
  441. }
  442. SECTION("combinations") {
  443. SECTION("Single character flags can be combined") {
  444. CHECK(cli.parse({"test", "-abe"}));
  445. CHECK(config.abortAfter == 1);
  446. CHECK(config.shouldDebugBreak);
  447. CHECK(config.noThrow == true);
  448. }
  449. }
  450. SECTION( "use-colour") {
  451. using Catch::UseColour;
  452. SECTION( "without option" ) {
  453. CHECK(cli.parse({"test"}));
  454. REQUIRE( config.useColour == UseColour::Auto );
  455. }
  456. SECTION( "auto" ) {
  457. CHECK(cli.parse({"test", "--use-colour", "auto"}));
  458. REQUIRE( config.useColour == UseColour::Auto );
  459. }
  460. SECTION( "yes" ) {
  461. CHECK(cli.parse({"test", "--use-colour", "yes"}));
  462. REQUIRE( config.useColour == UseColour::Yes );
  463. }
  464. SECTION( "no" ) {
  465. CHECK(cli.parse({"test", "--use-colour", "no"}));
  466. REQUIRE( config.useColour == UseColour::No );
  467. }
  468. SECTION( "error" ) {
  469. auto result = cli.parse({"test", "--use-colour", "wrong"});
  470. CHECK( !result );
  471. #ifndef CATCH_CONFIG_DISABLE_MATCHERS
  472. CHECK_THAT( result.errorMessage(), Contains( "colour mode must be one of" ) );
  473. #endif
  474. }
  475. }
  476. SECTION("Benchmark options") {
  477. SECTION("samples") {
  478. CHECK(cli.parse({ "test", "--benchmark-samples=200" }));
  479. REQUIRE(config.benchmarkSamples == 200);
  480. }
  481. SECTION("resamples") {
  482. CHECK(cli.parse({ "test", "--benchmark-resamples=20000" }));
  483. REQUIRE(config.benchmarkResamples == 20000);
  484. }
  485. SECTION("confidence-interval") {
  486. CHECK(cli.parse({ "test", "--benchmark-confidence-interval=0.99" }));
  487. REQUIRE(config.benchmarkConfidenceInterval == Catch::Detail::Approx(0.99));
  488. }
  489. SECTION("no-analysis") {
  490. CHECK(cli.parse({ "test", "--benchmark-no-analysis" }));
  491. REQUIRE(config.benchmarkNoAnalysis);
  492. }
  493. SECTION("warmup-time") {
  494. CHECK(cli.parse({ "test", "--benchmark-warmup-time=10" }));
  495. REQUIRE(config.benchmarkWarmupTime == 10);
  496. }
  497. }
  498. }
  499. TEST_CASE("Test with special, characters \"in name", "[cli][regression]") {
  500. // This test case succeeds if we can invoke it from the CLI
  501. SUCCEED();
  502. }