1
2mtn_setup()
3
4-- add a file without attributes
5addfile("testfile", "foo")
6commit("mainbranch")
7
8-- at first check for the version on the file w/o attributes
9check(mtn("automate", "get_attributes", "testfile"), 0, true, true)
10check(fsize("stderr") == 0)
11check(fsize("stdout") == 0)
12
13-- add three test attributes and commit them
14check(mtn("attr", "set", "testfile", "key1", "persists"), 0, false, false)
15check(mtn("attr", "set", "testfile", "key2", "will_be_dropped"), 0, false, false)
16check(mtn("attr", "set", "testfile", "key3", "will_be_changed"), 0, false, false)
17commit("mainbranch");
18
19-- now add another one, drop one of the existing and
20-- re-add one of the existing
21check(mtn("attr", "set", "testfile", "key4", "has_been_added"), 0, false, false)
22check(mtn("attr", "drop", "testfile", "key3"), 0, false, false)
23check(mtn("attr", "set", "testfile", "key3", "has_been_changed"), 0, false, false)
24check(mtn("attr", "drop", "testfile", "key2"), 0, false, false)
25
26-- the actual check of the interface
27check(mtn("automate", "get_attributes", "testfile"), 0, true, true)
28check(fsize("stderr") == 0)
29parsed = parse_basic_io(readfile("stdout"))
30-- make sure the output generated 8 stanzas
31check(#parsed == 8)
32lastkey = ""
33checked = {}
34for _,l in pairs(parsed) do
35    if l.name == "attr" then
36        lastkey = l.values[1]
37        val = l.values[2]
38        if lastkey == "key1" then check(val == "persists") end
39        if lastkey == "key2" then check(val == "will_be_dropped") end
40        if lastkey == "key3" then check(val == "has_been_changed") end
41        if lastkey == "key4" then check(val == "has_been_added") end
42    end
43    if l.name == "state" then
44        state = l.values[1]
45
46        if lastkey == "key1" then
47            check(state == "unchanged")
48            checked[lastkey] = true
49        end
50        if lastkey == "key2" then
51            check(state == "dropped")
52            checked[lastkey] = true
53        end
54        if lastkey == "key3" then
55            check(state == "changed")
56            checked[lastkey] = true
57        end
58        if lastkey == "key4" then
59            check(state == "added")
60            checked[lastkey] = true
61        end
62    end
63end
64
65check(checked["key1"] and checked["key2"] and checked["key3"] and checked["key4"])
66
67commit("mainbranch")
68
69-- check that dropped attributes do not popup in further revisions
70check(mtn("automate", "get_attributes", "testfile"), 0, true, true)
71check(fsize("stderr") == 0)
72parsed = parse_basic_io(readfile("stdout"))
73
74for _,l in pairs(parsed) do
75    if l.name == "attr" then
76        curkey = l.values[1]
77        check(curkey ~= "key2")
78    end
79end
80
81-- check that new attributes which resemble the name of previously
82-- dropped attributes are correctly listed as added, and not changed
83-- (bug in 0.35)
84check(mtn("attr", "set", "testfile", "key2", "new_value"), 0, false, false)
85check(mtn("automate", "get_attributes", "testfile"), 0, true, true)
86check(fsize("stderr") == 0)
87parsed = parse_basic_io(readfile("stdout"))
88
89curkey = ""
90for _,l in pairs(parsed) do
91    if l.name == "attr" then
92        curkey = l.values[1]
93    end
94    if l.name == "state" and curkey == "key2" then
95        state = l.values[1]
96        check(state == "added")
97    end
98end
99
100-- check that we can query arbitrary attributes from earlier revisions
101check(mtn("automate", "get_attributes", "-r", "0123456789012345678901234567890123456789", "bla"), 1, false, true)
102check(qgrep("no revision 0123456789012345678901234567890123456789 found in database", "stderr"))
103
104rev = base_revision()
105check(mtn("automate", "get_attributes", "foo", "-r", rev), 1, false, true)
106check(qgrep("unknown path 'foo' in " .. rev, "stderr"))
107
108check(mtn("automate", "get_attributes", "testfile", "-r", rev), 0, true, false)
109
110parsed = parse_basic_io(readfile("stdout"))
111check(#parsed == 6)
112
113lastkey = ""
114checked = {}
115for _,l in pairs(parsed) do
116    if l.name == "attr" then
117        lastkey = l.values[1]
118        val = l.values[2]
119        if lastkey == "key1" then check(val == "persists")
120        elseif lastkey == "key3" then check(val == "has_been_changed")
121        elseif lastkey == "key4" then check(val == "has_been_added")
122        else check(false) end
123    end
124    if l.name == "state" then
125        check(l.values[1] == "unchanged")
126        checked[lastkey] = true
127    end
128end
129
130check(checked["key1"] and checked["key3"] and checked["key4"])
131
132