diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt
index d4f8f04..50c0175 100644
--- a/test/CMakeLists.txt
+++ b/test/CMakeLists.txt
@@ -29,11 +29,6 @@
include_directories(${CMAKE_CURRENT_SOURCE_DIR}/../)
if("${CMAKE_C_COMPILER_ID}" STREQUAL "GNU")
- list(FIND CMAKE_C_COMPILE_FEATURES c_std_11 IDX)
- if (${IDX} GREATER -1)
- set_source_files_properties(type_printers.c PROPERTIES
- COMPILE_FLAGS "-std=gnu11")
- endif()
set_source_files_properties(main.c test.c PROPERTIES
COMPILE_FLAGS "-Wall -Wextra -Werror -std=gnu89"
)
@@ -49,6 +44,28 @@
message(WARNING "Unknown compiler '${CMAKE_C_COMPILER_ID}'!")
endif()
+list(FIND CMAKE_C_COMPILE_FEATURES c_std_11 IDX)
+if (${IDX} GREATER -1)
+ if("${CMAKE_C_COMPILER_ID}" STREQUAL "GNU")
+ set_source_files_properties(type_printers.c PROPERTIES
+ COMPILE_FLAGS "-std=gnu11")
+
+ set_source_files_properties(test11.c PROPERTIES
+ COMPILE_FLAGS "-Wall -Wextra -Werror -std=c11"
+ )
+ elseif("${CMAKE_C_COMPILER_ID}" STREQUAL "Clang")
+ set_source_files_properties(test11.c PROPERTIES
+ COMPILE_FLAGS "-Wall -Wextra -Weverything -Werror -std=c11"
+ )
+ elseif("${CMAKE_C_COMPILER_ID}" STREQUAL "MSVC")
+ set_source_files_properties(test11.c PROPERTIES
+ COMPILE_FLAGS "/Wall /WX /wd4514 /wd5045"
+ )
+ else()
+ message(WARNING "Unknown compiler '${CMAKE_C_COMPILER_ID}'!")
+ endif()
+endif()
+
if("${CMAKE_CXX_COMPILER_ID}" STREQUAL "GNU")
set_source_files_properties(test.cpp PROPERTIES
COMPILE_FLAGS "-Wall -Wextra -Werror -std=gnu++98"
diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt
index d4f8f04..50c0175 100644
--- a/test/CMakeLists.txt
+++ b/test/CMakeLists.txt
@@ -29,11 +29,6 @@
include_directories(${CMAKE_CURRENT_SOURCE_DIR}/../)
if("${CMAKE_C_COMPILER_ID}" STREQUAL "GNU")
- list(FIND CMAKE_C_COMPILE_FEATURES c_std_11 IDX)
- if (${IDX} GREATER -1)
- set_source_files_properties(type_printers.c PROPERTIES
- COMPILE_FLAGS "-std=gnu11")
- endif()
set_source_files_properties(main.c test.c PROPERTIES
COMPILE_FLAGS "-Wall -Wextra -Werror -std=gnu89"
)
@@ -49,6 +44,28 @@
message(WARNING "Unknown compiler '${CMAKE_C_COMPILER_ID}'!")
endif()
+list(FIND CMAKE_C_COMPILE_FEATURES c_std_11 IDX)
+if (${IDX} GREATER -1)
+ if("${CMAKE_C_COMPILER_ID}" STREQUAL "GNU")
+ set_source_files_properties(type_printers.c PROPERTIES
+ COMPILE_FLAGS "-std=gnu11")
+
+ set_source_files_properties(test11.c PROPERTIES
+ COMPILE_FLAGS "-Wall -Wextra -Werror -std=c11"
+ )
+ elseif("${CMAKE_C_COMPILER_ID}" STREQUAL "Clang")
+ set_source_files_properties(test11.c PROPERTIES
+ COMPILE_FLAGS "-Wall -Wextra -Weverything -Werror -std=c11"
+ )
+ elseif("${CMAKE_C_COMPILER_ID}" STREQUAL "MSVC")
+ set_source_files_properties(test11.c PROPERTIES
+ COMPILE_FLAGS "/Wall /WX /wd4514 /wd5045"
+ )
+ else()
+ message(WARNING "Unknown compiler '${CMAKE_C_COMPILER_ID}'!")
+ endif()
+endif()
+
if("${CMAKE_CXX_COMPILER_ID}" STREQUAL "GNU")
set_source_files_properties(test.cpp PROPERTIES
COMPILE_FLAGS "-Wall -Wextra -Werror -std=gnu++98"
diff --git a/test/test11.c b/test/test11.c
new file mode 100644
index 0000000..eab366b
--- /dev/null
+++ b/test/test11.c
@@ -0,0 +1,232 @@
+/*
+ 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)
+#pragma
+#endif
+
+UTEST(c11, ASSERT_TRUE) { ASSERT_TRUE(1); }
+
+UTEST(c11, ASSERT_FALSE) { ASSERT_FALSE(0); }
+
+UTEST(c11, ASSERT_EQ) { ASSERT_EQ(1, 1); }
+
+UTEST(c11, ASSERT_NE) { ASSERT_NE(1, 2); }
+
+UTEST(c11, ASSERT_LT) { ASSERT_LT(1, 2); }
+
+UTEST(c11, ASSERT_LE) {
+ ASSERT_LE(1, 1);
+ ASSERT_LE(1, 2);
+}
+
+UTEST(c11, ASSERT_GT) { ASSERT_GT(2, 1); }
+
+UTEST(c11, ASSERT_GE) {
+ ASSERT_GE(1, 1);
+ ASSERT_GE(2, 1);
+}
+
+UTEST(c11, ASSERT_STREQ) { ASSERT_STREQ("foo", "foo"); }
+
+UTEST(c11, ASSERT_STRNE) { ASSERT_STRNE("foo", "bar"); }
+
+UTEST(c11, EXPECT_TRUE) { EXPECT_TRUE(1); }
+
+UTEST(c11, EXPECT_FALSE) { EXPECT_FALSE(0); }
+
+UTEST(c11, EXPECT_EQ) { EXPECT_EQ(1, 1); }
+
+UTEST(c11, EXPECT_NE) { EXPECT_NE(1, 2); }
+
+UTEST(c11, EXPECT_LT) { EXPECT_LT(1, 2); }
+
+UTEST(c11, EXPECT_LE) {
+ EXPECT_LE(1, 1);
+ EXPECT_LE(1, 2);
+}
+
+UTEST(c11, EXPECT_GT) { EXPECT_GT(2, 1); }
+
+UTEST(c11, EXPECT_GE) {
+ EXPECT_GE(1, 1);
+ EXPECT_GE(2, 1);
+}
+
+UTEST(c11, EXPECT_STREQ) { EXPECT_STREQ("foo", "foo"); }
+
+UTEST(c11, EXPECT_STRNE) { EXPECT_STRNE("foo", "bar"); }
+
+UTEST(c11, 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, c) {
+ ASSERT_EQ(42, utest_fixture->foo);
+ utest_fixture->foo = 13;
+}
+
+UTEST_F(MyTestF, c2) {
+ ASSERT_EQ(42, utest_fixture->foo);
+ utest_fixture->foo = 13;
+}
+
+struct MyTestI {
+ size_t foo;
+ size_t bar;
+};
+
+UTEST_I_SETUP(MyTestI) {
+ ASSERT_EQ(0u, utest_fixture->foo);
+ ASSERT_EQ(0u, utest_fixture->bar);
+ utest_fixture->foo = 42;
+ utest_fixture->bar = utest_index;
+}
+
+UTEST_I_TEARDOWN(MyTestI) {
+ ASSERT_EQ(13u, utest_fixture->foo);
+ ASSERT_EQ(utest_index, utest_fixture->bar);
+}
+
+UTEST_I(MyTestI, c, 2) {
+ ASSERT_GT(2u, utest_fixture->bar);
+ utest_fixture->foo = 13;
+}
+
+UTEST_I(MyTestI, c2, 128) {
+ ASSERT_GT(128u, utest_fixture->bar);
+ utest_fixture->foo = 13;
+}
+
+UTEST(c11, Float) {
+ float a = 1;
+ float b = 2;
+ EXPECT_NE(a, b);
+ ASSERT_NE(a, b);
+}
+
+UTEST(c11, Double) {
+ double a = 1;
+ double b = 2;
+ EXPECT_NE(a, b);
+ ASSERT_NE(a, b);
+}
+
+UTEST(c11, LongDouble) {
+ long double a = 1;
+ long double b = 2;
+ EXPECT_NE(a, b);
+ ASSERT_NE(a, b);
+}
+
+UTEST(c11, Char) {
+ signed char a = 1;
+ signed char b = 2;
+ EXPECT_NE(a, b);
+ ASSERT_NE(a, b);
+}
+
+UTEST(c11, UChar) {
+ unsigned char a = 1;
+ unsigned char b = 2;
+ EXPECT_NE(a, b);
+ ASSERT_NE(a, b);
+}
+
+UTEST(c11, Short) {
+ short a = 1;
+ short b = 2;
+ EXPECT_NE(a, b);
+ ASSERT_NE(a, b);
+}
+
+UTEST(c11, UShort) {
+ unsigned short a = 1;
+ unsigned short b = 2;
+ EXPECT_NE(a, b);
+ ASSERT_NE(a, b);
+}
+
+UTEST(c11, Int) {
+ int a = 1;
+ int b = 2;
+ EXPECT_NE(a, b);
+ ASSERT_NE(a, b);
+}
+
+UTEST(c11, UInt) {
+ unsigned int a = 1;
+ unsigned int b = 2;
+ EXPECT_NE(a, b);
+ ASSERT_NE(a, b);
+}
+
+UTEST(c11, Long) {
+ long a = 1;
+ long b = 2;
+ EXPECT_NE(a, b);
+ ASSERT_NE(a, b);
+}
+
+UTEST(c11, ULong) {
+ unsigned long a = 1;
+ unsigned long b = 2;
+ EXPECT_NE(a, b);
+ ASSERT_NE(a, b);
+}
+
+UTEST(c11, Ptr) {
+ char foo = 42;
+ EXPECT_NE(&foo, &foo + 1);
+}
+
+UTEST(c11, VoidPtr) {
+ void *foo = 0;
+ EXPECT_NE(foo, (c11har *)foo + 1);
+}
+
+static const int data[4] = {42, 13, 6, -53};
+
+UTEST(c11, Array) { EXPECT_NE(data, data + 1); }
diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt
index d4f8f04..50c0175 100644
--- a/test/CMakeLists.txt
+++ b/test/CMakeLists.txt
@@ -29,11 +29,6 @@
include_directories(${CMAKE_CURRENT_SOURCE_DIR}/../)
if("${CMAKE_C_COMPILER_ID}" STREQUAL "GNU")
- list(FIND CMAKE_C_COMPILE_FEATURES c_std_11 IDX)
- if (${IDX} GREATER -1)
- set_source_files_properties(type_printers.c PROPERTIES
- COMPILE_FLAGS "-std=gnu11")
- endif()
set_source_files_properties(main.c test.c PROPERTIES
COMPILE_FLAGS "-Wall -Wextra -Werror -std=gnu89"
)
@@ -49,6 +44,28 @@
message(WARNING "Unknown compiler '${CMAKE_C_COMPILER_ID}'!")
endif()
+list(FIND CMAKE_C_COMPILE_FEATURES c_std_11 IDX)
+if (${IDX} GREATER -1)
+ if("${CMAKE_C_COMPILER_ID}" STREQUAL "GNU")
+ set_source_files_properties(type_printers.c PROPERTIES
+ COMPILE_FLAGS "-std=gnu11")
+
+ set_source_files_properties(test11.c PROPERTIES
+ COMPILE_FLAGS "-Wall -Wextra -Werror -std=c11"
+ )
+ elseif("${CMAKE_C_COMPILER_ID}" STREQUAL "Clang")
+ set_source_files_properties(test11.c PROPERTIES
+ COMPILE_FLAGS "-Wall -Wextra -Weverything -Werror -std=c11"
+ )
+ elseif("${CMAKE_C_COMPILER_ID}" STREQUAL "MSVC")
+ set_source_files_properties(test11.c PROPERTIES
+ COMPILE_FLAGS "/Wall /WX /wd4514 /wd5045"
+ )
+ else()
+ message(WARNING "Unknown compiler '${CMAKE_C_COMPILER_ID}'!")
+ endif()
+endif()
+
if("${CMAKE_CXX_COMPILER_ID}" STREQUAL "GNU")
set_source_files_properties(test.cpp PROPERTIES
COMPILE_FLAGS "-Wall -Wextra -Werror -std=gnu++98"
diff --git a/test/test11.c b/test/test11.c
new file mode 100644
index 0000000..eab366b
--- /dev/null
+++ b/test/test11.c
@@ -0,0 +1,232 @@
+/*
+ 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)
+#pragma
+#endif
+
+UTEST(c11, ASSERT_TRUE) { ASSERT_TRUE(1); }
+
+UTEST(c11, ASSERT_FALSE) { ASSERT_FALSE(0); }
+
+UTEST(c11, ASSERT_EQ) { ASSERT_EQ(1, 1); }
+
+UTEST(c11, ASSERT_NE) { ASSERT_NE(1, 2); }
+
+UTEST(c11, ASSERT_LT) { ASSERT_LT(1, 2); }
+
+UTEST(c11, ASSERT_LE) {
+ ASSERT_LE(1, 1);
+ ASSERT_LE(1, 2);
+}
+
+UTEST(c11, ASSERT_GT) { ASSERT_GT(2, 1); }
+
+UTEST(c11, ASSERT_GE) {
+ ASSERT_GE(1, 1);
+ ASSERT_GE(2, 1);
+}
+
+UTEST(c11, ASSERT_STREQ) { ASSERT_STREQ("foo", "foo"); }
+
+UTEST(c11, ASSERT_STRNE) { ASSERT_STRNE("foo", "bar"); }
+
+UTEST(c11, EXPECT_TRUE) { EXPECT_TRUE(1); }
+
+UTEST(c11, EXPECT_FALSE) { EXPECT_FALSE(0); }
+
+UTEST(c11, EXPECT_EQ) { EXPECT_EQ(1, 1); }
+
+UTEST(c11, EXPECT_NE) { EXPECT_NE(1, 2); }
+
+UTEST(c11, EXPECT_LT) { EXPECT_LT(1, 2); }
+
+UTEST(c11, EXPECT_LE) {
+ EXPECT_LE(1, 1);
+ EXPECT_LE(1, 2);
+}
+
+UTEST(c11, EXPECT_GT) { EXPECT_GT(2, 1); }
+
+UTEST(c11, EXPECT_GE) {
+ EXPECT_GE(1, 1);
+ EXPECT_GE(2, 1);
+}
+
+UTEST(c11, EXPECT_STREQ) { EXPECT_STREQ("foo", "foo"); }
+
+UTEST(c11, EXPECT_STRNE) { EXPECT_STRNE("foo", "bar"); }
+
+UTEST(c11, 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, c) {
+ ASSERT_EQ(42, utest_fixture->foo);
+ utest_fixture->foo = 13;
+}
+
+UTEST_F(MyTestF, c2) {
+ ASSERT_EQ(42, utest_fixture->foo);
+ utest_fixture->foo = 13;
+}
+
+struct MyTestI {
+ size_t foo;
+ size_t bar;
+};
+
+UTEST_I_SETUP(MyTestI) {
+ ASSERT_EQ(0u, utest_fixture->foo);
+ ASSERT_EQ(0u, utest_fixture->bar);
+ utest_fixture->foo = 42;
+ utest_fixture->bar = utest_index;
+}
+
+UTEST_I_TEARDOWN(MyTestI) {
+ ASSERT_EQ(13u, utest_fixture->foo);
+ ASSERT_EQ(utest_index, utest_fixture->bar);
+}
+
+UTEST_I(MyTestI, c, 2) {
+ ASSERT_GT(2u, utest_fixture->bar);
+ utest_fixture->foo = 13;
+}
+
+UTEST_I(MyTestI, c2, 128) {
+ ASSERT_GT(128u, utest_fixture->bar);
+ utest_fixture->foo = 13;
+}
+
+UTEST(c11, Float) {
+ float a = 1;
+ float b = 2;
+ EXPECT_NE(a, b);
+ ASSERT_NE(a, b);
+}
+
+UTEST(c11, Double) {
+ double a = 1;
+ double b = 2;
+ EXPECT_NE(a, b);
+ ASSERT_NE(a, b);
+}
+
+UTEST(c11, LongDouble) {
+ long double a = 1;
+ long double b = 2;
+ EXPECT_NE(a, b);
+ ASSERT_NE(a, b);
+}
+
+UTEST(c11, Char) {
+ signed char a = 1;
+ signed char b = 2;
+ EXPECT_NE(a, b);
+ ASSERT_NE(a, b);
+}
+
+UTEST(c11, UChar) {
+ unsigned char a = 1;
+ unsigned char b = 2;
+ EXPECT_NE(a, b);
+ ASSERT_NE(a, b);
+}
+
+UTEST(c11, Short) {
+ short a = 1;
+ short b = 2;
+ EXPECT_NE(a, b);
+ ASSERT_NE(a, b);
+}
+
+UTEST(c11, UShort) {
+ unsigned short a = 1;
+ unsigned short b = 2;
+ EXPECT_NE(a, b);
+ ASSERT_NE(a, b);
+}
+
+UTEST(c11, Int) {
+ int a = 1;
+ int b = 2;
+ EXPECT_NE(a, b);
+ ASSERT_NE(a, b);
+}
+
+UTEST(c11, UInt) {
+ unsigned int a = 1;
+ unsigned int b = 2;
+ EXPECT_NE(a, b);
+ ASSERT_NE(a, b);
+}
+
+UTEST(c11, Long) {
+ long a = 1;
+ long b = 2;
+ EXPECT_NE(a, b);
+ ASSERT_NE(a, b);
+}
+
+UTEST(c11, ULong) {
+ unsigned long a = 1;
+ unsigned long b = 2;
+ EXPECT_NE(a, b);
+ ASSERT_NE(a, b);
+}
+
+UTEST(c11, Ptr) {
+ char foo = 42;
+ EXPECT_NE(&foo, &foo + 1);
+}
+
+UTEST(c11, VoidPtr) {
+ void *foo = 0;
+ EXPECT_NE(foo, (c11har *)foo + 1);
+}
+
+static const int data[4] = {42, 13, 6, -53};
+
+UTEST(c11, Array) { EXPECT_NE(data, data + 1); }
diff --git a/utest.h b/utest.h
index e5cea7b..7f2bcaa 100644
--- a/utest.h
+++ b/utest.h
@@ -198,12 +198,16 @@
(counter.QuadPart * 1000000000) / frequency.QuadPart);
#elif defined(__linux)
struct timespec ts;
+#if defined(__STDC_VERSION__) && (__STDC_VERSION__ >= 201112L)
+ timespec_get(&ts, TIME_UTC);
+#else
const clockid_t cid = CLOCK_REALTIME;
#if defined(UTEST_USE_CLOCKGETTIME)
clock_gettime(cid, &ts);
#else
syscall(SYS_clock_gettime, cid, &ts);
#endif
+#endif
return UTEST_CAST(utest_int64_t, ts.tv_sec) * 1000 * 1000 * 1000 + ts.tv_nsec;
#elif __APPLE__
return UTEST_CAST(utest_int64_t, mach_absolute_time());