Constructs test definition from the config and reference path essentially constructing the command lines to be run on run() function call.
154{
155 if (reference_path.empty())
156 {
158 "Reference path containing expected result files can not be "
159 "empty.");
160 }
161
163
164
166 auto const& vtkdiff_configs = config_tree.getConfigSubtreeList("vtkdiff");
168 for (auto const& vtkdiff_config : vtkdiff_configs)
169 {
170 std::string const& field_name =
172 vtkdiff_config.getConfigParameter<std::string>("field");
173 DBUG(
"vtkdiff will compare field '{:s}'.", field_name);
174
175 std::vector<std::string> filenames;
176 if (auto const regex_string =
178 vtkdiff_config.getConfigParameterOptional<std::string>("regex"))
179 {
180
181 DBUG(
"vtkdiff regex is '{}'.", *regex_string);
182 auto const regex = std::regex(*regex_string);
183 for (auto const& p : std::filesystem::directory_iterator(
184 std::filesystem::path(reference_path)))
185 {
186 auto const filename =
p.path().filename().string();
187 if (std::regex_match(filename, regex))
188 {
189 DBUG(
" -> matched '{}'", filename);
190 filenames.push_back(filename);
191 }
192 }
193 }
194 else
195 {
196 std::string filename =
198 vtkdiff_config.getConfigParameter<std::string>("file");
199#ifdef USE_PETSC
200 int mpi_size;
201 MPI_Comm_size(PETSC_COMM_WORLD, &mpi_size);
202 if (mpi_size > 1)
203 {
204 int rank;
205 MPI_Comm_rank(PETSC_COMM_WORLD, &rank);
206 filename =
208 filename) +
209 "_" + std::to_string(rank) + ".vtu";
210 }
211#endif
212 filenames.push_back(filename);
213 }
214
215 if (empty(filenames))
216 {
218 "No files from test definitions were added for tests but {} "
219 "{:s} specified.",
220 std::size(vtkdiff_configs),
221 (std::size(vtkdiff_configs) == 1 ? "test was" : "tests were"));
222 }
223
224 auto const absolute_tolerance =
226 vtkdiff_config.getConfigParameter<std::string>("absolute_tolerance",
227 "");
228 if (!absolute_tolerance.empty() &&
230 {
232 "The absolute tolerance value '{:s}' is not convertible to "
233 "double.",
234 absolute_tolerance);
235 }
236 std::string const absolute_tolerance_parameter =
237 "--abs " + absolute_tolerance;
238 auto const relative_tolerance =
240 vtkdiff_config.getConfigParameter<std::string>("relative_tolerance",
241 "");
242 if (!relative_tolerance.empty() &&
244 {
246 "The relative tolerance value '{:s}' is not convertible to "
247 "double.",
248 relative_tolerance);
249 }
250 std::string const relative_tolerance_parameter =
251 "--rel " + relative_tolerance;
252
253 for (auto const& filename : filenames)
254 {
255 std::string output_filename =
258 std::string reference_filename =
260#if _WIN32
261
262
263
264
265
266 auto const& long_path_indicator = R"(\\?\)";
267
268 reference_filename =
269 std::filesystem::absolute(reference_filename).string();
270 reference_filename = std::format("\"{}{}\"", long_path_indicator,
271 reference_filename);
272 output_filename =
273 std::filesystem::absolute(output_filename).string();
274 output_filename =
275 std::format("\"{}{}\"", long_path_indicator, output_filename);
276
277#else
278 output_filename =
safeString(output_filename);
279 reference_filename =
safeString(reference_filename);
280#endif
281
282
283
284 std::string command_line =
285 vtkdiff +
" -a " +
safeString(field_name) +
" -b " +
286 safeString(field_name) +
" " + reference_filename +
" " +
287 output_filename + " " + absolute_tolerance_parameter + " " +
288 relative_tolerance_parameter;
289 INFO(
"Will run '{:s}'", command_line);
291 }
292 }
293}
void INFO(fmt::format_string< Args... > fmt, Args &&... args)
void DBUG(fmt::format_string< Args... > fmt, Args &&... args)
std::vector< std::string > _output_files
std::vector< std::string > _command_lines
std::string joinPaths(std::string const &pathA, std::string const &pathB)
std::string getVtuFileNameForPetscOutputWithoutExtension(std::string const &file_name)
std::string findVtkdiff()
bool isConvertibleToDouble(std::string const &s)
Test if the given string is convertible to a valid double value, not a NaN.
std::string safeString(std::string const &s)
Wraps a string into double ticks.