summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorsanine-a <sanine.not@pm.me>2021-08-08 16:58:19 -0500
committersanine-a <sanine.not@pm.me>2021-08-08 16:58:19 -0500
commit76df823a8f754a6adaae0b4231fb1f1716f124e9 (patch)
tree19bb141f9bb81a5f4a95f22cbac0c87e90f6ccd3
parent1459422a3dc158fa4c7222f7780d134261458b7c (diff)
add helper macro for hs_throw_error() tests and add extremely long string test
-rw-r--r--src/tests/hs_throw_error_tests.c62
1 files changed, 30 insertions, 32 deletions
diff --git a/src/tests/hs_throw_error_tests.c b/src/tests/hs_throw_error_tests.c
index ebb05b4..7ae683c 100644
--- a/src/tests/hs_throw_error_tests.c
+++ b/src/tests/hs_throw_error_tests.c
@@ -10,42 +10,39 @@ int set_err_string(lua_State *L)
}
-int throw_const_error(lua_State *L)
-{
- hs_throw_error(L, "a constant error");
- return 0;
-}
+#define HS_ERROR_TEST(name, error_body, expectation) \
+ int name ## _errfunc(lua_State *L) error_body; \
+ TEST(name) { \
+ lua_pushcfunction(L, set_err_string); \
+ int pos = lua_gettop(L); \
+ lua_pushcfunction(L, name ## _errfunc); \
+ int result = lua_pcall(L, 0, 0, pos); \
+ mu_assert_equal(result, LUA_ERRRUN); \
+ mu_assert_str_not_equal(err_string, ""); \
+ mu_assert_str_equal(err_string, expectation); \
+ return 0; \
+ }
-TEST(hs_throw_error_constant)
-{
- lua_pushcfunction(L, set_err_string);
- int pos = lua_gettop(L);
- lua_pushcfunction(L, throw_const_error);
- int result = lua_pcall(L, 0, 0, pos);
- mu_assert_equal(result, LUA_ERRRUN);
- mu_assert_str_not_equal(err_string, "");
- mu_assert_str_equal(err_string, "a constant error");
- return 0;
-}
+HS_ERROR_TEST(hs_throw_error_constant, {
+ hs_throw_error(L, "a constant error");
+ return 0;
+ }, "a constant error");
-int throw_number_error(lua_State *L)
-{
- hs_throw_error(L, "%s number %d", "error", 10);
- return 0;
-}
-TEST(hs_throw_error_format)
-{
- lua_pushcfunction(L, set_err_string);
- int pos = lua_gettop(L);
- lua_pushcfunction(L, throw_number_error);
- int result = lua_pcall(L, 0, 0, pos);
- mu_assert_equal(result, LUA_ERRRUN);
- mu_assert_str_not_equal(err_string, "");
- mu_assert_str_equal(err_string, "error number 10");
- return 0;
-}
+HS_ERROR_TEST(hs_throw_error_format, {
+ hs_throw_error(L, "%s number %d", "error", 10);
+ return 0;
+ }, "error number 10");
+
+
+HS_ERROR_TEST(hs_throw_error_long, {
+ hs_throw_error(L, "%s is a %s is a %s",
+ "a very, very, very long string",
+ "a very, very, very long string",
+ "a very, very, very long string");
+ return 0;
+ }, "a very, very, very long string is a a very, very, very long string is a a very, very, very long string");
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
@@ -56,4 +53,5 @@ void hs_throw_error_tests()
mu_run_test("throw constant error string", hs_throw_error_constant);
mu_run_test("throw error with format string", hs_throw_error_format);
+ mu_run_test("throw error with very long string", hs_throw_error_long);
}