Mercurial > luasocket
comparison 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 |
comparison
equal
deleted
inserted
replaced
-1:000000000000 | 0:4b915342e2a8 |
---|---|
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 | |
8 | |
9 function similar(s1, s2) | |
10 return string.lower(string.gsub(s1 or "", "%s", "")) == | |
11 string.lower(string.gsub(s2 or "", "%s", "")) | |
12 end | |
13 | |
14 function fail(msg) | |
15 msg = msg or "failed" | |
16 error(msg, 2) | |
17 end | |
18 | |
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 | |
25 | |
26 local G = _G | |
27 local set = rawset | |
28 local warn = print | |
29 | |
30 local setglobal = function(table, key, value) | |
31 warn("changed " .. key) | |
32 set(table, key, value) | |
33 end | |
34 | |
35 setmetatable(G, { | |
36 __newindex = setglobal | |
37 }) |