]> git.saurik.com Git - apt.git/blame - test/integration/test-method-rred
avoid using global PendingError to avoid failing too often too soon
[apt.git] / test / integration / test-method-rred
CommitLineData
6d3e5bd8
DK
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}
42
43testrred 'Remove' 'first line' '1d' "$(tail -n +2 ./Packages)"
44testrred 'Remove' 'empty line' '10d' "$(head -n 9 ./Packages)
45$(tail -n 9 ./Packages)"
46testrred 'Remove' 'line in a paragraph' '5d' "$(head -n 4 ./Packages)
47$(tail -n 14 ./Packages)"
48testrred 'Remove' 'last line' '19d' "$(head -n -1 ./Packages)"
49testrred 'Remove' 'multiple single lines' '17d
507d' "$(sed -e '/^ - even more stuff$/ d' ./Packages)"
51testrred 'Remove' 'first paragraph' '1,10d' "$(tail -n 9 ./Packages)"
52testrred 'Remove' 'a few lines in the middle' '5,14d' "$(head -n 4 ./Packages)
53$(tail -n 5 ./Packages)"
54testrred 'Remove' 'second paragraph' '10,19d' "$(head -n 9 ./Packages)"
55testrred 'Mass Remove' 'all stuff lines' '15,17d
5613d
5711d
585,7d
593d
601d' "$(sed '/stuff/ d' ./Packages)"
61
62testrred 'Single line add' 'first line' '0a
63Format: 3.0 (native)
64.' "Format: 3.0 (native)
65$(cat ./Packages)"
66testrred 'Single line add' 'last line' '19a
67Multi-Arch: foreign
68.' "$(cat ./Packages)
69Multi-Arch: foreign"
70testrred 'Single line add' 'middle' '9a
71Multi-Arch: foreign
72.' "$(head -n 9 ./Packages)
73Multi-Arch: foreign
74$(tail -n 10 ./Packages)"
75
76testrred 'Multi line add' 'first line' '0a
77Format: 3.0 (native)
78Source: apt
79.' "Format: 3.0 (native)
80Source: apt
81$(cat ./Packages)"
82testrred 'Multi line add' 'last line' '19a
83Multi-Arch: foreign
84Homepage: https://debian.org
85.' "$(cat ./Packages)
86Multi-Arch: foreign
87Homepage: https://debian.org"
88testrred 'Multi line add' 'middle' '9a
89Multi-Arch: foreign
90Homepage: https://debian.org
91.' "$(head -n 9 ./Packages)
92Multi-Arch: foreign
93Homepage: https://debian.org
94$(tail -n 10 ./Packages)"
95
96testrred 'Single line change' 'first line' '1c
97Package: supercoolstuff
98.' "Package: supercoolstuff
99$(tail -n +2 ./Packages)"
100testrred 'Single line change' 'in the middle' '9c
101 And a super cow.
102.' "$(head -n 8 ./Packages)
103 And a super cow.
104$(tail -n 10 ./Packages)"
105testrred 'Single line change' 'an empty line' '10c
106
107.' "$(head -n 9 ./Packages)
108
109$(tail -n 9 ./Packages)"
110testrred 'Single line change' 'a spacy line' '10c
111
112.' "$(head -n 9 ./Packages)
113
114$(tail -n 9 ./Packages)"
115testrred 'Single line change' 'last line' '19c
116 And a cat.
117.' "$(head -n -1 ./Packages)
118 And a cat."
119
120testrred 'Multi line change' 'exchange' '5,7c
121 - good stuff
122 - more good stuff
123 - even more good stuff
124.' "$(head -n 4 ./Packages)
125 - good stuff
126 - more good stuff
127 - even more good stuff
128$(tail -n 12 ./Packages)"
129testrred 'Multi line change' 'less' '5,7c
130 - good stuff
131 - more good stuff
132.' "$(head -n 4 ./Packages)
133 - good stuff
134 - more good stuff
135$(tail -n 12 ./Packages)"
136testrred 'Multi line change' 'more' '5,7c
137 - good stuff
138 - more good stuff
139 - even more good stuff
140 - bonus good stuff
141.' "$(head -n 4 ./Packages)
142 - good stuff
143 - more good stuff
144 - even more good stuff
145 - bonus good stuff
146$(tail -n 12 ./Packages)"
147
148failrred() {
149 msgtest 'Failure caused by' "$1"
150 echo "$2" > Packages.ed
151 rred() {
152 cat Packages | runapt "${METHODSDIR}/rred" "$@"
153 }
154 testfailure --nomsg rred -f Packages.ed
155}
156
157failrred 'Bogus content' '<html>
158</html>'
159
160# not a problem per-se, but we want our parser to be really strict
161failrred 'Empty patch file' ''
162failrred 'Empty line patch file' '
163'
164failrred 'Empty line before command' '
1651d'
166failrred 'Empty line after command' '1d
167'
168failrred 'Empty line between commands' '17d
169
1707d'
171failrred 'Empty spaces lines before command' '
1721d'
173failrred 'Empty spaces lines after command' '1d
174 '
175failrred 'Empty spaces lines between commands' '17d
176
1777d'
178
179# the line before the first one can't be deleted/changed
180failrred 'zero line delete' '0d'
181failrred 'zero line change' '0c
182Package: supercoolstuff
183.'
184# and this makes no sense at all
185failrred 'negative line delete' '-1d'
186failrred 'negative line change' '-1c
187Package: supercoolstuff
188.'
189failrred 'negative line add' '-1a
190Package: supercoolstuff
191.'
192failrred 'Wrong order of commands' '7d
19317d'
194failrred 'End before start' '7,6d'