HART  0.2.0
High level Audio Regression and Testing
Loading...
Searching...
No Matches
hart.hpp
Go to the documentation of this file.
1#pragma once
2
3#if defined (HART_IMPLEMENTATION)
4#define DR_WAV_IMPLEMENTATION // Wav single header library's implementation
5#endif
6
7#include <stdexcept>
8
11#include "dsp/hart_dsp_all.hpp"
13#include "envelopes/hart_envelopes_all.hpp"
17#include "matchers/hart_matchers_all.hpp"
18#include "metrics/hart_metrics_all.hpp"
22#include "signals/hart_signals_all.hpp"
24#include "hart_str.hpp"
26#include "hart_units.hpp"
28
29namespace hart
30{
31
32/// @brief Fails a test case unconditionally with a text message
33/// @param message Message to be displayed
34/// @ingroup TestRunner
35#define HART_FAIL_TEST_MSG(message) throw hart::TestAssertException (std::string ("HART_FAIL_TEST_MSG() triggered test fail at line ") + std::to_string (__LINE__) + " with message: \"" + message + '\"')
36
37/// @brief Fails a test case unconditionally
38/// @ingroup TestRunner
39#define HART_FAIL_TEST() throw hart::TestAssertException (std::string ("HART_FAIL_TEST() triggered test fail at line ") + std::to_string (__LINE__))
40
41#define HART_CONCAT_IMPL(x, y) x##y
42#define HART_CONCAT(x, y) HART_CONCAT_IMPL(x, y)
43#define HART_UNIQUE_ID(x) HART_CONCAT(x, __LINE__)
44
45#define HART_ITEM_WITH_TAGS(name, tags, category)
46 static void HART_UNIQUE_ID(HART_RunTask)();
47 namespace {
48 struct HART_UNIQUE_ID(HART_RegistrarType) {
49 HART_UNIQUE_ID(HART_RegistrarType)() {
50 hart::TestRegistry::getInstance().add (name, tags, __FILE__, __LINE__, category, &HART_UNIQUE_ID (HART_RunTask));
51 }
52 };
53 }
54 static HART_UNIQUE_ID(HART_RegistrarType) HART_UNIQUE_ID(HART_registrar);
55 static void HART_UNIQUE_ID(HART_RunTask)()
56
57/// @brief Declares a test case with tags
58/// @warning Tags aren't supported yet
59/// @param name Name for the test case
60/// @param tags Tags like "[my-tag-1][my-tag-2]"
61/// @ingroup TestRunner
62#define HART_TEST_WITH_TAGS(name, tags) HART_ITEM_WITH_TAGS(name, tags, hart::TaskCategory::test)
63
64/// @brief Declares a generator with tags
65/// @details Pretty much the same as a usual test case, but will be called only if the `--run-generators` CLI flag is set
66/// @warning Tags aren't supported yet
67/// @param name Name for the generator
68/// @param tags Tags like "[my-tag-1][my-tag-2]"
69/// @ingroup TestRunner
70#define HART_GENERATE_WITH_TAGS(name, tags) HART_ITEM_WITH_TAGS(name, tags, hart::TaskCategory::generate)
71
72/// @brief Declares a test case
73/// @param name Name for the test case
74/// @ingroup TestRunner
75#define HART_TEST(name) HART_TEST_WITH_TAGS(name, "")
76
77/// @brief Declares a generator
78/// @details Pretty much the same as a usual test case, but will be called only if the `--run-generators` CLI flag is set
79/// @param name Name for generator
80/// @ingroup TestRunner
81#define HART_GENERATE(name) HART_GENERATE_WITH_TAGS(name, "")
82
83#if HART_DO_NOT_THROW_EXCEPTIONS
84/// @brief Put it at the beginning of your tese case if it requires a properly set data path
85/// @details For example, when using relative paths to the wav files. The test will instantly fail is the path is not set.
86/// @ingroup TestRunner
87#define HART_REQUIRES_DATA_PATH_ARG if (hart::CLIConfig::getInstance().getDataRootPath().empty()) { hart::ExpectationFailureMessages::get().emplace_back ("This test requires a data path set by the --data-root-path CLI argument, but it's empty"); return; }
88#else
89/// @brief Put it at the beginning of your tese case if it requires a properly set data path
90/// @details For example, when using relative paths to the wav files. The test will instantly fail is the path is not set.
91/// @ingroup TestRunner
92#define HART_REQUIRES_DATA_PATH_ARG if (hart::CLIConfig::getInstance().getDataRootPath().empty()) { throw hart::ConfigurationError ("This test requires a data path set by the --data-root-path CLI argument, but it's empty"); }
93#endif // HART_DO_NOT_THROW_EXCEPTIONS
94
95/// @brief Runs all tests or generators
96/// @details Place this macro in your `main()` function
97/// @ingroup TestRunner
98#define HART_RUN_ALL_TESTS(argc, argv)
99 do
100 {
101 hart::CLIConfig::getInstance().initCommandLineArgs();
102 CLI11_PARSE (hart::CLIConfig::getInstance().getCLIApp(), argc, argv);
103 return hart::TestRegistry::getInstance().runAll();
104 }
105 while (false);
106
107/// @brief Put it before you test cases to use hart classes without hart:: namespace prefix and explicit `float` template value
108#define HART_DECLARE_ALIASES_FOR_FLOAT using namespace hart::aliases_float
109
110/// @brief Put it before you test cases to use hart classes without hart:: namespace prefix and explicit `double` template value
111#define HART_DECLARE_ALIASES_FOR_DOUBLE using namespace hart::aliases_double
112
113} // namespace hart
#define HART_GENERATE_WITH_TAGS(name, tags)
Declares a generator with tags.
Definition hart.hpp:70
#define HART_TEST_WITH_TAGS(name, tags)
Declares a test case with tags.
Definition hart.hpp:62
#define HART_CONCAT(x, y)
Definition hart.hpp:42
#define HART_UNIQUE_ID(x)
Definition hart.hpp:43
#define HART_CONCAT_IMPL(x, y)
Definition hart.hpp:41
#define HART_ITEM_WITH_TAGS(name, tags, category)
Definition hart.hpp:45