File: testsupport.lua

package info (click to toggle)
luasocket 3.0~rc1%2Bgit%2Bac3201d-4
  • links: PTS, VCS
  • area: main
  • in suites: bullseye, buster
  • size: 2,216 kB
  • sloc: ansic: 4,487; makefile: 320; sh: 116
file content (37 lines) | stat: -rw-r--r-- 767 bytes parent folder | download | duplicates (13)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
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
})