Skip to content

Commit

Permalink
Merge pull request #1 from soupglasses/dev
Browse files Browse the repository at this point in the history
Fix various pedantic compile time warnings from clang.
  • Loading branch information
MortenSchou authored Oct 22, 2023
2 parents 4fc43bf + 08dc435 commit fb0c03d
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 4 deletions.
8 changes: 4 additions & 4 deletions include/mtest.h
Original file line number Diff line number Diff line change
Expand Up @@ -63,10 +63,10 @@
#define REQUIRE_NE_STRING(expected, actual) REQUIRE_(strcmp((expected), (actual)), "REQUIRE_NE_STRING(%s,%s) failed (\"%s\" == \"%s\")", #expected, #actual, expected, actual)

// A test case is implemented as a function that returns 0 if the test passes and 1 if it fails.
#define TEST_CASE(test_name, command...) \
#define TEST_CASE(test_name, ...) \
static int test_name(void) { \
int _mtest_result_ = 0; \
{ command } \
{ __VA_ARGS__ } \
return _mtest_result_; \
}

Expand All @@ -75,7 +75,7 @@ static int test_name(void) {
#define RUN_TESTS(...) do { \
int success = 0, failed = 0; \
int(*test_functions[])(void) = {__VA_ARGS__}; \
for (int i = 0; i < sizeof(test_functions)/sizeof(int(*)(void)); ++i) \
for (int i = 0; i < (int)(sizeof(test_functions)/sizeof(int(*)(void))); ++i) \
test_functions[i]() ? failed++ : success++; \
printf("Tests run: %d. Succeeded: %d. Failed: %d", success+failed, success, failed); \
if (failed) exit(EXIT_FAILURE); \
Expand All @@ -94,7 +94,7 @@ int main (int argc, char *argv[]) {
char* names = (char *)malloc(strlen(names_static)+1); \
strcpy(names, names_static); \
char* token = strtok(names, " ,"); \
for (int i = 0; token != NULL && i < sizeof(test_functions)/sizeof(int(*)(void)); ++i) { \
for (int i = 0; token != NULL && i < (int)(sizeof(test_functions)/sizeof(int(*)(void))); ++i) { \
if (list_test_cases) { \
printf("%s;", token); \
} else if (strcmp(argv[1], token) == 0) { \
Expand Down
2 changes: 2 additions & 0 deletions test/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
add_executable(test_mtest test_mtest.c)
target_link_libraries(test_mtest mtest)
# Avoid relying on hidden compiler behavior when compiling test_mtest.
target_compile_options(test_mtest PRIVATE -Wall -Wextra -Wpedantic)

# Automatically discover test cases in test_mtest and add them to CTest.
discover_tests(test_mtest)

0 comments on commit fb0c03d

Please sign in to comment.