summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/honeysuckle.c7
-rw-r--r--src/tests/hs_throw_error_tests.c57
-rw-r--r--src/tests/tests_main.c1
3 files changed, 65 insertions, 0 deletions
diff --git a/src/honeysuckle.c b/src/honeysuckle.c
index 97c60c4..339b278 100644
--- a/src/honeysuckle.c
+++ b/src/honeysuckle.c
@@ -47,6 +47,13 @@ void hs_pt_set_number(lua_Number value, void *data) { value=value; data=data; }
void hs_pt_set_string(const char *value, void *data) { value=value; data=data; }
+void hs_throw_error(lua_State *L, const char *format_string, ...)
+{
+ L = L;
+ format_string = format_string;
+}
+
+
void hs_pushstring(lua_State *L, const char *format_string, ...)
{
lua_pushnumber(L, 0.4);
diff --git a/src/tests/hs_throw_error_tests.c b/src/tests/hs_throw_error_tests.c
new file mode 100644
index 0000000..1c5af6a
--- /dev/null
+++ b/src/tests/hs_throw_error_tests.c
@@ -0,0 +1,57 @@
+#include "hs_tests.h"
+
+const char *err_string = "";
+
+int set_err_string(lua_State *L)
+{
+ if (lua_isstring(L, -1))
+ err_string = lua_tostring(L, -1);
+ return 0;
+}
+
+
+int throw_const_error(lua_State *L)
+{
+ hs_throw_error(L, "a constant error");
+ return 0;
+}
+
+TEST(hs_throw_error_constant)
+{
+ lua_pushcfunction(L, throw_const_error);
+ int pos = lua_gettop(L);
+ 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;
+}
+
+
+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, throw_number_error);
+ int pos = lua_gettop(L);
+ 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;
+}
+
+
+// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+
+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);
+}
diff --git a/src/tests/tests_main.c b/src/tests/tests_main.c
index 9a871c1..171b253 100644
--- a/src/tests/tests_main.c
+++ b/src/tests/tests_main.c
@@ -21,6 +21,7 @@ int main()
mu_run_suite(hs_create_table_tests);
mu_run_suite(hs_create_enum_tests);
mu_run_suite(hs_process_table_tests);
+ mu_run_suite(hs_throw_error_tests);
mu_run_suite(hs_pushstring_tests);