Files
soci/tests/common/test-main.cpp
Vadim Zeitlin 547a62eec1 Add fmt library as submodule and use it in the tests
Replace existing use of std::cout and std::cerr with fmt::print[ln]():
this is simpler and more convenient and also faster to compile.

Also configure all CI jobs to clone submodules, as fmt submodule is
required now.
2026-01-14 23:40:06 +01:00

70 lines
1.9 KiB
C++

//
// Copyright (C) 2024 Vadim Zeitlin
// Distributed under the Boost Software License, Version 1.0.
// (See accompanying file LICENSE_1_0.txt or copy at
// https://www.boost.org/LICENSE_1_0.txt)
//
#define CATCH_CONFIG_RUNNER
#include <catch.hpp>
#include <fmt/format.h>
#include "test-context.h"
using namespace soci;
tests::test_context_base* tests::test_context_base::the_test_context_ = nullptr;
int main(int argc, char** argv)
{
auto* const tc = tests::test_context_base::get_instance_pointer();
if (!tc)
{
fmt::println(stderr, "Internal error: each test must create its test context.");
return EXIT_FAILURE;
}
#ifdef _MSC_VER
// Redirect errors, unrecoverable problems, and assert() failures to STDERR,
// instead of debug message window.
// This hack is required to run assert()-driven tests by Buildbot.
// NOTE: Comment this 2 lines for debugging with Visual C++ debugger to catch assertions inside.
_CrtSetReportMode(_CRT_ERROR, _CRTDBG_MODE_FILE);
_CrtSetReportFile(_CRT_ERROR, _CRTDBG_FILE_STDERR);
#endif //_MSC_VER
std::string argFromCommandLine;
if (argc >= 2 && argv[1][0] != '-')
{
argFromCommandLine = argv[1];
// Replace the connect string with the process name to ensure that
// CATCH uses the correct name in its messages.
argv[1] = argv[0];
argc--;
argv++;
}
if ( !tc->initialize_connect_string(std::move(argFromCommandLine)) )
{
fmt::println("usage: {} <connection-string> [test-arguments...]", argv[0]);
auto const& dsn = tc->get_example_connection_string();
if ( !dsn.empty() )
{
fmt::println("example: {} '{}'", argv[0], dsn);
}
return EXIT_FAILURE;
}
if ( !tc->start_testing() )
{
return EXIT_FAILURE;
}
return Catch::Session().run(argc, argv);
}