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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
|
#!/usr/bin/env lua5.1-courseware
require 'osutil'
local posix = require 'courseware-posix'
local stringf = string.format
local function runf(...) return os.execute(string.format(...)) end
local function eprintf(...) return io.stderr:write(string.format(...)) end
local backends = { 'toascii', 'toroff', 'unmarkup', 'nt', 'tohtml', 'totex' }
local filters = { 'noidx' }
local fields = (require 'flags').parser()
:string('old', '/usr/lib/noweb'):help('installation directory of old version')
:numarg(1)
:parse(arg)
local newdir = assert(arg[1])
local function outfiles(command)
local tmp = os.capture 'mktemp'
local tmp2 = os.capture 'mktemp'
runf('%s > %s 2> %s', command, tmp, tmp2)
return tmp, tmp2
end
local options = { nt = '-R*' }
local pipelines = { }
do
local function extend(c, i)
local n = i == nil and #pipelines or i < 0 and #pipelines + 1 + i or i
assert(pipelines[n])
local next = stringf('%s | %s', pipelines[n], stringf('$L/%s %s', c, options[c] or ''))
table.insert(pipelines, next)
end
table.insert(pipelines, '$L/markup %s')
for _, f in ipairs(filters) do
if posix.access(stringf('%s/%s', newdir, f)) then
extend(f)
end
end
for i = 1, #pipelines do
for _, b in ipairs(backends) do
extend(b, i)
end
end
end
local sources = os.capture('echo $HOME/noweb/dist/src/c/*.nw')
for _, p in ipairs(pipelines) do
eprintf('%s\n', p)
for f in sources:gmatch '%S+' do
local oldc = stringf(p:gsub('%$L', fields.old), f)
local newc = stringf(p:gsub('%$L', newdir), f)
local oldout, o2 = outfiles(oldc)
local newout, n2 = outfiles(newc)
local rc = runf('cmp -s %s %s', oldout, newout)
local rc2 = runf('cmp -s %s %s', o2, n2)
if rc ~= 0 or rc2 ~= 0 then
eprintf('FAILED: %s\n %s\n', oldc, newc)
if rc2 ~= 0 then
runf('colordiff -u %s %s | head -40', o2, n2)
end
if rc ~= 0 then
runf('colordiff -u %s %s | head -40', oldout, newout)
end
os.exit(1)
else
os.remove(oldout)
os.remove(newout)
end
end
end
|