test-method-rred 4.7 KB

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