]> git.saurik.com Git - apt.git/blob - test/integration/test-method-rred
show apt-key warnings in apt update
[apt.git] / test / integration / test-method-rred
1 #!/bin/sh
2 set -e
3
4 TESTDIR="$(readlink -f "$(dirname "$0")")"
5 . "$TESTDIR/framework"
6
7 setupenvironment
8 configarchitecture 'i386'
9
10 echo 'Package: coolstuff
11 Version: 0.8.15
12 Description: 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
20 Package: oldstuff
21 Version: 0-1
22 Description: 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
30 testrred() {
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
45 testrred 'Remove' 'first line' '1d' "$(tail -n +2 ./Packages)"
46 testrred 'Remove' 'empty line' '10d' "$(head -n 9 ./Packages)
47 $(tail -n 9 ./Packages)"
48 testrred 'Remove' 'line in a paragraph' '5d' "$(head -n 4 ./Packages)
49 $(tail -n 14 ./Packages)"
50 testrred 'Remove' 'last line' '19d' "$(head -n -1 ./Packages)"
51 testrred 'Remove' 'multiple single lines' '17d
52 7d' "$(sed -e '/^ - even more stuff$/ d' ./Packages)"
53 testrred 'Remove' 'first paragraph' '1,10d' "$(tail -n 9 ./Packages)"
54 testrred 'Remove' 'a few lines in the middle' '5,14d' "$(head -n 4 ./Packages)
55 $(tail -n 5 ./Packages)"
56 testrred 'Remove' 'second paragraph' '10,19d' "$(head -n 9 ./Packages)"
57 testrred 'Mass Remove' 'all stuff lines' '15,17d
58 13d
59 11d
60 5,7d
61 3d
62 1d' "$(sed '/stuff/ d' ./Packages)"
63
64 testrred 'Single line add' 'first line' '0a
65 Format: 3.0 (native)
66 .' "Format: 3.0 (native)
67 $(cat ./Packages)"
68 testrred 'Single line add' 'last line' '19a
69 Multi-Arch: foreign
70 .' "$(cat ./Packages)
71 Multi-Arch: foreign"
72 testrred 'Single line add' 'middle' '9a
73 Multi-Arch: foreign
74 .' "$(head -n 9 ./Packages)
75 Multi-Arch: foreign
76 $(tail -n 10 ./Packages)"
77
78 testrred 'Multi line add' 'first line' '0a
79 Format: 3.0 (native)
80 Source: apt
81 .' "Format: 3.0 (native)
82 Source: apt
83 $(cat ./Packages)"
84 testrred 'Multi line add' 'last line' '19a
85 Multi-Arch: foreign
86 Homepage: https://debian.org
87 .' "$(cat ./Packages)
88 Multi-Arch: foreign
89 Homepage: https://debian.org"
90 testrred 'Multi line add' 'middle' '9a
91 Multi-Arch: foreign
92 Homepage: https://debian.org
93 .' "$(head -n 9 ./Packages)
94 Multi-Arch: foreign
95 Homepage: https://debian.org
96 $(tail -n 10 ./Packages)"
97
98 testrred 'Single line change' 'first line' '1c
99 Package: supercoolstuff
100 .' "Package: supercoolstuff
101 $(tail -n +2 ./Packages)"
102 testrred '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)"
107 testrred 'Single line change' 'an empty line' '10c
108
109 .' "$(head -n 9 ./Packages)
110
111 $(tail -n 9 ./Packages)"
112 testrred 'Single line change' 'a spacy line' '10c
113
114 .' "$(head -n 9 ./Packages)
115
116 $(tail -n 9 ./Packages)"
117 testrred 'Single line change' 'last line' '19c
118 And a cat.
119 .' "$(head -n -1 ./Packages)
120 And a cat."
121
122 testrred '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)"
131 testrred '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)"
138 testrred '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
150 failrred() {
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
160 failrred 'Bogus content' '<html>
161 </html>'
162
163 # not a problem per-se, but we want our parser to be really strict
164 failrred 'Empty patch file' ''
165 failrred 'Empty line patch file' '
166 '
167 failrred 'Empty line before command' '
168 1d'
169 failrred 'Empty line after command' '1d
170 '
171 failrred 'Empty line between commands' '17d
172
173 7d'
174 failrred 'Empty spaces lines before command' '
175 1d'
176 failrred 'Empty spaces lines after command' '1d
177 '
178 failrred 'Empty spaces lines between commands' '17d
179
180 7d'
181
182 # the line before the first one can't be deleted/changed
183 failrred 'zero line delete' '0d'
184 failrred 'zero line change' '0c
185 Package: supercoolstuff
186 .'
187 # and this makes no sense at all
188 failrred 'negative line delete' '-1d'
189 failrred 'negative line change' '-1c
190 Package: supercoolstuff
191 .'
192 failrred 'negative line add' '-1a
193 Package: supercoolstuff
194 .'
195 failrred 'Wrong order of commands' '7d
196 17d'
197 failrred 'End before start' '7,6d'