Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Comparing changes

Choose two branches to see what's changed or to start a new pull request. If you need to, you can also compare across forks.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also compare across forks.
base fork: liuliu/case
base: b82761f7c6
...
head fork: liuliu/case
compare: 14146c887a
Checking mergeability… Don't worry, you can still create the pull request.
  • 2 commits
  • 2 files changed
  • 0 commit comments
  • 1 contributor
Showing with 20 additions and 14 deletions.
  1. +15 −9 case.h
  2. +5 −5 case_main.h
View
24 case.h
@@ -4,7 +4,7 @@
#include <stdio.h>
#include <stdint.h>
-/* the following 3 lines to generate unique name was taken from Catch: https://github.com/philsquared/Catch
+/* the following 9 lines to generate unique name was taken from Catch: https://github.com/philsquared/Catch
* here is the licence:
* Boost Software License - Version 1.0 - August 17th, 2003
*
@@ -29,9 +29,15 @@
* FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
* ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
* DEALINGS IN THE SOFTWARE. */
+#ifndef INTERNAL_CATCH_UNIQUE_NAME_LINE2
#define INTERNAL_CATCH_UNIQUE_NAME_LINE2( name, line ) name##line
+#endif
+#ifndef INTERNAL_CATCH_UNIQUE_NAME_LINE
#define INTERNAL_CATCH_UNIQUE_NAME_LINE( name, line ) INTERNAL_CATCH_UNIQUE_NAME_LINE2( name, line )
+#endif
+#ifndef INTERNAL_CATCH_UNIQUE_NAME
#define INTERNAL_CATCH_UNIQUE_NAME( name ) INTERNAL_CATCH_UNIQUE_NAME_LINE( name, __LINE__ )
+#endif
typedef void (*case_f)(char*, int*);
@@ -51,7 +57,7 @@ static void INTERNAL_CATCH_UNIQUE_NAME(__test_case_driver__) (char* __case_name_
#define REQUIRE_EQ(a, b, err, ...) { \
if ((a) != (b)) \
{ \
- printf("\n\t\033[0;31mREQUIRE_EQ\033[0;30m: %s:%d: %s(%lg) != %s(%lg), " err, __FILE__, __LINE__, #a, (double)(a), #b, (double)(b), ##__VA_ARGS__); \
+ printf("\n\t\033[0;31mREQUIRE_EQ\033[0;0m: %s:%d: %s(%lg) != %s(%lg), " err, __FILE__, __LINE__, #a, (double)(a), #b, (double)(b), ##__VA_ARGS__); \
ABORT_CASE; \
} }
@@ -60,14 +66,14 @@ int __case_i__; \
for (__case_i__ = 0; __case_i__ < (len); __case_i__++) \
if (((type*)(a))[__case_i__] != ((type*)(b))[__case_i__]) \
{ \
- printf("\n\t\033[0;31mREQUIRE_ARRAY_EQ\033[0;30m: %s:%d: %s[%d](%lg) != %s[%d](%lg), " err, __FILE__, __LINE__, #a, __case_i__, (double)((type*)(a))[__case_i__], #b, __case_i__, (double)((type*)(b))[__case_i__], ##__VA_ARGS__); \
+ printf("\n\t\033[0;31mREQUIRE_ARRAY_EQ\033[0;0m: %s:%d: %s[%d](%lg) != %s[%d](%lg), " err, __FILE__, __LINE__, #a, __case_i__, (double)((type*)(a))[__case_i__], #b, __case_i__, (double)((type*)(b))[__case_i__], ##__VA_ARGS__); \
ABORT_CASE; \
} }
#define REQUIRE_EQ_WITH_TOLERANCE(a, b, t, err, ...) { \
if ((double)((a) - (b)) > (t) || (double)((a) - (b)) < -(t)) \
{ \
- printf("\n\t\033[0;31mREQUIRE_EQ_WITH_TOLERANCE\033[0;30m: %s:%d: %s(%lg) != %s(%lg) | +-%lg, " err, __FILE__, __LINE__, #a, (double)(a), #b, (double)(b), (double)(t), ##__VA_ARGS__); \
+ printf("\n\t\033[0;31mREQUIRE_EQ_WITH_TOLERANCE\033[0;0m: %s:%d: %s(%lg) != %s(%lg) | +-%lg, " err, __FILE__, __LINE__, #a, (double)(a), #b, (double)(b), (double)(t), ##__VA_ARGS__); \
ABORT_CASE; \
} }
@@ -76,14 +82,14 @@ int __case_i__; \
for (__case_i__ = 0; __case_i__ < (len); __case_i__++) \
if ((double)(((type*)(a))[__case_i__] - ((type*)(b))[__case_i__]) > (t) || (double)(((type*)(a))[__case_i__] - ((type*)(b))[__case_i__]) < -(t)) \
{ \
- printf("\n\t\033[0;31mREQUIRE_ARRAY_EQ_WITH_TOLERANCE\033[0;30m: %s:%d: %s[%d](%lg) != %s[%d](%lg) | +-%lg, " err, __FILE__, __LINE__, #a, __case_i__, (double)((type*)(a))[__case_i__], #b, __case_i__, (double)((type*)(b))[__case_i__], (double)(t), ##__VA_ARGS__); \
+ printf("\n\t\033[0;31mREQUIRE_ARRAY_EQ_WITH_TOLERANCE\033[0;0m: %s:%d: %s[%d](%lg) != %s[%d](%lg) | +-%lg, " err, __FILE__, __LINE__, #a, __case_i__, (double)((type*)(a))[__case_i__], #b, __case_i__, (double)((type*)(b))[__case_i__], (double)(t), ##__VA_ARGS__); \
ABORT_CASE; \
} }
#define REQUIRE_NOT_EQ(a, b, err, ...) { \
if ((a) == (b)) \
{ \
- printf("\n\t\033[0;31mREQUIRE_NOT_EQ\033[0;30m: %s:%d: %s(%lg) == %s(%lg), " err, __FILE__, __LINE__, #a, (double)(a), #b, (double)(b), ##__VA_ARGS__); \
+ printf("\n\t\033[0;31mREQUIRE_NOT_EQ\033[0;0m: %s:%d: %s(%lg) == %s(%lg), " err, __FILE__, __LINE__, #a, (double)(a), #b, (double)(b), ##__VA_ARGS__); \
ABORT_CASE; \
} }
@@ -92,14 +98,14 @@ int __case_i__; \
for (__case_i__ = 0; __case_i__ < (len); __case_i__++) \
if (((type*)(a))[__case_i__] == ((type*)(b))[__case_i__]) \
{ \
- printf("\n\t\033[0;31mREQUIRE_ARRAY_NOT_EQ\033[0;30m: %s:%d: %s[%d](%lg) == %s[%d](%lg), " err, __FILE__, __LINE__, #a, __case_i__, (double)((type*)(a))[__case_i__], #b, __case_i__, (double)((type*)(b))[__case_i__], ##__VA_ARGS__); \
+ printf("\n\t\033[0;31mREQUIRE_ARRAY_NOT_EQ\033[0;0m: %s:%d: %s[%d](%lg) == %s[%d](%lg), " err, __FILE__, __LINE__, #a, __case_i__, (double)((type*)(a))[__case_i__], #b, __case_i__, (double)((type*)(b))[__case_i__], ##__VA_ARGS__); \
ABORT_CASE; \
} }
#define REQUIRE_NOT_EQ_WITH_TOLERANCE(a, b, t, err, ...) { \
if ((double)((a) - (b)) <= (t) && (double)((a) - (b)) >= -(t)) \
{ \
- printf("\n\t\033[0;31mREQUIRE_NOT_EQ_WITH_TLERANCE\033[0;30m: %s:%d: %s(%lg) == %s(%lg) | +-%lg, " err, __FILE__, __LINE__, #a, (double)(a), #b, (double)(b), (double)(t), ##__VA_ARGS__); \
+ printf("\n\t\033[0;31mREQUIRE_NOT_EQ_WITH_TLERANCE\033[0;0m: %s:%d: %s(%lg) == %s(%lg) | +-%lg, " err, __FILE__, __LINE__, #a, (double)(a), #b, (double)(b), (double)(t), ##__VA_ARGS__); \
ABORT_CASE; \
} }
@@ -108,7 +114,7 @@ int __case_i__; \
for (__case_i__ = 0; __case_i__ < (len); __case_i__++) \
if ((double)(((type*)(a))[__case_i__] - ((type*)(b))[__case_i__]) <= (t) && (double)(((type*)(a))[__case_i__] - ((type*)(b))[__case_i__]) >= -(t)) \
{ \
- printf("\n\t\033[0;31mREQUIRE_ARRAY_NOT_EQ_WITH_TOLERANCE\033[0;30m: %s:%d: %s[%d](%lg) == %s[%d](%lg) | +-%lg, " err, __FILE__, __LINE__, #a, __case_i__, (double)((type*)(a))[__case_i__], #b, __case_i__, (double)((type*)(b))[__case_i__], (double)(t), ##__VA_ARGS__); \
+ printf("\n\t\033[0;31mREQUIRE_ARRAY_NOT_EQ_WITH_TOLERANCE\033[0;0m: %s:%d: %s[%d](%lg) == %s[%d](%lg) | +-%lg, " err, __FILE__, __LINE__, #a, __case_i__, (double)((type*)(a))[__case_i__], #b, __case_i__, (double)((type*)(b))[__case_i__], (double)(t), ##__VA_ARGS__); \
ABORT_CASE; \
} }
View
10 case_main.h
@@ -258,24 +258,24 @@ int main(int argc, char** argv)
case_t* test_suite = (case_t*)(start_pointer + i);
if (test_suite->sig == 0x883253372849284B)
{
- printf("\033[0;34m[%d/%d]\033[0;30m \033[1;33m[RUN]\033[0;30m %s ...", j, total, test_suite->name);
+ printf("\033[0;34m[%d/%d]\033[0;0m \033[1;33m[RUN]\033[0;0m %s ...", j, total, test_suite->name);
int result = 0;
test_suite->driver(test_suite->name, &result);
if (result == 0)
{
pass++;
- printf("\r\033[0;34m[%d/%d]\033[0;30m \033[1;32m[PASS]\033[0;30m %s \n", j, total, test_suite->name);
+ printf("\r\033[0;34m[%d/%d]\033[0;0m \033[1;32m[PASS]\033[0;0m %s \n", j, total, test_suite->name);
} else {
fail++;
- printf("\n\033[0;34m[%d/%d]\033[0;30m \033[1;31m[FAIL]\033[0;30m %s\n", j, total, test_suite->name);
+ printf("\n\033[0;34m[%d/%d]\033[0;0m \033[1;31m[FAIL]\033[0;0m %s\n", j, total, test_suite->name);
}
j++;
}
}
if (fail == 0)
- printf("\033[0;32mall test case(s) passed, congratulations!\033[0;30m\n");
+ printf("\033[0;32mall test case(s) passed, congratulations!\033[0;0m\n");
else
- printf("\033[0;31m%d of %d test case(s) passed\033[0;30m\n", pass, fail + pass);
+ printf("\033[0;31m%d of %d test case(s) passed\033[0;0m\n", pass, fail + pass);
return 0;
}

No commit comments for this range

Something went wrong with that request. Please try again.