1*b0d29bc4SBrooks Davis // Copyright 2015 The Kyua Authors.
2*b0d29bc4SBrooks Davis // All rights reserved.
3*b0d29bc4SBrooks Davis //
4*b0d29bc4SBrooks Davis // Redistribution and use in source and binary forms, with or without
5*b0d29bc4SBrooks Davis // modification, are permitted provided that the following conditions are
6*b0d29bc4SBrooks Davis // met:
7*b0d29bc4SBrooks Davis //
8*b0d29bc4SBrooks Davis // * Redistributions of source code must retain the above copyright
9*b0d29bc4SBrooks Davis // notice, this list of conditions and the following disclaimer.
10*b0d29bc4SBrooks Davis // * Redistributions in binary form must reproduce the above copyright
11*b0d29bc4SBrooks Davis // notice, this list of conditions and the following disclaimer in the
12*b0d29bc4SBrooks Davis // documentation and/or other materials provided with the distribution.
13*b0d29bc4SBrooks Davis // * Neither the name of Google Inc. nor the names of its contributors
14*b0d29bc4SBrooks Davis // may be used to endorse or promote products derived from this software
15*b0d29bc4SBrooks Davis // without specific prior written permission.
16*b0d29bc4SBrooks Davis //
17*b0d29bc4SBrooks Davis // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
18*b0d29bc4SBrooks Davis // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
19*b0d29bc4SBrooks Davis // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
20*b0d29bc4SBrooks Davis // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
21*b0d29bc4SBrooks Davis // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
22*b0d29bc4SBrooks Davis // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
23*b0d29bc4SBrooks Davis // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
24*b0d29bc4SBrooks Davis // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
25*b0d29bc4SBrooks Davis // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
26*b0d29bc4SBrooks Davis // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
27*b0d29bc4SBrooks Davis // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28*b0d29bc4SBrooks Davis
29*b0d29bc4SBrooks Davis #include "engine/tap_parser.hpp"
30*b0d29bc4SBrooks Davis
31*b0d29bc4SBrooks Davis #include <fstream>
32*b0d29bc4SBrooks Davis
33*b0d29bc4SBrooks Davis #include <atf-c++.hpp>
34*b0d29bc4SBrooks Davis
35*b0d29bc4SBrooks Davis #include "engine/exceptions.hpp"
36*b0d29bc4SBrooks Davis #include "utils/format/containers.ipp"
37*b0d29bc4SBrooks Davis #include "utils/format/macros.hpp"
38*b0d29bc4SBrooks Davis #include "utils/fs/path.hpp"
39*b0d29bc4SBrooks Davis
40*b0d29bc4SBrooks Davis namespace fs = utils::fs;
41*b0d29bc4SBrooks Davis
42*b0d29bc4SBrooks Davis
43*b0d29bc4SBrooks Davis namespace {
44*b0d29bc4SBrooks Davis
45*b0d29bc4SBrooks Davis
46*b0d29bc4SBrooks Davis /// Helper to execute parse_tap_output() on inline text contents.
47*b0d29bc4SBrooks Davis ///
48*b0d29bc4SBrooks Davis /// \param contents The TAP output to parse.
49*b0d29bc4SBrooks Davis ///
50*b0d29bc4SBrooks Davis /// \return The tap_summary object resultingafter the parse.
51*b0d29bc4SBrooks Davis ///
52*b0d29bc4SBrooks Davis /// \throw engine::load_error If parse_tap_output() fails.
53*b0d29bc4SBrooks Davis static engine::tap_summary
do_parse(const std::string & contents)54*b0d29bc4SBrooks Davis do_parse(const std::string& contents)
55*b0d29bc4SBrooks Davis {
56*b0d29bc4SBrooks Davis std::ofstream output("tap.txt");
57*b0d29bc4SBrooks Davis ATF_REQUIRE(output);
58*b0d29bc4SBrooks Davis output << contents;
59*b0d29bc4SBrooks Davis output.close();
60*b0d29bc4SBrooks Davis return engine::parse_tap_output(fs::path("tap.txt"));
61*b0d29bc4SBrooks Davis }
62*b0d29bc4SBrooks Davis
63*b0d29bc4SBrooks Davis
64*b0d29bc4SBrooks Davis } // anonymous namespace
65*b0d29bc4SBrooks Davis
66*b0d29bc4SBrooks Davis
67*b0d29bc4SBrooks Davis ATF_TEST_CASE_WITHOUT_HEAD(tap_summary__bailed_out);
ATF_TEST_CASE_BODY(tap_summary__bailed_out)68*b0d29bc4SBrooks Davis ATF_TEST_CASE_BODY(tap_summary__bailed_out)
69*b0d29bc4SBrooks Davis {
70*b0d29bc4SBrooks Davis const engine::tap_summary summary = engine::tap_summary::new_bailed_out();
71*b0d29bc4SBrooks Davis ATF_REQUIRE(summary.bailed_out());
72*b0d29bc4SBrooks Davis }
73*b0d29bc4SBrooks Davis
74*b0d29bc4SBrooks Davis
75*b0d29bc4SBrooks Davis ATF_TEST_CASE_WITHOUT_HEAD(tap_summary__some_results);
ATF_TEST_CASE_BODY(tap_summary__some_results)76*b0d29bc4SBrooks Davis ATF_TEST_CASE_BODY(tap_summary__some_results)
77*b0d29bc4SBrooks Davis {
78*b0d29bc4SBrooks Davis const engine::tap_summary summary = engine::tap_summary::new_results(
79*b0d29bc4SBrooks Davis engine::tap_plan(1, 5), 3, 2);
80*b0d29bc4SBrooks Davis ATF_REQUIRE(!summary.bailed_out());
81*b0d29bc4SBrooks Davis ATF_REQUIRE_EQ(engine::tap_plan(1, 5), summary.plan());
82*b0d29bc4SBrooks Davis ATF_REQUIRE_EQ(3, summary.ok_count());
83*b0d29bc4SBrooks Davis ATF_REQUIRE_EQ(2, summary.not_ok_count());
84*b0d29bc4SBrooks Davis }
85*b0d29bc4SBrooks Davis
86*b0d29bc4SBrooks Davis
87*b0d29bc4SBrooks Davis ATF_TEST_CASE_WITHOUT_HEAD(tap_summary__all_skipped);
ATF_TEST_CASE_BODY(tap_summary__all_skipped)88*b0d29bc4SBrooks Davis ATF_TEST_CASE_BODY(tap_summary__all_skipped)
89*b0d29bc4SBrooks Davis {
90*b0d29bc4SBrooks Davis const engine::tap_summary summary = engine::tap_summary::new_all_skipped(
91*b0d29bc4SBrooks Davis "Skipped");
92*b0d29bc4SBrooks Davis ATF_REQUIRE(!summary.bailed_out());
93*b0d29bc4SBrooks Davis ATF_REQUIRE_EQ(engine::tap_plan(1, 0), summary.plan());
94*b0d29bc4SBrooks Davis ATF_REQUIRE_EQ("Skipped", summary.all_skipped_reason());
95*b0d29bc4SBrooks Davis }
96*b0d29bc4SBrooks Davis
97*b0d29bc4SBrooks Davis
98*b0d29bc4SBrooks Davis ATF_TEST_CASE_WITHOUT_HEAD(tap_summary__equality_operators);
ATF_TEST_CASE_BODY(tap_summary__equality_operators)99*b0d29bc4SBrooks Davis ATF_TEST_CASE_BODY(tap_summary__equality_operators)
100*b0d29bc4SBrooks Davis {
101*b0d29bc4SBrooks Davis const engine::tap_summary bailed_out =
102*b0d29bc4SBrooks Davis engine::tap_summary::new_bailed_out();
103*b0d29bc4SBrooks Davis const engine::tap_summary all_skipped_1 =
104*b0d29bc4SBrooks Davis engine::tap_summary::new_all_skipped("Reason 1");
105*b0d29bc4SBrooks Davis const engine::tap_summary results_1 =
106*b0d29bc4SBrooks Davis engine::tap_summary::new_results(engine::tap_plan(1, 5), 3, 2);
107*b0d29bc4SBrooks Davis
108*b0d29bc4SBrooks Davis // Self-equality checks.
109*b0d29bc4SBrooks Davis ATF_REQUIRE( bailed_out == bailed_out);
110*b0d29bc4SBrooks Davis ATF_REQUIRE(!(bailed_out != bailed_out));
111*b0d29bc4SBrooks Davis ATF_REQUIRE( all_skipped_1 == all_skipped_1);
112*b0d29bc4SBrooks Davis ATF_REQUIRE(!(all_skipped_1 != all_skipped_1));
113*b0d29bc4SBrooks Davis ATF_REQUIRE( results_1 == results_1);
114*b0d29bc4SBrooks Davis ATF_REQUIRE(!(results_1 != results_1));
115*b0d29bc4SBrooks Davis
116*b0d29bc4SBrooks Davis // Cross-equality checks.
117*b0d29bc4SBrooks Davis ATF_REQUIRE(!(bailed_out == all_skipped_1));
118*b0d29bc4SBrooks Davis ATF_REQUIRE( bailed_out != all_skipped_1);
119*b0d29bc4SBrooks Davis ATF_REQUIRE(!(bailed_out == results_1));
120*b0d29bc4SBrooks Davis ATF_REQUIRE( bailed_out != results_1);
121*b0d29bc4SBrooks Davis ATF_REQUIRE(!(all_skipped_1 == results_1));
122*b0d29bc4SBrooks Davis ATF_REQUIRE( all_skipped_1 != results_1);
123*b0d29bc4SBrooks Davis
124*b0d29bc4SBrooks Davis // Checks for the all_skipped "type".
125*b0d29bc4SBrooks Davis const engine::tap_summary all_skipped_2 =
126*b0d29bc4SBrooks Davis engine::tap_summary::new_all_skipped("Reason 2");
127*b0d29bc4SBrooks Davis ATF_REQUIRE(!(all_skipped_1 == all_skipped_2));
128*b0d29bc4SBrooks Davis ATF_REQUIRE( all_skipped_1 != all_skipped_2);
129*b0d29bc4SBrooks Davis
130*b0d29bc4SBrooks Davis
131*b0d29bc4SBrooks Davis // Checks for the results "type", different plan.
132*b0d29bc4SBrooks Davis const engine::tap_summary results_2 =
133*b0d29bc4SBrooks Davis engine::tap_summary::new_results(engine::tap_plan(2, 6),
134*b0d29bc4SBrooks Davis results_1.ok_count(),
135*b0d29bc4SBrooks Davis results_1.not_ok_count());
136*b0d29bc4SBrooks Davis ATF_REQUIRE(!(results_1 == results_2));
137*b0d29bc4SBrooks Davis ATF_REQUIRE( results_1 != results_2);
138*b0d29bc4SBrooks Davis
139*b0d29bc4SBrooks Davis
140*b0d29bc4SBrooks Davis // Checks for the results "type", different counts.
141*b0d29bc4SBrooks Davis const engine::tap_summary results_3 =
142*b0d29bc4SBrooks Davis engine::tap_summary::new_results(results_1.plan(),
143*b0d29bc4SBrooks Davis results_1.not_ok_count(),
144*b0d29bc4SBrooks Davis results_1.ok_count());
145*b0d29bc4SBrooks Davis ATF_REQUIRE(!(results_1 == results_3));
146*b0d29bc4SBrooks Davis ATF_REQUIRE( results_1 != results_3);
147*b0d29bc4SBrooks Davis }
148*b0d29bc4SBrooks Davis
149*b0d29bc4SBrooks Davis
150*b0d29bc4SBrooks Davis ATF_TEST_CASE_WITHOUT_HEAD(tap_summary__output);
ATF_TEST_CASE_BODY(tap_summary__output)151*b0d29bc4SBrooks Davis ATF_TEST_CASE_BODY(tap_summary__output)
152*b0d29bc4SBrooks Davis {
153*b0d29bc4SBrooks Davis {
154*b0d29bc4SBrooks Davis const engine::tap_summary summary =
155*b0d29bc4SBrooks Davis engine::tap_summary::new_bailed_out();
156*b0d29bc4SBrooks Davis ATF_REQUIRE_EQ(
157*b0d29bc4SBrooks Davis "tap_summary{bailed_out=true}",
158*b0d29bc4SBrooks Davis (F("%s") % summary).str());
159*b0d29bc4SBrooks Davis }
160*b0d29bc4SBrooks Davis
161*b0d29bc4SBrooks Davis {
162*b0d29bc4SBrooks Davis const engine::tap_summary summary =
163*b0d29bc4SBrooks Davis engine::tap_summary::new_results(engine::tap_plan(5, 10), 2, 4);
164*b0d29bc4SBrooks Davis ATF_REQUIRE_EQ(
165*b0d29bc4SBrooks Davis "tap_summary{bailed_out=false, plan=5..10, ok_count=2, "
166*b0d29bc4SBrooks Davis "not_ok_count=4}",
167*b0d29bc4SBrooks Davis (F("%s") % summary).str());
168*b0d29bc4SBrooks Davis }
169*b0d29bc4SBrooks Davis
170*b0d29bc4SBrooks Davis {
171*b0d29bc4SBrooks Davis const engine::tap_summary summary =
172*b0d29bc4SBrooks Davis engine::tap_summary::new_all_skipped("Who knows");
173*b0d29bc4SBrooks Davis ATF_REQUIRE_EQ(
174*b0d29bc4SBrooks Davis "tap_summary{bailed_out=false, plan=1..0, "
175*b0d29bc4SBrooks Davis "all_skipped_reason=Who knows}",
176*b0d29bc4SBrooks Davis (F("%s") % summary).str());
177*b0d29bc4SBrooks Davis }
178*b0d29bc4SBrooks Davis }
179*b0d29bc4SBrooks Davis
180*b0d29bc4SBrooks Davis
181*b0d29bc4SBrooks Davis ATF_TEST_CASE_WITHOUT_HEAD(parse_tap_output__only_one_result);
ATF_TEST_CASE_BODY(parse_tap_output__only_one_result)182*b0d29bc4SBrooks Davis ATF_TEST_CASE_BODY(parse_tap_output__only_one_result)
183*b0d29bc4SBrooks Davis {
184*b0d29bc4SBrooks Davis const engine::tap_summary summary = do_parse(
185*b0d29bc4SBrooks Davis "1..1\n"
186*b0d29bc4SBrooks Davis "ok - 1\n");
187*b0d29bc4SBrooks Davis
188*b0d29bc4SBrooks Davis const engine::tap_summary exp_summary =
189*b0d29bc4SBrooks Davis engine::tap_summary::new_results(engine::tap_plan(1, 1), 1, 0);
190*b0d29bc4SBrooks Davis ATF_REQUIRE_EQ(exp_summary, summary);
191*b0d29bc4SBrooks Davis }
192*b0d29bc4SBrooks Davis
193*b0d29bc4SBrooks Davis
194*b0d29bc4SBrooks Davis ATF_TEST_CASE_WITHOUT_HEAD(parse_tap_output__all_pass);
ATF_TEST_CASE_BODY(parse_tap_output__all_pass)195*b0d29bc4SBrooks Davis ATF_TEST_CASE_BODY(parse_tap_output__all_pass)
196*b0d29bc4SBrooks Davis {
197*b0d29bc4SBrooks Davis const engine::tap_summary summary = do_parse(
198*b0d29bc4SBrooks Davis "1..8\n"
199*b0d29bc4SBrooks Davis "ok - 1\n"
200*b0d29bc4SBrooks Davis " Some diagnostic message\n"
201*b0d29bc4SBrooks Davis "ok - 2 This test also passed\n"
202*b0d29bc4SBrooks Davis "garbage line\n"
203*b0d29bc4SBrooks Davis "ok - 3 This test passed\n"
204*b0d29bc4SBrooks Davis "not ok 4 # SKIP Some reason\n"
205*b0d29bc4SBrooks Davis "not ok 5 # TODO Another reason\n"
206*b0d29bc4SBrooks Davis "ok - 6 Doesn't make a difference SKIP\n"
207*b0d29bc4SBrooks Davis "ok - 7 Doesn't make a difference either TODO\n"
208*b0d29bc4SBrooks Davis "ok # Also works without a number\n");
209*b0d29bc4SBrooks Davis
210*b0d29bc4SBrooks Davis const engine::tap_summary exp_summary =
211*b0d29bc4SBrooks Davis engine::tap_summary::new_results(engine::tap_plan(1, 8), 8, 0);
212*b0d29bc4SBrooks Davis ATF_REQUIRE_EQ(exp_summary, summary);
213*b0d29bc4SBrooks Davis }
214*b0d29bc4SBrooks Davis
215*b0d29bc4SBrooks Davis
216*b0d29bc4SBrooks Davis ATF_TEST_CASE_WITHOUT_HEAD(parse_tap_output__some_fail);
ATF_TEST_CASE_BODY(parse_tap_output__some_fail)217*b0d29bc4SBrooks Davis ATF_TEST_CASE_BODY(parse_tap_output__some_fail)
218*b0d29bc4SBrooks Davis {
219*b0d29bc4SBrooks Davis const engine::tap_summary summary = do_parse(
220*b0d29bc4SBrooks Davis "garbage line\n"
221*b0d29bc4SBrooks Davis "not ok - 1 This test failed\n"
222*b0d29bc4SBrooks Davis "ok - 2 This test passed\n"
223*b0d29bc4SBrooks Davis "not ok - 3 This test failed\n"
224*b0d29bc4SBrooks Davis "1..6\n"
225*b0d29bc4SBrooks Davis "not ok - 4 This test failed\n"
226*b0d29bc4SBrooks Davis "ok - 5 This test passed\n"
227*b0d29bc4SBrooks Davis "not ok # Fails as well without a number\n");
228*b0d29bc4SBrooks Davis
229*b0d29bc4SBrooks Davis const engine::tap_summary exp_summary =
230*b0d29bc4SBrooks Davis engine::tap_summary::new_results(engine::tap_plan(1, 6), 2, 4);
231*b0d29bc4SBrooks Davis ATF_REQUIRE_EQ(exp_summary, summary);
232*b0d29bc4SBrooks Davis }
233*b0d29bc4SBrooks Davis
234*b0d29bc4SBrooks Davis
235*b0d29bc4SBrooks Davis ATF_TEST_CASE_WITHOUT_HEAD(parse_tap_output__skip_and_todo_variants);
ATF_TEST_CASE_BODY(parse_tap_output__skip_and_todo_variants)236*b0d29bc4SBrooks Davis ATF_TEST_CASE_BODY(parse_tap_output__skip_and_todo_variants)
237*b0d29bc4SBrooks Davis {
238*b0d29bc4SBrooks Davis const engine::tap_summary summary = do_parse(
239*b0d29bc4SBrooks Davis "1..8\n"
240*b0d29bc4SBrooks Davis "not ok - 1 # SKIP Some reason\n"
241*b0d29bc4SBrooks Davis "not ok - 2 # skip Some reason\n"
242*b0d29bc4SBrooks Davis "not ok - 3 # Skipped Some reason\n"
243*b0d29bc4SBrooks Davis "not ok - 4 # skipped Some reason\n"
244*b0d29bc4SBrooks Davis "not ok - 5 # Skipped: Some reason\n"
245*b0d29bc4SBrooks Davis "not ok - 6 # skipped: Some reason\n"
246*b0d29bc4SBrooks Davis "not ok - 7 # TODO Some reason\n"
247*b0d29bc4SBrooks Davis "not ok - 8 # todo Some reason\n");
248*b0d29bc4SBrooks Davis
249*b0d29bc4SBrooks Davis const engine::tap_summary exp_summary =
250*b0d29bc4SBrooks Davis engine::tap_summary::new_results(engine::tap_plan(1, 8), 8, 0);
251*b0d29bc4SBrooks Davis ATF_REQUIRE_EQ(exp_summary, summary);
252*b0d29bc4SBrooks Davis }
253*b0d29bc4SBrooks Davis
254*b0d29bc4SBrooks Davis
255*b0d29bc4SBrooks Davis ATF_TEST_CASE_WITHOUT_HEAD(parse_tap_output__skip_all_with_reason);
ATF_TEST_CASE_BODY(parse_tap_output__skip_all_with_reason)256*b0d29bc4SBrooks Davis ATF_TEST_CASE_BODY(parse_tap_output__skip_all_with_reason)
257*b0d29bc4SBrooks Davis {
258*b0d29bc4SBrooks Davis const engine::tap_summary summary = do_parse(
259*b0d29bc4SBrooks Davis "1..0 SKIP Some reason for skipping\n"
260*b0d29bc4SBrooks Davis "ok - 1\n"
261*b0d29bc4SBrooks Davis " Some diagnostic message\n"
262*b0d29bc4SBrooks Davis "ok - 6 Doesn't make a difference SKIP\n"
263*b0d29bc4SBrooks Davis "ok - 7 Doesn't make a difference either TODO\n");
264*b0d29bc4SBrooks Davis
265*b0d29bc4SBrooks Davis const engine::tap_summary exp_summary =
266*b0d29bc4SBrooks Davis engine::tap_summary::new_all_skipped("Some reason for skipping");
267*b0d29bc4SBrooks Davis ATF_REQUIRE_EQ(exp_summary, summary);
268*b0d29bc4SBrooks Davis }
269*b0d29bc4SBrooks Davis
270*b0d29bc4SBrooks Davis
271*b0d29bc4SBrooks Davis ATF_TEST_CASE_WITHOUT_HEAD(parse_tap_output__skip_all_without_reason);
ATF_TEST_CASE_BODY(parse_tap_output__skip_all_without_reason)272*b0d29bc4SBrooks Davis ATF_TEST_CASE_BODY(parse_tap_output__skip_all_without_reason)
273*b0d29bc4SBrooks Davis {
274*b0d29bc4SBrooks Davis const engine::tap_summary summary = do_parse(
275*b0d29bc4SBrooks Davis "1..0 unrecognized # garbage skip\n");
276*b0d29bc4SBrooks Davis
277*b0d29bc4SBrooks Davis const engine::tap_summary exp_summary =
278*b0d29bc4SBrooks Davis engine::tap_summary::new_all_skipped("No reason specified");
279*b0d29bc4SBrooks Davis ATF_REQUIRE_EQ(exp_summary, summary);
280*b0d29bc4SBrooks Davis }
281*b0d29bc4SBrooks Davis
282*b0d29bc4SBrooks Davis
283*b0d29bc4SBrooks Davis ATF_TEST_CASE_WITHOUT_HEAD(parse_tap_output__skip_all_invalid);
ATF_TEST_CASE_BODY(parse_tap_output__skip_all_invalid)284*b0d29bc4SBrooks Davis ATF_TEST_CASE_BODY(parse_tap_output__skip_all_invalid)
285*b0d29bc4SBrooks Davis {
286*b0d29bc4SBrooks Davis ATF_REQUIRE_THROW_RE(engine::load_error,
287*b0d29bc4SBrooks Davis "Skipped plan must be 1\\.\\.0",
288*b0d29bc4SBrooks Davis do_parse("1..3 # skip\n"));
289*b0d29bc4SBrooks Davis }
290*b0d29bc4SBrooks Davis
291*b0d29bc4SBrooks Davis
292*b0d29bc4SBrooks Davis ATF_TEST_CASE_WITHOUT_HEAD(parse_tap_output__plan_at_end);
ATF_TEST_CASE_BODY(parse_tap_output__plan_at_end)293*b0d29bc4SBrooks Davis ATF_TEST_CASE_BODY(parse_tap_output__plan_at_end)
294*b0d29bc4SBrooks Davis {
295*b0d29bc4SBrooks Davis const engine::tap_summary summary = do_parse(
296*b0d29bc4SBrooks Davis "ok - 1\n"
297*b0d29bc4SBrooks Davis " Some diagnostic message\n"
298*b0d29bc4SBrooks Davis "ok - 2 This test also passed\n"
299*b0d29bc4SBrooks Davis "garbage line\n"
300*b0d29bc4SBrooks Davis "ok - 3 This test passed\n"
301*b0d29bc4SBrooks Davis "not ok 4 # SKIP Some reason\n"
302*b0d29bc4SBrooks Davis "not ok 5 # TODO Another reason\n"
303*b0d29bc4SBrooks Davis "ok - 6 Doesn't make a difference SKIP\n"
304*b0d29bc4SBrooks Davis "ok - 7 Doesn't make a difference either TODO\n"
305*b0d29bc4SBrooks Davis "1..7\n");
306*b0d29bc4SBrooks Davis
307*b0d29bc4SBrooks Davis const engine::tap_summary exp_summary =
308*b0d29bc4SBrooks Davis engine::tap_summary::new_results(engine::tap_plan(1, 7), 7, 0);
309*b0d29bc4SBrooks Davis ATF_REQUIRE_EQ(exp_summary, summary);
310*b0d29bc4SBrooks Davis }
311*b0d29bc4SBrooks Davis
312*b0d29bc4SBrooks Davis
313*b0d29bc4SBrooks Davis ATF_TEST_CASE_WITHOUT_HEAD(parse_tap_output__stray_oks);
ATF_TEST_CASE_BODY(parse_tap_output__stray_oks)314*b0d29bc4SBrooks Davis ATF_TEST_CASE_BODY(parse_tap_output__stray_oks)
315*b0d29bc4SBrooks Davis {
316*b0d29bc4SBrooks Davis const engine::tap_summary summary = do_parse(
317*b0d29bc4SBrooks Davis "1..3\n"
318*b0d29bc4SBrooks Davis "ok - 1\n"
319*b0d29bc4SBrooks Davis "ok\n"
320*b0d29bc4SBrooks Davis "ok - 2 This test also passed\n"
321*b0d29bc4SBrooks Davis "not ok\n"
322*b0d29bc4SBrooks Davis "ok - 3 This test passed\n");
323*b0d29bc4SBrooks Davis
324*b0d29bc4SBrooks Davis const engine::tap_summary exp_summary =
325*b0d29bc4SBrooks Davis engine::tap_summary::new_results(engine::tap_plan(1, 3), 3, 0);
326*b0d29bc4SBrooks Davis ATF_REQUIRE_EQ(exp_summary, summary);
327*b0d29bc4SBrooks Davis }
328*b0d29bc4SBrooks Davis
329*b0d29bc4SBrooks Davis
330*b0d29bc4SBrooks Davis ATF_TEST_CASE_WITHOUT_HEAD(parse_tap_output__no_plan);
ATF_TEST_CASE_BODY(parse_tap_output__no_plan)331*b0d29bc4SBrooks Davis ATF_TEST_CASE_BODY(parse_tap_output__no_plan)
332*b0d29bc4SBrooks Davis {
333*b0d29bc4SBrooks Davis ATF_REQUIRE_THROW_RE(
334*b0d29bc4SBrooks Davis engine::load_error,
335*b0d29bc4SBrooks Davis "Output did not contain any TAP plan",
336*b0d29bc4SBrooks Davis do_parse(
337*b0d29bc4SBrooks Davis "not ok - 1 This test failed\n"
338*b0d29bc4SBrooks Davis "ok - 2 This test passed\n"));
339*b0d29bc4SBrooks Davis }
340*b0d29bc4SBrooks Davis
341*b0d29bc4SBrooks Davis
342*b0d29bc4SBrooks Davis ATF_TEST_CASE_WITHOUT_HEAD(parse_tap_output__double_plan);
ATF_TEST_CASE_BODY(parse_tap_output__double_plan)343*b0d29bc4SBrooks Davis ATF_TEST_CASE_BODY(parse_tap_output__double_plan)
344*b0d29bc4SBrooks Davis {
345*b0d29bc4SBrooks Davis ATF_REQUIRE_THROW_RE(
346*b0d29bc4SBrooks Davis engine::load_error,
347*b0d29bc4SBrooks Davis "Found duplicate plan",
348*b0d29bc4SBrooks Davis do_parse(
349*b0d29bc4SBrooks Davis "garbage line\n"
350*b0d29bc4SBrooks Davis "1..5\n"
351*b0d29bc4SBrooks Davis "not ok - 1 This test failed\n"
352*b0d29bc4SBrooks Davis "ok - 2 This test passed\n"
353*b0d29bc4SBrooks Davis "1..8\n"
354*b0d29bc4SBrooks Davis "ok\n"));
355*b0d29bc4SBrooks Davis }
356*b0d29bc4SBrooks Davis
357*b0d29bc4SBrooks Davis
358*b0d29bc4SBrooks Davis ATF_TEST_CASE_WITHOUT_HEAD(parse_tap_output__inconsistent_plan);
ATF_TEST_CASE_BODY(parse_tap_output__inconsistent_plan)359*b0d29bc4SBrooks Davis ATF_TEST_CASE_BODY(parse_tap_output__inconsistent_plan)
360*b0d29bc4SBrooks Davis {
361*b0d29bc4SBrooks Davis ATF_REQUIRE_THROW_RE(
362*b0d29bc4SBrooks Davis engine::load_error,
363*b0d29bc4SBrooks Davis "Reported plan differs from actual executed tests",
364*b0d29bc4SBrooks Davis do_parse(
365*b0d29bc4SBrooks Davis "1..3\n"
366*b0d29bc4SBrooks Davis "not ok - 1 This test failed\n"
367*b0d29bc4SBrooks Davis "ok - 2 This test passed\n"));
368*b0d29bc4SBrooks Davis }
369*b0d29bc4SBrooks Davis
370*b0d29bc4SBrooks Davis
371*b0d29bc4SBrooks Davis ATF_TEST_CASE_WITHOUT_HEAD(parse_tap_output__inconsistent_trailing_plan);
ATF_TEST_CASE_BODY(parse_tap_output__inconsistent_trailing_plan)372*b0d29bc4SBrooks Davis ATF_TEST_CASE_BODY(parse_tap_output__inconsistent_trailing_plan)
373*b0d29bc4SBrooks Davis {
374*b0d29bc4SBrooks Davis ATF_REQUIRE_THROW_RE(
375*b0d29bc4SBrooks Davis engine::load_error,
376*b0d29bc4SBrooks Davis "Reported plan differs from actual executed tests",
377*b0d29bc4SBrooks Davis do_parse(
378*b0d29bc4SBrooks Davis "not ok - 1 This test failed\n"
379*b0d29bc4SBrooks Davis "ok - 2 This test passed\n"
380*b0d29bc4SBrooks Davis "1..3\n"));
381*b0d29bc4SBrooks Davis }
382*b0d29bc4SBrooks Davis
383*b0d29bc4SBrooks Davis
384*b0d29bc4SBrooks Davis ATF_TEST_CASE_WITHOUT_HEAD(parse_tap_output__insane_plan);
ATF_TEST_CASE_BODY(parse_tap_output__insane_plan)385*b0d29bc4SBrooks Davis ATF_TEST_CASE_BODY(parse_tap_output__insane_plan)
386*b0d29bc4SBrooks Davis {
387*b0d29bc4SBrooks Davis ATF_REQUIRE_THROW_RE(
388*b0d29bc4SBrooks Davis engine::load_error, "Invalid value",
389*b0d29bc4SBrooks Davis do_parse("120830981209831..234891793874080981092803981092312\n"));
390*b0d29bc4SBrooks Davis }
391*b0d29bc4SBrooks Davis
392*b0d29bc4SBrooks Davis
393*b0d29bc4SBrooks Davis ATF_TEST_CASE_WITHOUT_HEAD(parse_tap_output__reversed_plan);
ATF_TEST_CASE_BODY(parse_tap_output__reversed_plan)394*b0d29bc4SBrooks Davis ATF_TEST_CASE_BODY(parse_tap_output__reversed_plan)
395*b0d29bc4SBrooks Davis {
396*b0d29bc4SBrooks Davis ATF_REQUIRE_THROW_RE(engine::load_error,
397*b0d29bc4SBrooks Davis "Found reversed plan 8\\.\\.5",
398*b0d29bc4SBrooks Davis do_parse("8..5\n"));
399*b0d29bc4SBrooks Davis }
400*b0d29bc4SBrooks Davis
401*b0d29bc4SBrooks Davis
402*b0d29bc4SBrooks Davis ATF_TEST_CASE_WITHOUT_HEAD(parse_tap_output__bail_out);
ATF_TEST_CASE_BODY(parse_tap_output__bail_out)403*b0d29bc4SBrooks Davis ATF_TEST_CASE_BODY(parse_tap_output__bail_out)
404*b0d29bc4SBrooks Davis {
405*b0d29bc4SBrooks Davis const engine::tap_summary summary = do_parse(
406*b0d29bc4SBrooks Davis "1..3\n"
407*b0d29bc4SBrooks Davis "not ok - 1 This test failed\n"
408*b0d29bc4SBrooks Davis "Bail out! There is some unknown problem\n"
409*b0d29bc4SBrooks Davis "ok - 2 This test passed\n");
410*b0d29bc4SBrooks Davis
411*b0d29bc4SBrooks Davis const engine::tap_summary exp_summary =
412*b0d29bc4SBrooks Davis engine::tap_summary::new_bailed_out();
413*b0d29bc4SBrooks Davis ATF_REQUIRE_EQ(exp_summary, summary);
414*b0d29bc4SBrooks Davis }
415*b0d29bc4SBrooks Davis
416*b0d29bc4SBrooks Davis
417*b0d29bc4SBrooks Davis ATF_TEST_CASE_WITHOUT_HEAD(parse_tap_output__bail_out_wins_over_no_plan);
ATF_TEST_CASE_BODY(parse_tap_output__bail_out_wins_over_no_plan)418*b0d29bc4SBrooks Davis ATF_TEST_CASE_BODY(parse_tap_output__bail_out_wins_over_no_plan)
419*b0d29bc4SBrooks Davis {
420*b0d29bc4SBrooks Davis const engine::tap_summary summary = do_parse(
421*b0d29bc4SBrooks Davis "not ok - 1 This test failed\n"
422*b0d29bc4SBrooks Davis "Bail out! There is some unknown problem\n"
423*b0d29bc4SBrooks Davis "ok - 2 This test passed\n");
424*b0d29bc4SBrooks Davis
425*b0d29bc4SBrooks Davis const engine::tap_summary exp_summary =
426*b0d29bc4SBrooks Davis engine::tap_summary::new_bailed_out();
427*b0d29bc4SBrooks Davis ATF_REQUIRE_EQ(exp_summary, summary);
428*b0d29bc4SBrooks Davis }
429*b0d29bc4SBrooks Davis
430*b0d29bc4SBrooks Davis
431*b0d29bc4SBrooks Davis ATF_TEST_CASE_WITHOUT_HEAD(parse_tap_output__open_failure);
ATF_TEST_CASE_BODY(parse_tap_output__open_failure)432*b0d29bc4SBrooks Davis ATF_TEST_CASE_BODY(parse_tap_output__open_failure)
433*b0d29bc4SBrooks Davis {
434*b0d29bc4SBrooks Davis ATF_REQUIRE_THROW_RE(engine::load_error, "hello.txt.*Failed to open",
435*b0d29bc4SBrooks Davis engine::parse_tap_output(fs::path("hello.txt")));
436*b0d29bc4SBrooks Davis }
437*b0d29bc4SBrooks Davis
438*b0d29bc4SBrooks Davis
ATF_INIT_TEST_CASES(tcs)439*b0d29bc4SBrooks Davis ATF_INIT_TEST_CASES(tcs)
440*b0d29bc4SBrooks Davis {
441*b0d29bc4SBrooks Davis ATF_ADD_TEST_CASE(tcs, tap_summary__bailed_out);
442*b0d29bc4SBrooks Davis ATF_ADD_TEST_CASE(tcs, tap_summary__some_results);
443*b0d29bc4SBrooks Davis ATF_ADD_TEST_CASE(tcs, tap_summary__all_skipped);
444*b0d29bc4SBrooks Davis ATF_ADD_TEST_CASE(tcs, tap_summary__equality_operators);
445*b0d29bc4SBrooks Davis ATF_ADD_TEST_CASE(tcs, tap_summary__output);
446*b0d29bc4SBrooks Davis
447*b0d29bc4SBrooks Davis ATF_ADD_TEST_CASE(tcs, parse_tap_output__only_one_result);
448*b0d29bc4SBrooks Davis ATF_ADD_TEST_CASE(tcs, parse_tap_output__all_pass);
449*b0d29bc4SBrooks Davis ATF_ADD_TEST_CASE(tcs, parse_tap_output__some_fail);
450*b0d29bc4SBrooks Davis ATF_ADD_TEST_CASE(tcs, parse_tap_output__skip_and_todo_variants);
451*b0d29bc4SBrooks Davis ATF_ADD_TEST_CASE(tcs, parse_tap_output__skip_all_without_reason);
452*b0d29bc4SBrooks Davis ATF_ADD_TEST_CASE(tcs, parse_tap_output__skip_all_with_reason);
453*b0d29bc4SBrooks Davis ATF_ADD_TEST_CASE(tcs, parse_tap_output__skip_all_invalid);
454*b0d29bc4SBrooks Davis ATF_ADD_TEST_CASE(tcs, parse_tap_output__plan_at_end);
455*b0d29bc4SBrooks Davis ATF_ADD_TEST_CASE(tcs, parse_tap_output__stray_oks);
456*b0d29bc4SBrooks Davis ATF_ADD_TEST_CASE(tcs, parse_tap_output__no_plan);
457*b0d29bc4SBrooks Davis ATF_ADD_TEST_CASE(tcs, parse_tap_output__double_plan);
458*b0d29bc4SBrooks Davis ATF_ADD_TEST_CASE(tcs, parse_tap_output__inconsistent_plan);
459*b0d29bc4SBrooks Davis ATF_ADD_TEST_CASE(tcs, parse_tap_output__inconsistent_trailing_plan);
460*b0d29bc4SBrooks Davis ATF_ADD_TEST_CASE(tcs, parse_tap_output__insane_plan);
461*b0d29bc4SBrooks Davis ATF_ADD_TEST_CASE(tcs, parse_tap_output__reversed_plan);
462*b0d29bc4SBrooks Davis ATF_ADD_TEST_CASE(tcs, parse_tap_output__bail_out);
463*b0d29bc4SBrooks Davis ATF_ADD_TEST_CASE(tcs, parse_tap_output__bail_out_wins_over_no_plan);
464*b0d29bc4SBrooks Davis ATF_ADD_TEST_CASE(tcs, parse_tap_output__open_failure);
465*b0d29bc4SBrooks Davis }
466