1use strict; 2use warnings; 3 4use Test2::Tools::Tiny; 5use Test2::EventFacet::Trace; 6use Test2::Event::Ok; 7use Test2::Event::Diag; 8 9use Test2::API qw/context/; 10 11my $trace; 12sub before_each { 13 # Make sure there is a fresh trace object for each group 14 $trace = Test2::EventFacet::Trace->new( 15 frame => ['main_foo', 'foo.t', 42, 'main_foo::flubnarb'], 16 ); 17} 18 19tests Passing => sub { 20 my $ok = Test2::Event::Ok->new( 21 trace => $trace, 22 pass => 1, 23 name => 'the_test', 24 ); 25 ok($ok->increments_count, "Bumps the count"); 26 ok(!$ok->causes_fail, "Passing 'OK' event does not cause failure"); 27 is($ok->pass, 1, "got pass"); 28 is($ok->name, 'the_test', "got name"); 29 is($ok->effective_pass, 1, "effective pass"); 30 is($ok->summary, "the_test", "Summary is just the name of the test"); 31 32 my $facet_data = $ok->facet_data; 33 ok($facet_data->{about}, "got common facet data"); 34 ok(!$facet_data->{amnesty}, "No amnesty by default"); 35 is_deeply( 36 $facet_data->{assert}, 37 { 38 no_debug => 1, 39 pass => 1, 40 details => 'the_test', 41 }, 42 "Got assert facet", 43 ); 44 45 46 $ok = Test2::Event::Ok->new( 47 trace => $trace, 48 pass => 1, 49 name => '', 50 ); 51 is($ok->summary, "Nameless Assertion", "Nameless test"); 52 53 $facet_data = $ok->facet_data; 54 ok($facet_data->{about}, "got common facet data"); 55 ok(!$facet_data->{amnesty}, "No amnesty by default"); 56 is_deeply( 57 $facet_data->{assert}, 58 { 59 no_debug => 1, 60 pass => 1, 61 details => '', 62 }, 63 "Got assert facet", 64 ); 65}; 66 67tests Failing => sub { 68 local $ENV{HARNESS_ACTIVE} = 1; 69 local $ENV{HARNESS_IS_VERBOSE} = 1; 70 my $ok = Test2::Event::Ok->new( 71 trace => $trace, 72 pass => 0, 73 name => 'the_test', 74 ); 75 ok($ok->increments_count, "Bumps the count"); 76 ok($ok->causes_fail, "A failing test causes failures"); 77 is($ok->pass, 0, "got pass"); 78 is($ok->name, 'the_test', "got name"); 79 is($ok->effective_pass, 0, "effective pass"); 80 is($ok->summary, "the_test", "Summary is just the name of the test"); 81 82 my $facet_data = $ok->facet_data; 83 ok($facet_data->{about}, "got common facet data"); 84 ok(!$facet_data->{amnesty}, "No amnesty by default"); 85 is_deeply( 86 $facet_data->{assert}, 87 { 88 no_debug => 1, 89 pass => 0, 90 details => 'the_test', 91 }, 92 "Got assert facet", 93 ); 94}; 95 96tests "Failing TODO" => sub { 97 local $ENV{HARNESS_ACTIVE} = 1; 98 local $ENV{HARNESS_IS_VERBOSE} = 1; 99 my $ok = Test2::Event::Ok->new( 100 trace => $trace, 101 pass => 0, 102 name => 'the_test', 103 todo => 'A Todo', 104 ); 105 ok($ok->increments_count, "Bumps the count"); 106 is($ok->pass, 0, "got pass"); 107 is($ok->name, 'the_test', "got name"); 108 is($ok->effective_pass, 1, "effective pass is true from todo"); 109 is($ok->summary, "the_test (TODO: A Todo)", "Summary is just the name of the test + todo"); 110 111 my $facet_data = $ok->facet_data; 112 ok($facet_data->{about}, "got common facet data"); 113 is_deeply( 114 $facet_data->{assert}, 115 { 116 no_debug => 1, 117 pass => 0, 118 details => 'the_test', 119 }, 120 "Got assert facet", 121 ); 122 is_deeply( 123 $facet_data->{amnesty}, 124 [{ 125 tag => 'TODO', 126 details => 'A Todo', 127 }], 128 "Got amnesty facet", 129 ); 130 131 132 $ok = Test2::Event::Ok->new( 133 trace => $trace, 134 pass => 0, 135 name => 'the_test2', 136 todo => '', 137 ); 138 ok($ok->effective_pass, "empty string todo is still a todo"); 139 is($ok->summary, "the_test2 (TODO)", "Summary is just the name of the test + todo"); 140 141 $facet_data = $ok->facet_data; 142 ok($facet_data->{about}, "got common facet data"); 143 is_deeply( 144 $facet_data->{assert}, 145 { 146 no_debug => 1, 147 pass => 0, 148 details => 'the_test2', 149 }, 150 "Got assert facet", 151 ); 152 is_deeply( 153 $facet_data->{amnesty}, 154 [{ 155 tag => 'TODO', 156 details => '', 157 }], 158 "Got amnesty facet", 159 ); 160 161}; 162 163tests init => sub { 164 my $ok = Test2::Event::Ok->new( 165 trace => $trace, 166 pass => 1, 167 ); 168 is($ok->effective_pass, 1, "set effective pass"); 169}; 170 171done_testing; 172