Test-Rail-Parser.t 19 KB

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