diff test/testsupport.lua @ 0:4b915342e2a8

LuaSocket 2.0.2 + CMake build description.
author Eric Wing <ewing . public |-at-| gmail . com>
date Tue, 26 Aug 2008 18:40:01 -0700
parents
children
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/test/testsupport.lua	Tue Aug 26 18:40:01 2008 -0700
@@ -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
+})