Remove building with NOCRYPTO option
[minix3.git] / external / bsd / atf / dist / tools / expand_test.cpp
blobfb59de8db2aec657a857ca61f15451e050622d70
1 //
2 // Automated Testing Framework (atf)
3 //
4 // Copyright (c) 2007 The NetBSD Foundation, Inc.
5 // All rights reserved.
6 //
7 // Redistribution and use in source and binary forms, with or without
8 // modification, are permitted provided that the following conditions
9 // are met:
10 // 1. Redistributions of source code must retain the above copyright
11 // notice, this list of conditions and the following disclaimer.
12 // 2. Redistributions in binary form must reproduce the above copyright
13 // notice, this list of conditions and the following disclaimer in the
14 // documentation and/or other materials provided with the distribution.
16 // THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND
17 // CONTRIBUTORS ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES,
18 // INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
19 // MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
20 // IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS BE LIABLE FOR ANY
21 // DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
22 // DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
23 // GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
24 // INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER
25 // IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
26 // OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
27 // IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
30 #include <cstring>
32 #include <atf-c++.hpp>
34 #include "expand.hpp"
36 // XXX Many of the tests here are duplicated in atf-c/t_expand. Should
37 // find a way to easily share them, or maybe remove the ones here.
39 // ------------------------------------------------------------------------
40 // Test cases for the free functions.
41 // ------------------------------------------------------------------------
43 ATF_TEST_CASE(is_glob);
44 ATF_TEST_CASE_HEAD(is_glob)
46 set_md_var("descr", "Tests the is_glob function.");
48 ATF_TEST_CASE_BODY(is_glob)
50 using tools::expand::is_glob;
52 ATF_REQUIRE(!is_glob(""));
53 ATF_REQUIRE(!is_glob("a"));
54 ATF_REQUIRE(!is_glob("foo"));
56 ATF_REQUIRE( is_glob("*"));
57 ATF_REQUIRE( is_glob("a*"));
58 ATF_REQUIRE( is_glob("*a"));
59 ATF_REQUIRE( is_glob("a*b"));
61 ATF_REQUIRE( is_glob("?"));
62 ATF_REQUIRE( is_glob("a?"));
63 ATF_REQUIRE( is_glob("?a"));
64 ATF_REQUIRE( is_glob("a?b"));
67 ATF_TEST_CASE(matches_glob_plain);
68 ATF_TEST_CASE_HEAD(matches_glob_plain)
70 set_md_var("descr", "Tests the matches_glob function by using plain "
71 "text strings as patterns only.");
73 ATF_TEST_CASE_BODY(matches_glob_plain)
75 using tools::expand::matches_glob;
77 ATF_REQUIRE( matches_glob("", ""));
78 ATF_REQUIRE(!matches_glob("a", ""));
79 ATF_REQUIRE(!matches_glob("", "a"));
81 ATF_REQUIRE( matches_glob("ab", "ab"));
82 ATF_REQUIRE(!matches_glob("abc", "ab"));
83 ATF_REQUIRE(!matches_glob("ab", "abc"));
86 ATF_TEST_CASE(matches_glob_star);
87 ATF_TEST_CASE_HEAD(matches_glob_star)
89 set_md_var("descr", "Tests the matches_glob function by using the '*' "
90 "meta-character as part of the pattern.");
92 ATF_TEST_CASE_BODY(matches_glob_star)
94 using tools::expand::matches_glob;
96 ATF_REQUIRE( matches_glob("*", ""));
97 ATF_REQUIRE( matches_glob("*", "a"));
98 ATF_REQUIRE( matches_glob("*", "ab"));
100 ATF_REQUIRE(!matches_glob("a*", ""));
101 ATF_REQUIRE( matches_glob("a*", "a"));
102 ATF_REQUIRE( matches_glob("a*", "aa"));
103 ATF_REQUIRE( matches_glob("a*", "ab"));
104 ATF_REQUIRE( matches_glob("a*", "abc"));
105 ATF_REQUIRE(!matches_glob("a*", "ba"));
107 ATF_REQUIRE( matches_glob("*a", "a"));
108 ATF_REQUIRE( matches_glob("*a", "ba"));
109 ATF_REQUIRE(!matches_glob("*a", "bc"));
110 ATF_REQUIRE(!matches_glob("*a", "bac"));
112 ATF_REQUIRE( matches_glob("*ab", "ab"));
113 ATF_REQUIRE( matches_glob("*ab", "aab"));
114 ATF_REQUIRE( matches_glob("*ab", "aaab"));
115 ATF_REQUIRE( matches_glob("*ab", "bab"));
116 ATF_REQUIRE(!matches_glob("*ab", "bcb"));
117 ATF_REQUIRE(!matches_glob("*ab", "bacb"));
119 ATF_REQUIRE( matches_glob("a*b", "ab"));
120 ATF_REQUIRE( matches_glob("a*b", "acb"));
121 ATF_REQUIRE( matches_glob("a*b", "acdeb"));
122 ATF_REQUIRE(!matches_glob("a*b", "acdebz"));
123 ATF_REQUIRE(!matches_glob("a*b", "zacdeb"));
126 ATF_TEST_CASE(matches_glob_question);
127 ATF_TEST_CASE_HEAD(matches_glob_question)
129 set_md_var("descr", "Tests the matches_glob function by using the '?' "
130 "meta-character as part of the pattern.");
132 ATF_TEST_CASE_BODY(matches_glob_question)
134 using tools::expand::matches_glob;
136 ATF_REQUIRE(!matches_glob("?", ""));
137 ATF_REQUIRE( matches_glob("?", "a"));
138 ATF_REQUIRE(!matches_glob("?", "ab"));
140 ATF_REQUIRE( matches_glob("?", "b"));
141 ATF_REQUIRE( matches_glob("?", "c"));
143 ATF_REQUIRE( matches_glob("a?", "ab"));
144 ATF_REQUIRE( matches_glob("a?", "ac"));
145 ATF_REQUIRE(!matches_glob("a?", "ca"));
147 ATF_REQUIRE( matches_glob("???", "abc"));
148 ATF_REQUIRE( matches_glob("???", "def"));
149 ATF_REQUIRE(!matches_glob("???", "a"));
150 ATF_REQUIRE(!matches_glob("???", "ab"));
151 ATF_REQUIRE(!matches_glob("???", "abcd"));
154 ATF_TEST_CASE(expand_glob_base);
155 ATF_TEST_CASE_HEAD(expand_glob_base)
157 set_md_var("descr", "Tests the expand_glob function with random "
158 "patterns.");
160 ATF_TEST_CASE_BODY(expand_glob_base)
162 using tools::expand::expand_glob;
164 std::vector< std::string > candidates;
165 candidates.push_back("foo");
166 candidates.push_back("bar");
167 candidates.push_back("baz");
168 candidates.push_back("foobar");
169 candidates.push_back("foobarbaz");
170 candidates.push_back("foobarbazfoo");
172 std::vector< std::string > exps;
174 exps = expand_glob("foo", candidates);
175 ATF_REQUIRE_EQ(exps.size(), 1);
176 ATF_REQUIRE(exps[0] == "foo");
178 exps = expand_glob("bar", candidates);
179 ATF_REQUIRE_EQ(exps.size(), 1);
180 ATF_REQUIRE(exps[0] == "bar");
182 exps = expand_glob("foo*", candidates);
183 ATF_REQUIRE_EQ(exps.size(), 4);
184 ATF_REQUIRE(exps[0] == "foo");
185 ATF_REQUIRE(exps[1] == "foobar");
186 ATF_REQUIRE(exps[2] == "foobarbaz");
187 ATF_REQUIRE(exps[3] == "foobarbazfoo");
189 exps = expand_glob("*foo", candidates);
190 ATF_REQUIRE_EQ(exps.size(), 2);
191 ATF_REQUIRE(exps[0] == "foo");
192 ATF_REQUIRE(exps[1] == "foobarbazfoo");
194 exps = expand_glob("*foo*", candidates);
195 ATF_REQUIRE_EQ(exps.size(), 4);
196 ATF_REQUIRE(exps[0] == "foo");
197 ATF_REQUIRE(exps[1] == "foobar");
198 ATF_REQUIRE(exps[2] == "foobarbaz");
199 ATF_REQUIRE(exps[3] == "foobarbazfoo");
201 exps = expand_glob("ba", candidates);
202 ATF_REQUIRE_EQ(exps.size(), 0);
204 exps = expand_glob("ba*", candidates);
205 ATF_REQUIRE_EQ(exps.size(), 2);
206 ATF_REQUIRE(exps[0] == "bar");
207 ATF_REQUIRE(exps[1] == "baz");
209 exps = expand_glob("*ba", candidates);
210 ATF_REQUIRE_EQ(exps.size(), 0);
212 exps = expand_glob("*ba*", candidates);
213 ATF_REQUIRE_EQ(exps.size(), 5);
214 ATF_REQUIRE(exps[0] == "bar");
215 ATF_REQUIRE(exps[1] == "baz");
216 ATF_REQUIRE(exps[2] == "foobar");
217 ATF_REQUIRE(exps[3] == "foobarbaz");
218 ATF_REQUIRE(exps[4] == "foobarbazfoo");
221 ATF_TEST_CASE(expand_glob_tps);
222 ATF_TEST_CASE_HEAD(expand_glob_tps)
224 set_md_var("descr", "Tests the expand_glob function with patterns that "
225 "match typical test program names. This is just a subcase "
226 "of expand_base, but it is nice to make sure that it really "
227 "works.");
229 ATF_TEST_CASE_BODY(expand_glob_tps)
231 using tools::expand::expand_glob;
233 std::vector< std::string > candidates;
234 candidates.push_back("Atffile");
235 candidates.push_back("h_foo");
236 candidates.push_back("t_foo");
237 candidates.push_back("t_bar");
238 candidates.push_back("t_baz");
239 candidates.push_back("foo_helper");
240 candidates.push_back("foo_test");
241 candidates.push_back("bar_test");
242 candidates.push_back("baz_test");
244 std::vector< std::string > exps;
246 exps = expand_glob("t_*", candidates);
247 ATF_REQUIRE_EQ(exps.size(), 3);
248 ATF_REQUIRE(exps[0] == "t_foo");
249 ATF_REQUIRE(exps[1] == "t_bar");
250 ATF_REQUIRE(exps[2] == "t_baz");
252 exps = expand_glob("*_test", candidates);
253 ATF_REQUIRE_EQ(exps.size(), 3);
254 ATF_REQUIRE(exps[0] == "foo_test");
255 ATF_REQUIRE(exps[1] == "bar_test");
256 ATF_REQUIRE(exps[2] == "baz_test");
259 // ------------------------------------------------------------------------
260 // Main.
261 // ------------------------------------------------------------------------
263 ATF_INIT_TEST_CASES(tcs)
265 // Add the tests for the free functions.
266 ATF_ADD_TEST_CASE(tcs, is_glob);
267 ATF_ADD_TEST_CASE(tcs, matches_glob_plain);
268 ATF_ADD_TEST_CASE(tcs, matches_glob_star);
269 ATF_ADD_TEST_CASE(tcs, matches_glob_question);
270 ATF_ADD_TEST_CASE(tcs, expand_glob_base);
271 ATF_ADD_TEST_CASE(tcs, expand_glob_tps);