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 (131 lines) | stat: -rw-r--r-- 4,363 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
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131

mtn_setup()

-- add a file without attributes
addfile("testfile", "foo")
commit("mainbranch")

-- at first check for the version on the file w/o attributes
check(mtn("automate", "get_attributes", "testfile"), 0, true, true)
check(fsize("stderr") == 0)
check(fsize("stdout") == 0)

-- add three test attributes and commit them
check(mtn("attr", "set", "testfile", "key1", "persists"), 0, false, false)
check(mtn("attr", "set", "testfile", "key2", "will_be_dropped"), 0, false, false)
check(mtn("attr", "set", "testfile", "key3", "will_be_changed"), 0, false, false)
commit("mainbranch");

-- now add another one, drop one of the existing and
-- re-add one of the existing
check(mtn("attr", "set", "testfile", "key4", "has_been_added"), 0, false, false)
check(mtn("attr", "drop", "testfile", "key3"), 0, false, false)
check(mtn("attr", "set", "testfile", "key3", "has_been_changed"), 0, false, false)
check(mtn("attr", "drop", "testfile", "key2"), 0, false, false)

-- the actual check of the interface
check(mtn("automate", "get_attributes", "testfile"), 0, true, true)
check(fsize("stderr") == 0)
parsed = parse_basic_io(readfile("stdout"))
-- make sure the output generated 8 stanzas
check(#parsed == 8)
lastkey = ""
checked = {}
for _,l in pairs(parsed) do
    if l.name == "attr" then
        lastkey = l.values[1]
        val = l.values[2]
        if lastkey == "key1" then check(val == "persists") end
        if lastkey == "key2" then check(val == "will_be_dropped") end
        if lastkey == "key3" then check(val == "has_been_changed") end
        if lastkey == "key4" then check(val == "has_been_added") end
    end
    if l.name == "state" then
        state = l.values[1]

        if lastkey == "key1" then
            check(state == "unchanged")
            checked[lastkey] = true
        end
        if lastkey == "key2" then
            check(state == "dropped")
            checked[lastkey] = true
        end
        if lastkey == "key3" then
            check(state == "changed")
            checked[lastkey] = true
        end
        if lastkey == "key4" then
            check(state == "added")
            checked[lastkey] = true
        end
    end
end

check(checked["key1"] and checked["key2"] and checked["key3"] and checked["key4"])

commit("mainbranch")

-- check that dropped attributes do not popup in further revisions
check(mtn("automate", "get_attributes", "testfile"), 0, true, true)
check(fsize("stderr") == 0)
parsed = parse_basic_io(readfile("stdout"))

for _,l in pairs(parsed) do
    if l.name == "attr" then
        curkey = l.values[1]
        check(curkey ~= "key2")
    end
end

-- check that new attributes which resemble the name of previously
-- dropped attributes are correctly listed as added, and not changed
-- (bug in 0.35)
check(mtn("attr", "set", "testfile", "key2", "new_value"), 0, false, false)
check(mtn("automate", "get_attributes", "testfile"), 0, true, true)
check(fsize("stderr") == 0)
parsed = parse_basic_io(readfile("stdout"))

curkey = ""
for _,l in pairs(parsed) do
    if l.name == "attr" then
        curkey = l.values[1]
    end
    if l.name == "state" and curkey == "key2" then
        state = l.values[1]
        check(state == "added")
    end
end

-- check that we can query arbitrary attributes from earlier revisions
check(mtn("automate", "get_attributes", "-r", "0123456789012345678901234567890123456789", "bla"), 1, false, true)
check(qgrep("no revision 0123456789012345678901234567890123456789 found in database", "stderr"))

rev = base_revision()
check(mtn("automate", "get_attributes", "foo", "-r", rev), 1, false, true)
check(qgrep("unknown path 'foo' in " .. rev, "stderr"))

check(mtn("automate", "get_attributes", "testfile", "-r", rev), 0, true, false)

parsed = parse_basic_io(readfile("stdout"))
check(#parsed == 6)

lastkey = ""
checked = {}
for _,l in pairs(parsed) do
    if l.name == "attr" then
        lastkey = l.values[1]
        val = l.values[2]
        if lastkey == "key1" then check(val == "persists")
        elseif lastkey == "key3" then check(val == "has_been_changed")
        elseif lastkey == "key4" then check(val == "has_been_added")
        else check(false) end
    end
    if l.name == "state" then
        check(l.values[1] == "unchanged")
        checked[lastkey] = true
    end
end

check(checked["key1"] and checked["key3"] and checked["key4"])