1use strict;
2
3use Test::Tester;
4
5use Data::Dumper qw(Dumper);
6
7my $test = Test::Builder->new;
8$test->plan(tests => 54);
9
10my $cap;
11
12{
13	$cap = Test::Tester->capture;
14	my ($prem, @results) = run_tests(
15		sub {$cap->ok(1, "run pass")}
16	);
17
18	local $Test::Builder::Level = 0;
19
20	$test->is_eq($prem, "", "run pass no prem");
21	$test->is_num(scalar (@results), 1, "run pass result count");
22
23	my $res = $results[0];
24
25	$test->is_eq($res->{name}, "run pass", "run pass name");
26	$test->is_eq($res->{ok}, 1, "run pass ok");
27	$test->is_eq($res->{actual_ok}, 1, "run pass actual_ok");
28	$test->is_eq($res->{reason}, "", "run pass reason");
29	$test->is_eq($res->{type}, "", "run pass type");
30	$test->is_eq($res->{diag}, "", "run pass diag");
31	$test->is_num($res->{depth}, 0, "run pass depth");
32}
33
34{
35	my ($prem, @results) = run_tests(
36		sub {$cap->ok(0, "run fail")}
37	);
38
39	local $Test::Builder::Level = 0;
40
41	$test->is_eq($prem, "", "run fail no prem");
42	$test->is_num(scalar (@results), 1, "run fail result count");
43
44	my $res = $results[0];
45
46	$test->is_eq($res->{name}, "run fail", "run fail name");
47	$test->is_eq($res->{actual_ok}, 0, "run fail actual_ok");
48	$test->is_eq($res->{ok}, 0, "run fail ok");
49	$test->is_eq($res->{reason}, "", "run fail reason");
50	$test->is_eq($res->{type}, "", "run fail type");
51	$test->is_eq($res->{diag}, "", "run fail diag");
52	$test->is_num($res->{depth}, 0, "run fail depth");
53}
54
55{
56	my ($prem, @results) = run_tests(
57		sub {$cap->skip("just because")}
58	);
59
60	local $Test::Builder::Level = 0;
61
62	$test->is_eq($prem, "", "skip no prem");
63	$test->is_num(scalar (@results), 1, "skip result count");
64
65	my $res = $results[0];
66
67	$test->is_eq($res->{name}, "", "skip name");
68	$test->is_eq($res->{actual_ok}, 1, "skip actual_ok");
69	$test->is_eq($res->{ok}, 1, "skip ok");
70	$test->is_eq($res->{reason}, "just because", "skip reason");
71	$test->is_eq($res->{type}, "skip", "skip type");
72	$test->is_eq($res->{diag}, "", "skip diag");
73	$test->is_num($res->{depth}, 0, "skip depth");
74}
75
76{
77	my ($prem, @results) = run_tests(
78		sub {$cap->todo_skip("just because")}
79	);
80
81	local $Test::Builder::Level = 0;
82
83	$test->is_eq($prem, "", "todo_skip no prem");
84	$test->is_num(scalar (@results), 1, "todo_skip result count");
85
86	my $res = $results[0];
87
88	$test->is_eq($res->{name}, "", "todo_skip name");
89	$test->is_eq($res->{actual_ok}, 0, "todo_skip actual_ok");
90	$test->is_eq($res->{ok}, 1, "todo_skip ok");
91	$test->is_eq($res->{reason}, "just because", "todo_skip reason");
92	$test->is_eq($res->{type}, "todo_skip", "todo_skip type");
93	$test->is_eq($res->{diag}, "", "todo_skip diag");
94	$test->is_num($res->{depth}, 0, "todo_skip depth");
95}
96
97{
98	my ($prem, @results) = run_tests(
99		sub {$cap->diag("run diag")}
100	);
101
102	local $Test::Builder::Level = 0;
103
104	$test->is_eq($prem, "run diag\n", "run diag prem");
105	$test->is_num(scalar (@results), 0, "run diag result count");
106}
107
108{
109	my ($prem, @results) = run_tests(
110		sub {
111			$cap->ok(1, "multi pass");
112			$cap->diag("multi pass diag1");
113			$cap->diag("multi pass diag2");
114			$cap->ok(0, "multi fail");
115			$cap->diag("multi fail diag");
116		}
117	);
118
119	local $Test::Builder::Level = 0;
120
121	$test->is_eq($prem, "", "run multi no prem");
122	$test->is_num(scalar (@results), 2, "run multi result count");
123
124	my $res_pass = $results[0];
125
126	$test->is_eq($res_pass->{name}, "multi pass", "run multi pass name");
127	$test->is_eq($res_pass->{actual_ok}, 1, "run multi pass actual_ok");
128	$test->is_eq($res_pass->{ok}, 1, "run multi pass ok");
129	$test->is_eq($res_pass->{reason}, "", "run multi pass reason");
130	$test->is_eq($res_pass->{type}, "", "run multi pass type");
131	$test->is_eq($res_pass->{diag}, "multi pass diag1\nmulti pass diag2\n",
132		"run multi pass diag");
133	$test->is_num($res_pass->{depth}, 0, "run multi pass depth");
134
135	my $res_fail = $results[1];
136
137	$test->is_eq($res_fail->{name}, "multi fail", "run multi fail name");
138	$test->is_eq($res_pass->{actual_ok}, 1, "run multi fail actual_ok");
139	$test->is_eq($res_fail->{ok}, 0, "run multi fail ok");
140	$test->is_eq($res_pass->{reason}, "", "run multi fail reason");
141	$test->is_eq($res_pass->{type}, "", "run multi fail type");
142	$test->is_eq($res_fail->{diag}, "multi fail diag\n", "run multi fail diag");
143	$test->is_num($res_pass->{depth}, 0, "run multi fail depth");
144}
145
146