diff --git a/.cirrus.yml b/.cirrus.yml index c3752f90..4ec88d50 100644 --- a/.cirrus.yml +++ b/.cirrus.yml @@ -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 diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 34b220a6..72ad67e0 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -141,6 +141,8 @@ jobs: steps: - name: Checkout uses: actions/checkout@v4 + with: + submodules: 'recursive' - name: Set environment variables shell: bash diff --git a/.gitmodules b/.gitmodules index 4019cba1..bea8fd73 100644 --- a/.gitmodules +++ b/.gitmodules @@ -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 diff --git a/3rdparty/fmt b/3rdparty/fmt new file mode 160000 index 00000000..407c905e --- /dev/null +++ b/3rdparty/fmt @@ -0,0 +1 @@ +Subproject commit 407c905e45ad75fc29bf0f9bb7c5c2fd3475976f diff --git a/CMakeLists.txt b/CMakeLists.txt index c1dbacd0..fce3ee87 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -121,6 +121,8 @@ endfunction() include(soci_compiler_options) include(soci_install_dirs) +add_subdirectory(3rdparty/fmt) + add_subdirectory(src) include(soci_compat) diff --git a/tests/common/CMakeLists.txt b/tests/common/CMakeLists.txt index 3f726469..74f1c85e 100644 --- a/tests/common/CMakeLists.txt +++ b/tests/common/CMakeLists.txt @@ -33,6 +33,7 @@ target_link_libraries(soci_tests_common PUBLIC soci_compiler_interface SOCI::Core + fmt::fmt ) target_include_directories(soci_tests_common diff --git a/tests/common/test-main.cpp b/tests/common/test-main.cpp index 145d750f..7e22e534 100644 --- a/tests/common/test-main.cpp +++ b/tests/common/test-main.cpp @@ -8,6 +8,8 @@ #define CATCH_CONFIG_RUNNER #include +#include + #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] - << " [test-arguments...]\n"; + fmt::println("usage: {} [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; diff --git a/tests/common/test-manual.cpp b/tests/common/test-manual.cpp index 1113c07d..a112170e 100644 --- a/tests/common/test-manual.cpp +++ b/tests/common/test-manual.cpp @@ -11,6 +11,9 @@ #include +#include +#include + #include #include @@ -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(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; diff --git a/tests/firebird/test-firebird.cpp b/tests/firebird/test-firebird.cpp index 38104d59..d5a42096 100644 --- a/tests/firebird/test-firebird.cpp +++ b/tests/firebird/test-firebird.cpp @@ -13,7 +13,6 @@ #include "firebird/common.h" #include "test-assert.h" #include "test-context.h" -#include #include #include #include diff --git a/tests/mysql/test-mysql.cpp b/tests/mysql/test-mysql.cpp index 26f0d591..7837e44b 100644 --- a/tests/mysql/test-mysql.cpp +++ b/tests/mysql/test-mysql.cpp @@ -13,7 +13,6 @@ #include "soci/mysql/soci-mysql.h" #include "mysql/test-mysql.h" #include -#include #include #include #include @@ -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; diff --git a/tests/odbc/test-odbc-access.cpp b/tests/odbc/test-odbc-access.cpp index f7620e2b..447e1140 100644 --- a/tests/odbc/test-odbc-access.cpp +++ b/tests/odbc/test-odbc-access.cpp @@ -8,7 +8,6 @@ #include "soci/soci.h" #include "soci/odbc/soci-odbc.h" #include "test-context.h" -#include #include #include #include diff --git a/tests/odbc/test-odbc-db2.cpp b/tests/odbc/test-odbc-db2.cpp index df2048e6..3a39ec75 100644 --- a/tests/odbc/test-odbc-db2.cpp +++ b/tests/odbc/test-odbc-db2.cpp @@ -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; diff --git a/tests/odbc/test-odbc-mssql.cpp b/tests/odbc/test-odbc-mssql.cpp index e4666eff..5910fc78 100644 --- a/tests/odbc/test-odbc-mssql.cpp +++ b/tests/odbc/test-odbc-mssql.cpp @@ -8,7 +8,6 @@ #include "soci/soci.h" #include "soci/odbc/soci-odbc.h" #include "test-context.h" -#include #include #include #include diff --git a/tests/odbc/test-odbc-mysql.cpp b/tests/odbc/test-odbc-mysql.cpp index 7c956cbe..bab3cdd0 100644 --- a/tests/odbc/test-odbc-mysql.cpp +++ b/tests/odbc/test-odbc-mysql.cpp @@ -7,7 +7,6 @@ #include "soci/soci.h" #include "soci/odbc/soci-odbc.h" -#include #include #include #include diff --git a/tests/odbc/test-odbc-postgresql.cpp b/tests/odbc/test-odbc-postgresql.cpp index 9191cd26..794bbb45 100644 --- a/tests/odbc/test-odbc-postgresql.cpp +++ b/tests/odbc/test-odbc-postgresql.cpp @@ -8,7 +8,6 @@ #include "soci/soci.h" #include "soci/odbc/soci-odbc.h" #include "test-context.h" -#include #include #include #include @@ -16,6 +15,8 @@ #include +#include + 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(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; diff --git a/tests/oracle/test-oracle.cpp b/tests/oracle/test-oracle.cpp index 7a431fc5..379b1ba7 100644 --- a/tests/oracle/test-oracle.cpp +++ b/tests/oracle/test-oracle.cpp @@ -11,7 +11,6 @@ #include "test-context.h" #include "test-myint.h" #include -#include #include #include #include @@ -19,6 +18,8 @@ #include +#include + 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; } diff --git a/tests/postgresql/test-postgresql.cpp b/tests/postgresql/test-postgresql.cpp index 0e38a3fb..197a4c58 100644 --- a/tests/postgresql/test-postgresql.cpp +++ b/tests/postgresql/test-postgresql.cpp @@ -9,7 +9,6 @@ #include "soci/postgresql/soci-postgresql.h" #include "test-context.h" #include "test-myint.h" -#include #include #include #include @@ -19,6 +18,8 @@ #include +#include + 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;