38 value = std::stod(s, &pos);
42 ERR(
"The given string '{:s}' is not convertible to double.", s);
47 ERR(
"Only {:d} characters were used for double conversion of string "
53 if (std::isnan(value))
55 ERR(
"The given string '{:s}' results in a NaN value.", s);
74 if (
const char* vtkdiff_exe_environment_variable =
75 std::getenv(
"VTKDIFF_EXE"))
77 std::string
const vtkdiff_exe{vtkdiff_exe_environment_variable};
78 DBUG(
"VTKDIFF_EXE set to {:s}.", vtkdiff_exe);
84 auto const& base_name =
86 if (base_name !=
"vtkdiff")
89 "The VTKDIFF_EXE environment variable does not point to "
90 "'vtkdiff'. VTKDIFF_EXE='{:s}'",
98 "The VTKDIFF_EXE points to a non-existing file. "
107 int const return_value =
115 std::system((vtkdiff_exe +
" --version").c_str());
116 if (return_value == 0)
121 "Calling {:s} from the VTKDIFF_EXE environment variable didn't "
122 "work as expected. Return value was {:d}.",
123 vtkdiff_exe, return_value);
126 std::string
const vtkdiff_exe{
"vtkdiff"};
127 std::vector<std::string>
const paths = {
"",
"bin"};
129 find_if(begin(paths), end(paths),
130 [&vtkdiff_exe](std::string
const& path)
132 int const return_value =
138 return return_value == 0;
140 if (path == end(paths))
152 std::string
const& reference_path,
153 std::string
const& output_directory)
155 if (reference_path.empty())
158 "Reference path containing expected result files can not be "
162 std::string
const vtkdiff = findVtkdiff();
168 for (
auto const& vtkdiff_config : vtkdiff_configs)
170 std::string
const& field_name =
172 vtkdiff_config.getConfigParameter<std::string>(
"field");
173 DBUG(
"vtkdiff will compare field '{:s}'.", field_name);
175 std::vector<std::string> filenames;
176 if (
auto const regex_string =
178 vtkdiff_config.getConfigParameterOptional<std::string>(
"regex"))
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)))
186 auto const filename = p.path().filename().string();
187 if (std::regex_match(filename, regex))
189 DBUG(
" -> matched '{}'", filename);
190 filenames.push_back(filename);
196 std::string filename =
198 vtkdiff_config.getConfigParameter<std::string>(
"file");
201 MPI_Comm_size(PETSC_COMM_WORLD, &mpi_size);
205 MPI_Comm_rank(PETSC_COMM_WORLD, &rank);
209 "_" + std::to_string(rank) +
".vtu";
212 filenames.push_back(filename);
215 if (empty(filenames))
218 "No files from test definitions were added for tests but {} "
220 std::size(vtkdiff_configs),
221 (std::size(vtkdiff_configs) == 1 ?
"test was" :
"tests were"));
224 auto const absolute_tolerance =
226 vtkdiff_config.getConfigParameter<std::string>(
"absolute_tolerance",
228 if (!absolute_tolerance.empty() &&
229 !isConvertibleToDouble(absolute_tolerance))
232 "The absolute tolerance value '{:s}' is not convertible to "
236 std::string
const absolute_tolerance_parameter =
237 "--abs " + absolute_tolerance;
238 auto const relative_tolerance =
240 vtkdiff_config.getConfigParameter<std::string>(
"relative_tolerance",
242 if (!relative_tolerance.empty() &&
243 !isConvertibleToDouble(relative_tolerance))
246 "The relative tolerance value '{:s}' is not convertible to "
250 std::string
const relative_tolerance_parameter =
251 "--rel " + relative_tolerance;
253 for (
auto const& filename : filenames)
255 std::string output_filename =
258 std::string reference_filename =
266 auto const& long_path_indicator = R
"(\\?\)";
269 std::filesystem::absolute(reference_filename).string();
270 reference_filename = std::format("\"{}{}\"", long_path_indicator,
273 std::filesystem::absolute(output_filename).string();
275 std::format(
"\"{}{}\"", long_path_indicator, output_filename);
278 output_filename = safeString(output_filename);
279 reference_filename = safeString(reference_filename);
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);
297 std::vector<int> return_values;
299 back_inserter(return_values),
300 [](std::string
const& command_line)
302 INFO(
"---------- vtkdiff begin ----------");
303 int const return_value = std::system(command_line.c_str());
304 if (return_value != 0)
306 WARN(
"Return value {:d} was returned by '{:s}'.",
307 return_value, command_line);
309 INFO(
"---------- vtkdiff end ----------\n");
312 return !return_values.empty() &&
313 all_of(begin(return_values), end(return_values),
314 [](
int const& return_value) {
return return_value == 0; });
void INFO(fmt::format_string< Args... > fmt, Args &&... args)
void DBUG(fmt::format_string< Args... > fmt, Args &&... args)
void ERR(fmt::format_string< Args... > fmt, Args &&... args)
void WARN(fmt::format_string< Args... > fmt, Args &&... args)
Implementation of the VtuInterface class.
OGS_EXPORT_SYMBOL bool runTests() const
std::vector< std::string > _output_files
std::vector< std::string > _command_lines
TestDefinition(BaseLib::ConfigTree const &config_tree, std::string const &reference_path, std::string const &output_directory)
std::size_t numberOfTests() const
std::vector< std::string > const & getOutputFiles() const
Range< SubtreeIterator > getConfigSubtreeList(std::string const &root) const
bool IsFileExisting(const std::string &strFilename)
Returns true if given file exists.
std::string extractBaseNameWithoutExtension(std::string const &pathname)
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.