From 460557c6e0d6ea8ed996e38c72db3b0492ee3098 Mon Sep 17 00:00:00 2001 From: Daniel Evers Date: Mon, 28 Jan 2019 10:10:08 +0100 Subject: [PATCH] Added string_view tests and C++17 tests for travis --- .travis.yml | 4 +++- test_constraints/CMakeLists.txt | 6 ++++++ test_serializer/CMakeLists.txt | 7 +++++++ test_serializer/Insert.cpp | 6 ++++++ test_serializer/Where.cpp | 5 +++++ test_static_asserts/CMakeLists.txt | 6 ++++++ test_types/CMakeLists.txt | 6 ++++++ tests/CMakeLists.txt | 6 ++++++ 8 files changed, 45 insertions(+), 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index f94d0e1b..e07bb015 100644 --- a/.travis.yml +++ b/.travis.yml @@ -13,6 +13,7 @@ compiler: env: - CONFIG=Release + - CONFIG=Release TESTS_CXX_STD=17 #- CONFIG=Debug notifications: @@ -40,7 +41,8 @@ before_script: - cmake .. -DCMAKE_BUILD_TYPE=$CONFIG -DCMAKE_PREFIX_PATH=$PWD/../date script: - - cmake --build . --config $CONFIG + - [[ -n "$TESTS_CXX_STD" ]] && ARGS="-DSQLPP11_TESTS_CXX_STD=$TESTS_CXX_STD" + - cmake --build . --config $CONFIG $ARGS - ctest --output-on-failure after_script: diff --git a/test_constraints/CMakeLists.txt b/test_constraints/CMakeLists.txt index 1bfda1ed..e88f1a02 100644 --- a/test_constraints/CMakeLists.txt +++ b/test_constraints/CMakeLists.txt @@ -31,6 +31,12 @@ function(test_constraint name pattern) COMMAND ${CMAKE_COMMAND} --build ${CMAKE_BINARY_DIR} --target ${target} ) set_property(TEST ${test} PROPERTY PASS_REGULAR_EXPRESSION ${pattern}) + # conditionally bump to a higher C++ standard to test compatibility + if (SQLPP11_TESTS_CXX_STD) + set_property(TARGET ${target} PROPERTY CXX_STANDARD ${SQLPP11_TESTS_CXX_STD}) + set_property(TARGET ${target} PROPERTY CXX_STANDARD_REQUIRED yes) + set_property(TARGET ${target} PROPERTY CXX_EXTENSIONS no) + endif() endfunction() # Compiling these is required to fail (testing some static_assert) diff --git a/test_serializer/CMakeLists.txt b/test_serializer/CMakeLists.txt index 042908e0..2e20950c 100644 --- a/test_serializer/CMakeLists.txt +++ b/test_serializer/CMakeLists.txt @@ -38,6 +38,13 @@ create_test_sourcelist(test_serializer_sources test_serializer_main.cpp ${test_s add_executable(sqlpp11_test_serializer ${test_serializer_sources}) target_link_libraries(sqlpp11_test_serializer PRIVATE sqlpp11 sqlpp11_testing) +# conditionally bump to a higher C++ standard to test compatibility +if (SQLPP11_TESTS_CXX_STD) + set_property(TARGET sqlpp11_test_serializer PROPERTY CXX_STANDARD ${SQLPP11_TESTS_CXX_STD}) + set_property(TARGET sqlpp11_test_serializer PROPERTY CXX_STANDARD_REQUIRED yes) + set_property(TARGET sqlpp11_test_serializer PROPERTY CXX_EXTENSIONS no) +endif() + foreach(test_serializer IN LISTS test_serializer_names) add_test(NAME sqlpp11.test_serializer.${test_serializer} COMMAND sqlpp11_test_serializer ${test_serializer} diff --git a/test_serializer/Insert.cpp b/test_serializer/Insert.cpp index e145cf7d..5cacf6eb 100644 --- a/test_serializer/Insert.cpp +++ b/test_serializer/Insert.cpp @@ -45,6 +45,12 @@ int Insert(int, char* []) compare(__LINE__, insert_into(bar).default_values(), "INSERT INTO tab_bar DEFAULT VALUES"); compare(__LINE__, insert_into(bar).set(bar.beta = "cheesecake", bar.gamma = true), "INSERT INTO tab_bar (beta,gamma) VALUES('cheesecake'," + getTrue() + ")"); +#if __cplusplus >= 201703L + // string_view argument + std::string_view cheeseCake = "cheesecake"; + compare(__LINE__, insert_into(bar).set(bar.beta = cheeseCake, bar.gamma = true), + "INSERT INTO tab_bar (beta,gamma) VALUES('cheesecake'," + getTrue() + ")"); +#endif return 0; } diff --git a/test_serializer/Where.cpp b/test_serializer/Where.cpp index a4e80112..ff369a99 100644 --- a/test_serializer/Where.cpp +++ b/test_serializer/Where.cpp @@ -62,6 +62,11 @@ int Where(int, char* []) compare(__LINE__, where(bar.gamma), " WHERE tab_bar.gamma"); compare(__LINE__, where(bar.gamma == false), " WHERE (tab_bar.gamma=" + getFalse() + ")"); compare(__LINE__, where(bar.beta == "SQL"), " WHERE (tab_bar.beta='SQL')"); +#if __cplusplus >= 201703L + // string_view argument + std::string_view sqlString = "SQL"; + compare(__LINE__, where(bar.beta == sqlString), " WHERE (tab_bar.beta='SQL')"); +#endif return 0; } diff --git a/test_static_asserts/CMakeLists.txt b/test_static_asserts/CMakeLists.txt index f9b76f35..9ecec43f 100644 --- a/test_static_asserts/CMakeLists.txt +++ b/test_static_asserts/CMakeLists.txt @@ -26,6 +26,12 @@ function(test_compile name) set(target sqlpp11_assert_${name}) add_executable(${target} ${name}.cpp) target_link_libraries(${target} PRIVATE sqlpp11 sqlpp11_testing) + # conditionally bump to a higher C++ standard to test compatibility + if (SQLPP11_TESTS_CXX_STD) + set_property(TARGET sqlpp11_assert_${name} PROPERTY CXX_STANDARD ${SQLPP11_TESTS_CXX_STD}) + set_property(TARGET sqlpp11_assert_${name} PROPERTY CXX_STANDARD_REQUIRED yes) + set_property(TARGET sqlpp11_assert_${name} PROPERTY CXX_EXTENSIONS no) + endif() endfunction() test_compile(aggregates) diff --git a/test_types/CMakeLists.txt b/test_types/CMakeLists.txt index cb2b8a8b..1d310542 100644 --- a/test_types/CMakeLists.txt +++ b/test_types/CMakeLists.txt @@ -26,6 +26,12 @@ function(test_compile name) set(target sqlpp11_${name}) add_executable(${target} ${name}.cpp) target_link_libraries(${target} PRIVATE sqlpp11 sqlpp11_testing) + # conditionally bump to a higher C++ standard to test compatibility + if (SQLPP11_TESTS_CXX_STD) + set_property(TARGET sqlpp11_${name} PROPERTY CXX_STANDARD ${SQLPP11_TESTS_CXX_STD}) + set_property(TARGET sqlpp11_${name} PROPERTY CXX_STANDARD_REQUIRED yes) + set_property(TARGET sqlpp11_${name} PROPERTY CXX_EXTENSIONS no) + endif() endfunction() test_compile(result_row) diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index 08bb2e9e..ed5d8a02 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -57,6 +57,12 @@ endif() create_test_sourcelist(test_sources test_main.cpp ${test_names}) add_executable(sqlpp11_tests ${test_sources}) target_link_libraries(sqlpp11_tests PRIVATE sqlpp11 sqlpp11_testing) +# conditionally bump to a higher C++ standard to test compatibility +if (SQLPP11_TESTS_CXX_STD) + set_property(TARGET sqlpp11_tests PROPERTY CXX_STANDARD ${SQLPP11_TESTS_CXX_STD}) + set_property(TARGET sqlpp11_tests PROPERTY CXX_STANDARD_REQUIRED yes) + set_property(TARGET sqlpp11_tests PROPERTY CXX_EXTENSIONS no) +endif() foreach(test IN LISTS test_names) add_test(NAME sqlpp11.tests.${test}