From 40e1208847fccbb6a14fd97858c346905e2bf178 Mon Sep 17 00:00:00 2001 From: Bas Vodde Date: Tue, 19 May 2020 12:26:56 +0800 Subject: [PATCH] Added new C++ standard to the check_all build and added a CompatabilityTest file for e.g. StdC++ compatability --- Makefile.am | 7 ++++ configure.ac | 38 ++++++++++++++++++++- platforms/CCStudio/CppUTestRunAllTests1.pjt | 1 + platforms/Dos/sources.mk | 1 + platforms/Eclipse-Cygwin/.project | 15 ++++++++ platforms/iar/CppUTestTest.ewp | 3 ++ tests/AllTests.vcproj | 23 +++++++++++++ tests/AllTests.vcxproj | 1 + tests/CppUTest/CMakeLists.txt | 1 + tests/CppUTest/CompatabilityTests.cpp | 26 ++++++++++++++ 10 files changed, 115 insertions(+), 1 deletion(-) create mode 100644 tests/CppUTest/CompatabilityTests.cpp diff --git a/Makefile.am b/Makefile.am index 97c357ae8..a770a68b8 100644 --- a/Makefile.am +++ b/Makefile.am @@ -162,6 +162,7 @@ CppUTestTests_SOURCES = \ tests/CppUTest/AllocLetTestFreeTest.cpp \ tests/CppUTest/AllTests.cpp \ tests/CppUTest/CheatSheetTest.cpp \ + tests/CppUTest/CompatabilityTests.cpp \ tests/CppUTest/CommandLineArgumentsTest.cpp \ tests/CppUTest/CommandLineTestRunnerTest.cpp \ tests/CppUTest/DummyMemoryLeakDetector.cpp \ @@ -339,6 +340,12 @@ check_basic: @echo "Building with the Std C++ 14 turned on. Compiler acts differently then." make distclean; $(srcdir)/configure --enable-std-cpp14; make + @echo "Building with the Std C++ 17 turned on. Compiler acts differently then." + make distclean; $(srcdir)/configure --enable-std-cpp17; make + + @echo "Building with the Std C++ 20 turned on. Compiler acts differently then." + make distclean; $(srcdir)/configure --enable-std-cpp20; make + @echo "Building without the Standard C library" make distclean; $(srcdir)/configure --disable-std-c; make diff --git a/configure.ac b/configure.ac index c354f0441..5c68f8a0c 100644 --- a/configure.ac +++ b/configure.ac @@ -85,7 +85,7 @@ fi AC_LANG_PUSH([C++]) ##################################################################################### -##### C++ 14 checks +##### C++ checks # FLag -std=c++1y CXXFLAGS="-Werror -std=c++1y" @@ -99,6 +99,24 @@ AC_MSG_CHECKING([whether CXX supports -std=c++14]) AC_COMPILE_IFELSE([AC_LANG_PROGRAM([])], [AC_MSG_RESULT([yes]); CPPUTEST_CPP14FLAG="-std=c++14" ], [AC_MSG_RESULT([no])]) CXXFLAGS="$saved_cxxflags" +# FLag std=c++17 +CXXFLAGS="-Werror -std=c++17" +AC_MSG_CHECKING([whether CXX supports -std=c++17]) +AC_COMPILE_IFELSE([AC_LANG_PROGRAM([])], [AC_MSG_RESULT([yes]); CPPUTEST_CPP17FLAG="-std=c++17" ], [AC_MSG_RESULT([no])]) +CXXFLAGS="$saved_cxxflags" + +# FLag std=c++20 +CXXFLAGS="-Werror -std=c++2a" +AC_MSG_CHECKING([whether CXX supports -std=c++2a]) +AC_COMPILE_IFELSE([AC_LANG_PROGRAM([])], [AC_MSG_RESULT([yes]); CPPUTEST_CPP20FLAG="-std=c++2a" ], [AC_MSG_RESULT([no])]) +CXXFLAGS="$saved_cxxflags" + +# FLag std=c++20 +CXXFLAGS="-Werror -std=c++20" +AC_MSG_CHECKING([whether CXX supports -std=c++20]) +AC_COMPILE_IFELSE([AC_LANG_PROGRAM([])], [AC_MSG_RESULT([yes]); CPPUTEST_CPP20FLAG="-std=c++20" ], [AC_MSG_RESULT([no])]) +CXXFLAGS="$saved_cxxflags" + ##################################################################################### ##### C++ version checks @@ -373,6 +391,12 @@ AC_ARG_ENABLE([std-cpp11], [AC_HELP_STRING([--enable-std-cpp11], [enable the use AC_ARG_ENABLE([std-cpp14], [AC_HELP_STRING([--enable-std-cpp14], [enable the use of Standard C++ 14 (if the compiler supports that)])], [use_std_cpp14=${enableval}], [use_std_cpp14=no]) +AC_ARG_ENABLE([std-cpp17], [AC_HELP_STRING([--enable-std-cpp17], [enable the use of Standard C++ 17 (if the compiler supports that)])], + [use_std_cpp17=${enableval}], [use_std_cpp17=no]) + +AC_ARG_ENABLE([std-cpp20], [AC_HELP_STRING([--enable-std-cpp20], [enable the use of Standard C++ 20 (if the compiler supports that)])], + [use_std_cpp20=${enableval}], [use_std_cpp20=no]) + AC_ARG_ENABLE([cpputest-flags], [AC_HELP_STRING([--disable-cpputest-flags], [disable CFLAGS/CPPFLAGS/CXXFLAGS set by CppUTest])], [cpputest_flags=${enableval}], [cpputest_flags=yes]) @@ -441,6 +465,18 @@ if test "x${use_std_cpp14}" = xyes; then cpp_standard_used="C++14" fi +# Using the C++17 standard? +if test "x${use_std_cpp17}" = xyes; then + CPPUTEST_CXXFLAGS="${CPPUTEST_CXXFLAGS} ${CPPUTEST_CPP17FLAG}" + cpp_standard_used="C++17" +fi + +# Using the C++20 standard? +if test "x${use_std_cpp20}" = xyes; then + CPPUTEST_CXXFLAGS="${CPPUTEST_CXXFLAGS} ${CPPUTEST_CPP20FLAG}" + cpp_standard_used="C++20" +fi + # Dealing with memory leak detection if test "x${memory_leak_detection}" = xno; then AC_DEFINE([MEM_LEAK_DETECTION_DISABLED], 1, [memory leak detection disabled]) diff --git a/platforms/CCStudio/CppUTestRunAllTests1.pjt b/platforms/CCStudio/CppUTestRunAllTests1.pjt index 18a4470b4..9625021ee 100644 --- a/platforms/CCStudio/CppUTestRunAllTests1.pjt +++ b/platforms/CCStudio/CppUTestRunAllTests1.pjt @@ -36,6 +36,7 @@ Source="..\..\tests\AllocationInCppFile.cpp" Source="..\..\tests\AllocLetTestFree.c" Source="..\..\tests\AllocLetTestFreeTest.cpp" Source="..\..\tests\CheatSheetTest.cpp" +Source="..\..\tests\CompatabilityTests.cpp" Source="..\..\tests\CommandLineArgumentsTest.cpp" Source="..\..\tests\CommandLineTestRunnerTest.cpp" Source="..\..\tests\JUnitOutputTest.cpp" diff --git a/platforms/Dos/sources.mk b/platforms/Dos/sources.mk index dcd4be57c..7515febe6 100644 --- a/platforms/Dos/sources.mk +++ b/platforms/Dos/sources.mk @@ -41,6 +41,7 @@ CPPU1_OBJECTS := \ $(CPPUTEST_HOME)/tests/CppUTest/AllocLetTestFree.o \ $(CPPUTEST_HOME)/tests/CppUTest/AllocLetTestFreeTest.o \ $(CPPUTEST_HOME)/tests/CppUTest/CheatSheetTest.o \ + $(CPPUTEST_HOME)/tests/CppUTest/CompatabilityTests.o \ $(CPPUTEST_HOME)/tests/CppUTest/CommandLineArgumentsTest.o \ $(CPPUTEST_HOME)/tests/CppUTest/CommandLineTestRunnerTest.o \ $(CPPUTEST_HOME)/tests/CppUTest/JUnitOutputTest.o diff --git a/platforms/Eclipse-Cygwin/.project b/platforms/Eclipse-Cygwin/.project index bed0ca0b5..5dcd2654c 100644 --- a/platforms/Eclipse-Cygwin/.project +++ b/platforms/Eclipse-Cygwin/.project @@ -724,6 +724,11 @@ 1 PARENT-2-ECLIPSE_HOME/00_Dev/05_CppUTest/cpputest/tests/CheatSheetTest.cpp + + tests/CompatabilityTests.cpp + 1 + PARENT-2-ECLIPSE_HOME/00_Dev/05_CppUTest/cpputest/tests/CompatabilityTests.cpp + tests/CommandLineArgumentsTest.cpp 1 @@ -1884,6 +1889,16 @@ 1 PARENT-2-ECLIPSE_HOME/00_Dev/05_CppUTest/cpputest/tests/Debug/CodeMemoryReportFormatterTest.sbr + + tests/Debug/CompatabilityTests.obj + 1 + PARENT-2-ECLIPSE_HOME/00_Dev/05_CppUTest/cpputest/tests/Debug/CompatabilityTests.obj + + + tests/Debug/CompatabilityTests.sbr + 1 + PARENT-2-ECLIPSE_HOME/00_Dev/05_CppUTest/cpputest/tests/Debug/CompatabilityTests.sbr + tests/Debug/CommandLineArgumentsTest.obj 1 diff --git a/platforms/iar/CppUTestTest.ewp b/platforms/iar/CppUTestTest.ewp index 7e060041f..d9200406c 100644 --- a/platforms/iar/CppUTestTest.ewp +++ b/platforms/iar/CppUTestTest.ewp @@ -1942,6 +1942,9 @@ $PROJ_DIR$\..\..\tests\CppUTest\CheatSheetTest.cpp + + $PROJ_DIR$\..\..\tests\CppUTest\CompatabilityTests.cpp + $PROJ_DIR$\..\..\tests\CppUTest\CommandLineArgumentsTest.cpp diff --git a/tests/AllTests.vcproj b/tests/AllTests.vcproj index 6193a77c2..16ab375c9 100644 --- a/tests/AllTests.vcproj +++ b/tests/AllTests.vcproj @@ -354,6 +354,29 @@ /> + + + + + + + + diff --git a/tests/AllTests.vcxproj b/tests/AllTests.vcxproj index 193be1dcb..4dc79fb44 100644 --- a/tests/AllTests.vcxproj +++ b/tests/AllTests.vcxproj @@ -247,6 +247,7 @@ + diff --git a/tests/CppUTest/CMakeLists.txt b/tests/CppUTest/CMakeLists.txt index 54fe351a4..9ac1ea715 100644 --- a/tests/CppUTest/CMakeLists.txt +++ b/tests/CppUTest/CMakeLists.txt @@ -4,6 +4,7 @@ set(CppUTestTests_src CheatSheetTest.cpp SimpleStringTest.cpp SimpleStringCacheTest.cpp + CompatabilityTests.cpp CommandLineArgumentsTest.cpp TestFailureTest.cpp TestFailureNaNTest.cpp diff --git a/tests/CppUTest/CompatabilityTests.cpp b/tests/CppUTest/CompatabilityTests.cpp new file mode 100644 index 000000000..85136e221 --- /dev/null +++ b/tests/CppUTest/CompatabilityTests.cpp @@ -0,0 +1,26 @@ + +#include "CppUTest/TestHarness.h" + +#if CPPUTEST_USE_STD_CPP_LIB + +#include + +TEST_GROUP(StandardCppLibrary) +{ +}; + +#if defined(__cplusplus) && __cplusplus >= 201103L && 0 + +TEST(StandardCppLibrary, UniquePtrConversationToBool) +{ + auto const aNull = std::unique_ptr(nullptr); + CHECK_FALSE(aNull); + + auto const notNull = std::make_unique(1); + CHECK_TRUE(notNull); +}; + +#endif + +#endif +