diff options
| author | Diego Nehab <diego@tecgraf.puc-rio.br> | 2004-03-22 04:15:03 +0000 |
|---|---|---|
| committer | Diego Nehab <diego@tecgraf.puc-rio.br> | 2004-03-22 04:15:03 +0000 |
| commit | 1fa65d89ca5dc64756f7933d7cc3f524e4627dce (patch) | |
| tree | df614c8b86b0f7c2f45c2afcacc993ab3c0dcf11 /test/testsupport.lua | |
| parent | 4919a83d2271a9e43b83c7d488e3f94c850681e3 (diff) | |
| download | luasocket-1fa65d89ca5dc64756f7933d7cc3f524e4627dce.tar.gz luasocket-1fa65d89ca5dc64756f7933d7cc3f524e4627dce.tar.bz2 luasocket-1fa65d89ca5dc64756f7933d7cc3f524e4627dce.zip | |
Adjusted some details, got rid of old files, added some new.
Diffstat (limited to 'test/testsupport.lua')
| -rw-r--r-- | test/testsupport.lua | 37 |
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 @@ | |||
| 1 | function 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 | ||
| 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 | }) | ||
