]> git.saurik.com Git - apt.git/blame_incremental - test/integration/test-method-rred
test: Get rid of debhelper rules.tiny example dep
[apt.git] / test / integration / test-method-rred
... / ...
CommitLineData
1#!/bin/sh
2set -e
3
4TESTDIR="$(readlink -f "$(dirname "$0")")"
5. "$TESTDIR/framework"
6
7setupenvironment
8configarchitecture 'i386'
9
10echo 'Package: coolstuff
11Version: 0.8.15
12Description: collection of stuff
13 A lot, too much to iterate all, but at least this:
14 - stuff
15 - more stuff
16 - even more stuff
17 .
18 And a cow.
19
20Package: oldstuff
21Version: 0-1
22Description: collection of outdated stuff
23 A lot, but of no use nowadays, but at least this:
24 - stuff
25 - more stuff
26 - even more stuff
27 .
28 And a dog.' > Packages
29
30testrred() {
31 msgtest "$1" "$2"
32 if [ -z "$3" ]; then
33 echo -n '' > Packages.ed
34 else
35 echo "$3" > Packages.ed
36 fi
37 rred() {
38 cat Packages | runapt "${METHODSDIR}/rred" "$@"
39 }
40 testsuccessequal "$4" --nomsg rred -f Packages.ed
41 testsuccess runapt "${METHODSDIR}/rred" -t Packages Packages-patched Packages.ed
42 testfileequal Packages-patched "$4"
43}
44
45testrred 'Remove' 'first line' '1d' "$(tail -n +2 ./Packages)"
46testrred 'Remove' 'empty line' '10d' "$(head -n 9 ./Packages)
47$(tail -n 9 ./Packages)"
48testrred 'Remove' 'line in a paragraph' '5d' "$(head -n 4 ./Packages)
49$(tail -n 14 ./Packages)"
50testrred 'Remove' 'last line' '19d' "$(head -n -1 ./Packages)"
51testrred 'Remove' 'multiple single lines' '17d
527d' "$(sed -e '/^ - even more stuff$/ d' ./Packages)"
53testrred 'Remove' 'first paragraph' '1,10d' "$(tail -n 9 ./Packages)"
54testrred 'Remove' 'a few lines in the middle' '5,14d' "$(head -n 4 ./Packages)
55$(tail -n 5 ./Packages)"
56testrred 'Remove' 'second paragraph' '10,19d' "$(head -n 9 ./Packages)"
57testrred 'Mass Remove' 'all stuff lines' '15,17d
5813d
5911d
605,7d
613d
621d' "$(sed '/stuff/ d' ./Packages)"
63
64testrred 'Single line add' 'first line' '0a
65Format: 3.0 (native)
66.' "Format: 3.0 (native)
67$(cat ./Packages)"
68testrred 'Single line add' 'last line' '19a
69Multi-Arch: foreign
70.' "$(cat ./Packages)
71Multi-Arch: foreign"
72testrred 'Single line add' 'middle' '9a
73Multi-Arch: foreign
74.' "$(head -n 9 ./Packages)
75Multi-Arch: foreign
76$(tail -n 10 ./Packages)"
77
78testrred 'Multi line add' 'first line' '0a
79Format: 3.0 (native)
80Source: apt
81.' "Format: 3.0 (native)
82Source: apt
83$(cat ./Packages)"
84testrred 'Multi line add' 'last line' '19a
85Multi-Arch: foreign
86Homepage: https://debian.org
87.' "$(cat ./Packages)
88Multi-Arch: foreign
89Homepage: https://debian.org"
90testrred 'Multi line add' 'middle' '9a
91Multi-Arch: foreign
92Homepage: https://debian.org
93.' "$(head -n 9 ./Packages)
94Multi-Arch: foreign
95Homepage: https://debian.org
96$(tail -n 10 ./Packages)"
97
98testrred 'Single line change' 'first line' '1c
99Package: supercoolstuff
100.' "Package: supercoolstuff
101$(tail -n +2 ./Packages)"
102testrred 'Single line change' 'in the middle' '9c
103 And a super cow.
104.' "$(head -n 8 ./Packages)
105 And a super cow.
106$(tail -n 10 ./Packages)"
107testrred 'Single line change' 'an empty line' '10c
108
109.' "$(head -n 9 ./Packages)
110
111$(tail -n 9 ./Packages)"
112testrred 'Single line change' 'a spacy line' '10c
113
114.' "$(head -n 9 ./Packages)
115
116$(tail -n 9 ./Packages)"
117testrred 'Single line change' 'last line' '19c
118 And a cat.
119.' "$(head -n -1 ./Packages)
120 And a cat."
121
122testrred 'Multi line change' 'exchange' '5,7c
123 - good stuff
124 - more good stuff
125 - even more good stuff
126.' "$(head -n 4 ./Packages)
127 - good stuff
128 - more good stuff
129 - even more good stuff
130$(tail -n 12 ./Packages)"
131testrred 'Multi line change' 'less' '5,7c
132 - good stuff
133 - more good stuff
134.' "$(head -n 4 ./Packages)
135 - good stuff
136 - more good stuff
137$(tail -n 12 ./Packages)"
138testrred 'Multi line change' 'more' '5,7c
139 - good stuff
140 - more good stuff
141 - even more good stuff
142 - bonus good stuff
143.' "$(head -n 4 ./Packages)
144 - good stuff
145 - more good stuff
146 - even more good stuff
147 - bonus good stuff
148$(tail -n 12 ./Packages)"
149
150failrred() {
151 msgtest 'Failure caused by' "$1"
152 echo "$2" > Packages.ed
153 rred() {
154 cat Packages | runapt "${METHODSDIR}/rred" "$@"
155 }
156 testfailure --nomsg rred -f Packages.ed
157 testfailure runapt "${METHODSDIR}/rred" -t Packages Packages-patched Packages.ed
158}
159
160failrred 'Bogus content' '<html>
161</html>'
162
163# not a problem per-se, but we want our parser to be really strict
164failrred 'Empty patch file' ''
165failrred 'Empty line patch file' '
166'
167failrred 'Empty line before command' '
1681d'
169failrred 'Empty line after command' '1d
170'
171failrred 'Empty line between commands' '17d
172
1737d'
174failrred 'Empty spaces lines before command' '
1751d'
176failrred 'Empty spaces lines after command' '1d
177 '
178failrred 'Empty spaces lines between commands' '17d
179
1807d'
181
182# the line before the first one can't be deleted/changed
183failrred 'zero line delete' '0d'
184failrred 'zero line change' '0c
185Package: supercoolstuff
186.'
187# and this makes no sense at all
188failrred 'negative line delete' '-1d'
189failrred 'negative line change' '-1c
190Package: supercoolstuff
191.'
192failrred 'negative line add' '-1a
193Package: supercoolstuff
194.'
195failrred 'Wrong order of commands' '7d
19617d'
197failrred 'End before start' '7,6d'