summaryrefslogtreecommitdiff
path: root/libs/honeysuckle/src/tests/hs_throw_error_tests.c
diff options
context:
space:
mode:
authorsanine <sanine.not@pm.me>2022-04-16 11:55:09 -0500
committersanine <sanine.not@pm.me>2022-04-16 11:55:09 -0500
commitdb81b925d776103326128bf629cbdda576a223e7 (patch)
tree58bea8155c686733310009f6bed7363f91fbeb9d /libs/honeysuckle/src/tests/hs_throw_error_tests.c
parent55860037b14fb3893ba21cf2654c83d349cc1082 (diff)
move 3rd-party librarys into libs/ and add built-in honeysuckle
Diffstat (limited to 'libs/honeysuckle/src/tests/hs_throw_error_tests.c')
-rw-r--r--libs/honeysuckle/src/tests/hs_throw_error_tests.c57
1 files changed, 57 insertions, 0 deletions
diff --git a/libs/honeysuckle/src/tests/hs_throw_error_tests.c b/libs/honeysuckle/src/tests/hs_throw_error_tests.c
new file mode 100644
index 0000000..7ae683c
--- /dev/null
+++ b/libs/honeysuckle/src/tests/hs_throw_error_tests.c
@@ -0,0 +1,57 @@
+#include "hs_tests.h"
+
+char err_string[32] = "";
+
+int set_err_string(lua_State *L)
+{
+ if (lua_isstring(L, -1))
+ strcpy(err_string, lua_tostring(L, -1));
+ 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; \
+ }
+
+
+HS_ERROR_TEST(hs_throw_error_constant, {
+ hs_throw_error(L, "a constant error");
+ return 0;
+ }, "a constant error");
+
+
+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");
+
+
+// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+
+void hs_throw_error_tests()
+{
+ printf("running hs_throw_error() tests...\n");
+
+ 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);
+}