diff --git a/README.md b/README.md index eeb6073..b67fffa 100644 --- a/README.md +++ b/README.md @@ -310,6 +310,60 @@ } ``` +### ASSERT_STREQ(x, y) + +Asserts that the strings x and y are equal. + +```c +UTEST(foo, bar) { + char* a = "foo"; + char* b = "bar"; + ASSERT_STREQ(a, a); // pass! + ASSERT_STREQ(b, b); // pass! + ASSERT_STREQ(a, b); // fail! +} +``` + +### ASSERT_STRNE(x, y) + +Asserts that the strings x and y are not equal. + +```c +UTEST(foo, bar) { + char* a = "foo"; + char* b = "bar"; + ASSERT_STREQ(a, b); // pass! + ASSERT_STREQ(a, a); // fail! +} +``` + +### ASSERT_STRNEQ(x, y) + +Asserts that the strings x and y are equal up to the length of the string x. + +```c +UTEST(foo, bar) { + char* a = "foobar"; + char* b = "foo"; + ASSERT_STRNEQ(a, a); // pass! + ASSERT_STRNEQ(b, b); // pass! + ASSERT_STRNEQ(a, b); // pass! +} +``` + +### ASSERT_STRNNE(x, y) + +Asserts that the strings x and y are not equal up to the length of the string x. + +```c +UTEST(foo, bar) { + char* a = "foobar"; + char* b = "bar"; + ASSERT_STRNNE(a, b); // pass! + ASSERT_STRNNE(a, a); // fail! +} +``` + ### EXPECT_TRUE(x) Expects that x evaluates to true (i.e. non-zero). @@ -437,6 +491,60 @@ } ``` +### EXPECT_STREQ(x, y) + +Expects that the strings x and y are equal. + +```c +UTEST(foo, bar) { + char* a = "foo"; + char* b = "bar"; + EXPECT_STREQ(a, a); // pass! + EXPECT_STREQ(b, b); // pass! + EXPECT_STREQ(a, b); // fail! +} +``` + +### EXPECT_STRNE(x, y) + +Expects that the strings x and y are not equal. + +```c +UTEST(foo, bar) { + char* a = "foo"; + char* b = "bar"; + EXPECT_STRNE(a, b); // pass! + EXPECT_STRNE(a, a); // fail! +} +``` + +### EXPECT_STRNEQ(x, y) + +Expects that the strings x and y are equal up to the length of the string x. + +```c +UTEST(foo, bar) { + char* a = "foobar"; + char* b = "foo"; + EXPECT_STRNEQ(a, a); // pass! + EXPECT_STRNEQ(b, b); // pass! + EXPECT_STRNEQ(a, b); // pass! +} +``` + +### EXPECT_STRNNE(x, y) + +Expects that the strings x and y are not equal up to the length of the string x. + +```c +UTEST(foo, bar) { + char* a = "foobar"; + char* b = "bar"; + EXPECT_STRNNE(a, b); // pass! + EXPECT_STRNNE(a, a); // fail! +} +``` + ## Types Supported for Checks The library supports asserting on any builtin integer, floating-point, or diff --git a/README.md b/README.md index eeb6073..b67fffa 100644 --- a/README.md +++ b/README.md @@ -310,6 +310,60 @@ } ``` +### ASSERT_STREQ(x, y) + +Asserts that the strings x and y are equal. + +```c +UTEST(foo, bar) { + char* a = "foo"; + char* b = "bar"; + ASSERT_STREQ(a, a); // pass! + ASSERT_STREQ(b, b); // pass! + ASSERT_STREQ(a, b); // fail! +} +``` + +### ASSERT_STRNE(x, y) + +Asserts that the strings x and y are not equal. + +```c +UTEST(foo, bar) { + char* a = "foo"; + char* b = "bar"; + ASSERT_STREQ(a, b); // pass! + ASSERT_STREQ(a, a); // fail! +} +``` + +### ASSERT_STRNEQ(x, y) + +Asserts that the strings x and y are equal up to the length of the string x. + +```c +UTEST(foo, bar) { + char* a = "foobar"; + char* b = "foo"; + ASSERT_STRNEQ(a, a); // pass! + ASSERT_STRNEQ(b, b); // pass! + ASSERT_STRNEQ(a, b); // pass! +} +``` + +### ASSERT_STRNNE(x, y) + +Asserts that the strings x and y are not equal up to the length of the string x. + +```c +UTEST(foo, bar) { + char* a = "foobar"; + char* b = "bar"; + ASSERT_STRNNE(a, b); // pass! + ASSERT_STRNNE(a, a); // fail! +} +``` + ### EXPECT_TRUE(x) Expects that x evaluates to true (i.e. non-zero). @@ -437,6 +491,60 @@ } ``` +### EXPECT_STREQ(x, y) + +Expects that the strings x and y are equal. + +```c +UTEST(foo, bar) { + char* a = "foo"; + char* b = "bar"; + EXPECT_STREQ(a, a); // pass! + EXPECT_STREQ(b, b); // pass! + EXPECT_STREQ(a, b); // fail! +} +``` + +### EXPECT_STRNE(x, y) + +Expects that the strings x and y are not equal. + +```c +UTEST(foo, bar) { + char* a = "foo"; + char* b = "bar"; + EXPECT_STRNE(a, b); // pass! + EXPECT_STRNE(a, a); // fail! +} +``` + +### EXPECT_STRNEQ(x, y) + +Expects that the strings x and y are equal up to the length of the string x. + +```c +UTEST(foo, bar) { + char* a = "foobar"; + char* b = "foo"; + EXPECT_STRNEQ(a, a); // pass! + EXPECT_STRNEQ(b, b); // pass! + EXPECT_STRNEQ(a, b); // pass! +} +``` + +### EXPECT_STRNNE(x, y) + +Expects that the strings x and y are not equal up to the length of the string x. + +```c +UTEST(foo, bar) { + char* a = "foobar"; + char* b = "bar"; + EXPECT_STRNNE(a, b); // pass! + EXPECT_STRNNE(a, a); // fail! +} +``` + ## Types Supported for Checks The library supports asserting on any builtin integer, floating-point, or diff --git a/test/test.c b/test/test.c index b85ae16..5e2125b 100644 --- a/test/test.c +++ b/test/test.c @@ -59,6 +59,10 @@ UTEST(c, ASSERT_STRNE) { ASSERT_STRNE("foo", "bar"); } +UTEST(c, ASSERT_STRNEQ) { ASSERT_STRNEQ("foo", "foobar"); } + +UTEST(c, ASSERT_STRNNE) { ASSERT_STRNNE("foobar", "bar"); } + UTEST(c, EXPECT_TRUE) { EXPECT_TRUE(1); } UTEST(c, EXPECT_FALSE) { EXPECT_FALSE(0); } @@ -85,6 +89,10 @@ UTEST(c, EXPECT_STRNE) { EXPECT_STRNE("foo", "bar"); } +UTEST(c, EXPECT_STRNEQ) { EXPECT_STRNEQ("foo", "foobar"); } + +UTEST(c, EXPECT_STRNNE) { EXPECT_STRNNE("foobar", "bar"); } + UTEST(c, no_double_eval) { int i = 0; ASSERT_EQ(i++, 0); diff --git a/README.md b/README.md index eeb6073..b67fffa 100644 --- a/README.md +++ b/README.md @@ -310,6 +310,60 @@ } ``` +### ASSERT_STREQ(x, y) + +Asserts that the strings x and y are equal. + +```c +UTEST(foo, bar) { + char* a = "foo"; + char* b = "bar"; + ASSERT_STREQ(a, a); // pass! + ASSERT_STREQ(b, b); // pass! + ASSERT_STREQ(a, b); // fail! +} +``` + +### ASSERT_STRNE(x, y) + +Asserts that the strings x and y are not equal. + +```c +UTEST(foo, bar) { + char* a = "foo"; + char* b = "bar"; + ASSERT_STREQ(a, b); // pass! + ASSERT_STREQ(a, a); // fail! +} +``` + +### ASSERT_STRNEQ(x, y) + +Asserts that the strings x and y are equal up to the length of the string x. + +```c +UTEST(foo, bar) { + char* a = "foobar"; + char* b = "foo"; + ASSERT_STRNEQ(a, a); // pass! + ASSERT_STRNEQ(b, b); // pass! + ASSERT_STRNEQ(a, b); // pass! +} +``` + +### ASSERT_STRNNE(x, y) + +Asserts that the strings x and y are not equal up to the length of the string x. + +```c +UTEST(foo, bar) { + char* a = "foobar"; + char* b = "bar"; + ASSERT_STRNNE(a, b); // pass! + ASSERT_STRNNE(a, a); // fail! +} +``` + ### EXPECT_TRUE(x) Expects that x evaluates to true (i.e. non-zero). @@ -437,6 +491,60 @@ } ``` +### EXPECT_STREQ(x, y) + +Expects that the strings x and y are equal. + +```c +UTEST(foo, bar) { + char* a = "foo"; + char* b = "bar"; + EXPECT_STREQ(a, a); // pass! + EXPECT_STREQ(b, b); // pass! + EXPECT_STREQ(a, b); // fail! +} +``` + +### EXPECT_STRNE(x, y) + +Expects that the strings x and y are not equal. + +```c +UTEST(foo, bar) { + char* a = "foo"; + char* b = "bar"; + EXPECT_STRNE(a, b); // pass! + EXPECT_STRNE(a, a); // fail! +} +``` + +### EXPECT_STRNEQ(x, y) + +Expects that the strings x and y are equal up to the length of the string x. + +```c +UTEST(foo, bar) { + char* a = "foobar"; + char* b = "foo"; + EXPECT_STRNEQ(a, a); // pass! + EXPECT_STRNEQ(b, b); // pass! + EXPECT_STRNEQ(a, b); // pass! +} +``` + +### EXPECT_STRNNE(x, y) + +Expects that the strings x and y are not equal up to the length of the string x. + +```c +UTEST(foo, bar) { + char* a = "foobar"; + char* b = "bar"; + EXPECT_STRNNE(a, b); // pass! + EXPECT_STRNNE(a, a); // fail! +} +``` + ## Types Supported for Checks The library supports asserting on any builtin integer, floating-point, or diff --git a/test/test.c b/test/test.c index b85ae16..5e2125b 100644 --- a/test/test.c +++ b/test/test.c @@ -59,6 +59,10 @@ UTEST(c, ASSERT_STRNE) { ASSERT_STRNE("foo", "bar"); } +UTEST(c, ASSERT_STRNEQ) { ASSERT_STRNEQ("foo", "foobar"); } + +UTEST(c, ASSERT_STRNNE) { ASSERT_STRNNE("foobar", "bar"); } + UTEST(c, EXPECT_TRUE) { EXPECT_TRUE(1); } UTEST(c, EXPECT_FALSE) { EXPECT_FALSE(0); } @@ -85,6 +89,10 @@ UTEST(c, EXPECT_STRNE) { EXPECT_STRNE("foo", "bar"); } +UTEST(c, EXPECT_STRNEQ) { EXPECT_STRNEQ("foo", "foobar"); } + +UTEST(c, EXPECT_STRNNE) { EXPECT_STRNNE("foobar", "bar"); } + UTEST(c, no_double_eval) { int i = 0; ASSERT_EQ(i++, 0); diff --git a/test/test.cpp b/test/test.cpp index bd837d1..52bb463 100644 --- a/test/test.cpp +++ b/test/test.cpp @@ -56,6 +56,10 @@ UTEST(cpp, ASSERT_STRNE) { ASSERT_STRNE("foo", "bar"); } +UTEST(cpp, ASSERT_STRNEQ) { ASSERT_STRNEQ("foo", "foobar"); } + +UTEST(cpp, ASSERT_STRNNE) { ASSERT_STRNNE("foobar", "bar"); } + UTEST(cpp, EXPECT_TRUE) { EXPECT_TRUE(1); } UTEST(cpp, EXPECT_FALSE) { EXPECT_FALSE(0); } @@ -82,6 +86,10 @@ UTEST(cpp, EXPECT_STRNE) { EXPECT_STRNE("foo", "bar"); } +UTEST(cpp, EXPECT_STRNEQ) { EXPECT_STRNEQ("foo", "foobar"); } + +UTEST(cpp, EXPECT_STRNNE) { EXPECT_STRNNE("foobar", "bar"); } + UTEST(cpp, no_double_eval) { int i = 0; ASSERT_EQ(i++, 0); diff --git a/README.md b/README.md index eeb6073..b67fffa 100644 --- a/README.md +++ b/README.md @@ -310,6 +310,60 @@ } ``` +### ASSERT_STREQ(x, y) + +Asserts that the strings x and y are equal. + +```c +UTEST(foo, bar) { + char* a = "foo"; + char* b = "bar"; + ASSERT_STREQ(a, a); // pass! + ASSERT_STREQ(b, b); // pass! + ASSERT_STREQ(a, b); // fail! +} +``` + +### ASSERT_STRNE(x, y) + +Asserts that the strings x and y are not equal. + +```c +UTEST(foo, bar) { + char* a = "foo"; + char* b = "bar"; + ASSERT_STREQ(a, b); // pass! + ASSERT_STREQ(a, a); // fail! +} +``` + +### ASSERT_STRNEQ(x, y) + +Asserts that the strings x and y are equal up to the length of the string x. + +```c +UTEST(foo, bar) { + char* a = "foobar"; + char* b = "foo"; + ASSERT_STRNEQ(a, a); // pass! + ASSERT_STRNEQ(b, b); // pass! + ASSERT_STRNEQ(a, b); // pass! +} +``` + +### ASSERT_STRNNE(x, y) + +Asserts that the strings x and y are not equal up to the length of the string x. + +```c +UTEST(foo, bar) { + char* a = "foobar"; + char* b = "bar"; + ASSERT_STRNNE(a, b); // pass! + ASSERT_STRNNE(a, a); // fail! +} +``` + ### EXPECT_TRUE(x) Expects that x evaluates to true (i.e. non-zero). @@ -437,6 +491,60 @@ } ``` +### EXPECT_STREQ(x, y) + +Expects that the strings x and y are equal. + +```c +UTEST(foo, bar) { + char* a = "foo"; + char* b = "bar"; + EXPECT_STREQ(a, a); // pass! + EXPECT_STREQ(b, b); // pass! + EXPECT_STREQ(a, b); // fail! +} +``` + +### EXPECT_STRNE(x, y) + +Expects that the strings x and y are not equal. + +```c +UTEST(foo, bar) { + char* a = "foo"; + char* b = "bar"; + EXPECT_STRNE(a, b); // pass! + EXPECT_STRNE(a, a); // fail! +} +``` + +### EXPECT_STRNEQ(x, y) + +Expects that the strings x and y are equal up to the length of the string x. + +```c +UTEST(foo, bar) { + char* a = "foobar"; + char* b = "foo"; + EXPECT_STRNEQ(a, a); // pass! + EXPECT_STRNEQ(b, b); // pass! + EXPECT_STRNEQ(a, b); // pass! +} +``` + +### EXPECT_STRNNE(x, y) + +Expects that the strings x and y are not equal up to the length of the string x. + +```c +UTEST(foo, bar) { + char* a = "foobar"; + char* b = "bar"; + EXPECT_STRNNE(a, b); // pass! + EXPECT_STRNNE(a, a); // fail! +} +``` + ## Types Supported for Checks The library supports asserting on any builtin integer, floating-point, or diff --git a/test/test.c b/test/test.c index b85ae16..5e2125b 100644 --- a/test/test.c +++ b/test/test.c @@ -59,6 +59,10 @@ UTEST(c, ASSERT_STRNE) { ASSERT_STRNE("foo", "bar"); } +UTEST(c, ASSERT_STRNEQ) { ASSERT_STRNEQ("foo", "foobar"); } + +UTEST(c, ASSERT_STRNNE) { ASSERT_STRNNE("foobar", "bar"); } + UTEST(c, EXPECT_TRUE) { EXPECT_TRUE(1); } UTEST(c, EXPECT_FALSE) { EXPECT_FALSE(0); } @@ -85,6 +89,10 @@ UTEST(c, EXPECT_STRNE) { EXPECT_STRNE("foo", "bar"); } +UTEST(c, EXPECT_STRNEQ) { EXPECT_STRNEQ("foo", "foobar"); } + +UTEST(c, EXPECT_STRNNE) { EXPECT_STRNNE("foobar", "bar"); } + UTEST(c, no_double_eval) { int i = 0; ASSERT_EQ(i++, 0); diff --git a/test/test.cpp b/test/test.cpp index bd837d1..52bb463 100644 --- a/test/test.cpp +++ b/test/test.cpp @@ -56,6 +56,10 @@ UTEST(cpp, ASSERT_STRNE) { ASSERT_STRNE("foo", "bar"); } +UTEST(cpp, ASSERT_STRNEQ) { ASSERT_STRNEQ("foo", "foobar"); } + +UTEST(cpp, ASSERT_STRNNE) { ASSERT_STRNNE("foobar", "bar"); } + UTEST(cpp, EXPECT_TRUE) { EXPECT_TRUE(1); } UTEST(cpp, EXPECT_FALSE) { EXPECT_FALSE(0); } @@ -82,6 +86,10 @@ UTEST(cpp, EXPECT_STRNE) { EXPECT_STRNE("foo", "bar"); } +UTEST(cpp, EXPECT_STRNEQ) { EXPECT_STRNEQ("foo", "foobar"); } + +UTEST(cpp, EXPECT_STRNNE) { EXPECT_STRNNE("foobar", "bar"); } + UTEST(cpp, no_double_eval) { int i = 0; ASSERT_EQ(i++, 0); diff --git a/test/test11.cpp b/test/test11.cpp index fa548f8..7b060ff 100644 --- a/test/test11.cpp +++ b/test/test11.cpp @@ -56,6 +56,10 @@ UTEST(cpp11, ASSERT_STRNE) { ASSERT_STRNE("foo", "bar"); } +UTEST(cpp11, ASSERT_STRNEQ) { ASSERT_STRNEQ("foo", "foobar"); } + +UTEST(cpp11, ASSERT_STRNNE) { ASSERT_STRNNE("foobar", "bar"); } + UTEST(cpp11, EXPECT_TRUE) { EXPECT_TRUE(1); } UTEST(cpp11, EXPECT_FALSE) { EXPECT_FALSE(0); } @@ -82,6 +86,10 @@ UTEST(cpp11, EXPECT_STRNE) { EXPECT_STRNE("foo", "bar"); } +UTEST(cpp11, EXPECT_STRNEQ) { EXPECT_STRNEQ("foo", "foobar"); } + +UTEST(cpp11, EXPECT_STRNNE) { EXPECT_STRNNE("foobar", "bar"); } + UTEST(cpp11, no_double_eval) { int i = 0; ASSERT_EQ(i++, 0); diff --git a/README.md b/README.md index eeb6073..b67fffa 100644 --- a/README.md +++ b/README.md @@ -310,6 +310,60 @@ } ``` +### ASSERT_STREQ(x, y) + +Asserts that the strings x and y are equal. + +```c +UTEST(foo, bar) { + char* a = "foo"; + char* b = "bar"; + ASSERT_STREQ(a, a); // pass! + ASSERT_STREQ(b, b); // pass! + ASSERT_STREQ(a, b); // fail! +} +``` + +### ASSERT_STRNE(x, y) + +Asserts that the strings x and y are not equal. + +```c +UTEST(foo, bar) { + char* a = "foo"; + char* b = "bar"; + ASSERT_STREQ(a, b); // pass! + ASSERT_STREQ(a, a); // fail! +} +``` + +### ASSERT_STRNEQ(x, y) + +Asserts that the strings x and y are equal up to the length of the string x. + +```c +UTEST(foo, bar) { + char* a = "foobar"; + char* b = "foo"; + ASSERT_STRNEQ(a, a); // pass! + ASSERT_STRNEQ(b, b); // pass! + ASSERT_STRNEQ(a, b); // pass! +} +``` + +### ASSERT_STRNNE(x, y) + +Asserts that the strings x and y are not equal up to the length of the string x. + +```c +UTEST(foo, bar) { + char* a = "foobar"; + char* b = "bar"; + ASSERT_STRNNE(a, b); // pass! + ASSERT_STRNNE(a, a); // fail! +} +``` + ### EXPECT_TRUE(x) Expects that x evaluates to true (i.e. non-zero). @@ -437,6 +491,60 @@ } ``` +### EXPECT_STREQ(x, y) + +Expects that the strings x and y are equal. + +```c +UTEST(foo, bar) { + char* a = "foo"; + char* b = "bar"; + EXPECT_STREQ(a, a); // pass! + EXPECT_STREQ(b, b); // pass! + EXPECT_STREQ(a, b); // fail! +} +``` + +### EXPECT_STRNE(x, y) + +Expects that the strings x and y are not equal. + +```c +UTEST(foo, bar) { + char* a = "foo"; + char* b = "bar"; + EXPECT_STRNE(a, b); // pass! + EXPECT_STRNE(a, a); // fail! +} +``` + +### EXPECT_STRNEQ(x, y) + +Expects that the strings x and y are equal up to the length of the string x. + +```c +UTEST(foo, bar) { + char* a = "foobar"; + char* b = "foo"; + EXPECT_STRNEQ(a, a); // pass! + EXPECT_STRNEQ(b, b); // pass! + EXPECT_STRNEQ(a, b); // pass! +} +``` + +### EXPECT_STRNNE(x, y) + +Expects that the strings x and y are not equal up to the length of the string x. + +```c +UTEST(foo, bar) { + char* a = "foobar"; + char* b = "bar"; + EXPECT_STRNNE(a, b); // pass! + EXPECT_STRNNE(a, a); // fail! +} +``` + ## Types Supported for Checks The library supports asserting on any builtin integer, floating-point, or diff --git a/test/test.c b/test/test.c index b85ae16..5e2125b 100644 --- a/test/test.c +++ b/test/test.c @@ -59,6 +59,10 @@ UTEST(c, ASSERT_STRNE) { ASSERT_STRNE("foo", "bar"); } +UTEST(c, ASSERT_STRNEQ) { ASSERT_STRNEQ("foo", "foobar"); } + +UTEST(c, ASSERT_STRNNE) { ASSERT_STRNNE("foobar", "bar"); } + UTEST(c, EXPECT_TRUE) { EXPECT_TRUE(1); } UTEST(c, EXPECT_FALSE) { EXPECT_FALSE(0); } @@ -85,6 +89,10 @@ UTEST(c, EXPECT_STRNE) { EXPECT_STRNE("foo", "bar"); } +UTEST(c, EXPECT_STRNEQ) { EXPECT_STRNEQ("foo", "foobar"); } + +UTEST(c, EXPECT_STRNNE) { EXPECT_STRNNE("foobar", "bar"); } + UTEST(c, no_double_eval) { int i = 0; ASSERT_EQ(i++, 0); diff --git a/test/test.cpp b/test/test.cpp index bd837d1..52bb463 100644 --- a/test/test.cpp +++ b/test/test.cpp @@ -56,6 +56,10 @@ UTEST(cpp, ASSERT_STRNE) { ASSERT_STRNE("foo", "bar"); } +UTEST(cpp, ASSERT_STRNEQ) { ASSERT_STRNEQ("foo", "foobar"); } + +UTEST(cpp, ASSERT_STRNNE) { ASSERT_STRNNE("foobar", "bar"); } + UTEST(cpp, EXPECT_TRUE) { EXPECT_TRUE(1); } UTEST(cpp, EXPECT_FALSE) { EXPECT_FALSE(0); } @@ -82,6 +86,10 @@ UTEST(cpp, EXPECT_STRNE) { EXPECT_STRNE("foo", "bar"); } +UTEST(cpp, EXPECT_STRNEQ) { EXPECT_STRNEQ("foo", "foobar"); } + +UTEST(cpp, EXPECT_STRNNE) { EXPECT_STRNNE("foobar", "bar"); } + UTEST(cpp, no_double_eval) { int i = 0; ASSERT_EQ(i++, 0); diff --git a/test/test11.cpp b/test/test11.cpp index fa548f8..7b060ff 100644 --- a/test/test11.cpp +++ b/test/test11.cpp @@ -56,6 +56,10 @@ UTEST(cpp11, ASSERT_STRNE) { ASSERT_STRNE("foo", "bar"); } +UTEST(cpp11, ASSERT_STRNEQ) { ASSERT_STRNEQ("foo", "foobar"); } + +UTEST(cpp11, ASSERT_STRNNE) { ASSERT_STRNNE("foobar", "bar"); } + UTEST(cpp11, EXPECT_TRUE) { EXPECT_TRUE(1); } UTEST(cpp11, EXPECT_FALSE) { EXPECT_FALSE(0); } @@ -82,6 +86,10 @@ UTEST(cpp11, EXPECT_STRNE) { EXPECT_STRNE("foo", "bar"); } +UTEST(cpp11, EXPECT_STRNEQ) { EXPECT_STRNEQ("foo", "foobar"); } + +UTEST(cpp11, EXPECT_STRNNE) { EXPECT_STRNNE("foobar", "bar"); } + UTEST(cpp11, no_double_eval) { int i = 0; ASSERT_EQ(i++, 0); diff --git a/utest.h b/utest.h index 5c77310..e5cea7b 100644 --- a/utest.h +++ b/utest.h @@ -388,13 +388,22 @@ #endif #if defined(__clang__) +#define UTEST_STRNCMP(x, y, size) \ + _Pragma("clang diagnostic push") \ + _Pragma("clang diagnostic ignored \"-Wdisabled-macro-expansion\"") \ + strncmp(x, y, size) _Pragma("clang diagnostic pop") +#else +#define UTEST_STRNCMP(x, y, size) strncmp(x, y, size) +#endif + +#if defined(__clang__) #define UTEST_EXPECT(x, y, cond) \ { \ _Pragma("clang diagnostic push") \ _Pragma("clang diagnostic ignored \"-Wlanguage-extension-token\"") \ _Pragma("clang diagnostic ignored \"-Wc++98-compat-pedantic\"") \ _Pragma("clang diagnostic ignored \"-Wfloat-equal\"") \ - UTEST_AUTO(x) xEval = (x); \ + UTEST_AUTO(x) xEval = (x); \ UTEST_AUTO(y) yEval = (y); \ if (!((xEval)cond(yEval))) { \ _Pragma("clang diagnostic pop") \ @@ -473,6 +482,22 @@ *utest_result = 1; \ } +#define EXPECT_STRNEQ(x, y) \ + if (0 != UTEST_STRNCMP(x, y, strlen(x))) { \ + UTEST_PRINTF("%s:%u: Failure\n", __FILE__, __LINE__); \ + UTEST_PRINTF(" Expected : \"%s\"\n", x); \ + UTEST_PRINTF(" Actual : \"%s\"\n", y); \ + *utest_result = 1; \ + } + +#define EXPECT_STRNNE(x, y) \ + if (0 == UTEST_STRNCMP(x, y, strlen(x))) { \ + UTEST_PRINTF("%s:%u: Failure\n", __FILE__, __LINE__); \ + UTEST_PRINTF(" Expected : \"%s\"\n", x); \ + UTEST_PRINTF(" Actual : \"%s\"\n", y); \ + *utest_result = 1; \ + } + #if defined(__clang__) #define UTEST_ASSERT(x, y, cond) \ { \ @@ -480,7 +505,7 @@ _Pragma("clang diagnostic ignored \"-Wlanguage-extension-token\"") \ _Pragma("clang diagnostic ignored \"-Wc++98-compat-pedantic\"") \ _Pragma("clang diagnostic ignored \"-Wfloat-equal\"") \ - UTEST_AUTO(x) xEval = (x); \ + UTEST_AUTO(x) xEval = (x); \ UTEST_AUTO(y) yEval = (y); \ if (!((xEval)cond(yEval))) { \ _Pragma("clang diagnostic pop") \ @@ -549,7 +574,6 @@ #define ASSERT_GE(x, y) UTEST_ASSERT(x, y, >=) #define ASSERT_STREQ(x, y) \ - EXPECT_STREQ(x, y); \ if (0 != strcmp(x, y)) { \ UTEST_PRINTF("%s:%u: Failure\n", __FILE__, __LINE__); \ UTEST_PRINTF(" Expected : \"%s\"\n", x); \ @@ -559,7 +583,6 @@ } #define ASSERT_STRNE(x, y) \ - EXPECT_STRNE(x, y); \ if (0 == strcmp(x, y)) { \ UTEST_PRINTF("%s:%u: Failure\n", __FILE__, __LINE__); \ UTEST_PRINTF(" Expected : \"%s\"\n", x); \ @@ -568,6 +591,24 @@ return; \ } +#define ASSERT_STRNEQ(x, y) \ + if (0 != UTEST_STRNCMP(x, y, strlen(x))) { \ + UTEST_PRINTF("%s:%u: Failure\n", __FILE__, __LINE__); \ + UTEST_PRINTF(" Expected : \"%s\"\n", x); \ + UTEST_PRINTF(" Actual : \"%s\"\n", y); \ + *utest_result = 1; \ + return; \ + } + +#define ASSERT_STRNNE(x, y) \ + if (0 == UTEST_STRNCMP(x, y, strlen(x))) { \ + UTEST_PRINTF("%s:%u: Failure\n", __FILE__, __LINE__); \ + UTEST_PRINTF(" Expected : \"%s\"\n", x); \ + UTEST_PRINTF(" Actual : \"%s\"\n", y); \ + *utest_result = 1; \ + return; \ + } + #define UTEST(SET, NAME) \ UTEST_EXTERN struct utest_state_s utest_state; \ static void utest_run_##SET##_##NAME(int *utest_result); \