Test-Rail-Parser.t 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616
  1. #!/usr/bin/env perl
  2. use strict;
  3. use warnings;
  4. use FindBin;
  5. use lib "$FindBin::Bin/lib";
  6. use Scalar::Util qw{reftype};
  7. use TestRail::API;
  8. use Test::LWP::UserAgent::TestRailMock;
  9. use Test::Rail::Parser;
  10. use Test::More 'tests' => 126;
  11. use Test::Fatal qw{exception};
  12. use Test::Deep qw{cmp_deeply};
  13. use Capture::Tiny qw{capture capture_stderr};
  14. #Same song and dance as in TestRail-API.t
  15. my $apiurl = $ENV{'TESTRAIL_API_URL'};
  16. my $login = $ENV{'TESTRAIL_USER'};
  17. my $pw = $ENV{'TESTRAIL_PASSWORD'};
  18. my $is_mock = (!$apiurl && !$login && !$pw);
  19. ($apiurl,$login,$pw) = ('http://testrail.local','teodesian@cpan.org','fake') if $is_mock;
  20. my ($debug,$browser);
  21. $debug = 1;
  22. if ($is_mock) {
  23. $browser = $Test::LWP::UserAgent::TestRailMock::mockObject;
  24. }
  25. #test exceptions...
  26. #TODO
  27. my $fcontents = "
  28. fake.test ..
  29. 1..2
  30. ok 1 - STORAGE TANKS SEARED
  31. #goo
  32. not ok 2 - NOT SO SEARED AFTER ARR
  33. ";
  34. my $tap;
  35. my $opts = {
  36. 'tap' => $fcontents,
  37. 'apiurl' => $apiurl,
  38. 'user' => $login,
  39. 'pass' => $pw,
  40. 'debug' => $debug,
  41. 'browser' => $browser,
  42. 'run' => 'TestingSuite',
  43. 'project' => 'TestProject',
  44. 'merge' => 1,
  45. };
  46. my $res = exception { $tap = Test::Rail::Parser->new($opts) };
  47. is($res,undef,"TR Parser doesn't explode on instantiation");
  48. isa_ok($tap,"Test::Rail::Parser");
  49. if (!$res) {
  50. $tap->run();
  51. is($tap->{'errors'},0,"No errors encountered uploading case results");
  52. }
  53. undef $tap;
  54. delete $opts->{'tap'};
  55. $opts->{'source'} = 't/fake.test';
  56. $res = exception { $tap = Test::Rail::Parser->new($opts) };
  57. is($res,undef,"TR Parser doesn't explode on instantiation");
  58. isa_ok($tap,"Test::Rail::Parser");
  59. if (!$res) {
  60. $tap->run();
  61. is($tap->{'errors'},0,"No errors encountered uploading case results");
  62. }
  63. $fcontents = "fake.test...
  64. ok 1 - STORAGE TANKS SEARED
  65. # whee
  66. not ok 2 - NOT SO SEARED AFTER ARR
  67. # Failed test 'NOT SO SEARED AFTER ARR'
  68. # at t/fake.test line 10.
  69. # Looks like you failed 1 test of 2.
  70. ";
  71. like($tap->{'raw_output'},qr/SEARED\n# whee.*\n.*AFTER ARR\n\n.*Failed/msxi,"Full raw content uploaded in non step results mode");
  72. #Check that time run is being uploaded
  73. my $timeResults = $tap->{'tr_opts'}->{'testrail'}->getTestResults(1);
  74. if ( ( reftype($timeResults) || 'undef') eq 'ARRAY') {
  75. is( $timeResults->[0]->{'elapsed'}, '2s', "Plugin correctly sets elapsed time");
  76. } else {
  77. fail("Could not get test results to check elapsed time!");
  78. }
  79. #Check the time formatting routine.
  80. is(Test::Rail::Parser::_compute_elapsed(0,0),undef,"Elapsed computation correct at second boundary");
  81. is(Test::Rail::Parser::_compute_elapsed(0,61),'1m 1s',"Elapsed computation correct at minute boundary");
  82. is(Test::Rail::Parser::_compute_elapsed(0,3661),'1h 1m 1s',"Elapsed computation correct at hour boundary");
  83. is(Test::Rail::Parser::_compute_elapsed(0,86461),'24h 1m 1s',"Elapsed computation correct at day boundary");
  84. undef $tap;
  85. $opts->{'source'} = 't/faker.test';
  86. $opts->{'run'} = 'OtherOtherSuite';
  87. $opts->{'step_results'} = 'step_results';
  88. $res = exception { $tap = Test::Rail::Parser->new($opts) };
  89. is($res,undef,"TR Parser doesn't explode on instantiation");
  90. isa_ok($tap,"Test::Rail::Parser");
  91. if (!$res) {
  92. $tap->run();
  93. is($tap->{'errors'},0,"No errors encountered uploading case results");
  94. is($tap->{'global_status'},5, "Test global result is FAIL when one subtest fails even if there are TODO passes");
  95. subtest 'Timestamp/elapsed printed in step results' => sub {
  96. foreach my $result (@{$tap->{'tr_opts'}->{'result_custom_options'}->{'step_results'}}) {
  97. like($result->{'content'}, qr/^\[.*\(.*\)\]/i, "Timestamp printed in step results");
  98. }
  99. };
  100. }
  101. #Default mode
  102. undef $tap;
  103. delete $opts->{'step_results'};
  104. $res = exception { $tap = Test::Rail::Parser->new($opts) };
  105. is($res,undef,"TR Parser doesn't explode on instantiation");
  106. isa_ok($tap,"Test::Rail::Parser");
  107. if (!$res) {
  108. $tap->run();
  109. is($tap->{'errors'},0,"No errors encountered uploading case results");
  110. my @matches = $tap->{'raw_output'} =~ m/^(\[.*\(.*\)\])/msgi;
  111. ok(scalar(@matches),"Timestamps present in raw TAP");
  112. }
  113. #Default mode
  114. undef $tap;
  115. $fcontents = "
  116. fake.test ..
  117. 1..2
  118. ok 1 - STORAGE TANKS SEARED
  119. #Subtest NOT SO SEARED AFTER ARR
  120. ok 1 - STROGGIFY POPULATION CENTERS
  121. not ok 2 - STROGGIFY POPULATION CENTERS
  122. #goo
  123. not ok 2 - NOT SO SEARED AFTER ARR
  124. ";
  125. $opts->{'tap'} = $fcontents;
  126. delete $opts->{'source'};
  127. delete $opts->{'step_results'};
  128. $opts->{'run'} = 'TestingSuite';
  129. $res = exception { $tap = Test::Rail::Parser->new($opts) };
  130. is($res,undef,"TR Parser doesn't explode on instantiation");
  131. isa_ok($tap,"Test::Rail::Parser");
  132. if (!$res) {
  133. $tap->run();
  134. is($tap->{'errors'},0,"No errors encountered uploading case results");
  135. }
  136. undef $tap;
  137. delete $opts->{'tap'};
  138. $opts->{'source'} = 't/skip.test';
  139. $res = exception { $tap = Test::Rail::Parser->new($opts) };
  140. is($res,undef,"TR Parser doesn't explode on instantiation");
  141. isa_ok($tap,"Test::Rail::Parser");
  142. if (!$res) {
  143. $tap->run();
  144. is($tap->{'errors'},0,"No errors encountered uploading case results");
  145. }
  146. #Default mode skip (skip_all)
  147. undef $tap;
  148. $opts->{'source'} = 't/skipall.test';
  149. $res = exception { $tap = Test::Rail::Parser->new($opts) };
  150. is($res,undef,"TR Parser doesn't explode on instantiation");
  151. isa_ok($tap,"Test::Rail::Parser");
  152. if (!$res) {
  153. $tap->run();
  154. is($tap->{'errors'},0,"No errors encountered uploading case results");
  155. like( $tap->{raw_output}, qr/cause I can/i, "SKIP_ALL reason recorded");
  156. is($tap->{'global_status'},6, "Test global result is SKIP on skip all");
  157. }
  158. #Ok, let's test the plan, config, and spawn bits.
  159. undef $tap;
  160. $opts->{'run'} = 'hoo hoo I do not exist';
  161. $opts->{'plan'} = 'mah dubz plan';
  162. $opts->{'configs'} = ['testPlatform1'];
  163. $res = exception { $tap = Test::Rail::Parser->new($opts) };
  164. isnt($res,undef,"TR Parser explodes on instantiation when asking for run not in plan");
  165. undef $tap;
  166. $opts->{'run'} = 'TestingSuite';
  167. $opts->{'configs'} = ['testConfig'];
  168. $res = exception { $tap = Test::Rail::Parser->new($opts) };
  169. is($res,undef,"TR Parser doesn't explode on instantiation looking for existing run in plan");
  170. isa_ok($tap,"Test::Rail::Parser");
  171. if (!$res) {
  172. $tap->run();
  173. is($tap->{'errors'},0,"No errors encountered uploading case results");
  174. }
  175. #Now, test spawning.
  176. undef $tap;
  177. $opts->{'run'} = 'TestingSuite2';
  178. $opts->{'configs'} = ['testPlatform1'];
  179. $opts->{'testsuite_id'} = 9;
  180. $res = exception { $tap = Test::Rail::Parser->new($opts) };
  181. is($res,undef,"TR Parser doesn't explode on instantiation when spawning run in plan");
  182. isa_ok($tap,"Test::Rail::Parser");
  183. if (!$res) {
  184. $tap->run();
  185. is($tap->{'errors'},0,"No errors encountered uploading case results");
  186. }
  187. #Test spawning of builds not in plans.
  188. #Now, test spawning.
  189. undef $tap;
  190. delete $opts->{'testsuite_id'};
  191. delete $opts->{'plan'};
  192. delete $opts->{'configs'};
  193. $opts->{'testsuite'} = 'HAMBURGER-IZE HUMANITY';
  194. $res = exception { $tap = Test::Rail::Parser->new($opts) };
  195. is($res,undef,"TR Parser doesn't explode on instantiation when spawning run in plan");
  196. isa_ok($tap,"Test::Rail::Parser");
  197. if (!$res) {
  198. $tap->run();
  199. is($tap->{'errors'},0,"No errors encountered uploading case results");
  200. }
  201. #Test spawning of plans and runs.
  202. undef $tap;
  203. $opts->{'run'} = 'BogoRun';
  204. $opts->{'plan'} = 'BogoPlan';
  205. $opts->{'testsuite_id'} = 9;
  206. delete $opts->{'testsuite'};
  207. $res = exception { $tap = Test::Rail::Parser->new($opts) };
  208. is($res,undef,"TR Parser doesn't explode on instantiation when spawning run in plan");
  209. isa_ok($tap,"Test::Rail::Parser");
  210. if (!$res) {
  211. $tap->run();
  212. is($tap->{'errors'},0,"No errors encountered uploading case results");
  213. }
  214. #Check that per-section spawn works
  215. undef $tap;
  216. $opts->{'source'} = 't/fake.test';
  217. delete $opts->{'plan'};
  218. $opts->{'sections'} = ['fake.test'];
  219. delete $opts->{'step_results'};
  220. $res = exception { $tap = Test::Rail::Parser->new($opts) };
  221. is($res,undef,"TR Parser doesn't explode on instantiation");
  222. isa_ok($tap,"Test::Rail::Parser");
  223. if (!$res) {
  224. $tap->run();
  225. is($tap->{'errors'},0,"No errors encountered uploading case results");
  226. }
  227. #Check that per-section spawn works
  228. undef $tap;
  229. $opts->{'plan'} = 'BogoPlan';
  230. $res = exception { $tap = Test::Rail::Parser->new($opts) };
  231. is($res,undef,"TR Parser doesn't explode on instantiation");
  232. isa_ok($tap,"Test::Rail::Parser");
  233. if (!$res) {
  234. $tap->run();
  235. is($tap->{'errors'},0,"No errors encountered uploading case results");
  236. }
  237. undef $tap;
  238. $opts->{'sections'} = ['potzrebie'];
  239. delete $opts->{'plan'};
  240. $res = exception { $tap = Test::Rail::Parser->new($opts) };
  241. isnt($res,undef,"TR Parser explodes on instantiation with invalid section");
  242. undef $tap;
  243. $opts->{'source'} = 't/notests.test';
  244. delete $opts->{'sections'};
  245. $res = exception { $tap = Test::Rail::Parser->new($opts) };
  246. is($res,undef,"TR Parser doesn't explode on instantiation");
  247. isa_ok($tap,"Test::Rail::Parser");
  248. if (!$res) {
  249. $tap->run();
  250. is($tap->{'errors'},0,"No errors encountered uploading case results");
  251. is($tap->{'global_status'},5, "Test global result is FAIL by default on env fail");
  252. }
  253. undef $tap;
  254. $opts->{'source'} = 't/pass.test';
  255. $res = exception { $tap = Test::Rail::Parser->new($opts) };
  256. is($res,undef,"TR Parser doesn't explode on instantiation");
  257. isa_ok($tap,"Test::Rail::Parser");
  258. if (!$res) {
  259. $tap->run();
  260. is($tap->{'errors'},0,"No errors encountered uploading case results");
  261. is($tap->{'global_status'},1, "Test global result is PASS on ok test");
  262. }
  263. undef $tap;
  264. $opts->{'source'} = 't/todo_pass.test';
  265. $res = exception { $tap = Test::Rail::Parser->new($opts) };
  266. is($res,undef,"TR Parser doesn't explode on instantiation");
  267. isa_ok($tap,"Test::Rail::Parser");
  268. if (!$res) {
  269. $tap->run();
  270. is($tap->{'errors'},0,"No errors encountered uploading case results");
  271. is($tap->{'global_status'},8, "Test global result is TODO PASS on todo pass test");
  272. }
  273. undef $tap;
  274. $opts->{'step_results'} = 'bogus_garbage';
  275. $res = exception { $tap = Test::Rail::Parser->new($opts) };
  276. like($res,qr/invalid step results/i,"Bogus step results name throws");
  277. undef $tap;
  278. $opts->{'source'} = 't/todo_pass_and_fail.test';
  279. $opts->{'step_results'} = 'step_results';
  280. $res = exception { $tap = Test::Rail::Parser->new($opts) };
  281. is($res,undef,"TR Parser doesn't explode on instantiation");
  282. isa_ok($tap,"Test::Rail::Parser");
  283. if (!$res) {
  284. capture { $tap->run() };
  285. is($tap->{'errors'},1,"Errors encountered uploading case results for case that does not exist in TestRail");
  286. is($tap->{'global_status'},7, "Test global result is TODO FAIL on todo pass & fail test");
  287. my @desired_statuses = qw{1 8 7};
  288. my @got_statuses = map {$_->{'status_id'}} @{$tap->{'tr_opts'}->{'result_custom_options'}->{'step_results'}};
  289. my @desired_expected = ('OK', 'OK', 'OK');
  290. my @got_expected = map {$_->{'expected'}} @{$tap->{'tr_opts'}->{'result_custom_options'}->{'step_results'}};
  291. my @desired_actual = ('OK', 'TODO PASS', 'TODO FAIL');
  292. my @got_actual = map {$_->{'actual'}} @{$tap->{'tr_opts'}->{'result_custom_options'}->{'step_results'}};
  293. cmp_deeply(\@got_expected,\@desired_expected,"Expected status names look OK");
  294. cmp_deeply(\@got_actual,\@desired_actual,"Actual status names look OK");
  295. cmp_deeply(\@got_statuses,\@desired_statuses,"Step result status codes set correctly");
  296. like($tap->{'tr_opts'}->{'test_notes'},qr/ez duz it/i,"TODO reason captured in test notes");
  297. }
  298. undef $opts->{'step_results'};
  299. undef $tap;
  300. #Check bad plan w/ todo pass logic
  301. $fcontents = "
  302. todo_pass.test ..
  303. 1..2
  304. ok 1 - STORAGE TANKS SEARED #TODO todo pass
  305. # goo
  306. ";
  307. undef $opts->{'source'};
  308. $opts->{'tap'} = $fcontents;
  309. $opts->{'step_results'} = 'step_results';
  310. $res = exception { $tap = Test::Rail::Parser->new($opts) };
  311. is($res,undef,"TR Parser doesn't explode on instantiation");
  312. isa_ok($tap,"Test::Rail::Parser");
  313. if (!$res) {
  314. $tap->run();
  315. is($tap->{'errors'},0,"No errors encountered uploading case results");
  316. is($tap->{'global_status'},5, "Test global result is FAIL on todo pass test w/ bad plan");
  317. my $srs = $tap->{'tr_opts'}->{'result_custom_options'}->{'step_results'};
  318. is($srs->[-1]->{'content'},"Bad Plan.","Bad plan noted in step results");
  319. }
  320. undef $opts->{'step_results'};
  321. #Check instant pizza
  322. $fcontents = "
  323. todo_pass.test ..
  324. 1..2
  325. ";
  326. undef $opts->{'source'};
  327. $opts->{'tap'} = $fcontents;
  328. $opts->{'step_results'} = 'step_results';
  329. $res = exception { $tap = Test::Rail::Parser->new($opts) };
  330. is($res,undef,"TR Parser doesn't explode on instantiation");
  331. isa_ok($tap,"Test::Rail::Parser");
  332. if (!$res) {
  333. $tap->run();
  334. is($tap->{'errors'},0,"No errors encountered uploading case results");
  335. is($tap->{'global_status'},5, "Test global result is FAILURE when insta-bombout occurs");
  336. my $srs = $tap->{'tr_opts'}->{'result_custom_options'}->{'step_results'};
  337. is($srs->[-1]->{'content'},"Bad Plan.","Bad plan noted in step results");
  338. }
  339. $opts->{test_bad_status} = 'bogus_status';
  340. $res = exception { $tap = Test::Rail::Parser->new($opts) };
  341. like($res,qr/bogus_status/,"TR Parser explodes on instantiation w bogus status");
  342. $opts->{test_bad_status} = 'blocked';
  343. $res = exception { $tap = Test::Rail::Parser->new($opts) };
  344. is($res,undef,"TR Parser doesn't explode on instantiation");
  345. isa_ok($tap,"Test::Rail::Parser");
  346. if (!$res) {
  347. $tap->run();
  348. is($tap->{'errors'},0,"No errors encountered uploading case results");
  349. is($tap->{'global_status'},2, "Test global result is BLOCKED when insta-bombout occurs & custom status set");
  350. }
  351. undef $opts->{'step_results'};
  352. #Check unplanned tests
  353. $fcontents = "
  354. todo_pass.test ..
  355. 1..1
  356. ok 1 - STORAGE TANKS SEARED
  357. ok 2 - ZIPPPEEE
  358. ";
  359. $opts->{'tap'} = $fcontents;
  360. $res = exception { $tap = Test::Rail::Parser->new($opts) };
  361. is($res,undef,"TR Parser doesn't explode on instantiation");
  362. isa_ok($tap,"Test::Rail::Parser");
  363. if (!$res) {
  364. $tap->run();
  365. is($tap->{'errors'},0,"No errors encountered uploading case results w/ unplanned tests");
  366. is($tap->{'global_status'},5, "Test global result is FAIL when unplanned test seen without case-per-ok");
  367. }
  368. undef $tap;
  369. #Check bad plan w/ todo pass logic
  370. $fcontents = "
  371. todo_pass.test ..
  372. 1..2
  373. ok 1 - STORAGE TANKS SEARED #TODO todo pass
  374. # goo
  375. % mark_status=todo_fail #Appears tanks weren't so sealed after all
  376. ";
  377. undef $opts->{'source'};
  378. $opts->{'tap'} = $fcontents;
  379. $res = exception { $tap = Test::Rail::Parser->new($opts) };
  380. is($res,undef,"TR Parser doesn't explode on instantiation");
  381. isa_ok($tap,"Test::Rail::Parser");
  382. if (!$res) {
  383. $tap->run();
  384. is($tap->{'errors'},0,"No errors encountered uploading case results");
  385. is($tap->{'global_status'},7, "Test global result is respected when using global status override");
  386. }
  387. undef $opts->{'tap'};
  388. #Check autoclose functionality against Run with all tests in run status.
  389. undef $tap;
  390. $opts->{'source'} = 't/skip.test';
  391. $opts->{'run'} = 'FinalRun';
  392. $opts->{'autoclose'} = 1;
  393. $res = exception { $tap = Test::Rail::Parser->new($opts) };
  394. is($res,undef,"TR Parser doesn't explode on instantiation");
  395. isa_ok($tap,"Test::Rail::Parser");
  396. if (!$res) {
  397. $tap->run();
  398. is($tap->{'errors'},0,"No errors encountered uploading case results");
  399. is($tap->{'run_closed'},1, "Run closed by parser when all tests done");
  400. }
  401. #Check autoclose functionality against Run with not all tests in run status.
  402. undef $tap;
  403. $opts->{'source'} = 't/todo_pass.test';
  404. $opts->{'run'} = 'BogoRun';
  405. $res = exception { $tap = Test::Rail::Parser->new($opts) };
  406. is($res,undef,"TR Parser doesn't explode on instantiation");
  407. isa_ok($tap,"Test::Rail::Parser");
  408. if (!$res) {
  409. $tap->run();
  410. is($tap->{'errors'},0,"No errors encountered uploading case results");
  411. is($tap->{'run_closed'},undef, "Run not closed by parser when results are outstanding");
  412. }
  413. #Check that autoclose works against plan with all tests in run status
  414. undef $tap;
  415. $opts->{'source'} = 't/fake.test';
  416. $opts->{'run'} = 'FinalRun';
  417. $opts->{'plan'} = 'FinalPlan';
  418. $opts->{'configs'} = ['testConfig'];
  419. $res = exception { $tap = Test::Rail::Parser->new($opts) };
  420. is($res,undef,"TR Parser doesn't explode on instantiation");
  421. isa_ok($tap,"Test::Rail::Parser");
  422. if (!$res) {
  423. $tap->run();
  424. is($tap->{'errors'},0,"No errors encountered uploading case results");
  425. is($tap->{'plan_closed'},1, "Plan closed by parser when all tests done");
  426. }
  427. #Check that autoclose works against plan with all tests not in run status
  428. undef $tap;
  429. $opts->{'run'} = 'BogoRun';
  430. $opts->{'plan'} = 'BogoPlan';
  431. $res = exception { $tap = Test::Rail::Parser->new($opts) };
  432. is($res,undef,"TR Parser doesn't explode on instantiation");
  433. isa_ok($tap,"Test::Rail::Parser");
  434. if (!$res) {
  435. $tap->run();
  436. is($tap->{'errors'},0,"No errors encountered uploading case results");
  437. is($tap->{'plan_closed'},undef, "Plan not closed by parser when results are outstanding");
  438. }
  439. #Plan but no run 'splodes
  440. undef $tap;
  441. $opts->{'plan'} = 'CompletePlan';
  442. delete $opts->{'run'};
  443. delete $opts->{'configs'};
  444. $res = exception { $tap = Test::Rail::Parser->new($opts) };
  445. like($res,qr/but no run passed/i,"TR Parser explodes on instantiation due to passing plan with no run");
  446. #Check that trying without spawn opts, using completed plan fails
  447. undef $tap;
  448. $opts->{'plan'} = 'ClosedPlan';
  449. $opts->{'run'} = 'BogoRun';
  450. delete $opts->{'testsuite_id'};
  451. $res = exception { $tap = Test::Rail::Parser->new($opts) };
  452. like($res,qr/plan provided is completed/i,"TR Parser explodes on instantiation due to passing closed plan");
  453. #Check that the above two will just spawn a new plan in these cases
  454. $opts->{'testsuite_id'} = 9;
  455. $res = exception { $tap = Test::Rail::Parser->new($opts) };
  456. is($res,undef,"TR Parser runs all the way through on completed run when spawning");
  457. #Check that trying without spawn opts, using completed run fails
  458. undef $tap;
  459. delete $opts->{'testsuite_id'};
  460. delete $opts->{'plan'};
  461. $opts->{'run'} = 'ClosedRun';
  462. $res = exception { $tap = Test::Rail::Parser->new($opts) };
  463. like($res,qr/run provided is completed/i,"TR Parser explodes on instantiation due to passing closed run");
  464. #Check that the above two will just spawn a new run in these cases
  465. $opts->{'testsuite_id'} = 9;
  466. $res = exception { $tap = Test::Rail::Parser->new($opts) };
  467. is($res,undef,"TR Parser runs all the way through on completed run when spawning");
  468. $fcontents = "
  469. todo_pass.test ..
  470. 1..2
  471. ok 1 - STORAGE TANKS SEARED #TODO todo pass
  472. # goo
  473. Bail out! #YOLO
  474. ";
  475. undef $opts->{'source'};
  476. $opts->{'tap'} = $fcontents;
  477. $opts->{'step_results'} = 'step_results';
  478. $res = exception { $tap = Test::Rail::Parser->new($opts) };
  479. is($res,undef,"TR Parser runs all the way through on bailout");
  480. if (!$res) {
  481. $tap->run();
  482. is($tap->{'errors'},0,"No errors encountered uploading case results");
  483. is($tap->{'global_status'},5, "Test global result is FAIL on todo pass test w/ bailout");
  484. my $srs = $tap->{'tr_opts'}->{'result_custom_options'}->{'step_results'};
  485. is($srs->[-1]->{'content'},"Bail Out!.","Bailout noted in step results");
  486. }
  487. #Check section spawn recursion is done correctly
  488. undef $opts->{'tap'};
  489. $opts->{'source'} = 't/pass.test';
  490. $opts->{'testsuite_id'} = 5;
  491. $opts->{'project_id'} = 3;
  492. $opts->{'run'} = 'zippyRun';
  493. $opts->{'sections'} = ['Recursing section','grandchild'];
  494. $res = exception { $tap = Test::Rail::Parser->new($opts) };
  495. is($res,undef,"TR Parser runs all the way through when recursing sections");
  496. if (!$res) {
  497. $tap->run();
  498. is($tap->{'errors'},0,"No errors encountered uploading case results");
  499. }
  500. #Check configuration group spawn is done correctly
  501. undef $opts->{'tap'};
  502. $opts->{'source'} = 't/pass.test';
  503. $opts->{'project_id'} = 9;
  504. $opts->{'run'} = 'TestingSuite';
  505. $opts->{'plan'} = 'mah dubz plan';
  506. $opts->{'config_group'} = 'noSuchGroup';
  507. $opts->{'configs'} = ['noSuchConfig'];
  508. $opts->{'sections'} = [];
  509. $res = exception { $tap = Test::Rail::Parser->new($opts) };
  510. is($res,undef,"TR Parser runs all the way through when spawning configurations");
  511. $fcontents = "
  512. todo_pass.test ..
  513. ok 1 - STORAGE TANKS SEARED #TODO todo pass
  514. # goo
  515. Bail out! #YOLO
  516. ";
  517. undef $opts->{'source'};
  518. $opts->{'tap'} = $fcontents;
  519. #Issue 143
  520. my $warns = capture_stderr { $tap = Test::Rail::Parser->new($opts) };
  521. is($warns, '', "No warnings parsing TAP with undef plans");
  522. #Issue 140
  523. $fcontents = "
  524. todo_pass.test ..
  525. ";
  526. undef $opts->{'source'};
  527. $opts->{'tap'} = $fcontents;
  528. $warns = capture_stderr { $tap = Test::Rail::Parser->new($opts) };
  529. is($warns, '', "No warnings parsing TAP with NOTESTS");