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.
This commit is contained in:
Vadim Zeitlin
2026-01-14 14:48:45 +01:00
parent 9c21322c01
commit 547a62eec1
17 changed files with 42 additions and 44 deletions

View File

@@ -3,6 +3,7 @@
# This is currently used for testing under FreeBSD, which is not available at
# the other CI providers already used by SOCI.
env:
CIRRUS_CLONE_SUBMODULES: true
SOCI_CI: true
SOCI_CI_BRANCH: ${CIRRUS_BRANCH}
SOCI_SOURCE_DIR: /tmp/cirrus-ci-build

View File

@@ -141,6 +141,8 @@ jobs:
steps:
- name: Checkout
uses: actions/checkout@v4
with:
submodules: 'recursive'
- name: Set environment variables
shell: bash

3
.gitmodules vendored
View File

@@ -1,3 +1,6 @@
[submodule "3rdparty/sqlite3"]
path = 3rdparty/sqlite3
url = https://github.com/vadz/sqlite-amalgamation.git
[submodule "3rdparty/fmt"]
path = 3rdparty/fmt
url = https://github.com/fmtlib/fmt.git

1
3rdparty/fmt vendored Submodule

Submodule 3rdparty/fmt added at 407c905e45

View File

@@ -121,6 +121,8 @@ endfunction()
include(soci_compiler_options)
include(soci_install_dirs)
add_subdirectory(3rdparty/fmt)
add_subdirectory(src)
include(soci_compat)

View File

@@ -33,6 +33,7 @@ target_link_libraries(soci_tests_common
PUBLIC
soci_compiler_interface
SOCI::Core
fmt::fmt
)
target_include_directories(soci_tests_common

View File

@@ -8,6 +8,8 @@
#define CATCH_CONFIG_RUNNER
#include <catch.hpp>
#include <fmt/format.h>
#include "test-context.h"
using namespace soci;
@@ -19,7 +21,7 @@ int main(int argc, char** argv)
auto* const tc = tests::test_context_base::get_instance_pointer();
if (!tc)
{
std::cerr << "Internal error: each test must create its test context.\n";
fmt::println(stderr, "Internal error: each test must create its test context.");
return EXIT_FAILURE;
}
@@ -47,13 +49,12 @@ int main(int argc, char** argv)
if ( !tc->initialize_connect_string(std::move(argFromCommandLine)) )
{
std::cerr << "usage: " << argv[0]
<< " <connection-string> [test-arguments...]\n";
fmt::println("usage: {} <connection-string> [test-arguments...]", argv[0]);
auto const& dsn = tc->get_example_connection_string();
if ( !dsn.empty() )
{
std::cerr << "example: " << argv[0] << " \'" << dsn << "\'\n";
fmt::println("example: {} '{}'", argv[0], dsn);
}
return EXIT_FAILURE;

View File

@@ -11,6 +11,9 @@
#include <catch.hpp>
#include <fmt/format.h>
#include <fmt/chrono.h>
#include <chrono>
#include <iostream>
@@ -40,9 +43,9 @@ TEST_CASE_METHOD(common_tests, "Reconnect", "[keep-alive][.]")
REQUIRE_NOTHROW( sql.commit() );
CHECK( sql.is_connected() );
std::cout << "Please break connection to the database "
fmt::print(stderr, "Please break connection to the database "
"(stop the server, unplug the network cable, ...) "
"and press Enter" << std::endl;
"and press Enter");
std::cin.get();
using Clock = std::chrono::steady_clock;
@@ -74,12 +77,10 @@ TEST_CASE_METHOD(common_tests, "Reconnect", "[keep-alive][.]")
}
auto const elapsed = Clock::now() - start;
std::cout << "Database query failed after "
<< std::chrono::duration_cast<std::chrono::seconds>(elapsed).count()
<< " seconds as expected.\n"
<< "Now please undo the previous action "
fmt::println("Database query failed after {} seconds as expected.", elapsed);
fmt::println("Now please undo the previous action "
"(restart the server, plug the cable back, ...) "
"and press Enter" << std::endl;
"and press Enter");
std::cin.get();
REQUIRE_NOTHROW( sql.reconnect() );
@@ -110,9 +111,9 @@ TEST_CASE_METHOD(common_tests, "Failover", "[keep-alive][.]")
void started() override
{
std::cout << "Please undo the previous action "
fmt::println("Please undo the previous action "
"(restart the server, plug the cable back, ...) "
"and press Enter" << std::endl;
"and press Enter");
std::cin.get();
}
@@ -146,9 +147,9 @@ TEST_CASE_METHOD(common_tests, "Failover", "[keep-alive][.]")
sql << "insert into soci_test (id) values (:id)", use(id);
REQUIRE_NOTHROW( sql.commit() );
std::cout << "Please break connection to the database "
fmt::println("Please break connection to the database "
"(stop the server, unplug the network cable, ...) "
"and press Enter" << std::endl;
"and press Enter");
std::cin.get();
int id2;

View File

@@ -13,7 +13,6 @@
#include "firebird/common.h"
#include "test-assert.h"
#include "test-context.h"
#include <iostream>
#include <string>
#include <ctime>
#include <cstring>

View File

@@ -13,7 +13,6 @@
#include "soci/mysql/soci-mysql.h"
#include "mysql/test-mysql.h"
#include <string.h>
#include <iostream>
#include <sstream>
#include <string>
#include <vector>
@@ -1106,8 +1105,6 @@ void test14()
sql << "select s5 from soci_test", into(s2);
CHECK(s == s2);
}
std::cout << "test 14 passed" << std::endl;
}
void test15()
@@ -1118,8 +1115,6 @@ void test15()
sql << "select @a := 123", into(n);
CHECK(n == 123);
}
std::cout << "test 15 passed" << std::endl;
}
test_context tc_mysql;

View File

@@ -8,7 +8,6 @@
#include "soci/soci.h"
#include "soci/odbc/soci-odbc.h"
#include "test-context.h"
#include <iostream>
#include <string>
#include <ctime>
#include <cmath>

View File

@@ -257,8 +257,6 @@ TEST_CASE("ODBC/DB2 vector unsigned long long", "[odbc][db2][vector][unsigned][l
}
CHECK(recs == num_recs);
}
std::cout << "test odbc_db2_unsigned_long_long_vector passed" << std::endl;
}
test_context tc_odbc_db2;

View File

@@ -8,7 +8,6 @@
#include "soci/soci.h"
#include "soci/odbc/soci-odbc.h"
#include "test-context.h"
#include <iostream>
#include <string>
#include <ctime>
#include <cmath>

View File

@@ -7,7 +7,6 @@
#include "soci/soci.h"
#include "soci/odbc/soci-odbc.h"
#include <iostream>
#include <string>
#include <ctime>
#include <cmath>

View File

@@ -8,7 +8,6 @@
#include "soci/soci.h"
#include "soci/odbc/soci-odbc.h"
#include "test-context.h"
#include <iostream>
#include <string>
#include <cstdio>
#include <ctime>
@@ -16,6 +15,8 @@
#include <catch.hpp>
#include <fmt/format.h>
using namespace soci;
using namespace soci::tests;
@@ -79,12 +80,6 @@ private:
bool initialized_;
};
std::ostream& operator<<(std::ostream& os, odbc_version const& v)
{
os << v.as_string();
return os;
}
std::string connectString;
backend_factory const &backEnd = *soci::factory_odbc();
@@ -165,7 +160,7 @@ public:
m_verDriver = get_driver_version();
std::cout << "Using ODBC driver version " << m_verDriver << "\n";
fmt::println("Using ODBC driver version {}", m_verDriver.as_string());
return true;
}
@@ -282,7 +277,7 @@ private:
odbc_session = static_cast<odbc_session_backend*>(sql.get_backend());
if (!odbc_session)
{
std::cerr << "Failed to get odbc_session_backend?\n";
fmt::println(stderr, "Failed to get odbc_session_backend?");
return odbc_version();
}
@@ -292,16 +287,16 @@ private:
driver_ver, len, &len);
if (soci::is_odbc_error(rc))
{
std::cerr << "Retrieving ODBC driver version failed: "
<< rc << "\n";
fmt::println(stderr, "Retrieving ODBC driver version failed: {}",
rc);
return odbc_version();
}
odbc_version v;
if (!v.init_from_string(driver_ver))
{
std::cerr << "Unknown ODBC driver version format: \""
<< driver_ver << "\"\n";
fmt::println(stderr, "Unknown ODBC driver version format: \"{}\"",
driver_ver);
}
return v;

View File

@@ -11,7 +11,6 @@
#include "test-context.h"
#include "test-myint.h"
#include <iomanip>
#include <iostream>
#include <string>
#include <cstdlib>
#include <cstring>
@@ -19,6 +18,8 @@
#include <catch.hpp>
#include <fmt/format.h>
using namespace soci;
using namespace soci::tests;
@@ -1546,7 +1547,7 @@ public:
{
if (!soci::getenv("ORACLE_HOME"))
{
std::cerr << "ORACLE_HOME environment variable must be defined for Oracle tests.\n";
fmt::println(stderr, "ORACLE_HOME environment variable must be defined for Oracle tests.");
return false;
}

View File

@@ -9,7 +9,6 @@
#include "soci/postgresql/soci-postgresql.h"
#include "test-context.h"
#include "test-myint.h"
#include <iostream>
#include <sstream>
#include <string>
#include <cmath>
@@ -19,6 +18,8 @@
#include <catch.hpp>
#include <fmt/format.h>
using namespace soci;
using namespace soci::tests;
@@ -1251,7 +1252,7 @@ private:
msession << "DROP TYPE IF EXISTS EnumType ;";
}
catch (soci_error const& e){
std::cerr << e.what() << std::endl;
fmt::println(stderr, "{}", e.what());
}
}
soci::session& msession;
@@ -1333,7 +1334,7 @@ private:
msession << "drop table if exists soci_test;";
}
catch (soci_error const& e){
std::cerr << e.what() << std::endl;
fmt::println(stderr, "{}", e.what());
}
}
soci::session& msession;