beta-0.89.2
[luatex.git] / source / texk / web2c / luatexdir / luasocket / test / testsupport.lua
blobb9860882c2f6223597cfdf9f6c986dd3e3f5ab84
1 function readfile(name)
2 local f = io.open(name, "rb")
3 if not f then return nil end
4 local s = f:read("*a")
5 f:close()
6 return s
7 end
9 function similar(s1, s2)
10 return string.lower(string.gsub(s1 or "", "%s", "")) ==
11 string.lower(string.gsub(s2 or "", "%s", ""))
12 end
14 function fail(msg)
15 msg = msg or "failed"
16 error(msg, 2)
17 end
19 function 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
24 end
26 local G = _G
27 local set = rawset
28 local warn = print
30 local setglobal = function(table, key, value)
31 warn("changed " .. key)
32 set(table, key, value)
33 end
35 setmetatable(G, {
36 __newindex = setglobal