Download | Plain Text | No Line Numbers


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