1*11be35a1SLionel Sambuc // Copyright 2010 Google Inc.
2*11be35a1SLionel Sambuc // All rights reserved.
3*11be35a1SLionel Sambuc //
4*11be35a1SLionel Sambuc // Redistribution and use in source and binary forms, with or without
5*11be35a1SLionel Sambuc // modification, are permitted provided that the following conditions are
6*11be35a1SLionel Sambuc // met:
7*11be35a1SLionel Sambuc //
8*11be35a1SLionel Sambuc // * Redistributions of source code must retain the above copyright
9*11be35a1SLionel Sambuc // notice, this list of conditions and the following disclaimer.
10*11be35a1SLionel Sambuc // * Redistributions in binary form must reproduce the above copyright
11*11be35a1SLionel Sambuc // notice, this list of conditions and the following disclaimer in the
12*11be35a1SLionel Sambuc // documentation and/or other materials provided with the distribution.
13*11be35a1SLionel Sambuc // * Neither the name of Google Inc. nor the names of its contributors
14*11be35a1SLionel Sambuc // may be used to endorse or promote products derived from this software
15*11be35a1SLionel Sambuc // without specific prior written permission.
16*11be35a1SLionel Sambuc //
17*11be35a1SLionel Sambuc // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
18*11be35a1SLionel Sambuc // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
19*11be35a1SLionel Sambuc // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
20*11be35a1SLionel Sambuc // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
21*11be35a1SLionel Sambuc // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
22*11be35a1SLionel Sambuc // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
23*11be35a1SLionel Sambuc // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
24*11be35a1SLionel Sambuc // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
25*11be35a1SLionel Sambuc // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
26*11be35a1SLionel Sambuc // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
27*11be35a1SLionel Sambuc // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28*11be35a1SLionel Sambuc
29*11be35a1SLionel Sambuc #include "engine/kyuafile.hpp"
30*11be35a1SLionel Sambuc
31*11be35a1SLionel Sambuc #include <stdexcept>
32*11be35a1SLionel Sambuc #include <typeinfo>
33*11be35a1SLionel Sambuc
34*11be35a1SLionel Sambuc #include <atf-c++.hpp>
35*11be35a1SLionel Sambuc #include <lutok/operations.hpp>
36*11be35a1SLionel Sambuc #include <lutok/state.ipp>
37*11be35a1SLionel Sambuc #include <lutok/test_utils.hpp>
38*11be35a1SLionel Sambuc
39*11be35a1SLionel Sambuc #include "engine/exceptions.hpp"
40*11be35a1SLionel Sambuc #include "engine/test_program.hpp"
41*11be35a1SLionel Sambuc #include "utils/datetime.hpp"
42*11be35a1SLionel Sambuc #include "utils/format/macros.hpp"
43*11be35a1SLionel Sambuc #include "utils/fs/operations.hpp"
44*11be35a1SLionel Sambuc #include "utils/optional.ipp"
45*11be35a1SLionel Sambuc
46*11be35a1SLionel Sambuc namespace datetime = utils::datetime;
47*11be35a1SLionel Sambuc namespace fs = utils::fs;
48*11be35a1SLionel Sambuc
49*11be35a1SLionel Sambuc using utils::none;
50*11be35a1SLionel Sambuc
51*11be35a1SLionel Sambuc
52*11be35a1SLionel Sambuc ATF_TEST_CASE_WITHOUT_HEAD(kyuafile__load__empty);
ATF_TEST_CASE_BODY(kyuafile__load__empty)53*11be35a1SLionel Sambuc ATF_TEST_CASE_BODY(kyuafile__load__empty)
54*11be35a1SLionel Sambuc {
55*11be35a1SLionel Sambuc atf::utils::create_file("config", "syntax(2)\n");
56*11be35a1SLionel Sambuc
57*11be35a1SLionel Sambuc const engine::kyuafile suite = engine::kyuafile::load(
58*11be35a1SLionel Sambuc fs::path("config"), none);
59*11be35a1SLionel Sambuc ATF_REQUIRE_EQ(fs::path("."), suite.source_root());
60*11be35a1SLionel Sambuc ATF_REQUIRE_EQ(fs::path("."), suite.build_root());
61*11be35a1SLionel Sambuc ATF_REQUIRE_EQ(0, suite.test_programs().size());
62*11be35a1SLionel Sambuc }
63*11be35a1SLionel Sambuc
64*11be35a1SLionel Sambuc
65*11be35a1SLionel Sambuc ATF_TEST_CASE_WITHOUT_HEAD(kyuafile__load__some_programs);
ATF_TEST_CASE_BODY(kyuafile__load__some_programs)66*11be35a1SLionel Sambuc ATF_TEST_CASE_BODY(kyuafile__load__some_programs)
67*11be35a1SLionel Sambuc {
68*11be35a1SLionel Sambuc atf::utils::create_file(
69*11be35a1SLionel Sambuc "config",
70*11be35a1SLionel Sambuc "syntax(2)\n"
71*11be35a1SLionel Sambuc "test_suite('one-suite')\n"
72*11be35a1SLionel Sambuc "atf_test_program{name='1st'}\n"
73*11be35a1SLionel Sambuc "atf_test_program{name='2nd', test_suite='first'}\n"
74*11be35a1SLionel Sambuc "plain_test_program{name='3rd'}\n"
75*11be35a1SLionel Sambuc "plain_test_program{name='4th', test_suite='second'}\n"
76*11be35a1SLionel Sambuc "include('dir/config')\n");
77*11be35a1SLionel Sambuc
78*11be35a1SLionel Sambuc fs::mkdir(fs::path("dir"), 0755);
79*11be35a1SLionel Sambuc atf::utils::create_file(
80*11be35a1SLionel Sambuc "dir/config",
81*11be35a1SLionel Sambuc "syntax(2)\n"
82*11be35a1SLionel Sambuc "atf_test_program{name='1st', test_suite='other-suite'}\n"
83*11be35a1SLionel Sambuc "include('subdir/config')\n");
84*11be35a1SLionel Sambuc
85*11be35a1SLionel Sambuc fs::mkdir(fs::path("dir/subdir"), 0755);
86*11be35a1SLionel Sambuc atf::utils::create_file(
87*11be35a1SLionel Sambuc "dir/subdir/config",
88*11be35a1SLionel Sambuc "syntax(2)\n"
89*11be35a1SLionel Sambuc "atf_test_program{name='5th', test_suite='last-suite'}\n");
90*11be35a1SLionel Sambuc
91*11be35a1SLionel Sambuc atf::utils::create_file("1st", "");
92*11be35a1SLionel Sambuc atf::utils::create_file("2nd", "");
93*11be35a1SLionel Sambuc atf::utils::create_file("3rd", "");
94*11be35a1SLionel Sambuc atf::utils::create_file("4th", "");
95*11be35a1SLionel Sambuc atf::utils::create_file("dir/1st", "");
96*11be35a1SLionel Sambuc atf::utils::create_file("dir/subdir/5th", "");
97*11be35a1SLionel Sambuc
98*11be35a1SLionel Sambuc const engine::kyuafile suite = engine::kyuafile::load(
99*11be35a1SLionel Sambuc fs::path("config"), none);
100*11be35a1SLionel Sambuc ATF_REQUIRE_EQ(fs::path("."), suite.source_root());
101*11be35a1SLionel Sambuc ATF_REQUIRE_EQ(fs::path("."), suite.build_root());
102*11be35a1SLionel Sambuc ATF_REQUIRE_EQ(6, suite.test_programs().size());
103*11be35a1SLionel Sambuc
104*11be35a1SLionel Sambuc ATF_REQUIRE_EQ("atf", suite.test_programs()[0]->interface_name());
105*11be35a1SLionel Sambuc ATF_REQUIRE_EQ(fs::path("1st"), suite.test_programs()[0]->relative_path());
106*11be35a1SLionel Sambuc ATF_REQUIRE_EQ("one-suite", suite.test_programs()[0]->test_suite_name());
107*11be35a1SLionel Sambuc
108*11be35a1SLionel Sambuc ATF_REQUIRE_EQ("atf", suite.test_programs()[1]->interface_name());
109*11be35a1SLionel Sambuc ATF_REQUIRE_EQ(fs::path("2nd"), suite.test_programs()[1]->relative_path());
110*11be35a1SLionel Sambuc ATF_REQUIRE_EQ("first", suite.test_programs()[1]->test_suite_name());
111*11be35a1SLionel Sambuc
112*11be35a1SLionel Sambuc ATF_REQUIRE_EQ("plain", suite.test_programs()[2]->interface_name());
113*11be35a1SLionel Sambuc ATF_REQUIRE_EQ(fs::path("3rd"), suite.test_programs()[2]->relative_path());
114*11be35a1SLionel Sambuc ATF_REQUIRE_EQ("one-suite", suite.test_programs()[2]->test_suite_name());
115*11be35a1SLionel Sambuc
116*11be35a1SLionel Sambuc ATF_REQUIRE_EQ("plain", suite.test_programs()[3]->interface_name());
117*11be35a1SLionel Sambuc ATF_REQUIRE_EQ(fs::path("4th"), suite.test_programs()[3]->relative_path());
118*11be35a1SLionel Sambuc ATF_REQUIRE_EQ("second", suite.test_programs()[3]->test_suite_name());
119*11be35a1SLionel Sambuc
120*11be35a1SLionel Sambuc ATF_REQUIRE_EQ("atf", suite.test_programs()[4]->interface_name());
121*11be35a1SLionel Sambuc ATF_REQUIRE_EQ(fs::path("dir/1st"),
122*11be35a1SLionel Sambuc suite.test_programs()[4]->relative_path());
123*11be35a1SLionel Sambuc ATF_REQUIRE_EQ("other-suite", suite.test_programs()[4]->test_suite_name());
124*11be35a1SLionel Sambuc
125*11be35a1SLionel Sambuc ATF_REQUIRE_EQ("atf", suite.test_programs()[5]->interface_name());
126*11be35a1SLionel Sambuc ATF_REQUIRE_EQ(fs::path("dir/subdir/5th"),
127*11be35a1SLionel Sambuc suite.test_programs()[5]->relative_path());
128*11be35a1SLionel Sambuc ATF_REQUIRE_EQ("last-suite", suite.test_programs()[5]->test_suite_name());
129*11be35a1SLionel Sambuc }
130*11be35a1SLionel Sambuc
131*11be35a1SLionel Sambuc
132*11be35a1SLionel Sambuc ATF_TEST_CASE_WITHOUT_HEAD(kyuafile__load__metadata);
ATF_TEST_CASE_BODY(kyuafile__load__metadata)133*11be35a1SLionel Sambuc ATF_TEST_CASE_BODY(kyuafile__load__metadata)
134*11be35a1SLionel Sambuc {
135*11be35a1SLionel Sambuc atf::utils::create_file(
136*11be35a1SLionel Sambuc "config",
137*11be35a1SLionel Sambuc "syntax(2)\n"
138*11be35a1SLionel Sambuc "atf_test_program{name='1st', test_suite='first',"
139*11be35a1SLionel Sambuc " allowed_architectures='amd64 i386', timeout=15}\n"
140*11be35a1SLionel Sambuc "plain_test_program{name='2nd', test_suite='second',"
141*11be35a1SLionel Sambuc " required_files='foo /bar//baz', required_user='root'}\n");
142*11be35a1SLionel Sambuc atf::utils::create_file("1st", "");
143*11be35a1SLionel Sambuc atf::utils::create_file("2nd", "");
144*11be35a1SLionel Sambuc
145*11be35a1SLionel Sambuc const engine::kyuafile suite = engine::kyuafile::load(
146*11be35a1SLionel Sambuc fs::path("config"), none);
147*11be35a1SLionel Sambuc ATF_REQUIRE_EQ(2, suite.test_programs().size());
148*11be35a1SLionel Sambuc
149*11be35a1SLionel Sambuc ATF_REQUIRE_EQ("atf", suite.test_programs()[0]->interface_name());
150*11be35a1SLionel Sambuc ATF_REQUIRE_EQ(fs::path("1st"), suite.test_programs()[0]->relative_path());
151*11be35a1SLionel Sambuc ATF_REQUIRE_EQ("first", suite.test_programs()[0]->test_suite_name());
152*11be35a1SLionel Sambuc const engine::metadata md1 = engine::metadata_builder()
153*11be35a1SLionel Sambuc .add_allowed_architecture("amd64")
154*11be35a1SLionel Sambuc .add_allowed_architecture("i386")
155*11be35a1SLionel Sambuc .set_timeout(datetime::delta(15, 0))
156*11be35a1SLionel Sambuc .build();
157*11be35a1SLionel Sambuc ATF_REQUIRE_EQ(md1, suite.test_programs()[0]->get_metadata());
158*11be35a1SLionel Sambuc
159*11be35a1SLionel Sambuc ATF_REQUIRE_EQ("plain", suite.test_programs()[1]->interface_name());
160*11be35a1SLionel Sambuc ATF_REQUIRE_EQ(fs::path("2nd"), suite.test_programs()[1]->relative_path());
161*11be35a1SLionel Sambuc ATF_REQUIRE_EQ("second", suite.test_programs()[1]->test_suite_name());
162*11be35a1SLionel Sambuc const engine::metadata md2 = engine::metadata_builder()
163*11be35a1SLionel Sambuc .add_required_file(fs::path("foo"))
164*11be35a1SLionel Sambuc .add_required_file(fs::path("/bar/baz"))
165*11be35a1SLionel Sambuc .set_required_user("root")
166*11be35a1SLionel Sambuc .build();
167*11be35a1SLionel Sambuc ATF_REQUIRE_EQ(md2, suite.test_programs()[1]->get_metadata());
168*11be35a1SLionel Sambuc }
169*11be35a1SLionel Sambuc
170*11be35a1SLionel Sambuc
171*11be35a1SLionel Sambuc ATF_TEST_CASE_WITHOUT_HEAD(kyuafile__load__current_directory);
ATF_TEST_CASE_BODY(kyuafile__load__current_directory)172*11be35a1SLionel Sambuc ATF_TEST_CASE_BODY(kyuafile__load__current_directory)
173*11be35a1SLionel Sambuc {
174*11be35a1SLionel Sambuc atf::utils::create_file(
175*11be35a1SLionel Sambuc "config",
176*11be35a1SLionel Sambuc "syntax(2)\n"
177*11be35a1SLionel Sambuc "atf_test_program{name='one', test_suite='first'}\n"
178*11be35a1SLionel Sambuc "include('config2')\n");
179*11be35a1SLionel Sambuc
180*11be35a1SLionel Sambuc atf::utils::create_file(
181*11be35a1SLionel Sambuc "config2",
182*11be35a1SLionel Sambuc "syntax(2)\n"
183*11be35a1SLionel Sambuc "test_suite('second')\n"
184*11be35a1SLionel Sambuc "atf_test_program{name='two'}\n");
185*11be35a1SLionel Sambuc
186*11be35a1SLionel Sambuc atf::utils::create_file("one", "");
187*11be35a1SLionel Sambuc atf::utils::create_file("two", "");
188*11be35a1SLionel Sambuc
189*11be35a1SLionel Sambuc const engine::kyuafile suite = engine::kyuafile::load(
190*11be35a1SLionel Sambuc fs::path("config"), none);
191*11be35a1SLionel Sambuc ATF_REQUIRE_EQ(fs::path("."), suite.source_root());
192*11be35a1SLionel Sambuc ATF_REQUIRE_EQ(fs::path("."), suite.build_root());
193*11be35a1SLionel Sambuc ATF_REQUIRE_EQ(2, suite.test_programs().size());
194*11be35a1SLionel Sambuc ATF_REQUIRE_EQ(fs::path("one"), suite.test_programs()[0]->relative_path());
195*11be35a1SLionel Sambuc ATF_REQUIRE_EQ("first", suite.test_programs()[0]->test_suite_name());
196*11be35a1SLionel Sambuc ATF_REQUIRE_EQ(fs::path("two"),
197*11be35a1SLionel Sambuc suite.test_programs()[1]->relative_path());
198*11be35a1SLionel Sambuc ATF_REQUIRE_EQ("second", suite.test_programs()[1]->test_suite_name());
199*11be35a1SLionel Sambuc }
200*11be35a1SLionel Sambuc
201*11be35a1SLionel Sambuc
202*11be35a1SLionel Sambuc ATF_TEST_CASE_WITHOUT_HEAD(kyuafile__load__other_directory);
ATF_TEST_CASE_BODY(kyuafile__load__other_directory)203*11be35a1SLionel Sambuc ATF_TEST_CASE_BODY(kyuafile__load__other_directory)
204*11be35a1SLionel Sambuc {
205*11be35a1SLionel Sambuc fs::mkdir(fs::path("root"), 0755);
206*11be35a1SLionel Sambuc atf::utils::create_file(
207*11be35a1SLionel Sambuc "root/config",
208*11be35a1SLionel Sambuc "syntax(2)\n"
209*11be35a1SLionel Sambuc "test_suite('abc')\n"
210*11be35a1SLionel Sambuc "atf_test_program{name='one'}\n"
211*11be35a1SLionel Sambuc "include('dir/config')\n");
212*11be35a1SLionel Sambuc
213*11be35a1SLionel Sambuc fs::mkdir(fs::path("root/dir"), 0755);
214*11be35a1SLionel Sambuc atf::utils::create_file(
215*11be35a1SLionel Sambuc "root/dir/config",
216*11be35a1SLionel Sambuc "syntax(2)\n"
217*11be35a1SLionel Sambuc "test_suite('foo')\n"
218*11be35a1SLionel Sambuc "atf_test_program{name='two', test_suite='def'}\n"
219*11be35a1SLionel Sambuc "atf_test_program{name='three'}\n");
220*11be35a1SLionel Sambuc
221*11be35a1SLionel Sambuc atf::utils::create_file("root/one", "");
222*11be35a1SLionel Sambuc atf::utils::create_file("root/dir/two", "");
223*11be35a1SLionel Sambuc atf::utils::create_file("root/dir/three", "");
224*11be35a1SLionel Sambuc
225*11be35a1SLionel Sambuc const engine::kyuafile suite = engine::kyuafile::load(
226*11be35a1SLionel Sambuc fs::path("root/config"), none);
227*11be35a1SLionel Sambuc ATF_REQUIRE_EQ(fs::path("root"), suite.source_root());
228*11be35a1SLionel Sambuc ATF_REQUIRE_EQ(fs::path("root"), suite.build_root());
229*11be35a1SLionel Sambuc ATF_REQUIRE_EQ(3, suite.test_programs().size());
230*11be35a1SLionel Sambuc ATF_REQUIRE_EQ(fs::path("one"), suite.test_programs()[0]->relative_path());
231*11be35a1SLionel Sambuc ATF_REQUIRE_EQ("abc", suite.test_programs()[0]->test_suite_name());
232*11be35a1SLionel Sambuc ATF_REQUIRE_EQ(fs::path("dir/two"),
233*11be35a1SLionel Sambuc suite.test_programs()[1]->relative_path());
234*11be35a1SLionel Sambuc ATF_REQUIRE_EQ("def", suite.test_programs()[1]->test_suite_name());
235*11be35a1SLionel Sambuc ATF_REQUIRE_EQ(fs::path("dir/three"),
236*11be35a1SLionel Sambuc suite.test_programs()[2]->relative_path());
237*11be35a1SLionel Sambuc ATF_REQUIRE_EQ("foo", suite.test_programs()[2]->test_suite_name());
238*11be35a1SLionel Sambuc }
239*11be35a1SLionel Sambuc
240*11be35a1SLionel Sambuc
241*11be35a1SLionel Sambuc ATF_TEST_CASE_WITHOUT_HEAD(kyuafile__load__build_directory);
ATF_TEST_CASE_BODY(kyuafile__load__build_directory)242*11be35a1SLionel Sambuc ATF_TEST_CASE_BODY(kyuafile__load__build_directory)
243*11be35a1SLionel Sambuc {
244*11be35a1SLionel Sambuc fs::mkdir(fs::path("srcdir"), 0755);
245*11be35a1SLionel Sambuc atf::utils::create_file(
246*11be35a1SLionel Sambuc "srcdir/config",
247*11be35a1SLionel Sambuc "syntax(2)\n"
248*11be35a1SLionel Sambuc "test_suite('abc')\n"
249*11be35a1SLionel Sambuc "atf_test_program{name='one'}\n"
250*11be35a1SLionel Sambuc "include('dir/config')\n");
251*11be35a1SLionel Sambuc
252*11be35a1SLionel Sambuc fs::mkdir(fs::path("srcdir/dir"), 0755);
253*11be35a1SLionel Sambuc atf::utils::create_file(
254*11be35a1SLionel Sambuc "srcdir/dir/config",
255*11be35a1SLionel Sambuc "syntax(2)\n"
256*11be35a1SLionel Sambuc "test_suite('foo')\n"
257*11be35a1SLionel Sambuc "atf_test_program{name='two', test_suite='def'}\n"
258*11be35a1SLionel Sambuc "atf_test_program{name='three'}\n");
259*11be35a1SLionel Sambuc
260*11be35a1SLionel Sambuc fs::mkdir(fs::path("builddir"), 0755);
261*11be35a1SLionel Sambuc atf::utils::create_file("builddir/one", "");
262*11be35a1SLionel Sambuc fs::mkdir(fs::path("builddir/dir"), 0755);
263*11be35a1SLionel Sambuc atf::utils::create_file("builddir/dir/two", "");
264*11be35a1SLionel Sambuc atf::utils::create_file("builddir/dir/three", "");
265*11be35a1SLionel Sambuc
266*11be35a1SLionel Sambuc const engine::kyuafile suite = engine::kyuafile::load(
267*11be35a1SLionel Sambuc fs::path("srcdir/config"), utils::make_optional(fs::path("builddir")));
268*11be35a1SLionel Sambuc ATF_REQUIRE_EQ(fs::path("srcdir"), suite.source_root());
269*11be35a1SLionel Sambuc ATF_REQUIRE_EQ(fs::path("builddir"), suite.build_root());
270*11be35a1SLionel Sambuc ATF_REQUIRE_EQ(3, suite.test_programs().size());
271*11be35a1SLionel Sambuc ATF_REQUIRE_EQ(fs::path("builddir/one").to_absolute(),
272*11be35a1SLionel Sambuc suite.test_programs()[0]->absolute_path());
273*11be35a1SLionel Sambuc ATF_REQUIRE_EQ(fs::path("one"), suite.test_programs()[0]->relative_path());
274*11be35a1SLionel Sambuc ATF_REQUIRE_EQ("abc", suite.test_programs()[0]->test_suite_name());
275*11be35a1SLionel Sambuc ATF_REQUIRE_EQ(fs::path("builddir/dir/two").to_absolute(),
276*11be35a1SLionel Sambuc suite.test_programs()[1]->absolute_path());
277*11be35a1SLionel Sambuc ATF_REQUIRE_EQ(fs::path("dir/two"),
278*11be35a1SLionel Sambuc suite.test_programs()[1]->relative_path());
279*11be35a1SLionel Sambuc ATF_REQUIRE_EQ("def", suite.test_programs()[1]->test_suite_name());
280*11be35a1SLionel Sambuc ATF_REQUIRE_EQ(fs::path("builddir/dir/three").to_absolute(),
281*11be35a1SLionel Sambuc suite.test_programs()[2]->absolute_path());
282*11be35a1SLionel Sambuc ATF_REQUIRE_EQ(fs::path("dir/three"),
283*11be35a1SLionel Sambuc suite.test_programs()[2]->relative_path());
284*11be35a1SLionel Sambuc ATF_REQUIRE_EQ("foo", suite.test_programs()[2]->test_suite_name());
285*11be35a1SLionel Sambuc }
286*11be35a1SLionel Sambuc
287*11be35a1SLionel Sambuc
288*11be35a1SLionel Sambuc ATF_TEST_CASE_WITHOUT_HEAD(kyuafile__load__test_program_not_basename);
ATF_TEST_CASE_BODY(kyuafile__load__test_program_not_basename)289*11be35a1SLionel Sambuc ATF_TEST_CASE_BODY(kyuafile__load__test_program_not_basename)
290*11be35a1SLionel Sambuc {
291*11be35a1SLionel Sambuc atf::utils::create_file(
292*11be35a1SLionel Sambuc "config",
293*11be35a1SLionel Sambuc "syntax(2)\n"
294*11be35a1SLionel Sambuc "test_suite('abc')\n"
295*11be35a1SLionel Sambuc "atf_test_program{name='one'}\n"
296*11be35a1SLionel Sambuc "atf_test_program{name='./ls'}\n");
297*11be35a1SLionel Sambuc
298*11be35a1SLionel Sambuc atf::utils::create_file("one", "");
299*11be35a1SLionel Sambuc ATF_REQUIRE_THROW_RE(engine::load_error, "./ls.*path components",
300*11be35a1SLionel Sambuc engine::kyuafile::load(fs::path("config"), none));
301*11be35a1SLionel Sambuc }
302*11be35a1SLionel Sambuc
303*11be35a1SLionel Sambuc
304*11be35a1SLionel Sambuc ATF_TEST_CASE_WITHOUT_HEAD(kyuafile__load__lua_error);
ATF_TEST_CASE_BODY(kyuafile__load__lua_error)305*11be35a1SLionel Sambuc ATF_TEST_CASE_BODY(kyuafile__load__lua_error)
306*11be35a1SLionel Sambuc {
307*11be35a1SLionel Sambuc atf::utils::create_file("config", "this syntax is invalid\n");
308*11be35a1SLionel Sambuc
309*11be35a1SLionel Sambuc ATF_REQUIRE_THROW(engine::load_error, engine::kyuafile::load(
310*11be35a1SLionel Sambuc fs::path("config"), none));
311*11be35a1SLionel Sambuc }
312*11be35a1SLionel Sambuc
313*11be35a1SLionel Sambuc
314*11be35a1SLionel Sambuc ATF_TEST_CASE_WITHOUT_HEAD(kyuafile__load__syntax__not_called);
ATF_TEST_CASE_BODY(kyuafile__load__syntax__not_called)315*11be35a1SLionel Sambuc ATF_TEST_CASE_BODY(kyuafile__load__syntax__not_called)
316*11be35a1SLionel Sambuc {
317*11be35a1SLionel Sambuc atf::utils::create_file("config", "");
318*11be35a1SLionel Sambuc
319*11be35a1SLionel Sambuc ATF_REQUIRE_THROW_RE(engine::load_error, "syntax.* never called",
320*11be35a1SLionel Sambuc engine::kyuafile::load(fs::path("config"), none));
321*11be35a1SLionel Sambuc }
322*11be35a1SLionel Sambuc
323*11be35a1SLionel Sambuc
324*11be35a1SLionel Sambuc ATF_TEST_CASE_WITHOUT_HEAD(kyuafile__load__syntax__deprecated_format);
ATF_TEST_CASE_BODY(kyuafile__load__syntax__deprecated_format)325*11be35a1SLionel Sambuc ATF_TEST_CASE_BODY(kyuafile__load__syntax__deprecated_format)
326*11be35a1SLionel Sambuc {
327*11be35a1SLionel Sambuc atf::utils::create_file("config", "syntax('kyuafile', 1)\n");
328*11be35a1SLionel Sambuc (void)engine::kyuafile::load(fs::path("config"), none);
329*11be35a1SLionel Sambuc
330*11be35a1SLionel Sambuc atf::utils::create_file("config", "syntax('foo', 1)\n");
331*11be35a1SLionel Sambuc ATF_REQUIRE_THROW_RE(engine::load_error, "must be 'kyuafile'",
332*11be35a1SLionel Sambuc engine::kyuafile::load(fs::path("config"), none));
333*11be35a1SLionel Sambuc
334*11be35a1SLionel Sambuc atf::utils::create_file("config", "syntax('config', 2)\n");
335*11be35a1SLionel Sambuc ATF_REQUIRE_THROW_RE(engine::load_error, "only takes one argument",
336*11be35a1SLionel Sambuc engine::kyuafile::load(fs::path("config"), none));
337*11be35a1SLionel Sambuc }
338*11be35a1SLionel Sambuc
339*11be35a1SLionel Sambuc
340*11be35a1SLionel Sambuc ATF_TEST_CASE_WITHOUT_HEAD(kyuafile__load__syntax__twice);
ATF_TEST_CASE_BODY(kyuafile__load__syntax__twice)341*11be35a1SLionel Sambuc ATF_TEST_CASE_BODY(kyuafile__load__syntax__twice)
342*11be35a1SLionel Sambuc {
343*11be35a1SLionel Sambuc atf::utils::create_file(
344*11be35a1SLionel Sambuc "config",
345*11be35a1SLionel Sambuc "syntax(2)\n"
346*11be35a1SLionel Sambuc "syntax(2)\n");
347*11be35a1SLionel Sambuc
348*11be35a1SLionel Sambuc ATF_REQUIRE_THROW_RE(engine::load_error, "Can only call syntax.* once",
349*11be35a1SLionel Sambuc engine::kyuafile::load(fs::path("config"), none));
350*11be35a1SLionel Sambuc }
351*11be35a1SLionel Sambuc
352*11be35a1SLionel Sambuc
353*11be35a1SLionel Sambuc ATF_TEST_CASE_WITHOUT_HEAD(kyuafile__load__syntax__bad_version);
ATF_TEST_CASE_BODY(kyuafile__load__syntax__bad_version)354*11be35a1SLionel Sambuc ATF_TEST_CASE_BODY(kyuafile__load__syntax__bad_version)
355*11be35a1SLionel Sambuc {
356*11be35a1SLionel Sambuc atf::utils::create_file("config", "syntax(12)\n");
357*11be35a1SLionel Sambuc
358*11be35a1SLionel Sambuc ATF_REQUIRE_THROW_RE(engine::load_error, "Unsupported file version 12",
359*11be35a1SLionel Sambuc engine::kyuafile::load(fs::path("config"), none));
360*11be35a1SLionel Sambuc }
361*11be35a1SLionel Sambuc
362*11be35a1SLionel Sambuc
363*11be35a1SLionel Sambuc ATF_TEST_CASE_WITHOUT_HEAD(kyuafile__load__test_suite__twice);
ATF_TEST_CASE_BODY(kyuafile__load__test_suite__twice)364*11be35a1SLionel Sambuc ATF_TEST_CASE_BODY(kyuafile__load__test_suite__twice)
365*11be35a1SLionel Sambuc {
366*11be35a1SLionel Sambuc atf::utils::create_file(
367*11be35a1SLionel Sambuc "config",
368*11be35a1SLionel Sambuc "syntax(2)\n"
369*11be35a1SLionel Sambuc "test_suite('foo')\n"
370*11be35a1SLionel Sambuc "test_suite('bar')\n");
371*11be35a1SLionel Sambuc
372*11be35a1SLionel Sambuc ATF_REQUIRE_THROW_RE(engine::load_error, "Can only call test_suite.* once",
373*11be35a1SLionel Sambuc engine::kyuafile::load(fs::path("config"), none));
374*11be35a1SLionel Sambuc }
375*11be35a1SLionel Sambuc
376*11be35a1SLionel Sambuc
377*11be35a1SLionel Sambuc ATF_TEST_CASE_WITHOUT_HEAD(kyuafile__load__missing_file);
ATF_TEST_CASE_BODY(kyuafile__load__missing_file)378*11be35a1SLionel Sambuc ATF_TEST_CASE_BODY(kyuafile__load__missing_file)
379*11be35a1SLionel Sambuc {
380*11be35a1SLionel Sambuc ATF_REQUIRE_THROW_RE(engine::load_error, "Load of 'missing' failed",
381*11be35a1SLionel Sambuc engine::kyuafile::load(fs::path("missing"), none));
382*11be35a1SLionel Sambuc }
383*11be35a1SLionel Sambuc
384*11be35a1SLionel Sambuc
385*11be35a1SLionel Sambuc ATF_TEST_CASE_WITHOUT_HEAD(kyuafile__load__missing_test_program);
ATF_TEST_CASE_BODY(kyuafile__load__missing_test_program)386*11be35a1SLionel Sambuc ATF_TEST_CASE_BODY(kyuafile__load__missing_test_program)
387*11be35a1SLionel Sambuc {
388*11be35a1SLionel Sambuc atf::utils::create_file(
389*11be35a1SLionel Sambuc "config",
390*11be35a1SLionel Sambuc "syntax(2)\n"
391*11be35a1SLionel Sambuc "atf_test_program{name='one', test_suite='first'}\n"
392*11be35a1SLionel Sambuc "atf_test_program{name='two', test_suite='first'}\n");
393*11be35a1SLionel Sambuc
394*11be35a1SLionel Sambuc atf::utils::create_file("one", "");
395*11be35a1SLionel Sambuc
396*11be35a1SLionel Sambuc ATF_REQUIRE_THROW_RE(engine::load_error, "Non-existent.*'two'",
397*11be35a1SLionel Sambuc engine::kyuafile::load(fs::path("config"), none));
398*11be35a1SLionel Sambuc }
399*11be35a1SLionel Sambuc
400*11be35a1SLionel Sambuc
ATF_INIT_TEST_CASES(tcs)401*11be35a1SLionel Sambuc ATF_INIT_TEST_CASES(tcs)
402*11be35a1SLionel Sambuc {
403*11be35a1SLionel Sambuc ATF_ADD_TEST_CASE(tcs, kyuafile__load__empty);
404*11be35a1SLionel Sambuc ATF_ADD_TEST_CASE(tcs, kyuafile__load__some_programs);
405*11be35a1SLionel Sambuc ATF_ADD_TEST_CASE(tcs, kyuafile__load__metadata);
406*11be35a1SLionel Sambuc ATF_ADD_TEST_CASE(tcs, kyuafile__load__current_directory);
407*11be35a1SLionel Sambuc ATF_ADD_TEST_CASE(tcs, kyuafile__load__other_directory);
408*11be35a1SLionel Sambuc ATF_ADD_TEST_CASE(tcs, kyuafile__load__build_directory);
409*11be35a1SLionel Sambuc ATF_ADD_TEST_CASE(tcs, kyuafile__load__test_program_not_basename);
410*11be35a1SLionel Sambuc ATF_ADD_TEST_CASE(tcs, kyuafile__load__lua_error);
411*11be35a1SLionel Sambuc ATF_ADD_TEST_CASE(tcs, kyuafile__load__syntax__not_called);
412*11be35a1SLionel Sambuc ATF_ADD_TEST_CASE(tcs, kyuafile__load__syntax__deprecated_format);
413*11be35a1SLionel Sambuc ATF_ADD_TEST_CASE(tcs, kyuafile__load__syntax__twice);
414*11be35a1SLionel Sambuc ATF_ADD_TEST_CASE(tcs, kyuafile__load__syntax__bad_version);
415*11be35a1SLionel Sambuc ATF_ADD_TEST_CASE(tcs, kyuafile__load__test_suite__twice);
416*11be35a1SLionel Sambuc ATF_ADD_TEST_CASE(tcs, kyuafile__load__missing_file);
417*11be35a1SLionel Sambuc ATF_ADD_TEST_CASE(tcs, kyuafile__load__missing_test_program);
418*11be35a1SLionel Sambuc }
419