diff options
-rw-r--r-- | src/colors.h | 22 | ||||
-rw-r--r-- | src/test.c | 54 |
2 files changed, 56 insertions, 20 deletions
diff --git a/src/colors.h b/src/colors.h new file mode 100644 index 0000000..21451de --- /dev/null +++ b/src/colors.h @@ -0,0 +1,22 @@ +#ifndef COLORS_H +#define COLORS_H + +#define RESET "\033[0m" +#define BLACK "\033[30m" /* Black */ +#define RED "\033[31m" /* Red */ +#define GREEN "\033[32m" /* Green */ +#define YELLOW "\033[33m" /* Yellow */ +#define BLUE "\033[34m" /* Blue */ +#define MAGENTA "\033[35m" /* Magenta */ +#define CYAN "\033[36m" /* Cyan */ +#define WHITE "\033[37m" /* White */ +#define BOLDBLACK "\033[1m\033[30m" /* Bold Black */ +#define BOLDRED "\033[1m\033[31m" /* Bold Red */ +#define BOLDGREEN "\033[1m\033[32m" /* Bold Green */ +#define BOLDYELLOW "\033[1m\033[33m" /* Bold Yellow */ +#define BOLDBLUE "\033[1m\033[34m" /* Bold Blue */ +#define BOLDMAGENTA "\033[1m\033[35m" /* Bold Magenta */ +#define BOLDCYAN "\033[1m\033[36m" /* Bold Cyan */ +#define BOLDWHITE "\033[1m\033[37m" /* Bold White */ + +#endif @@ -7,6 +7,7 @@ #include <lauxlib.h> #include "honeysuckle.h" +#include "colors.h" /* minunit testing macros modified from those at www.jera.com/techinfo/jtns/jtn002.html */ @@ -18,7 +19,7 @@ lua_close(L); \ tests_run++; \ if (message) { \ - printf("test '%s' failed: %s\n", name, message); \ + printf(RED " test '%s' failed: %s\n" RESET, name, message); \ tests_failed++; \ } \ } while (0) @@ -115,7 +116,7 @@ TEST(hs_any_to_string) /* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ * - * tests for hs_parse_args + * hs_parse_args typechecking tests * * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ */ @@ -438,6 +439,14 @@ PARSE_TYPECHECK_TEST(parse_any_typecheck, int, HS_ANY) return 0; } + +/* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + * + * hs_parse_args parsing tests + * + * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + */ + TEST(parse_bool) { lua_pushboolean(L, true); @@ -475,17 +484,18 @@ TEST(parse_str) return 0; } -int testfunc(lua_State *L) { return 0; } - TEST(parse_func) { - lua_pushcfunction(L, testfunc); - lua_CFunction f; - hs_parse_args(L, HS_FUNC, &f, HS_END); - mu_assert("failed to properly parse function!", f == testfunc); + lua_getglobal(L, "type"); + int correct_index = lua_gettop(L); + int index = 0; + hs_parse_args(L, HS_FUNC, &index, HS_END); + mu_assert("failed to properly parse function!", index == correct_index); return 0; } +int testfunc(lua_State *L) { return 0; } + TEST(parse_cfunc) { lua_pushcfunction(L, testfunc); @@ -505,7 +515,7 @@ int should_fail(lua_State *L) TEST(fail_parse_noncfunc) { lua_pushcfunction(L, should_fail); - lua_getglobal(L, "assert"); + lua_getglobal(L, "type"); mu_assert("incorrectly parsed non-C function!", lua_pcall(L, 1, 0, 0) != 0); return 0; @@ -533,14 +543,14 @@ TEST(parse_lightuserdata) return 0; } -int parse_nil_testfunc(lua_State *L) { hs_parse_args(L, HS_NIL, HS_END); } - TEST(parse_nil) { - lua_pushcfunction(L, parse_nil_testfunc); lua_pushnil(L); + int correct_index = lua_gettop(L); + int index = 0; + hs_parse_args(L, HS_NIL, &index, HS_END); mu_assert("failed to properly parse nil!", - lua_pcall(L, 1, 0, 0) == 0); + index == correct_index); return 0; } @@ -603,9 +613,8 @@ int main() mu_run_test("light to string", hs_light_to_string); mu_run_test("nil to string", hs_nil_to_string); mu_run_test("any to string", hs_any_to_string); - printf("\n"); - printf("running hs_parse_args() tests...\n"); + printf("running hs_parse_args() typechecking tests...\n"); mu_run_test("parse bool typecheck", parse_bool_typecheck); mu_run_test("parse int typecheck", parse_int_typecheck); mu_run_test("parse num typecheck", parse_num_typecheck); @@ -616,7 +625,9 @@ int main() mu_run_test("parse user typecheck", parse_user_typecheck); mu_run_test("parse light typecheck", parse_light_typecheck); mu_run_test("parse nil typecheck", parse_nil_typecheck); - mu_run_test("parse any typecheck", parse_any_typecheck); + mu_run_test("parse any typecheck", parse_any_typecheck); + + printf("running hs_parse_args() parsing tests...\n"); mu_run_test("parse bool", parse_bool); mu_run_test("parse int", parse_int); mu_run_test("parse num", parse_num); @@ -624,15 +635,18 @@ int main() mu_run_test("parse func", parse_func); mu_run_test("parse cfunc", parse_cfunc); mu_run_test("fail parse noncfunc", fail_parse_noncfunc); - printf("\n"); + mu_run_test("parse userdata", parse_userdata); + mu_run_test("parse lightuserdata", parse_lightuserdata); + mu_run_test("parse_nil", parse_nil); printf("running hs_pushstring() tests...\n"); mu_run_test("hs_pushstring (no printf formatting)", push_noformat); mu_run_test("hs_pushstring (integer formatting)", push_formatint); mu_run_test("hs_pushstring (string formatting)", push_formatstring); - printf("\n"); - + printf("\n=============== tests finished ===============\n\n"); - printf("ran %d tests, %d failed\n", tests_run, tests_failed); + + const char *color = tests_failed == 0 ? GREEN : RED; + printf("%sran %d tests, %d failed\n" RESET, color, tests_run, tests_failed); return 0; } |