ores.cpp.component.test_main
Table of Contents
Catch2 main with the project's logging/test-env setup.
Every component's test target links ores.testing, so its main installs the
logging listener, the database lifecycle listener and the OpenSSL cleanup. A
component whose tests link none of that – because it has no database and no
fixture – declares #+test_fixture: none on its component overview, and this
template emits the bare Catch2 session its CMake target can compile.
See the Template variable reference for the complete list of available variables and their semantics.
1. Template
The full template source. Edit here and re-tangle with
compass build --direct tangle_codegen_templates to regenerate
library/templates/cpp_component_test_main.cpp.mustache.
{{! GENERATED FILE — tangled from projects/ores.codegen/library/templates/ores.cpp.component.test_main.org. Edit the org source. }}
{{{cpp_license}}}
{{#component}}
{{#has_test_fixture}}
#include <openssl/crypto.h>
{{/has_test_fixture}}
#include <catch2/catch_session.hpp>
{{#has_test_fixture}}
#include <catch2/reporters/catch_reporter_registrars.hpp>
#include "ores.testing/logging_listener.hpp"
#include "ores.testing/database_lifecycle_listener.hpp"
CATCH_REGISTER_LISTENER(ores::testing::logging_listener)
CATCH_REGISTER_LISTENER(ores::testing::database_lifecycle_listener)
{{/has_test_fixture}}
int main(int argc, char* argv[]) {
{{#has_test_fixture}}
// Runs OPENSSL_cleanup() however main returns.
struct openssl_cleanup final {
~openssl_cleanup() {
OPENSSL_cleanup();
}
} cleanup;
ores::testing::logging_listener::set_test_module_name("{{full_name}}.tests");
{{/has_test_fixture}}
return Catch::Session().run(argc, argv);
}
{{/component}}
2. See also
- Parent facet: ores.cpp.component
- Template variable reference