diff --git a/README.md b/README.md
index 2db2732..37c43bb 100644
--- a/README.md
+++ b/README.md
@@ -1,7 +1,6 @@
-# utest.h #
+# 🧪 utest.h
[](https://ci.appveyor.com/project/sheredom/utest-h)
-
[](https://travis-ci.org/sheredom/utest.h)
A simple one header solution to unit testing for C/C++.
diff --git a/README.md b/README.md
index 2db2732..37c43bb 100644
--- a/README.md
+++ b/README.md
@@ -1,7 +1,6 @@
-# utest.h #
+# 🧪 utest.h
[](https://ci.appveyor.com/project/sheredom/utest-h)
-
[](https://travis-ci.org/sheredom/utest.h)
A simple one header solution to unit testing for C/C++.
diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt
index 7fc2262..a634c04 100644
--- a/test/CMakeLists.txt
+++ b/test/CMakeLists.txt
@@ -33,6 +33,7 @@
main.c
test.c
test.cpp
+ test11.cpp
stdint_include.c
type_printers.c
type_printers.cpp
@@ -61,11 +62,11 @@
if("${CMAKE_CXX_COMPILER_ID}" STREQUAL "GNU")
set_source_files_properties(test.cpp PROPERTIES
- COMPILE_FLAGS "-Wall -Wextra -Werror"
+ COMPILE_FLAGS "-Wall -Wextra -Werror -std=gnu++98"
)
elseif("${CMAKE_CXX_COMPILER_ID}" STREQUAL "Clang")
set_source_files_properties(test.cpp PROPERTIES
- COMPILE_FLAGS "-Wall -Wextra -Weverything -Werror"
+ COMPILE_FLAGS "-Wall -Wextra -Weverything -Werror -std=gnu++98"
)
elseif("${CMAKE_CXX_COMPILER_ID}" STREQUAL "MSVC")
set_source_files_properties(test.cpp PROPERTIES
@@ -74,3 +75,19 @@
else()
message(WARNING "Unknown compiler '${CMAKE_C_COMPILER_ID}'!")
endif()
+
+if("${CMAKE_CXX_COMPILER_ID}" STREQUAL "GNU")
+ set_source_files_properties(test11.cpp PROPERTIES
+ COMPILE_FLAGS "-Wall -Wextra -Werror -std=c++11"
+ )
+elseif("${CMAKE_CXX_COMPILER_ID}" STREQUAL "Clang")
+ set_source_files_properties(test11.cpp PROPERTIES
+ COMPILE_FLAGS "-Wall -Wextra -Weverything -Werror -std=c++11"
+ )
+elseif("${CMAKE_CXX_COMPILER_ID}" STREQUAL "MSVC")
+ set_source_files_properties(test11.cpp PROPERTIES
+ COMPILE_FLAGS "/Wall /WX /wd4514 /wd5045"
+ )
+else()
+ message(WARNING "Unknown compiler '${CMAKE_C_COMPILER_ID}'!")
+endif()
diff --git a/README.md b/README.md
index 2db2732..37c43bb 100644
--- a/README.md
+++ b/README.md
@@ -1,7 +1,6 @@
-# utest.h #
+# 🧪 utest.h
[](https://ci.appveyor.com/project/sheredom/utest-h)
-
[](https://travis-ci.org/sheredom/utest.h)
A simple one header solution to unit testing for C/C++.
diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt
index 7fc2262..a634c04 100644
--- a/test/CMakeLists.txt
+++ b/test/CMakeLists.txt
@@ -33,6 +33,7 @@
main.c
test.c
test.cpp
+ test11.cpp
stdint_include.c
type_printers.c
type_printers.cpp
@@ -61,11 +62,11 @@
if("${CMAKE_CXX_COMPILER_ID}" STREQUAL "GNU")
set_source_files_properties(test.cpp PROPERTIES
- COMPILE_FLAGS "-Wall -Wextra -Werror"
+ COMPILE_FLAGS "-Wall -Wextra -Werror -std=gnu++98"
)
elseif("${CMAKE_CXX_COMPILER_ID}" STREQUAL "Clang")
set_source_files_properties(test.cpp PROPERTIES
- COMPILE_FLAGS "-Wall -Wextra -Weverything -Werror"
+ COMPILE_FLAGS "-Wall -Wextra -Weverything -Werror -std=gnu++98"
)
elseif("${CMAKE_CXX_COMPILER_ID}" STREQUAL "MSVC")
set_source_files_properties(test.cpp PROPERTIES
@@ -74,3 +75,19 @@
else()
message(WARNING "Unknown compiler '${CMAKE_C_COMPILER_ID}'!")
endif()
+
+if("${CMAKE_CXX_COMPILER_ID}" STREQUAL "GNU")
+ set_source_files_properties(test11.cpp PROPERTIES
+ COMPILE_FLAGS "-Wall -Wextra -Werror -std=c++11"
+ )
+elseif("${CMAKE_CXX_COMPILER_ID}" STREQUAL "Clang")
+ set_source_files_properties(test11.cpp PROPERTIES
+ COMPILE_FLAGS "-Wall -Wextra -Weverything -Werror -std=c++11"
+ )
+elseif("${CMAKE_CXX_COMPILER_ID}" STREQUAL "MSVC")
+ set_source_files_properties(test11.cpp PROPERTIES
+ COMPILE_FLAGS "/Wall /WX /wd4514 /wd5045"
+ )
+else()
+ message(WARNING "Unknown compiler '${CMAKE_C_COMPILER_ID}'!")
+endif()
diff --git a/test/test.cpp b/test/test.cpp
index 61c1b68..1903ad2 100644
--- a/test/test.cpp
+++ b/test/test.cpp
@@ -52,9 +52,9 @@
ASSERT_GE(2, 1);
}
-UTEST(c, ASSERT_STREQ) { ASSERT_STREQ("foo", "foo"); }
+UTEST(cpp, ASSERT_STREQ) { ASSERT_STREQ("foo", "foo"); }
-UTEST(c, ASSERT_STRNE) { ASSERT_STRNE("foo", "bar"); }
+UTEST(cpp, ASSERT_STRNE) { ASSERT_STRNE("foo", "bar"); }
UTEST(cpp, EXPECT_TRUE) { EXPECT_TRUE(1); }
@@ -78,9 +78,9 @@
EXPECT_GE(2, 1);
}
-UTEST(c, EXPECT_STREQ) { EXPECT_STREQ("foo", "foo"); }
+UTEST(cpp, EXPECT_STREQ) { EXPECT_STREQ("foo", "foo"); }
-UTEST(c, EXPECT_STRNE) { EXPECT_STRNE("foo", "bar"); }
+UTEST(cpp, EXPECT_STRNE) { EXPECT_STRNE("foo", "bar"); }
UTEST(cpp, no_double_eval) {
int i = 0;
@@ -101,12 +101,12 @@
ASSERT_EQ(13, utest_fixture->foo);
}
-UTEST_F(MyTestF, cpp) {
+UTEST_F(MyTestF, cpp_1) {
ASSERT_EQ(42, utest_fixture->foo);
utest_fixture->foo = 13;
}
-UTEST_F(MyTestF, cpp2) {
+UTEST_F(MyTestF, cpp_2) {
ASSERT_EQ(42, utest_fixture->foo);
utest_fixture->foo = 13;
}
@@ -128,12 +128,12 @@
ASSERT_EQ(utest_index, utest_fixture->bar);
}
-UTEST_I(MyTestI, cpp, 2) {
+UTEST_I(MyTestI, cpp_1, 2) {
ASSERT_GT(2, utest_fixture->bar);
utest_fixture->foo = 13;
}
-UTEST_I(MyTestI, cpp2, 128) {
+UTEST_I(MyTestI, cpp_2, 128) {
ASSERT_GT(128, utest_fixture->bar);
utest_fixture->foo = 13;
}
diff --git a/README.md b/README.md
index 2db2732..37c43bb 100644
--- a/README.md
+++ b/README.md
@@ -1,7 +1,6 @@
-# utest.h #
+# 🧪 utest.h
[](https://ci.appveyor.com/project/sheredom/utest-h)
-
[](https://travis-ci.org/sheredom/utest.h)
A simple one header solution to unit testing for C/C++.
diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt
index 7fc2262..a634c04 100644
--- a/test/CMakeLists.txt
+++ b/test/CMakeLists.txt
@@ -33,6 +33,7 @@
main.c
test.c
test.cpp
+ test11.cpp
stdint_include.c
type_printers.c
type_printers.cpp
@@ -61,11 +62,11 @@
if("${CMAKE_CXX_COMPILER_ID}" STREQUAL "GNU")
set_source_files_properties(test.cpp PROPERTIES
- COMPILE_FLAGS "-Wall -Wextra -Werror"
+ COMPILE_FLAGS "-Wall -Wextra -Werror -std=gnu++98"
)
elseif("${CMAKE_CXX_COMPILER_ID}" STREQUAL "Clang")
set_source_files_properties(test.cpp PROPERTIES
- COMPILE_FLAGS "-Wall -Wextra -Weverything -Werror"
+ COMPILE_FLAGS "-Wall -Wextra -Weverything -Werror -std=gnu++98"
)
elseif("${CMAKE_CXX_COMPILER_ID}" STREQUAL "MSVC")
set_source_files_properties(test.cpp PROPERTIES
@@ -74,3 +75,19 @@
else()
message(WARNING "Unknown compiler '${CMAKE_C_COMPILER_ID}'!")
endif()
+
+if("${CMAKE_CXX_COMPILER_ID}" STREQUAL "GNU")
+ set_source_files_properties(test11.cpp PROPERTIES
+ COMPILE_FLAGS "-Wall -Wextra -Werror -std=c++11"
+ )
+elseif("${CMAKE_CXX_COMPILER_ID}" STREQUAL "Clang")
+ set_source_files_properties(test11.cpp PROPERTIES
+ COMPILE_FLAGS "-Wall -Wextra -Weverything -Werror -std=c++11"
+ )
+elseif("${CMAKE_CXX_COMPILER_ID}" STREQUAL "MSVC")
+ set_source_files_properties(test11.cpp PROPERTIES
+ COMPILE_FLAGS "/Wall /WX /wd4514 /wd5045"
+ )
+else()
+ message(WARNING "Unknown compiler '${CMAKE_C_COMPILER_ID}'!")
+endif()
diff --git a/test/test.cpp b/test/test.cpp
index 61c1b68..1903ad2 100644
--- a/test/test.cpp
+++ b/test/test.cpp
@@ -52,9 +52,9 @@
ASSERT_GE(2, 1);
}
-UTEST(c, ASSERT_STREQ) { ASSERT_STREQ("foo", "foo"); }
+UTEST(cpp, ASSERT_STREQ) { ASSERT_STREQ("foo", "foo"); }
-UTEST(c, ASSERT_STRNE) { ASSERT_STRNE("foo", "bar"); }
+UTEST(cpp, ASSERT_STRNE) { ASSERT_STRNE("foo", "bar"); }
UTEST(cpp, EXPECT_TRUE) { EXPECT_TRUE(1); }
@@ -78,9 +78,9 @@
EXPECT_GE(2, 1);
}
-UTEST(c, EXPECT_STREQ) { EXPECT_STREQ("foo", "foo"); }
+UTEST(cpp, EXPECT_STREQ) { EXPECT_STREQ("foo", "foo"); }
-UTEST(c, EXPECT_STRNE) { EXPECT_STRNE("foo", "bar"); }
+UTEST(cpp, EXPECT_STRNE) { EXPECT_STRNE("foo", "bar"); }
UTEST(cpp, no_double_eval) {
int i = 0;
@@ -101,12 +101,12 @@
ASSERT_EQ(13, utest_fixture->foo);
}
-UTEST_F(MyTestF, cpp) {
+UTEST_F(MyTestF, cpp_1) {
ASSERT_EQ(42, utest_fixture->foo);
utest_fixture->foo = 13;
}
-UTEST_F(MyTestF, cpp2) {
+UTEST_F(MyTestF, cpp_2) {
ASSERT_EQ(42, utest_fixture->foo);
utest_fixture->foo = 13;
}
@@ -128,12 +128,12 @@
ASSERT_EQ(utest_index, utest_fixture->bar);
}
-UTEST_I(MyTestI, cpp, 2) {
+UTEST_I(MyTestI, cpp_1, 2) {
ASSERT_GT(2, utest_fixture->bar);
utest_fixture->foo = 13;
}
-UTEST_I(MyTestI, cpp2, 128) {
+UTEST_I(MyTestI, cpp_2, 128) {
ASSERT_GT(128, utest_fixture->bar);
utest_fixture->foo = 13;
}
diff --git a/test/test11.cpp b/test/test11.cpp
new file mode 100644
index 0000000..d9228ae
--- /dev/null
+++ b/test/test11.cpp
@@ -0,0 +1,139 @@
+// This is free and unencumbered software released into the public domain.
+//
+// Anyone is free to copy, modify, publish, use, compile, sell, or
+// distribute this software, either in source code form or as a compiled
+// binary, for any purpose, commercial or non-commercial, and by any
+// means.
+//
+// In jurisdictions that recognize copyright laws, the author or authors
+// of this software dedicate any and all copyright interest in the
+// software to the public domain. We make this dedication for the benefit
+// of the public at large and to the detriment of our heirs and
+// successors. We intend this dedication to be an overt act of
+// relinquishment in perpetuity of all present and future rights to this
+// software under copyright law.
+//
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
+// IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR
+// OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
+// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
+// OTHER DEALINGS IN THE SOFTWARE.
+//
+// For more information, please refer to
+
+#include "utest.h"
+
+#ifdef _MSC_VER
+// disable 'conditional expression is constant' - our examples below use this!
+#pragma warning(disable : 4127)
+#endif
+
+UTEST(cpp11, ASSERT_TRUE) { ASSERT_TRUE(1); }
+
+UTEST(cpp11, ASSERT_FALSE) { ASSERT_FALSE(0); }
+
+UTEST(cpp11, ASSERT_EQ) { ASSERT_EQ(1, 1); }
+
+UTEST(cpp11, ASSERT_NE) { ASSERT_NE(1, 2); }
+
+UTEST(cpp11, ASSERT_LT) { ASSERT_LT(1, 2); }
+
+UTEST(cpp11, ASSERT_LE) {
+ ASSERT_LE(1, 1);
+ ASSERT_LE(1, 2);
+}
+
+UTEST(cpp11, ASSERT_GT) { ASSERT_GT(2, 1); }
+
+UTEST(cpp11, ASSERT_GE) {
+ ASSERT_GE(1, 1);
+ ASSERT_GE(2, 1);
+}
+
+UTEST(cpp11, ASSERT_STREQ) { ASSERT_STREQ("foo", "foo"); }
+
+UTEST(cpp11, ASSERT_STRNE) { ASSERT_STRNE("foo", "bar"); }
+
+UTEST(cpp11, EXPECT_TRUE) { EXPECT_TRUE(1); }
+
+UTEST(cpp11, EXPECT_FALSE) { EXPECT_FALSE(0); }
+
+UTEST(cpp11, EXPECT_EQ) { EXPECT_EQ(1, 1); }
+
+UTEST(cpp11, EXPECT_NE) { EXPECT_NE(1, 2); }
+
+UTEST(cpp11, EXPECT_LT) { EXPECT_LT(1, 2); }
+
+UTEST(cpp11, EXPECT_LE) {
+ EXPECT_LE(1, 1);
+ EXPECT_LE(1, 2);
+}
+
+UTEST(cpp11, EXPECT_GT) { EXPECT_GT(2, 1); }
+
+UTEST(cpp11, EXPECT_GE) {
+ EXPECT_GE(1, 1);
+ EXPECT_GE(2, 1);
+}
+
+UTEST(cpp11, EXPECT_STREQ) { EXPECT_STREQ("foo", "foo"); }
+
+UTEST(cpp11, EXPECT_STRNE) { EXPECT_STRNE("foo", "bar"); }
+
+UTEST(cpp11, no_double_eval) {
+ int i = 0;
+ ASSERT_EQ(i++, 0);
+ ASSERT_EQ(i, 1);
+}
+
+struct MyTestF {
+ int foo;
+};
+
+UTEST_F_SETUP(MyTestF) {
+ ASSERT_EQ(0, utest_fixture->foo);
+ utest_fixture->foo = 42;
+}
+
+UTEST_F_TEARDOWN(MyTestF) {
+ ASSERT_EQ(13, utest_fixture->foo);
+}
+
+UTEST_F(MyTestF, cpp11_1) {
+ ASSERT_EQ(42, utest_fixture->foo);
+ utest_fixture->foo = 13;
+}
+
+UTEST_F(MyTestF, cpp11_2) {
+ ASSERT_EQ(42, utest_fixture->foo);
+ utest_fixture->foo = 13;
+}
+
+struct MyTestI {
+ size_t foo;
+ size_t bar;
+};
+
+UTEST_I_SETUP(MyTestI) {
+ ASSERT_EQ(0, utest_fixture->foo);
+ ASSERT_EQ(0, utest_fixture->bar);
+ utest_fixture->foo = 42;
+ utest_fixture->bar = utest_index;
+}
+
+UTEST_I_TEARDOWN(MyTestI) {
+ ASSERT_EQ(13, utest_fixture->foo);
+ ASSERT_EQ(utest_index, utest_fixture->bar);
+}
+
+UTEST_I(MyTestI, cpp11_1, 2) {
+ ASSERT_GT(2, utest_fixture->bar);
+ utest_fixture->foo = 13;
+}
+
+UTEST_I(MyTestI, cpp11_2, 128) {
+ ASSERT_GT(128, utest_fixture->bar);
+ utest_fixture->foo = 13;
+}
diff --git a/README.md b/README.md
index 2db2732..37c43bb 100644
--- a/README.md
+++ b/README.md
@@ -1,7 +1,6 @@
-# utest.h #
+# 🧪 utest.h
[](https://ci.appveyor.com/project/sheredom/utest-h)
-
[](https://travis-ci.org/sheredom/utest.h)
A simple one header solution to unit testing for C/C++.
diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt
index 7fc2262..a634c04 100644
--- a/test/CMakeLists.txt
+++ b/test/CMakeLists.txt
@@ -33,6 +33,7 @@
main.c
test.c
test.cpp
+ test11.cpp
stdint_include.c
type_printers.c
type_printers.cpp
@@ -61,11 +62,11 @@
if("${CMAKE_CXX_COMPILER_ID}" STREQUAL "GNU")
set_source_files_properties(test.cpp PROPERTIES
- COMPILE_FLAGS "-Wall -Wextra -Werror"
+ COMPILE_FLAGS "-Wall -Wextra -Werror -std=gnu++98"
)
elseif("${CMAKE_CXX_COMPILER_ID}" STREQUAL "Clang")
set_source_files_properties(test.cpp PROPERTIES
- COMPILE_FLAGS "-Wall -Wextra -Weverything -Werror"
+ COMPILE_FLAGS "-Wall -Wextra -Weverything -Werror -std=gnu++98"
)
elseif("${CMAKE_CXX_COMPILER_ID}" STREQUAL "MSVC")
set_source_files_properties(test.cpp PROPERTIES
@@ -74,3 +75,19 @@
else()
message(WARNING "Unknown compiler '${CMAKE_C_COMPILER_ID}'!")
endif()
+
+if("${CMAKE_CXX_COMPILER_ID}" STREQUAL "GNU")
+ set_source_files_properties(test11.cpp PROPERTIES
+ COMPILE_FLAGS "-Wall -Wextra -Werror -std=c++11"
+ )
+elseif("${CMAKE_CXX_COMPILER_ID}" STREQUAL "Clang")
+ set_source_files_properties(test11.cpp PROPERTIES
+ COMPILE_FLAGS "-Wall -Wextra -Weverything -Werror -std=c++11"
+ )
+elseif("${CMAKE_CXX_COMPILER_ID}" STREQUAL "MSVC")
+ set_source_files_properties(test11.cpp PROPERTIES
+ COMPILE_FLAGS "/Wall /WX /wd4514 /wd5045"
+ )
+else()
+ message(WARNING "Unknown compiler '${CMAKE_C_COMPILER_ID}'!")
+endif()
diff --git a/test/test.cpp b/test/test.cpp
index 61c1b68..1903ad2 100644
--- a/test/test.cpp
+++ b/test/test.cpp
@@ -52,9 +52,9 @@
ASSERT_GE(2, 1);
}
-UTEST(c, ASSERT_STREQ) { ASSERT_STREQ("foo", "foo"); }
+UTEST(cpp, ASSERT_STREQ) { ASSERT_STREQ("foo", "foo"); }
-UTEST(c, ASSERT_STRNE) { ASSERT_STRNE("foo", "bar"); }
+UTEST(cpp, ASSERT_STRNE) { ASSERT_STRNE("foo", "bar"); }
UTEST(cpp, EXPECT_TRUE) { EXPECT_TRUE(1); }
@@ -78,9 +78,9 @@
EXPECT_GE(2, 1);
}
-UTEST(c, EXPECT_STREQ) { EXPECT_STREQ("foo", "foo"); }
+UTEST(cpp, EXPECT_STREQ) { EXPECT_STREQ("foo", "foo"); }
-UTEST(c, EXPECT_STRNE) { EXPECT_STRNE("foo", "bar"); }
+UTEST(cpp, EXPECT_STRNE) { EXPECT_STRNE("foo", "bar"); }
UTEST(cpp, no_double_eval) {
int i = 0;
@@ -101,12 +101,12 @@
ASSERT_EQ(13, utest_fixture->foo);
}
-UTEST_F(MyTestF, cpp) {
+UTEST_F(MyTestF, cpp_1) {
ASSERT_EQ(42, utest_fixture->foo);
utest_fixture->foo = 13;
}
-UTEST_F(MyTestF, cpp2) {
+UTEST_F(MyTestF, cpp_2) {
ASSERT_EQ(42, utest_fixture->foo);
utest_fixture->foo = 13;
}
@@ -128,12 +128,12 @@
ASSERT_EQ(utest_index, utest_fixture->bar);
}
-UTEST_I(MyTestI, cpp, 2) {
+UTEST_I(MyTestI, cpp_1, 2) {
ASSERT_GT(2, utest_fixture->bar);
utest_fixture->foo = 13;
}
-UTEST_I(MyTestI, cpp2, 128) {
+UTEST_I(MyTestI, cpp_2, 128) {
ASSERT_GT(128, utest_fixture->bar);
utest_fixture->foo = 13;
}
diff --git a/test/test11.cpp b/test/test11.cpp
new file mode 100644
index 0000000..d9228ae
--- /dev/null
+++ b/test/test11.cpp
@@ -0,0 +1,139 @@
+// This is free and unencumbered software released into the public domain.
+//
+// Anyone is free to copy, modify, publish, use, compile, sell, or
+// distribute this software, either in source code form or as a compiled
+// binary, for any purpose, commercial or non-commercial, and by any
+// means.
+//
+// In jurisdictions that recognize copyright laws, the author or authors
+// of this software dedicate any and all copyright interest in the
+// software to the public domain. We make this dedication for the benefit
+// of the public at large and to the detriment of our heirs and
+// successors. We intend this dedication to be an overt act of
+// relinquishment in perpetuity of all present and future rights to this
+// software under copyright law.
+//
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
+// IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR
+// OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
+// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
+// OTHER DEALINGS IN THE SOFTWARE.
+//
+// For more information, please refer to
+
+#include "utest.h"
+
+#ifdef _MSC_VER
+// disable 'conditional expression is constant' - our examples below use this!
+#pragma warning(disable : 4127)
+#endif
+
+UTEST(cpp11, ASSERT_TRUE) { ASSERT_TRUE(1); }
+
+UTEST(cpp11, ASSERT_FALSE) { ASSERT_FALSE(0); }
+
+UTEST(cpp11, ASSERT_EQ) { ASSERT_EQ(1, 1); }
+
+UTEST(cpp11, ASSERT_NE) { ASSERT_NE(1, 2); }
+
+UTEST(cpp11, ASSERT_LT) { ASSERT_LT(1, 2); }
+
+UTEST(cpp11, ASSERT_LE) {
+ ASSERT_LE(1, 1);
+ ASSERT_LE(1, 2);
+}
+
+UTEST(cpp11, ASSERT_GT) { ASSERT_GT(2, 1); }
+
+UTEST(cpp11, ASSERT_GE) {
+ ASSERT_GE(1, 1);
+ ASSERT_GE(2, 1);
+}
+
+UTEST(cpp11, ASSERT_STREQ) { ASSERT_STREQ("foo", "foo"); }
+
+UTEST(cpp11, ASSERT_STRNE) { ASSERT_STRNE("foo", "bar"); }
+
+UTEST(cpp11, EXPECT_TRUE) { EXPECT_TRUE(1); }
+
+UTEST(cpp11, EXPECT_FALSE) { EXPECT_FALSE(0); }
+
+UTEST(cpp11, EXPECT_EQ) { EXPECT_EQ(1, 1); }
+
+UTEST(cpp11, EXPECT_NE) { EXPECT_NE(1, 2); }
+
+UTEST(cpp11, EXPECT_LT) { EXPECT_LT(1, 2); }
+
+UTEST(cpp11, EXPECT_LE) {
+ EXPECT_LE(1, 1);
+ EXPECT_LE(1, 2);
+}
+
+UTEST(cpp11, EXPECT_GT) { EXPECT_GT(2, 1); }
+
+UTEST(cpp11, EXPECT_GE) {
+ EXPECT_GE(1, 1);
+ EXPECT_GE(2, 1);
+}
+
+UTEST(cpp11, EXPECT_STREQ) { EXPECT_STREQ("foo", "foo"); }
+
+UTEST(cpp11, EXPECT_STRNE) { EXPECT_STRNE("foo", "bar"); }
+
+UTEST(cpp11, no_double_eval) {
+ int i = 0;
+ ASSERT_EQ(i++, 0);
+ ASSERT_EQ(i, 1);
+}
+
+struct MyTestF {
+ int foo;
+};
+
+UTEST_F_SETUP(MyTestF) {
+ ASSERT_EQ(0, utest_fixture->foo);
+ utest_fixture->foo = 42;
+}
+
+UTEST_F_TEARDOWN(MyTestF) {
+ ASSERT_EQ(13, utest_fixture->foo);
+}
+
+UTEST_F(MyTestF, cpp11_1) {
+ ASSERT_EQ(42, utest_fixture->foo);
+ utest_fixture->foo = 13;
+}
+
+UTEST_F(MyTestF, cpp11_2) {
+ ASSERT_EQ(42, utest_fixture->foo);
+ utest_fixture->foo = 13;
+}
+
+struct MyTestI {
+ size_t foo;
+ size_t bar;
+};
+
+UTEST_I_SETUP(MyTestI) {
+ ASSERT_EQ(0, utest_fixture->foo);
+ ASSERT_EQ(0, utest_fixture->bar);
+ utest_fixture->foo = 42;
+ utest_fixture->bar = utest_index;
+}
+
+UTEST_I_TEARDOWN(MyTestI) {
+ ASSERT_EQ(13, utest_fixture->foo);
+ ASSERT_EQ(utest_index, utest_fixture->bar);
+}
+
+UTEST_I(MyTestI, cpp11_1, 2) {
+ ASSERT_GT(2, utest_fixture->bar);
+ utest_fixture->foo = 13;
+}
+
+UTEST_I(MyTestI, cpp11_2, 128) {
+ ASSERT_GT(128, utest_fixture->bar);
+ utest_fixture->foo = 13;
+}
diff --git a/utest.h b/utest.h
index e0e4e0d..a62eb9e 100644
--- a/utest.h
+++ b/utest.h
@@ -300,6 +300,12 @@
*/
#if defined(__STDC_VERSION__) && (__STDC_VERSION__ >= 199901L) || \
defined(__cplusplus) && (__cplusplus >= 201103L)
+
+#ifdef __clang__
+#pragma clang diagnostic push
+#pragma clang diagnostic ignored "-Wc++98-compat-pedantic"
+#endif
+
UTEST_WEAK UTEST_OVERLOADABLE void utest_type_printer(long long int i);
UTEST_WEAK UTEST_OVERLOADABLE void utest_type_printer(long long int i) {
UTEST_PRINTF("%lld", i);
@@ -310,6 +316,11 @@
utest_type_printer(long long unsigned int i) {
UTEST_PRINTF("%llu", i);
}
+
+#ifdef __clang__
+#pragma clang diagnostic pop
+#endif
+
#endif
#elif defined(__STDC_VERSION__) && (__STDC_VERSION__ >= 201112L)
#define utest_type_printer(val) \
@@ -335,13 +346,20 @@
#define utest_type_printer(...) UTEST_PRINTF("undef")
#endif
+#if defined(__cplusplus) && (__cplusplus >= 201103L)
+#define UTEST_TYPEOF(x) decltype(x)
+#else
+#define UTEST_TYPEOF(x) typeof(x)
+#endif
+
#if defined(__clang__)
#define UTEST_EXPECT(x, y, cond) \
{ \
- _Pragma("clang diagnostic push") _Pragma( \
- "clang diagnostic ignored \"-Wlanguage-extension-token\"") typeof(y) \
- xEval = (x); \
- typeof(y) yEval = (y); \
+ _Pragma("clang diagnostic push") \
+ _Pragma("clang diagnostic ignored \"-Wlanguage-extension-token\"") \
+ _Pragma("clang diagnostic ignored \"-Wc++98-compat-pedantic\"") \
+ UTEST_TYPEOF(y) xEval = (x); \
+ UTEST_TYPEOF(y) yEval = (y); \
_Pragma("clang diagnostic pop") if (!((xEval)cond(yEval))) { \
UTEST_PRINTF("%s:%u: Failure\n", __FILE__, __LINE__); \
UTEST_PRINTF(" Expected : "); \
@@ -356,8 +374,8 @@
#elif defined(__GNUC__)
#define UTEST_EXPECT(x, y, cond) \
{ \
- typeof(y) xEval = (x); \
- typeof(y) yEval = (y); \
+ UTEST_TYPEOF(y) xEval = (x); \
+ UTEST_TYPEOF(y) yEval = (y); \
if (!((xEval)cond(yEval))) { \
UTEST_PRINTF("%s:%u: Failure\n", __FILE__, __LINE__); \
UTEST_PRINTF(" Expected : "); \
@@ -421,10 +439,11 @@
#if defined(__clang__)
#define UTEST_ASSERT(x, y, cond) \
{ \
- _Pragma("clang diagnostic push") _Pragma( \
- "clang diagnostic ignored \"-Wlanguage-extension-token\"") typeof(y) \
- xEval = (x); \
- typeof(y) yEval = (y); \
+ _Pragma("clang diagnostic push") \
+ _Pragma("clang diagnostic ignored \"-Wlanguage-extension-token\"") \
+ _Pragma("clang diagnostic ignored \"-Wc++98-compat-pedantic\"") \
+ UTEST_TYPEOF(y) xEval = (x); \
+ UTEST_TYPEOF(y) yEval = (y); \
_Pragma("clang diagnostic pop") if (!((xEval)cond(yEval))) { \
UTEST_PRINTF("%s:%u: Failure\n", __FILE__, __LINE__); \
UTEST_PRINTF(" Expected : "); \
@@ -440,8 +459,8 @@
#elif defined(__GNUC__)
#define UTEST_ASSERT(x, y, cond) \
{ \
- typeof(y) xEval = (x); \
- typeof(y) yEval = (y); \
+ UTEST_TYPEOF(y) xEval = (x); \
+ UTEST_TYPEOF(y) yEval = (y); \
if (!((xEval)cond(yEval))) { \
UTEST_PRINTF("%s:%u: Failure\n", __FILE__, __LINE__); \
UTEST_PRINTF(" Expected : "); \