Constructs test definition from the config and reference path essentially constructing the command lines to be run on run() function call.
146{
147 if (reference_path.empty())
148 {
150 "Reference path containing expected result files can not be "
151 "empty.");
152 }
153
155
156
158 auto const& vtkdiff_configs = config_tree.getConfigSubtreeList("vtkdiff");
160 for (auto const& vtkdiff_config : vtkdiff_configs)
161 {
162 std::string const& field_name =
164 vtkdiff_config.getConfigParameter<std::string>("field");
165 DBUG(
"vtkdiff will compare field '{:s}'.", field_name);
166
167 std::vector<std::string> filenames;
168 if (auto const regex_string =
170 vtkdiff_config.getConfigParameterOptional<std::string>("regex"))
171 {
172
173 DBUG(
"vtkdiff regex is '{}'.", *regex_string);
174 auto const regex = std::regex(*regex_string);
175 for (auto const& p : std::filesystem::directory_iterator(
176 std::filesystem::path(reference_path)))
177 {
178 auto const filename = p.path().filename().string();
179 if (std::regex_match(filename, regex))
180 {
181 DBUG(
" -> matched '{}'", filename);
182 filenames.push_back(filename);
183 }
184 }
185 }
186 else
187 {
188 std::string filename =
190 vtkdiff_config.getConfigParameter<std::string>("file");
191#ifdef USE_PETSC
192 BaseLib::MPI::Mpi mpi;
193 if (mpi.size > 1)
194 {
195 filename =
197 filename) +
198 "_" + std::to_string(mpi.rank) + ".vtu";
199 }
200#endif
201 filenames.push_back(filename);
202 }
203
204 if (empty(filenames))
205 {
207 "No files from test definitions were added for tests but {} "
208 "{:s} specified.",
209 std::size(vtkdiff_configs),
210 (std::size(vtkdiff_configs) == 1 ? "test was" : "tests were"));
211 }
212
213 auto const absolute_tolerance =
215 vtkdiff_config.getConfigParameter<std::string>("absolute_tolerance",
216 "");
217 if (!absolute_tolerance.empty() &&
219 {
221 "The absolute tolerance value '{:s}' is not convertible to "
222 "double.",
223 absolute_tolerance);
224 }
225 std::string const absolute_tolerance_parameter =
226 "--abs " + absolute_tolerance;
227 auto const relative_tolerance =
229 vtkdiff_config.getConfigParameter<std::string>("relative_tolerance",
230 "");
231 if (!relative_tolerance.empty() &&
233 {
235 "The relative tolerance value '{:s}' is not convertible to "
236 "double.",
237 relative_tolerance);
238 }
239 std::string const relative_tolerance_parameter =
240 "--rel " + relative_tolerance;
241
242 for (auto const& filename : filenames)
243 {
244 std::string output_filename =
247 std::string reference_filename =
249#if _WIN32
250
251
252
253
254
255 auto const& long_path_indicator = R"(\\?\)";
256
257 reference_filename =
258 std::filesystem::absolute(reference_filename).string();
259 reference_filename = std::format("\"{}{}\"", long_path_indicator,
260 reference_filename);
261 output_filename =
262 std::filesystem::absolute(output_filename).string();
263 output_filename =
264 std::format("\"{}{}\"", long_path_indicator, output_filename);
265
266#else
267 output_filename =
safeString(output_filename);
268 reference_filename =
safeString(reference_filename);
269#endif
270
271
272
273 std::string command_line =
274 vtkdiff +
" -a " +
safeString(field_name) +
" -b " +
275 safeString(field_name) +
" " + reference_filename +
" " +
276 output_filename + " " + absolute_tolerance_parameter + " " +
277 relative_tolerance_parameter;
278 INFO(
"Will run '{:s}'", command_line);
280 }
281 }
282}
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.