sedtest.sh 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238
  1. ##
  2. ## Sed test script
  3. ## Evan Green
  4. ## 12-Jul-2013
  5. ##
  6. ##
  7. ## Define the correct output of the sed program.
  8. ##
  9. SED_OUTPUT='hiya
  10. my
  11. wonderful
  12. amigo
  13. really
  14. great
  15. 7
  16. 9
  17. up
  18. up\nin$
  19. up
  20. in
  21. old
  22. up
  23. in
  24. town
  25. where
  26. the\nup\nin\ntown$
  27. the
  28. up
  29. in
  30. town
  31. 15
  32. old
  33. cactus
  34. cactus
  35. grow
  36. grow
  37. hiya
  38. there
  39. friend
  40. or enemy?
  41. great
  42. 18
  43. up
  44. in
  45. town
  46. and
  47. nobody
  48. knows
  49. what
  50. yoooou
  51. GONE
  52. done
  53. ##26
  54. abcdefghbcdefgh&xxcdecdeh***zzijklmno
  55. abCfghbCfgh&CCh***ZZijklmno
  56. My
  57. Great
  58. Day
  59. 12345678901234Fifteen67890
  60. 12345678901234Fifteen67890'
  61. ##
  62. ## Define the correct outputs for wfile1 and wfile2
  63. ##
  64. SED_WFILE1='the
  65. up
  66. in
  67. town
  68. '
  69. SED_WFILE2='12345678901234Fifteen67890**zzijklmno
  70. abCfghbCfgh&xxCCh***ZZijklmno
  71. '
  72. ##
  73. ## Define the input script
  74. ##
  75. SED_SCRIPT='
  76. b BeginLabel
  77. athis\
  78. never\
  79. runs
  80. :QuitLabel
  81. q
  82. :BeginLabel
  83. 2 {
  84. a\
  85. my
  86. awonderful
  87. }
  88. 2,3 camigo
  89. \cgreatc i\
  90. really\n
  91. / enemy?/ d
  92. / enemy?/,$ d
  93. 7 {=;N;N;D;p;}
  94. 9 =;9P;9l
  95. 9h;;;
  96. 11g
  97. 12H;14G
  98. 14l
  99. 14w wfile1
  100. 15{= ;;; n;15q}
  101. 16p
  102. 17p
  103. 17r stesta
  104. 18=;18x
  105. \ah\avea y/ahve/OGNE/
  106. \ah\avea =
  107. 27 {s/b\(c..\)fg\(h\)/&&\&xx\1\1\2***zz/pw wfile2
  108. s_c.._C_g
  109. tOverLabel
  110. q
  111. :OverLabel
  112. swzwZwgw wfile2
  113. s/x//g
  114. t
  115. tQuitLabel
  116. s/QQQ/DOESNOTMATCH/g
  117. t QuitLabel
  118. }
  119. 28,/cutstop/d
  120. 29p
  121. 32s/NEWLINE/\n/g
  122. 33s.\..Fifteen.15pw ././wfile2
  123. 99tQuitLabel
  124. ##
  125. ## These are comments
  126. #nawef
  127. '
  128. ##
  129. ## Define the contents of the input files.
  130. ##
  131. SED_INPUT1='hiya
  132. there
  133. friend
  134. or enemy?
  135. great
  136. '
  137. SED_INPUT2='whats
  138. up
  139. in
  140. old
  141. sasprilluh
  142. town
  143. where
  144. the
  145. old
  146. cactus
  147. grow
  148. and
  149. nobody
  150. knows
  151. what
  152. yoooou
  153. have
  154. done
  155. ##26
  156. abcdefghijklmno
  157. cutstart
  158. does
  159. not appear
  160. cutstop
  161. MyNEWLINEGreatNEWLINEDay
  162. 12345678901234567890'
  163. ##
  164. ## Get set up to run the test by outputting the input
  165. ## files and script.
  166. ##
  167. echo -n "$SED_INPUT1" > stesta
  168. echo -n "$SED_INPUT2" > stestb
  169. echo -n "$SED_SCRIPT" > stest
  170. ##
  171. ## Run the test.
  172. ##
  173. sed -f stest stesta stestb > stestout
  174. SED_RETURN=$?
  175. echo -n "$SED_OUTPUT" > stestout.ans
  176. echo -n "$SED_WFILE1" > wfile1.ans
  177. echo -n "$SED_WFILE2" > wfile2.ans
  178. ##
  179. ## Compare the results.
  180. ##
  181. SED_RECEIVED_OUTPUT="`cat stestout`"
  182. SED_RECEIVED_WFILE1="`cat wfile1`"
  183. SED_RECEIVED_WFILE2="`cat wfile2`"
  184. SED_ERRORS=0
  185. if [ $SED_RETURN -ne 0 ]; then
  186. echo "sed returned failing status $SED_RETURN."
  187. SED_ERRORS=$(($SED_ERRORS+1))
  188. fi
  189. if ! cmp stestout stestout.ans; then
  190. echo "sed output failed. Compare stestout with stestout.ans"
  191. SED_ERRORS=$(($SED_ERRORS+1))
  192. fi
  193. if ! cmp wfile1 wfile1.ans; then
  194. echo "sed wfile1 failed. Compare wfile1 with wfile1.ans"
  195. SED_ERRORS=$(($SED_ERRORS+1))
  196. fi
  197. if ! cmp wfile2 wfile2.ans; then
  198. echo "sed wfile2 failed. Compare wfile2 with wfile2.ans"
  199. SED_ERRORS=$(($SED_ERRORS+1))
  200. fi
  201. if [ $SED_ERRORS -ne 0 ]; then
  202. echo "*** sed test had $SED_ERRORS failures ***"
  203. fi
  204. if [ $SED_ERRORS -eq 0 ]; then
  205. rm stestout stestout.ans wfile1 wfile1.ans wfile2 wfile2.ans
  206. rm stesta stestb stest
  207. fi