summary refs log tree commit diff stats
path: root/test/testc.lua
diff options
context:
space:
mode:
authorSoniEx2 <endermoneymod@gmail.com>2024-05-27 00:11:26 -0300
committerSoniEx2 <endermoneymod@gmail.com>2024-05-27 00:11:26 -0300
commite62ec5ac36188cb12411a8c720daebce77ecf645 (patch)
treeb1a2ce8e95ffc6e92ee31c1e271b0fcafe8a0b2f /test/testc.lua
parent9dea1c26b487ae723d99ba1e5e5887b09aec87dd (diff)
Set up a "build system"
Diffstat (limited to 'test/testc.lua')
-rw-r--r--test/testc.lua41
1 files changed, 41 insertions, 0 deletions
diff --git a/test/testc.lua b/test/testc.lua
new file mode 100644
index 0000000..72ed393
--- /dev/null
+++ b/test/testc.lua
@@ -0,0 +1,41 @@
+
+local function printr(...)
+    print(...)
+    return ...
+end
+
+local collect = {}
+local function printr_collect(...)
+    table.insert(collect, (...))
+    return printr(...)
+end
+
+-- used to print what the lua parser (load) is seeing, after cratera has done its thing
+loadstring = nil
+local realload = load
+load = function(target, ...)
+    if type(target) == "function" then
+        return realload(function() return printr_collect(target()) end, ...)
+    else
+        return realload(printr_collect(target), ...)
+    end
+end
+
+local cratera = require "cratera"
+
+-- first test: does it handle empty files properly?
+assert(printr(cratera.load("")))()
+
+-- second test: does it handle lua code properly?
+assert(printr(cratera.load(io.open("src/cratera/compiler.lua"):read("*a"))))()
+
+print("-----------------------------------------------------------------------------------------------------------------------")
+print(table.concat(collect))
+
+collect = {}
+
+-- third test: does it handle cratera tests properly?
+assert(printr(cratera.load(io.open("test/tests.cratera"):read("*a"))))()
+
+print("-----------------------------------------------------------------------------------------------------------------------")
+print(table.concat(collect))