aboutsummaryrefslogtreecommitdiffstats
path: root/test
diff options
context:
space:
mode:
authorGravatar Andrew D. France 2025-07-14 17:51:23 -0500
committerGravatar Andrew D. France 2025-07-14 17:51:23 -0500
commit6f8c0f3abda585b3ee1d87e3b8e19c729b52b4a6 (patch)
tree8361fd3812991d43adca5b5c81029486aa955478 /test
parentv0.3.2 (diff)
Added compat53 support and fixed bugged non-interactive mode
Diffstat (limited to 'test')
-rw-r--r--test/compat_test.lua60
1 files changed, 60 insertions, 0 deletions
diff --git a/test/compat_test.lua b/test/compat_test.lua
new file mode 100644
index 0000000..bd7ef90
--- /dev/null
+++ b/test/compat_test.lua
@@ -0,0 +1,60 @@
+-- test/compat_test.lua
+-- A small test suite for the lua-compat-5.3 layer.
+-- Can be run in two ways:
+-- 1. ./lush test/compat_test.lua (runs all tests)
+-- 2. ./lush test/compat_test.lua test_table_unpack (runs a single test)
+
+local tests = {}
+
+function tests.test_table_unpack()
+ print("--- Running test: table.unpack ---")
+ local my_table = { "a", "b", "c" }
+ -- The compat layer provides table.unpack for Lua 5.1.
+ local x, y, z = table.unpack(my_table)
+ assert(x == "a", "unpack failed for first element")
+ assert(y == "b", "unpack failed for second element")
+ assert(z == "c", "unpack failed for third element")
+ print("...SUCCESS!")
+end
+
+function tests.test_math_log_base()
+ print("--- Running test: math.log with base ---")
+ -- Lua 5.1's math.log only takes one argument. The compat layer adds the base.
+ local result = math.log(100, 10)
+ -- Use a small epsilon for floating point comparison
+ assert(math.abs(result - 2) < 1e-9, "math.log(100, 10) should be 2")
+ print("...SUCCESS!")
+end
+
+function tests.test_string_rep_separator()
+ print("--- Running test: string.rep with separator ---")
+ -- Lua 5.1's string.rep doesn't have the separator argument.
+ local result = string.rep("a", 3, "-")
+ assert(result == "a-a-a", "string.rep with separator failed, got: " .. tostring(result))
+ print("...SUCCESS!")
+end
+
+
+-- NOTE: The lush C host provides arguments in a global table named 'args', not 'arg'.
+local test_to_run = args and args[1]
+
+if test_to_run and tests[test_to_run] then
+ -- If a valid test name is provided, run only that test.
+ local success, err = pcall(tests[test_to_run])
+ if not success then
+ print("...FAILURE: " .. err)
+ end
+elseif test_to_run then
+ -- If an invalid name is provided, show an error.
+ print("ERROR: Test function '" .. test_to_run .. "' not found.")
+else
+ -- If no specific test is requested, run all of them.
+ print("--- Running all compatibility tests ---")
+ for name, func in pairs(tests) do
+ local success, err = pcall(func)
+ if not success then
+ print("...FAILURE on test '" .. name .. "': " .. err)
+ end
+ end
+ print("--- All tests complete ---")
+end
>2024-09-13improved installation instructionsGravatar BanceDev 1-3/+3 2024-09-12v0.1.1Gravatar BanceDev 1-1/+1 2024-09-12fixed bug in input buffer handling due to misplaced printGravatar BanceDev 2-5/+8 2024-09-12Update build.yml checkout v4Gravatar Lance Borden 1-1/+1 2024-09-12Update build.yml to artifact v4Gravatar Lance Borden 1-1/+1 2024-09-12fixed exit status issue with non interative modeGravatar BanceDev 1-1/+1 2024-09-12added non interative mode for running lua scriptsGravatar BanceDev 2-4/+28 2024-09-12temporary github action fix until non-interactive mode is implementedGravatar BanceDev 1-2/+2 2024-09-12attempt to update build script to accept input into lush shellGravatar BanceDev 2-4/+6 2024-09-12prevent lush workflow from getting stuck in testsGravatar Lance Borden 1-1/+4 2024-09-12removed chsh in workflowGravatar Lance Borden 1-4/+1