Advertisement
Guest User

Untitled

a guest
Aug 28th, 2016
74
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.00 KB | None | 0 0
  1. #!/bin/bash
  2.  
  3. echo
  4. echo "__________COMPILING__________"
  5. exec_name="${PWD##*/}"
  6. echo "compiling $(find . -name *.h) $(find . -name *.cpp)"
  7. if g++ $(find . -name *.h -o -name *.cpp) -o $exec_name; then
  8. echo "compilation successful (saved as $exec_name)"
  9. echo
  10. else
  11. echo "compilation failure"
  12. exit
  13. fi
  14.  
  15. inputs=($(find . -name 'input[0-9].txt'))
  16. if [ ${#inputs[@]} -eq 0 ]; then
  17. echo "Error: no input files found. inputs must be saved as input<number>.txt"
  18. exit
  19. fi
  20.  
  21. echo "___________TESTING___________"
  22. echo "HINT: Comparisons are shown with vimdiff. To exit vim, type the command ':qa"
  23. echo
  24. hasvim=false
  25. for in in "${inputs[@]}"; do
  26. test_out="output${in//[^0-9]/}.txt"
  27. if [ -n "$(find . -name $test_out)" ]; then
  28. #test the program against test output
  29. ./$exec_name < $in > temp${in//[^0-9]/}.txt
  30. if [ -n "$(diff -u $test_out temp${in//[^0-9]/}.txt)" ]; then
  31. echo
  32. echo "test case $in failed. Would you like to check the difference? (y/n)"
  33. read check
  34. if [ $check == "y" ] || [ $check == "yes" ]; then
  35. if dpkg-query -l vim >/dev/null || $hasvim ; then
  36. gnome-terminal -e "vimdiff temp${in//[^0-9]/}.txt $test_out"
  37. hasvim=true
  38. else
  39. echo "vim needs to be installed. install vimdiff?"
  40. echo "(y to install)"
  41. read inst
  42. if [ $inst == "y" ] || [ $inst == "yes"]; then
  43. sudo apt-get install vim
  44. hasvim=true
  45. gnome-terminal -e "vimdiff temp.txt $test_out"
  46. fi
  47. fi
  48. # do nothing. keep looking through more files
  49. fi
  50. else
  51. echo "program passed $in"
  52. fi
  53. else
  54. echo "No corresponding output found for $in"
  55. fi
  56. done
  57.  
  58. # remove all temp files
  59. sleep 1
  60. find . -name "temp[0-9]*.txt" -exec rm {} +
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement