test.h: #define TEST_FAIL(message) \ do { \ printf("[file:%s][line:%d] %s\n", __FILE__, __LINE__, message); \ } while (0) #define TEST_ASSERT_TRUE(message, test) \ do { \ if (!(test)) { \ printf("[file:%s][line:%d] %s is not equals.\n", __FILE__, __LINE__, message); \ return; \ } \ } while (0) #define TEST_ASSERT_INT(message, expected, actual) \ do { \ if ((expected) != (actual)) { \ printf("[file:%s][line:%d] %s is expected %d, but actual %d.\n", \ __FILE__, __LINE__, message, expected, actual); \ return; \ } \ } while (0) #define TEST_ASSERT_LONG(message, expected, actual) \ do { \ if ((expected) != (actual)) { \ printf("[file:%s][line:%d] %s is expected %ld, but actual %ld.\n", \ __FILE__, __LINE__, message, expected, actual); \ return; \ } \ } while (0) #define TEST_ASSERT_FLOAT(message, expected, actual) \ do { \ if ((expected) != (actual)) { \ printf("[file:%s][line:%d] %s is expected %f, but actual %f.\n", \ __FILE__, __LINE__, message, expected, actual); \ return; \ } \ } while (0) #define TEST_ASSERT_DOUBLE(message, expected, actual) \ do { \ if ((expected) != (actual)) { \ printf("[file:%s][line:%d] %s is expected %f, but actual %f.\n", \ __FILE__, __LINE__, message, expected, actual); \ return; \ } \ } while (0) #define TEST_ASSERT_STRING(message, expected, actual) \ do { \ if ((expected) != (actual)) { \ printf("[file:%s][line:%d] %s is expected %s, but actual %s.\n", \ __FILE__, __LINE__, message, expected, actual); \ return; \
} \ } while (0) test.c: void test() { TEST_ASSERT_STRING("value", "foo", "bar"); } int main(int argc, char *argv[]) { test(); return 0; }