92SCENARIO(
"Getting a list of files",
"[ioutils::fileUtils]" )
94 std::string basedir =
"/tmp/fileUtils_test/dir";
95 createfiles( basedir );
97 GIVEN(
"a directory with files of various type and names" )
99 WHEN(
"directory only" )
101 std::vector<std::string> fnames;
105 REQUIRE( fnames.size() == 10 );
108 WHEN(
"single extension with ." )
110 std::vector<std::string> fnames;
114 REQUIRE( fnames.size() == 5 );
115 REQUIRE( fnames[0] == basedir +
"/elif_txt_3.txt" );
116 REQUIRE( fnames[1] == basedir +
"/elif_txt_5.txt" );
117 REQUIRE( fnames[2] == basedir +
"/file_txt_1.txt" );
118 REQUIRE( fnames[3] == basedir +
"/file_xtx_2.txt" );
119 REQUIRE( fnames[4] == basedir +
"/file_xtx_4.txt" );
122 WHEN(
"single extension without ." )
124 std::vector<std::string> fnames;
128 REQUIRE( fnames.size() == 5 );
129 REQUIRE( fnames[0] == basedir +
"/elif_txt_3.txt" );
130 REQUIRE( fnames[1] == basedir +
"/elif_txt_5.txt" );
131 REQUIRE( fnames[2] == basedir +
"/file_txt_1.txt" );
132 REQUIRE( fnames[3] == basedir +
"/file_xtx_2.txt" );
133 REQUIRE( fnames[4] == basedir +
"/file_xtx_4.txt" );
136 WHEN(
"different extension with ." )
138 std::vector<std::string> fnames;
142 REQUIRE( fnames.size() == 5 );
143 REQUIRE( fnames[0] == basedir +
"/elif_txt_2.xxx" );
144 REQUIRE( fnames[1] == basedir +
"/elif_txt_4.xxx" );
145 REQUIRE( fnames[2] == basedir +
"/elif_xtx_1.xxx" );
146 REQUIRE( fnames[3] == basedir +
"/file_xtx_3.xxx" );
147 REQUIRE( fnames[4] == basedir +
"/file_xtx_5.xxx" );
150 WHEN(
"a prefix, no extension" )
152 std::vector<std::string> fnames;
156 REQUIRE( fnames.size() == 5 );
157 REQUIRE( fnames[0] == basedir +
"/file_txt_1.txt" );
158 REQUIRE( fnames[1] == basedir +
"/file_xtx_2.txt" );
159 REQUIRE( fnames[2] == basedir +
"/file_xtx_3.xxx" );
160 REQUIRE( fnames[3] == basedir +
"/file_xtx_4.txt" );
161 REQUIRE( fnames[4] == basedir +
"/file_xtx_5.xxx" );
164 WHEN(
"a prefix, with extension with ." )
166 std::vector<std::string> fnames;
170 REQUIRE( fnames.size() == 3 );
171 REQUIRE( fnames[0] == basedir +
"/file_txt_1.txt" );
172 REQUIRE( fnames[1] == basedir +
"/file_xtx_2.txt" );
173 REQUIRE( fnames[2] == basedir +
"/file_xtx_4.txt" );
176 WHEN(
"a substr alone" )
178 std::vector<std::string> fnames;
182 REQUIRE( fnames.size() == 5 );
183 REQUIRE( fnames[0] == basedir +
"/elif_xtx_1.xxx" );
184 REQUIRE( fnames[1] == basedir +
"/file_xtx_2.txt" );
185 REQUIRE( fnames[2] == basedir +
"/file_xtx_3.xxx" );
186 REQUIRE( fnames[3] == basedir +
"/file_xtx_4.txt" );
187 REQUIRE( fnames[4] == basedir +
"/file_xtx_5.xxx" );
190 WHEN(
"a substr which is actually the prefix" )
192 std::vector<std::string> fnames;
196 REQUIRE( fnames.size() == 0 );
199 WHEN(
"a prefix and a substr which is actually the prefix" )
201 std::vector<std::string> fnames;
205 REQUIRE( fnames.size() == 0 );
208 WHEN(
"a prefix, and a substr, no extension" )
210 std::vector<std::string> fnames;
214 REQUIRE( fnames.size() == 4 );
215 REQUIRE( fnames[0] == basedir +
"/file_xtx_2.txt" );
216 REQUIRE( fnames[1] == basedir +
"/file_xtx_3.xxx" );
217 REQUIRE( fnames[2] == basedir +
"/file_xtx_4.txt" );
218 REQUIRE( fnames[3] == basedir +
"/file_xtx_5.xxx" );
221 WHEN(
"a prefix, a substr, and an extension with ." )
223 std::vector<std::string> fnames;
227 REQUIRE( fnames.size() == 2 );
228 REQUIRE( fnames[0] == basedir +
"/file_xtx_2.txt" );
229 REQUIRE( fnames[1] == basedir +
"/file_xtx_4.txt" );
233 GIVEN(
"a directory which does not exist" )
235 std::vector<std::string> fnames;
241 GIVEN(
"a directory which is a file" )
243 std::vector<std::string> fnames;
249 GIVEN(
"a directory which does not exist, verbose = vv" )
251 std::vector<std::string> fnames;
252 mx::error_t errc = mx::ioutils::getFileNames<mx::verbose::vv>( fnames, basedir +
"nf",
"file",
"xtx",
".txt" );
257 GIVEN(
"a directory which is a file, verbose = vv" )
259 std::vector<std::string> fnames;
260 mx::error_t errc = mx::ioutils::getFileNames<mx::verbose::vv>( fnames, basedir +
"/file_xtx_2.txt",
"file",
"xtx",
".txt" );
265 GIVEN(
"a directory which does not exist, verbose = v" )
267 std::vector<std::string> fnames;
268 mx::error_t errc = mx::ioutils::getFileNames<mx::verbose::v>( fnames, basedir +
"nf",
"file",
"xtx",
".txt" );
273 GIVEN(
"a directory which is a file, verbose = v" )
275 std::vector<std::string> fnames;
276 mx::error_t errc = mx::ioutils::getFileNames<mx::verbose::v>( fnames, basedir +
"/file_xtx_2.txt",
"file",
"xtx",
".txt" );
281 GIVEN(
"a directory which does not exist, verbose = o" )
283 std::vector<std::string> fnames;
284 mx::error_t errc = mx::ioutils::getFileNames<mx::verbose::o>( fnames, basedir +
"nf",
"file",
"xtx",
".txt" );
289 GIVEN(
"a directory which is a file, verbose = o" )
291 std::vector<std::string> fnames;
292 mx::error_t errc = mx::ioutils::getFileNames<mx::verbose::o>( fnames, basedir +
"/file_xtx_2.txt",
"file",
"xtx",
".txt" );
error_t getFileNames(std::vector< std::string > &fileNames, const std::string &directory, const std::string &prefix, const std::string &substr, const std::string &extension)
Get a list of file names from the specified directory, specifying a prefix, a substring to match,...