File: __driver__.lua

package info (click to toggle)
monotone 1.1-9
  • links: PTS, VCS
  • area: main
  • in suites: stretch
  • size: 20,984 kB
  • ctags: 8,622
  • sloc: cpp: 86,450; sh: 6,906; perl: 924; makefile: 813; python: 517; lisp: 379; sql: 118; exp: 91; ansic: 52
file content (83 lines) | stat: -rwxr-xr-x 2,744 bytes parent folder | download | duplicates (3)
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
83
includecommon("automate_stdio.lua")

mtn_setup()

-- check informational messages, warnings and errors
out = run_stdio("l8:bandtest4:infoe", 0, 0, "p")
check(type(out) == "table" and #out == 1)

out = run_stdio("l8:bandtest7:warninge", 0, 0, "w")
check(type(out) == "table" and #out == 1)

out = run_stdio("l8:bandtest5:errore", 2, 0, "e")
check(type(out) == "table" and #out == 1)

-- check tickers
tickers = run_stdio("l8:bandtest6:tickere", 0, 0, "t")
check(type(out) == "table")

function split(str, pat)
    local t = {}  -- NOTE: use {n = 0} in Lua-5.0
    local fpat = "(.-)" .. pat
    local last_end = 1
    local s, e, cap = str:find(fpat, 1)
    while s do
        if s ~= 1 or cap ~= "" then
            table.insert(t,cap)
        end
        last_end = e+1
        s, e, cap = str:find(fpat, last_end)
    end
    if last_end <= #str then
        cap = str:sub(last_end)
        table.insert(t, cap)
    end
    return t
end

ticker_data = {}
for _,tick in ipairs(tickers) do
    ticks = split(tick, ";")
    check(#ticks > 0)
    for _,mtick in ipairs(ticks) do
        if string.len(mtick) > 0 then
            local begin,End,short,ticktype,content =
                string.find(mtick, "([%l%u%d]+)([=:#])(.+)")
            if begin == nil then
               short = mtick
            end
            if ticker_data[short] == nil then
                -- check the ticker's name definition
                check(ticktype == ":")
                ticker_data[short] = {}
                check(string.len(content) > 0)
            else
                check(ticktype ~= ":")
                -- check and remember the ticker's total value (if any)
                if ticktype == "=" then
                    check(ticker_data[short].total == nil)
                    ticker_data[short].total = tonumber(content)
                    check(ticker_data[short].total ~= nil)
                -- check and remember the ticker's progress
                elseif ticktype == "#" then
                    progress = tonumber(content)
                    check(progress ~= nil)
                    check(ticker_data[short].total == 0 or
                            progress <= ticker_data[short].total)
                    ticker_data[short].progress = progress
                -- check for the ticker's end and remove it
                elseif ticktype == nil then
                    check(ticker_data[short] ~= nil)
                    check(ticker_data[short].total == 0 or
                            ticker_data[short].progress == ticker_data[short].total)
                    ticker_data[short] = nil
                end
            end
        end
    end
end

-- finally check if all tickers are completed
check(#ticker_data == 0)