PageRenderTime 47ms CodeModel.GetById 17ms RepoModel.GetById 0ms app.codeStats 0ms

/code/Text-NSP-1.09/Testing/count/error-handling.sh

https://github.com/wwwjscom/Segments-Tester
Shell | 300 lines | 176 code | 81 blank | 43 comment | 22 complexity | 98eac4862e648ea34fc754b780656c17 MD5 | raw file
  1. #!/bin/csh -f
  2. # shell program to test count.pl's response to erroneous conditions.
  3. # Subtest 1: check what happens when count.pl is not provided with a source file.
  4. echo "Subtest 1: When no source file is provided to count.pl"
  5. echo ""
  6. # required error output file
  7. set TARGETFILE = "test-2.sub-1.reqd"
  8. if (!(-e $TARGETFILE)) then
  9. echo "File $TARGETFILE does not exist... aborting"
  10. exit
  11. endif
  12. # now the test!
  13. echo "Test: count.pl temp >& error.out"
  14. count.pl temp >& error.out
  15. # compare the actual output with the required output
  16. diff error.out $TARGETFILE > difference
  17. if (-z difference) then
  18. echo "Status: OK\!\! Output matches target output (as provided in $TARGETFILE)"
  19. else
  20. echo "Status: ERROR\!\! Following differences exist between test-1.out and $TARGETFILE :"
  21. cat difference
  22. endif
  23. echo ""
  24. /bin/rm -f difference
  25. /bin/rm -f error.out
  26. /bin/rm -f temp
  27. # Subtest 2: check what happens when count.pl is provided with a
  28. # source file that doesnt exist!
  29. echo "Subtest 2: When source file does not exist"
  30. echo ""
  31. # required error output file
  32. set TARGETFILE = "test-2.sub-2.reqd"
  33. if (!(-e $TARGETFILE)) then
  34. echo "File $TARGETFILE does not exist... aborting"
  35. exit
  36. endif
  37. # now the test!
  38. echo "Test: count.pl temp hoho >& error.out"
  39. count.pl temp hoho >& error.out
  40. # compare the actual output with the required output
  41. diff error.out $TARGETFILE > difference
  42. if (-z difference) then
  43. echo "Status: OK\!\! Output matches target output (as provided in $TARGETFILE)"
  44. else
  45. echo "Status: ERROR\!\! Following differences exist between test-1.out and $TARGETFILE :"
  46. cat difference
  47. endif
  48. echo ""
  49. /bin/rm -f difference
  50. /bin/rm -f error.out
  51. /bin/rm -f temp
  52. # Subtest 3: check what happens when count.pl is provided with --ngram 0
  53. echo "Subtest 3: --ngram 0"
  54. echo ""
  55. # required error output file
  56. set TARGETFILE = "test-2.sub-3.reqd"
  57. if (!(-e $TARGETFILE)) then
  58. echo "File $TARGETFILE does not exist... aborting"
  59. exit
  60. endif
  61. # now the test!
  62. echo "Test: count.pl --ngram 0 >& error.out"
  63. count.pl --ngram 0 >& error.out
  64. # compare the actual output with the required output
  65. diff error.out $TARGETFILE > difference
  66. if (-z difference) then
  67. echo "Status: OK\!\! Output matches target output (as provided in $TARGETFILE)"
  68. else
  69. echo "Status: ERROR\!\! Following differences exist between test-1.out and $TARGETFILE :"
  70. cat difference
  71. endif
  72. echo ""
  73. /bin/rm -f difference
  74. /bin/rm -f error.out
  75. # Subtest 4: check what happens when count.pl is provided with --ngram 1 --window 2
  76. echo "Subtest 4: --ngram 1 --window 2"
  77. echo ""
  78. # required error output file
  79. set TARGETFILE = "test-2.sub-4.reqd"
  80. if (!(-e $TARGETFILE)) then
  81. echo "File $TARGETFILE does not exist... aborting"
  82. exit
  83. endif
  84. # now the test!
  85. echo "Test: count.pl --ngram 1 --window 2 >& error.out"
  86. count.pl --ngram 1 --window 2 >& error.out
  87. # compare the actual output with the required output
  88. diff error.out $TARGETFILE > difference
  89. if (-z difference) then
  90. echo "Status: OK\!\! Output matches target output (as provided in $TARGETFILE)"
  91. else
  92. echo "Status: ERROR\!\! Following differences exist between test-1.out and $TARGETFILE :"
  93. cat difference
  94. endif
  95. echo ""
  96. /bin/rm -f difference
  97. /bin/rm -f error.out
  98. # Subtest 5: check what happens when count.pl is provided with --ngram 3 --window 2
  99. echo "Subtest 5: --ngram 3 --window 2"
  100. echo ""
  101. # required error output file
  102. set TARGETFILE = "test-2.sub-4.reqd"
  103. if (!(-e $TARGETFILE)) then
  104. echo "File $TARGETFILE does not exist... aborting"
  105. exit
  106. endif
  107. # now the test!
  108. echo "Test: count.pl --ngram 3 --window 2 >& error.out"
  109. count.pl --ngram 3 --window 2 >& error.out
  110. # compare the actual output with the required output
  111. diff error.out $TARGETFILE > difference
  112. if (-z difference) then
  113. echo "Status: OK\!\! Output matches target output (as provided in $TARGETFILE)"
  114. else
  115. echo "Status: ERROR\!\! Following differences exist between test-1.out and $TARGETFILE :"
  116. cat difference
  117. endif
  118. echo ""
  119. /bin/rm -f difference
  120. /bin/rm -f error.out
  121. # Subtest 6: check what happens when count.pl is provided with non
  122. # existent file through --stop.
  123. echo "Subtest 6: Non-existent file through switch --stop"
  124. echo ""
  125. # input file
  126. set TESTFILE = "test-2.txt"
  127. if (!(-e $TESTFILE)) then
  128. echo "File $TESTFILE does not exist... aborting"
  129. exit
  130. endif
  131. # required error output file
  132. set TARGETFILE = "test-2.sub-6.reqd"
  133. if (!(-e $TARGETFILE)) then
  134. echo "File $TARGETFILE does not exist... aborting"
  135. exit
  136. endif
  137. # now the test!
  138. echo "Test: count.pl --stop hoho temp $TESTFILE >& error.out"
  139. count.pl --stop hoho temp $TESTFILE >& error.out
  140. # compare the actual output with the required output
  141. diff error.out $TARGETFILE > difference
  142. if (-z difference) then
  143. echo "Status: OK\!\! Output matches target output (as provided in $TARGETFILE)"
  144. else
  145. echo "Status: ERROR\!\! Following differences exist between test-1.out and $TARGETFILE :"
  146. cat difference
  147. endif
  148. echo ""
  149. /bin/rm -f difference
  150. /bin/rm -f error.out
  151. # Subtest 7: check what happens when count.pl is provided with non
  152. # existent file through switch --token.
  153. echo "Subtest 7: Non-existent file through switch --token"
  154. echo ""
  155. # input file
  156. set TESTFILE = "test-2.txt"
  157. if (!(-e $TESTFILE)) then
  158. echo "File $TESTFILE does not exist... aborting"
  159. exit
  160. endif
  161. # required error output file
  162. set TARGETFILE = "test-2.sub-7.reqd"
  163. if (!(-e $TARGETFILE)) then
  164. echo "File $TARGETFILE does not exist... aborting"
  165. exit
  166. endif
  167. # now the test!
  168. echo "Test: count.pl --token hoho temp $TESTFILE >& error.out"
  169. count.pl --token hoho $TESTFILE >& error.out
  170. # compare the actual output with the required output
  171. diff error.out $TARGETFILE > difference
  172. if (-z difference) then
  173. echo "Status: OK\!\! Output matches target output (as provided in $TARGETFILE)"
  174. else
  175. echo "Status: ERROR\!\! Following differences exist between test-1.out and $TARGETFILE :"
  176. cat difference
  177. endif
  178. echo ""
  179. /bin/rm -f difference
  180. /bin/rm -f error.out
  181. /bin/rm -f temp
  182. # Subtest 8: check what happens when count.pl is provided with a
  183. # frequency combination file that has indices inconsistent with the
  184. # current --ngram setting.
  185. echo "Subtest 8: Inconsistent frequency combination file"
  186. echo ""
  187. # input file
  188. set TESTFILE = "test-2.txt"
  189. if (!(-e $TESTFILE)) then
  190. echo "File $TESTFILE does not exist... aborting"
  191. exit
  192. endif
  193. # frequency combination file
  194. set FREQCOMBFILE = "test-2.sub-8.freq_combo.txt"
  195. if (!(-e $FREQCOMBFILE)) then
  196. echo "File $FREQCOMBFILE does not exist... aborting"
  197. exit
  198. endif
  199. # required error output file
  200. set TARGETFILE = "test-2.sub-8.reqd"
  201. if (!(-e $TARGETFILE)) then
  202. echo "File $TARGETFILE does not exist... aborting"
  203. exit
  204. endif
  205. # now the test!
  206. echo "Test: count.pl --set_freq_combo $FREQCOMBFILE temp $TESTFILE >& error.out"
  207. count.pl --set_freq_combo $FREQCOMBFILE temp $TESTFILE >& error.out
  208. # compare the actual output with the required output
  209. diff error.out $TARGETFILE > difference
  210. if (-z difference) then
  211. echo "Status: OK\!\! Output matches target output (as provided in $TARGETFILE)"
  212. else
  213. echo "Status: ERROR\!\! Following differences exist between test-1.out and $TARGETFILE :"
  214. cat difference
  215. endif
  216. echo ""
  217. /bin/rm -f difference
  218. /bin/rm -f error.out
  219. /bin/rm -f temp