Download | Plain Text | No Line Numbers


  1. #!/bin/bash
  2.  
  3. JAVA="java"
  4. JAVAFLAGS=""
  5. ANT="ant"
  6.  
  7. MAIN="ads1ws08.pa1.Main"
  8. VIEWER="ads1ws08.pa1.viewer.ViewerApplication"
  9. VIEWERTMP="viewertmp"
  10. MAINJAR="ads1ws08.jar"
  11.  
  12. function compile
  13. {
  14. $ANT jar
  15. }
  16.  
  17. function run
  18. {
  19. $JAVA $JAVAFLAGS -cp $MAINJAR $MAIN $*
  20. }
  21.  
  22. function view
  23. {
  24. run $* | tee $VIEWERTMP && \
  25. $JAVA $JAVAFLAGS -cp $MAINJAR $VIEWER $VIEWERTMP && \
  26. rm -f $VIEWERTMP
  27. }
  28.  
  29. function do_test
  30. {
  31. input="$1"
  32. output="$2"
  33.  
  34. if [ ! -f "$input" ]
  35. then
  36. return
  37. fi
  38. if [ ! -f "$output" ]
  39. then
  40. echo "ERROR: outputfile for $input doesn't exist"
  41. exit 1
  42. fi
  43.  
  44. echo "Testing $input ..."
  45. md5_1=$(run "$input" | md5sum)
  46. md5_2=$(md5sum < "$output")
  47. if [ "$md5_1" = "$md5_2" ]
  48. then
  49. echo " SUCCESS"
  50. else
  51. echo " ERROR: output file differ..."
  52. exit 1
  53. fi
  54. }
  55.  
  56. cmd="$1"
  57. shift
  58. case "$cmd" in
  59. c|compile|make)
  60. compile
  61. ;;
  62. r|run)
  63. compile >&2 && \
  64. run $*
  65. ;;
  66. test)
  67. file="$1"
  68. if [ ! -f "$file" ]
  69. then
  70. echo "ERROR: testfile doesn't exist"
  71. exit 1
  72. fi
  73. input="$file"
  74. output=$(dirname "$input")"/../output/"$(basename "$file")
  75. do_test "$input" "$output"
  76. ;;
  77. t|tests)
  78. for dir in $(find ./tests -type d -iname "input")
  79. do
  80. for file in $(ls $dir | sort)
  81. do
  82. input="$dir/$file"
  83. output="$dir/../output/$file"
  84. if [ ! -f "$input" ]
  85. then
  86. continue
  87. fi
  88. do_test "$input" "$output"
  89. done
  90. done
  91. ;;
  92. v|view)
  93. compile && \
  94. view $*
  95. ;;
  96. esac
  97.