21#ifndef WREPORT_TESTS_UTILS
22#define WREPORT_TESTS_UTILS
30#include <wreport/bulletin.h>
31#include <wreport/fwd.h>
32#include <wreport/notes.h>
33#include <wreport/tests.h>
34#include <wreport/utils/tests.h>
41std::filesystem::path datafile(
const std::filesystem::path& fname);
51std::filesystem::path path_from_env(
const char* varname,
52 const char* deflt =
nullptr);
59std::string slurpfile(
const std::filesystem::path& name);
64std::vector<std::filesystem::path> all_test_files(
const std::string& encoding);
72void dump_jsonl(
const Bulletin& bulletin, std::stringstream& out);
74void track_bulletin(Bulletin& b,
const char* tag,
75 const std::filesystem::path& fname);
77template <
typename BULLETIN>
78std::unique_ptr<BULLETIN> decode_checked(
const std::string& buf,
83 return BULLETIN::decode(buf, name);
85 catch (wreport::error_parse& e)
89 auto h = BULLETIN::decode_header(buf, name);
90 h->print_structured(stderr);
92 catch (wreport::error& e)
94 std::cerr <<
"Dump interrupted: " << e.
what();
100template <
typename BULLETIN>
101std::unique_ptr<BULLETIN> decode_checked(
const std::string& buf,
102 const char* name, FILE* verbose)
106 return BULLETIN::decode_verbose(buf, verbose, name);
108 catch (wreport::error_parse& e1)
112 auto h = BULLETIN::decode_header(buf, name);
113 h->print_structured(stderr);
115 catch (wreport::error& e2)
117 std::cerr <<
"Dump interrupted: " << e2.
what();
123template <
typename BULLETIN>
struct TestCodec
125 std::filesystem::path fname;
126 std::function<void(
const BULLETIN&)> check_contents =
127 [](
const BULLETIN&)
noexcept {};
129 explicit TestCodec(
const std::filesystem::path& fname) : fname(fname) {}
130 virtual ~TestCodec() {}
135void assert_var_equal(
const Var& actual,
const Var& expected);
136void assert_var_not_equal(
const Var& actual,
const Var& expected);
137template <
typename Val>
138void assert_var_value_equal(
const Var& actual, Val expected);
139template <
typename Val>
140void assert_var_value_not_equal(
const Var& actual, Val expected);
142struct ActualVar :
public Actual<Var>
144 explicit ActualVar(
const Var& actual) : Actual<Var>(actual) {}
146 void operator==(
const Var& expected)
const
148 assert_var_equal(_actual, expected);
150 void operator!=(
const Var& expected)
const
152 assert_var_not_equal(_actual, expected);
154 template <
typename Val>
void operator==(Val expected)
const
156 assert_var_value_equal(_actual, expected);
158 template <
typename Val>
void operator!=(Val expected)
const
160 assert_var_value_not_equal(_actual, expected);
163 void isunset()
const;
173 using Actual::Actual;
175 void operator==(
Varcode expected)
const;
176 void operator!=(
Varcode expected)
const;
A physical variable.
Definition var.h:25
const char * what() const noexcept override=0
Error message.
String functions.
Definition benchmark.h:13
uint16_t Varcode
Holds the WMO variable code of a variable.
Definition fwd.h:12
Implement fast access to information about WMO variables.