aboutsummaryrefslogtreecommitdiff
path: root/test/testsupport.lua
diff options
context:
space:
mode:
Diffstat (limited to 'test/testsupport.lua')
-rw-r--r--test/testsupport.lua37
1 files changed, 37 insertions, 0 deletions
diff --git a/test/testsupport.lua b/test/testsupport.lua
new file mode 100644
index 0000000..ca3cd95
--- /dev/null
+++ b/test/testsupport.lua
@@ -0,0 +1,37 @@
1function readfile(name)
2 local f = io.open(name, "r")
3 if not f then return nil end
4 local s = f:read("*a")
5 f:close()
6 return s
7end
8
9function similar(s1, s2)
10 return string.lower(string.gsub(s1 or "", "%s", "")) ==
11 string.lower(string.gsub(s2 or "", "%s", ""))
12end
13
14function fail(msg)
15 msg = msg or "failed"
16 error(msg, 2)
17end
18
19function compare(input, output)
20 local original = readfile(input)
21 local recovered = readfile(output)
22 if original ~= recovered then fail("comparison failed")
23 else print("ok") end
24end
25
26local G = _G
27local set = rawset
28local warn = print
29
30local setglobal = function(table, key, value)
31 warn("changed " .. key)
32 set(table, key, value)
33end
34
35setmetatable(G, {
36 __newindex = setglobal
37})