1use strict; 2use warnings; 3 4use Test2::Tools::Tiny; 5use Test2::API::InterceptResult::Event; 6 7my $CLASS = 'Test2::API::InterceptResult::Event'; 8 9tests facet_map => sub { 10 ok(!$CLASS->can('plugins'), "Did not expose 'plugins' sub"); 11 12 my $fm = $CLASS->facet_map; 13 14 is_deeply($fm->{__GENERIC__}, {class => 'Test2::API::InterceptResult::Facet', loaded => 1}, "Generic '__GENERIC__'"); 15 16 is_deeply($CLASS->facet_info('about'), {class => 'Test2::EventFacet::About', list => 0, loaded => 1}, "Found 'about' facet"); 17 is_deeply($CLASS->facet_info('amnesty'), {class => 'Test2::EventFacet::Amnesty', list => 1, loaded => 1}, "Found 'amnesty' facet"); 18 is_deeply($CLASS->facet_info('assert'), {class => 'Test2::EventFacet::Assert', list => 0, loaded => 1}, "Found 'assert' facet"); 19 is_deeply($CLASS->facet_info('control'), {class => 'Test2::EventFacet::Control', list => 0, loaded => 1}, "Found 'control' facet"); 20 is_deeply($CLASS->facet_info('errors'), {class => 'Test2::EventFacet::Error', list => 1, loaded => 1}, "Found 'errors' facet"); 21 is_deeply($CLASS->facet_info('hubs'), {class => 'Test2::EventFacet::Hub', list => 1, loaded => 1}, "Found 'hubs' facet"); 22 is_deeply($CLASS->facet_info('info'), {class => 'Test2::EventFacet::Info', list => 1, loaded => 1}, "Found 'info' facet"); 23 is_deeply($CLASS->facet_info('meta'), {class => 'Test2::EventFacet::Meta', list => 0, loaded => 1}, "Found 'meta' facet"); 24 is_deeply($CLASS->facet_info('parent'), {class => 'Test2::EventFacet::Parent', list => 0, loaded => 1}, "Found 'parent' facet"); 25 is_deeply($CLASS->facet_info('plan'), {class => 'Test2::EventFacet::Plan', list => 0, loaded => 1}, "Found 'plan' facet"); 26 is_deeply($CLASS->facet_info('render'), {class => 'Test2::EventFacet::Render', list => 1, loaded => 1}, "Found 'render' facet"); 27 is_deeply($CLASS->facet_info('trace'), {class => 'Test2::EventFacet::Trace', list => 0, loaded => 1}, "Found 'trace' facet"); 28}; 29 30tests init => sub { 31 # This is just here to make sure the later test is meaningful. If this 32 # starts to fail it probably means this test needs to be changed. 33 ok(!$INC{'Test2/API/InterceptResult.pm'}, "Did not load result class yes"); 34 my $one = $CLASS->new(); 35 ok($one->isa($CLASS), "Got an instance"); 36 is_deeply($one->facet_data, {}, "Got empty data"); 37 is($one->result_class, 'Test2::API::InterceptResult', "Got default result class"); 38 ok($INC{'Test2/API/InterceptResult.pm'}, "Loaded result class"); 39 40 like( 41 exception { $CLASS->new(facet_data => {assert => [{}]}) }, 42 qr/^Facet 'assert' is an only-one facet, but got 'ARRAY' instead of a hashref/, 43 "Check list vs non-list when we can (check for single)" 44 ); 45 46 like( 47 exception { $CLASS->new(facet_data => {info => {}}) }, 48 qr/^Facet 'info' is a list facet, but got 'HASH' instead of an arrayref/, 49 "Check list vs non-list when we can (check for list)" 50 ); 51 52 like( 53 exception { $CLASS->new(facet_data => {info => [{},[]]}) }, 54 qr/Got item type 'ARRAY' in list-facet 'info', all items must be hashrefs/, 55 "Check each item in a list facet is a hashref" 56 ); 57 58 my $two = $CLASS->new(facet_data => {assert => {}, info => [{}]}); 59 ok($two->isa($CLASS), "Got an instance with some actual facets"); 60}; 61 62tests facet => sub { 63 my $one = $CLASS->new(facet_data => { 64 other_single => {}, 65 other_list => [{}], 66 assert => {pass => 1, details => 'xxx'}, 67 info => [ 68 {tag => 'DIAG', details => 'xxx'}, 69 {tag => 'NOTE', details => 'xxx'}, 70 ], 71 }); 72 73 ok(($one->facet('assert'))[0]->isa('Test2::EventFacet::Assert'), "Bless the assert facet"); 74 ok(($one->facet('other_list'))[0]->isa('Test2::EventFacet'), "Bless the other_list as generic"); 75 ok(($one->facet('other_single'))[0]->isa('Test2::EventFacet'), "Bless the other_single as generic"); 76 ok(($one->facet('other_list'))[0]->isa('Test2::API::InterceptResult::Facet'), "Bless the other_list as generic"); 77 ok(($one->facet('other_single'))[0]->isa('Test2::API::InterceptResult::Facet'), "Bless the other_single as generic"); 78 79 is(($one->facet('other_list'))[0]->foo, undef, "Generic gives us autoload for field access"); 80 81 is_deeply( 82 [$one->facet('xxx')], 83 [], 84 "Got an empty list when facet is not present", 85 ); 86 87 is_deeply( 88 [$one->facet('assert')], 89 [{pass => 1, details => 'xxx'}], 90 "One item list for non-list facets", 91 ); 92 93 is_deeply( 94 [$one->facet('info')], 95 [ 96 {tag => 'DIAG', details => 'xxx'}, 97 {tag => 'NOTE', details => 'xxx'}, 98 ], 99 "Full list for list facets" 100 ); 101}; 102 103tests the_facet => sub { 104 my $one = $CLASS->new(facet_data => { 105 other_single => {}, 106 other_list => [{}], 107 assert => {pass => 1, details => 'xxx'}, 108 info => [ 109 {tag => 'DIAG', details => 'xxx'}, 110 {tag => 'NOTE', details => 'xxx'}, 111 ], 112 }); 113 114 ok($one->the_facet('assert')->isa('Test2::EventFacet::Assert'), "Bless the assert facet"); 115 ok($one->the_facet('other_list')->isa('Test2::EventFacet'), "Bless the other_list as generic"); 116 ok($one->the_facet('other_single')->isa('Test2::EventFacet'), "Bless the other_single as generic"); 117 ok($one->the_facet('other_list')->isa('Test2::API::InterceptResult::Facet'), "Bless the other_list as generic"); 118 ok($one->the_facet('other_single')->isa('Test2::API::InterceptResult::Facet'), "Bless the other_single as generic"); 119 120 is($one->the_facet('other_list')->foo, undef, "Generic gives us autoload for field access"); 121 122 is_deeply( 123 $one->the_facet('xxx'), 124 undef, 125 "Got an undef when facet is not present", 126 ); 127 128 is_deeply( 129 $one->the_facet('assert'), 130 {pass => 1, details => 'xxx'}, 131 "One item", 132 ); 133 134 like( 135 exception { $one->the_facet('info') }, 136 qr/'the_facet' called for facet 'info', but 'info' has '2' items/, 137 "the_facet dies if there are more than one" 138 ); 139}; 140 141tests causes_failure => sub { 142 my $one = $CLASS->new(facet_data => { assert => {pass => 1, details => 'xxx'}}); 143 ok(!$one->causes_fail, "No failure for passing test"); 144 ok(!$one->causes_failure, "No failure for passing test (alt name)"); 145 146 my $two = $CLASS->new(facet_data => { assert => {pass => 0, details => 'xxx'}}); 147 ok($two->causes_fail, "Failure for failing test"); 148 ok($two->causes_failure, "Failure for failing test (alt name)"); 149 150 my $three = $CLASS->new( 151 facet_data => { 152 assert => {pass => 0, details => 'xxx'}, 153 amnesty => [{tag => 'TODO', details => 'a todo'}], 154 } 155 ); 156 ok(!$three->causes_fail, "No failure for failing test (with amnesty)"); 157 ok(!$three->causes_failure, "No failure for failing test (with amnesty) (alt name)"); 158}; 159 160tests trace => sub { 161 my $one = $CLASS->new; 162 is($one->trace, undef, "No trace to get"); 163 is($one->frame, undef, "No frame to get"); 164 is($one->trace_details, undef, "No trace to get trace_details from"); 165 is($one->trace_file, undef, "No trace to get trace_file from"); 166 is($one->trace_line, undef, "No trace to get trace_line from"); 167 is($one->trace_package, undef, "No trace to get trace_package from"); 168 is($one->trace_subname, undef, "No trace to get trace_subname from"); 169 is($one->trace_tool, undef, "No trace to get trace_tool from"); 170 171 my $stamp = 123; 172 my $two = $CLASS->new( 173 facet_data => { 174 trace => { 175 frame => [], 176 details => 'xxx', 177 pid => 1, 178 tid => 1, 179 stamp => $stamp, 180 }, 181 } 182 ); 183 184 is_deeply($two->the_trace, {details => 'xxx', frame => [], pid => 1, tid => 1, stamp => $stamp}, "Got trace"); 185 is_deeply([$two->trace], [{details => 'xxx', frame => [], pid => 1, tid => 1, stamp => $stamp}], "Got trace"); 186 is($two->trace_details, 'xxx', "get trace_details"); 187 is($two->trace_stamp, $stamp, "get trace_stamp"); 188 is_deeply($two->frame, [], "No frame to get"); 189 is($two->trace_file, undef, "No frame to get trace_file from"); 190 is($two->trace_line, undef, "No frame to get trace_line from"); 191 is($two->trace_package, undef, "No frame to get trace_package from"); 192 is($two->trace_subname, undef, "No frame to get trace_subname from"); 193 is($two->trace_tool, undef, "No frame to get trace_tool from"); 194 195 my $three = $CLASS->new( 196 facet_data => { 197 trace => { 198 details => 'xxx', 199 frame => ['Foo::Bar', 'Foo/Bar.pm', 42, 'ok'], 200 pid => 1, 201 tid => 1, 202 stamp => $stamp, 203 }, 204 } 205 ); 206 is_deeply($three->the_trace, {details => 'xxx', frame => ['Foo::Bar', 'Foo/Bar.pm', 42, 'ok'], pid => 1, tid => 1, stamp => $stamp}, "Got trace"); 207 is($three->trace_details, 'xxx', "get trace_details"); 208 is($three->trace_stamp, $stamp, "get trace_stamp"); 209 is_deeply($three->frame, ['Foo::Bar', 'Foo/Bar.pm', 42, 'ok'], "Got frame"); 210 is($three->trace_file, 'Foo/Bar.pm', "Got trace_file"); 211 is($three->trace_line, 42, "Got trace_line"); 212 is($three->trace_package, 'Foo::Bar', "Got trace_package"); 213 is($three->trace_subname, 'ok', "Got trace_subname"); 214 is($three->trace_tool, 'ok', "Got trace_tool"); 215}; 216 217tests brief => sub { 218 my $one = $CLASS->new( 219 facet_data => { 220 control => {halt => 1, details => "some reason to bail out"}, 221 errors => [{tag => 'ERROR', details => "some kind of error"}], 222 assert => {pass => 1, details => "some passing assert"}, 223 plan => {count => 42}, 224 } 225 ); 226 227 is($one->brief, $one->bailout_brief, "bail-out is used when present"); 228 delete $one->{facet_data}->{control}; 229 230 is($one->brief, $one->error_brief, "error is next"); 231 delete $one->{facet_data}->{errors}; 232 233 is($one->brief, $one->assert_brief, "assert is next"); 234 delete $one->{facet_data}->{assert}; 235 236 is($one->brief, $one->plan_brief, "plan is last"); 237 delete $one->{facet_data}->{plan}; 238 239 is_deeply( 240 [$one->brief], 241 [], 242 "Empty list if no briefs are available." 243 ); 244}; 245 246tests summary => sub { 247 my $one = $CLASS->new(); 248 249 is_deeply( 250 $one->summary, 251 { 252 brief => '', 253 254 causes_failure => 0, 255 256 trace_line => undef, 257 trace_file => undef, 258 trace_tool => undef, 259 trace_details => undef, 260 261 facets => [], 262 }, 263 "Got summary for empty event" 264 ); 265 266 my $two = $CLASS->new(facet_data => { 267 assert => {pass => 0}, 268 trace => {frame => ['Foo::Bar', 'Foo/Bar.pm', 42, 'ok'], details => 'a trace'}, 269 parent => {}, 270 plan => {count => 1}, 271 control => {halt => 1, details => "bailout wins"}, 272 info => [ 273 {tag => 'DIAG', details => 'diag 1'}, 274 {tag => 'DIAG', details => 'diag 2'}, 275 {tag => 'NOTE', details => 'note 1'}, 276 {tag => 'NOTE', details => 'note 2'}, 277 {tag => 'OTHER', details => 'other 1'}, 278 {tag => 'OTHER', details => 'other 2'}, 279 ], 280 }); 281 282 is_deeply( 283 $two->summary, 284 { 285 brief => 'BAILED OUT: bailout wins', 286 287 causes_failure => 1, 288 289 trace_line => 42, 290 trace_file => 'Foo/Bar.pm', 291 trace_tool => 'ok', 292 trace_details => 'a trace', 293 294 facets => [qw{ assert control info parent plan trace }], 295 }, 296 "Got summary for lots" 297 ); 298 299 is_deeply( 300 $two->summary(fields => [qw/trace_line trace_file/]), 301 { 302 trace_line => 42, 303 trace_file => 'Foo/Bar.pm', 304 }, 305 "Got summary, specific fields" 306 ); 307 308 is_deeply( 309 $two->summary(remove => [qw/brief facets/]), 310 { 311 causes_failure => 1, 312 313 trace_line => 42, 314 trace_file => 'Foo/Bar.pm', 315 trace_tool => 'ok', 316 trace_details => 'a trace', 317 }, 318 "Got summary, removed some fields" 319 ); 320}; 321 322tests assert => sub { 323 my $one = $CLASS->new(); 324 ok(!$one->has_assert, "Not an assert"); 325 is_deeply([$one->assert], [], "empty list for assert()"); 326 is_deeply([$one->assert_brief], [], "empty list for assert_brief()"); 327 328 my $two = $CLASS->new(facet_data => {assert => {pass => 1, details => 'foo'}}); 329 ok($two->has_assert, "Is an assert"); 330 is_deeply([$two->assert], [{pass => 1, details => 'foo'}], "got assert item"); 331 is($two->assert_brief, "PASS", "got PASS for assert_brief()"); 332 333 my $three = $CLASS->new(facet_data => { 334 assert => {pass => 0, details => 'foo'}, 335 amnesty => [ 336 {tag => 'TODO', details => 'todo 1'}, 337 {tag => 'SKIP', details => 'skip 1'}, 338 {tag => 'OOPS', details => 'oops 1'}, 339 {tag => 'TODO', details => 'todo 2'}, 340 {tag => 'SKIP', details => 'skip 2'}, 341 {tag => 'OOPS', details => 'oops 2'}, 342 ], 343 }); 344 ok($three->has_assert, "Is an assert"); 345 is_deeply([$three->assert], [{pass => 0, details => 'foo'}], "got assert item"); 346 is($three->assert_brief, "FAIL with amnesty", "Fail with amnesty"); 347 348 my $four = $CLASS->new(facet_data => { 349 assert => {pass => 0, details => 'foo'}, 350 amnesty => [ 351 {tag => 'TODO'}, 352 {tag => 'SKIP'}, 353 {tag => 'OOPS'}, 354 ], 355 }); 356 ok($four->has_assert, "Is an assert"); 357 is_deeply([$four->assert], [{pass => 0, details => 'foo'}], "got assert item"); 358 is($four->assert_brief, "FAIL with amnesty", "Fail with amnesty"); 359}; 360 361tests subtest => sub { 362 my $one = $CLASS->new(); 363 ok(!$one->has_subtest, "Not a subtest"); 364 is_deeply([$one->subtest], [], "subtest() returns empty list"); 365 is_deeply([$one->subtest_result], [], "subtest_result returns an empty list"); 366 367 my $two = $CLASS->new( 368 facet_data => { 369 parent => { 370 hid => '1234', 371 children => [], 372 state => { 373 bailed_out => undef, 374 count => 5, 375 failed => 1, 376 follows_plan => 1, 377 is_passing => 0, 378 nested => 1, 379 skip_reason => undef, 380 }, 381 }, 382 } 383 ); 384 385 ok($two->has_subtest, "has a subtest"); 386 is_deeply([$two->subtest], [$two->facet_data->{parent}], "subtest() returns 1 item list"); 387 388 my $res = $two->subtest_result; 389 ok($res->isa('Test2::API::InterceptResult'), "Got a result instance"); 390}; 391 392tests flatten => sub { 393 my $one = $CLASS->new(); 394 is_deeply( 395 $one->flatten, 396 { 397 causes_failure => 0, 398 trace_file => undef, 399 trace_line => undef 400 }, 401 "Empty event flattens to almost nothing" 402 ); 403 404 my $two = $CLASS->new( 405 facet_data => { 406 hubs => [{details => "DO NOT SHOW"}], 407 meta => {details => "DO NOT SHOW"}, 408 control => {details => "A control"}, 409 assert => {pass => 1, details => "Test Name"}, 410 411 trace => { 412 frame => ['Foo::Bar', 'Foo/Bar.pm', 42, 'Test2::Tools::Tiny::ok'], 413 details => "Trace Details", 414 }, 415 416 parent => { 417 details => "A Subtest", 418 children => [ 419 $CLASS->new(facet_data => {assert => {pass => 1, details => 'nested assertion'}}), 420 $CLASS->new(facet_data => {plan => {count => 1}}), 421 ], 422 }, 423 424 errors => [ 425 {tag => 'error', fail => 0, details => "not a fatal error"}, 426 {tag => 'error', fail => 1, details => "a fatal error"}, 427 ], 428 429 info => [ 430 {tag => 'DIAG', details => 'diag 1'}, 431 {tag => 'DIAG', details => 'diag 2'}, 432 {tag => 'NOTE', details => 'note 1'}, 433 {tag => 'NOTE', details => 'note 2'}, 434 {tag => 'INFO', details => 'info 1'}, 435 {tag => 'INFO', details => 'info 2'}, 436 ], 437 amnesty => [ 438 {tag => 'TODO', details => 'todo 1'}, 439 {tag => 'TODO', details => 'todo 2'}, 440 {tag => 'SKIP', details => 'skip 1'}, 441 {tag => 'SKIP', details => 'skip 2'}, 442 {tag => 'OKOK', details => 'okok 1'}, 443 {tag => 'OKOK', details => 'okok 2'}, 444 ], 445 446 other_single => {details => 'other single'}, 447 other_multi => [{details => 'other multi'}], 448 }, 449 ); 450 451 is_deeply( 452 $two->flatten(include_subevents => 1), 453 { 454 # Summaries 455 causes_failure => 0, 456 trace_details => 'Trace Details', 457 trace_file => 'Foo/Bar.pm', 458 trace_line => 42, 459 460 # Info 461 diag => ['diag 1', 'diag 2'], 462 info => ['info 1', 'info 2'], 463 note => ['note 1', 'note 2'], 464 465 # Amnesty 466 okok => ['okok 1', 'okok 2'], 467 skip => ['skip 1', 'skip 2'], 468 todo => ['todo 1', 'todo 2'], 469 470 # Errors 471 error => ['not a fatal error', 'FATAL: a fatal error'], 472 473 # Assert 474 name => 'Test Name', 475 pass => 1, 476 477 # Control 478 control => 'A control', 479 480 # Other 481 other_multi => ['other multi'], 482 other_single => 'other single', 483 484 # Subtest related 485 subtest => { 486 follows_plan => 1, 487 is_passing => 1, 488 count => 1, 489 failed => 0, 490 plan => 1, 491 }, 492 493 subevents => [ 494 { 495 name => 'nested assertion', 496 trace_line => undef, 497 causes_failure => 0, 498 pass => 1, 499 trace_file => undef, 500 }, 501 { 502 trace_file => undef, 503 plan => '1', 504 trace_line => undef, 505 causes_failure => 0, 506 } 507 ], 508 }, 509 "Very full flattening, with subevents" 510 ); 511 512 is_deeply( 513 $two->flatten(), 514 { 515 # Summaries 516 causes_failure => 0, 517 trace_details => 'Trace Details', 518 trace_file => 'Foo/Bar.pm', 519 trace_line => 42, 520 521 # Info 522 diag => ['diag 1', 'diag 2'], 523 info => ['info 1', 'info 2'], 524 note => ['note 1', 'note 2'], 525 526 # Amnesty 527 okok => ['okok 1', 'okok 2'], 528 skip => ['skip 1', 'skip 2'], 529 todo => ['todo 1', 'todo 2'], 530 531 # Errors 532 error => ['not a fatal error', 'FATAL: a fatal error'], 533 534 # Assert 535 name => 'Test Name', 536 pass => 1, 537 538 # Control 539 control => 'A control', 540 541 # Other 542 other_multi => ['other multi'], 543 other_single => 'other single', 544 545 # Subtest related 546 subtest => { 547 follows_plan => 1, 548 is_passing => 1, 549 count => 1, 550 failed => 0, 551 plan => 1, 552 }, 553 }, 554 "Very full flattening, no subevents" 555 ); 556 557 my $three = $CLASS->new( 558 facet_data => { 559 trace => { 560 frame => ['Foo::Bar', 'Foo/Bar.pm', 42, 'Test2::Tools::Tiny::ok'], 561 }, 562 563 control => {halt => 1, details => "need to bail dude!"}, 564 565 amnesty => [{tag => 'TODO', details => 'todo 1'}], 566 }, 567 ); 568 569 is_deeply( 570 $three->flatten(include_subevents => 1), 571 { 572 # Summaries 573 causes_failure => 0, 574 575 trace_file => 'Foo/Bar.pm', 576 trace_line => 42, 577 578 bailed_out => "need to bail dude!", 579 580 # Amnesty does not show without an assert or parent 581 }, 582 "Bail-out test" 583 ); 584 585 my $four = $CLASS->new( 586 facet_data => { 587 trace => {frame => ['Foo::Bar', 'Foo/Bar.pm', 42, 'Test2::Tools::Tiny::ok']}, 588 errors => [{tag => 'ERROR', details => 'an error', fail => 1}], 589 amnesty => [{tag => 'TODO', details => 'todo 1'}], 590 }, 591 ); 592 593 is_deeply( 594 $four->flatten(), 595 { 596 # Summaries 597 causes_failure => 0, 598 599 trace_file => 'Foo/Bar.pm', 600 trace_line => 42, 601 602 todo => ['todo 1'], 603 error => ['FATAL: an error'], 604 }, 605 "Include amnesty when there is a fatal error" 606 ); 607 608 is_deeply( 609 $four->flatten(fields => [qw/trace_file trace_line/]), 610 { 611 trace_file => 'Foo/Bar.pm', 612 trace_line => 42, 613 }, 614 "Filtered to only specific fields" 615 ); 616 617 is_deeply( 618 $four->flatten(remove => [qw/todo error/]), 619 { 620 # Summaries 621 causes_failure => 0, 622 623 trace_file => 'Foo/Bar.pm', 624 trace_line => 42, 625 }, 626 "Remove specific fields" 627 ); 628 629}; 630 631tests bailout => sub { 632 my $one = $CLASS->new(); 633 ok(!$one->has_bailout, "No bailout"); 634 is_deeply([$one->bailout], [], "no bailout"); 635 is_deeply([$one->bailout_brief], [], "no bailout"); 636 is_deeply([$one->bailout_reason], [], "no bailout"); 637 638 my $two = $CLASS->new( 639 facet_data => { 640 trace => { 641 frame => ['Foo::Bar', 'Foo/Bar.pm', 42, 'Test2::Tools::Tiny::ok'], 642 }, 643 644 control => {halt => 1, details => "need to bail dude!"}, 645 }, 646 ); 647 648 ok($two->has_bailout, "did bail out"); 649 is_deeply([$two->bailout], [{halt => 1, details => "need to bail dude!"}], "Got the bailout"); 650 is_deeply([$two->bailout_brief], ["BAILED OUT: need to bail dude!"], "Got the bailout brief"); 651 is_deeply([$two->bailout_reason], ["need to bail dude!"], "Got the bailout reason"); 652}; 653 654tests plan => sub { 655 my $one = $CLASS->new; 656 ok(!$one->has_plan, "No plan"); 657 is_deeply([$one->plan], [], "No plan"); 658 is_deeply([$one->plan_brief], [], "No plan"); 659 660 my $two = $CLASS->new(facet_data => {plan => { count => 42 }}); 661 ok($two->has_plan, "Got a plan"); 662 is_deeply([$two->plan], [{ count => 42 }], "Got the plan facet"); 663 is_deeply([$two->plan_brief], ["PLAN 42"], "Got the brief"); 664 665 $two->{facet_data}->{plan}->{details} = "foo bar baz"; 666 is_deeply([$two->plan_brief], ["PLAN 42: foo bar baz"], "Got the brief with details"); 667 668 $two->{facet_data}->{plan}->{count} = 0; 669 is_deeply([$two->plan_brief], ["SKIP ALL: foo bar baz"], "Got the skip form no count with details"); 670 671 $two->{facet_data}->{plan}->{count} = 1; 672 $two->{facet_data}->{plan}->{skip} = 1; 673 is_deeply([$two->plan_brief], ["SKIP ALL: foo bar baz"], "Got the skip with details"); 674 675 $two->{facet_data}->{plan}->{skip} = 0; 676 $two->{facet_data}->{plan}->{none} = 1; 677 is_deeply([$two->plan_brief], ["NO PLAN: foo bar baz"], "Got the 'NO PLAN' with details"); 678}; 679 680tests amnesty => sub { 681 my $one = $CLASS->new(); 682 683 ok(!$one->has_amnesty, "No amnesty"); 684 ok(!$one->has_todos, "No todos"); 685 ok(!$one->has_skips, "No skips"); 686 ok(!$one->has_other_amnesty, "No other amnesty"); 687 688 is_deeply([$one->amnesty], [], "amnesty list is empty"); 689 is_deeply([$one->todos], [], "todos list is empty"); 690 is_deeply([$one->skips], [], "skips list is empty"); 691 is_deeply([$one->other_amnesty], [], "other_amnesty list is empty"); 692 693 is_deeply([$one->amnesty_reasons], [], "amnesty_reasons list is empty"); 694 is_deeply([$one->todo_reasons], [], "todo_reasons list is empty"); 695 is_deeply([$one->skip_reasons], [], "skip_reasons list is empty"); 696 is_deeply([$one->other_amnesty_reasons], [], "other_amnesty_reasons list is empty"); 697 698 my $two = $CLASS->new( 699 facet_data => { 700 amnesty => [ 701 {tag => 'TODO', details => 'todo 1'}, 702 {tag => 'TODO', details => 'todo 2'}, 703 {tag => 'SKIP', details => 'skip 1'}, 704 {tag => 'SKIP', details => 'skip 2'}, 705 {tag => 'OKOK', details => 'okok 1'}, 706 {tag => 'OKOK', details => 'okok 2'}, 707 ], 708 }, 709 ); 710 711 ok($two->has_amnesty, "amnesty"); 712 ok($two->has_todos, "todos"); 713 ok($two->has_skips, "skips"); 714 ok($two->has_other_amnesty, "other amnesty"); 715 716 is_deeply( 717 [$two->amnesty], 718 [ 719 {tag => 'TODO', details => 'todo 1'}, 720 {tag => 'TODO', details => 'todo 2'}, 721 {tag => 'SKIP', details => 'skip 1'}, 722 {tag => 'SKIP', details => 'skip 2'}, 723 {tag => 'OKOK', details => 'okok 1'}, 724 {tag => 'OKOK', details => 'okok 2'}, 725 ], 726 "amnesty list", 727 ); 728 is_deeply( 729 [$two->todos], 730 [ 731 {tag => 'TODO', details => 'todo 1'}, 732 {tag => 'TODO', details => 'todo 2'}, 733 ], 734 "todos list", 735 ); 736 is_deeply( 737 [$two->skips], 738 [ 739 {tag => 'SKIP', details => 'skip 1'}, 740 {tag => 'SKIP', details => 'skip 2'}, 741 ], 742 "skips list", 743 ); 744 is_deeply( 745 [$two->other_amnesty], 746 [ 747 {tag => 'OKOK', details => 'okok 1'}, 748 {tag => 'OKOK', details => 'okok 2'}, 749 ], 750 "other_amnesty list", 751 ); 752 753 is_deeply( 754 [$two->amnesty_reasons], 755 [ 756 'todo 1', 757 'todo 2', 758 'skip 1', 759 'skip 2', 760 'okok 1', 761 'okok 2', 762 ], 763 "amnesty_reasons list is empty" 764 ); 765 is_deeply( 766 [$two->todo_reasons], 767 [ 768 'todo 1', 769 'todo 2', 770 ], 771 "todo_reasons list is empty" 772 ); 773 is_deeply( 774 [$two->skip_reasons], 775 [ 776 'skip 1', 777 'skip 2', 778 ], 779 "skip_reasons list is empty" 780 ); 781 is_deeply( 782 [$two->other_amnesty_reasons], 783 [ 784 'okok 1', 785 'okok 2', 786 ], 787 "other_amnesty_reasons list is empty" 788 ); 789}; 790 791tests errors => sub { 792 my $one = $CLASS->new(); 793 ok(!$one->has_errors, "No errors"); 794 is_deeply([$one->errors], [], "No errors"); 795 is_deeply([$one->error_messages], [], "No errors"); 796 is_deeply([$one->error_brief], [], "No errors"); 797 798 my $two = $CLASS->new(facet_data => { 799 errors => [{tag => 'error', details => 'a non fatal error'}], 800 }); 801 ok($two->has_errors, "Got errors"); 802 is_deeply([$two->errors], [{tag => 'error', details => 'a non fatal error'}], "Got the error"); 803 is_deeply([$two->error_messages], ['a non fatal error'], "Got the message"); 804 is_deeply([$two->error_brief], ['ERROR: a non fatal error'], "Got the brief"); 805 806 my $three = $CLASS->new(facet_data => { 807 errors => [{tag => 'error', details => "a non fatal\nerror"}], 808 }); 809 ok($three->has_errors, "Got errors"); 810 is_deeply([$three->errors], [{tag => 'error', details => "a non fatal\nerror"}], "Got the error"); 811 is_deeply([$three->error_messages], ["a non fatal\nerror"], "Got the message"); 812 is_deeply([$three->error_brief], ["ERROR: a non fatal [...]"], "Got the brief"); 813 814 my $four = $CLASS->new(facet_data => { 815 errors => [ 816 {tag => 'error', details => "a fatal error", fail => 1}, 817 {tag => 'error', details => "a non fatal error", fail => 0}, 818 ], 819 }); 820 821 ok($four->has_errors, "Got errors"); 822 823 is_deeply( 824 [$four->errors], 825 [ 826 {tag => 'error', details => "a fatal error", fail => 1}, 827 {tag => 'error', details => "a non fatal error", fail => 0}, 828 ], 829 "Got the error" 830 ); 831 832 is_deeply( 833 [$four->error_messages], 834 [ 835 "a fatal error", 836 "a non fatal error", 837 ], 838 "Got the message" 839 ); 840 841 is_deeply([$four->error_brief], ['ERRORS: a fatal error [...]'], "Got the brief"); 842 843}; 844 845tests info => sub { 846 my $one = $CLASS->new(); 847 848 ok(!$one->has_info, "No info"); 849 ok(!$one->has_diags, "No diags"); 850 ok(!$one->has_notes, "No notes"); 851 ok(!$one->has_other_info, "No other info"); 852 853 is_deeply([$one->info], [], "info list is empty"); 854 is_deeply([$one->diags], [], "diags list is empty"); 855 is_deeply([$one->notes], [], "notes list is empty"); 856 is_deeply([$one->other_info], [], "other_info list is empty"); 857 858 is_deeply([$one->info_messages], [], "info_messages list is empty"); 859 is_deeply([$one->diag_messages], [], "diag_messages list is empty"); 860 is_deeply([$one->note_messages], [], "note_messages list is empty"); 861 is_deeply([$one->other_info_messages], [], "other_info_messages list is empty"); 862 863 my $two = $CLASS->new( 864 facet_data => { 865 info => [ 866 {tag => 'DIAG', details => 'diag 1'}, 867 {tag => 'DIAG', details => 'diag 2'}, 868 {tag => 'NOTE', details => 'note 1'}, 869 {tag => 'NOTE', details => 'note 2'}, 870 {tag => 'INFO', details => 'info 1'}, 871 {tag => 'INFO', details => 'info 2'}, 872 ], 873 }, 874 ); 875 876 ok($two->has_info, "info"); 877 ok($two->has_diags, "diags"); 878 ok($two->has_notes, "notes"); 879 ok($two->has_other_info, "other info"); 880 881 is_deeply( 882 [$two->info], 883 [ 884 {tag => 'DIAG', details => 'diag 1'}, 885 {tag => 'DIAG', details => 'diag 2'}, 886 {tag => 'NOTE', details => 'note 1'}, 887 {tag => 'NOTE', details => 'note 2'}, 888 {tag => 'INFO', details => 'info 1'}, 889 {tag => 'INFO', details => 'info 2'}, 890 ], 891 "info list", 892 ); 893 is_deeply( 894 [$two->diags], 895 [ 896 {tag => 'DIAG', details => 'diag 1'}, 897 {tag => 'DIAG', details => 'diag 2'}, 898 ], 899 "diags list", 900 ); 901 is_deeply( 902 [$two->notes], 903 [ 904 {tag => 'NOTE', details => 'note 1'}, 905 {tag => 'NOTE', details => 'note 2'}, 906 ], 907 "notes list", 908 ); 909 is_deeply( 910 [$two->other_info], 911 [ 912 {tag => 'INFO', details => 'info 1'}, 913 {tag => 'INFO', details => 'info 2'}, 914 ], 915 "other_info list", 916 ); 917 918 is_deeply( 919 [$two->info_messages], 920 [ 921 'diag 1', 922 'diag 2', 923 'note 1', 924 'note 2', 925 'info 1', 926 'info 2', 927 ], 928 "info_messages list is empty" 929 ); 930 is_deeply( 931 [$two->diag_messages], 932 [ 933 'diag 1', 934 'diag 2', 935 ], 936 "diag_messages list is empty" 937 ); 938 is_deeply( 939 [$two->note_messages], 940 [ 941 'note 1', 942 'note 2', 943 ], 944 "note_messages list is empty" 945 ); 946 is_deeply( 947 [$two->other_info_messages], 948 [ 949 'info 1', 950 'info 2', 951 ], 952 "other_info_messages list is empty" 953 ); 954}; 955 956done_testing; 957