combine repetitive code into convenience function
This commit is contained in:
@ -16,16 +16,19 @@
|
||||
#include "test_config.h"
|
||||
#include "test_config_reader.h"
|
||||
#include "utils.h"
|
||||
#include "yaml_writer.h"
|
||||
#include "gmock/gmock.h"
|
||||
#include "gtest/gtest.h"
|
||||
|
||||
#include <cstdlib>
|
||||
#include <cstring>
|
||||
#include <ctime>
|
||||
#include <iostream>
|
||||
#include <mpi.h>
|
||||
#include <vector>
|
||||
|
||||
using LAMMPS_NS::utils::split_words;
|
||||
using LAMMPS_NS::utils::trim;
|
||||
|
||||
// common read_yaml_file function
|
||||
bool read_yaml_file(const char *infile, TestConfig &config)
|
||||
@ -37,6 +40,55 @@ bool read_yaml_file(const char *infile, TestConfig &config)
|
||||
return true;
|
||||
}
|
||||
|
||||
// write out common header items for yaml files
|
||||
void write_yaml_header(YamlWriter *writer,
|
||||
TestConfig *cfg,
|
||||
const char *version)
|
||||
{
|
||||
// lammps_version
|
||||
writer->emit("lammps_version", version);
|
||||
|
||||
// date_generated
|
||||
std::time_t now = time(NULL);
|
||||
std::string block = trim(ctime(&now));
|
||||
writer->emit("date_generated", block);
|
||||
|
||||
// epsilon
|
||||
writer->emit("epsilon", cfg->epsilon);
|
||||
|
||||
// skip tests
|
||||
block.clear();
|
||||
for (auto &skip : cfg->skip_tests) {
|
||||
if (block.empty()) block = skip;
|
||||
else block += " " + skip;
|
||||
}
|
||||
writer->emit("skip_tests", block);
|
||||
|
||||
// prerequisites
|
||||
block.clear();
|
||||
for (auto &prerequisite : cfg->prerequisites) {
|
||||
block += prerequisite.first + " " + prerequisite.second + "\n";
|
||||
}
|
||||
writer->emit_block("prerequisites", block);
|
||||
|
||||
// pre_commands
|
||||
block.clear();
|
||||
for (auto &command : cfg->pre_commands) {
|
||||
block += command + "\n";
|
||||
}
|
||||
writer->emit_block("pre_commands", block);
|
||||
|
||||
// post_commands
|
||||
block.clear();
|
||||
for (auto &command : cfg->post_commands) {
|
||||
block += command + "\n";
|
||||
}
|
||||
writer->emit_block("post_commands", block);
|
||||
|
||||
// input_file
|
||||
writer->emit("input_file", cfg->input_file);
|
||||
}
|
||||
|
||||
// need to be defined in unit test body
|
||||
extern void generate_yaml_file(const char *, const TestConfig &);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user