summaryrefslogtreecommitdiff
path: root/ThirdParty/luasocket/test/testsupport.lua
diff options
context:
space:
mode:
authorchai <chaifix@163.com>2021-10-20 13:40:34 +0800
committerchai <chaifix@163.com>2021-10-20 13:40:34 +0800
commitff0f488c97fe8b554b909a0057cebc4c860eac8f (patch)
tree4e47262b52ffce7e9cfeaaeeab46371243bcaa78 /ThirdParty/luasocket/test/testsupport.lua
parentdde719dd575090b36aaa3ad85bb3cabf33f36c5a (diff)
+luasocket src
Diffstat (limited to 'ThirdParty/luasocket/test/testsupport.lua')
-rw-r--r--ThirdParty/luasocket/test/testsupport.lua37
1 files changed, 37 insertions, 0 deletions
diff --git a/ThirdParty/luasocket/test/testsupport.lua b/ThirdParty/luasocket/test/testsupport.lua
new file mode 100644
index 0000000..b986088
--- /dev/null
+++ b/ThirdParty/luasocket/test/testsupport.lua
@@ -0,0 +1,37 @@
+function readfile(name)
+ local f = io.open(name, "rb")
+ if not f then return nil end
+ local s = f:read("*a")
+ f:close()
+ return s
+end
+
+function similar(s1, s2)
+ return string.lower(string.gsub(s1 or "", "%s", "")) ==
+ string.lower(string.gsub(s2 or "", "%s", ""))
+end
+
+function fail(msg)
+ msg = msg or "failed"
+ error(msg, 2)
+end
+
+function compare(input, output)
+ local original = readfile(input)
+ local recovered = readfile(output)
+ if original ~= recovered then fail("comparison failed")
+ else print("ok") end
+end
+
+local G = _G
+local set = rawset
+local warn = print
+
+local setglobal = function(table, key, value)
+ warn("changed " .. key)
+ set(table, key, value)
+end
+
+setmetatable(G, {
+ __newindex = setglobal
+})