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