Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/bin/bash
- echo
- echo "__________COMPILING__________"
- exec_name="${PWD##*/}"
- echo "compiling $(find . -name *.h) $(find . -name *.cpp)"
- if g++ $(find . -name *.h -o -name *.cpp) -o $exec_name; then
- echo "compilation successful (saved as $exec_name)"
- echo
- else
- echo "compilation failure"
- exit
- fi
- inputs=($(find . -name 'input[0-9].txt'))
- if [ ${#inputs[@]} -eq 0 ]; then
- echo "Error: no input files found. inputs must be saved as input<number>.txt"
- exit
- fi
- echo "___________TESTING___________"
- echo "HINT: Comparisons are shown with vimdiff. To exit vim, type the command ':qa"
- echo
- hasvim=false
- for in in "${inputs[@]}"; do
- test_out="output${in//[^0-9]/}.txt"
- if [ -n "$(find . -name $test_out)" ]; then
- #test the program against test output
- ./$exec_name < $in > temp${in//[^0-9]/}.txt
- if [ -n "$(diff -u $test_out temp${in//[^0-9]/}.txt)" ]; then
- echo
- echo "test case $in failed. Would you like to check the difference? (y/n)"
- read check
- if [ $check == "y" ] || [ $check == "yes" ]; then
- if dpkg-query -l vim >/dev/null || $hasvim ; then
- gnome-terminal -e "vimdiff temp${in//[^0-9]/}.txt $test_out"
- hasvim=true
- else
- echo "vim needs to be installed. install vimdiff?"
- echo "(y to install)"
- read inst
- if [ $inst == "y" ] || [ $inst == "yes"]; then
- sudo apt-get install vim
- hasvim=true
- gnome-terminal -e "vimdiff temp.txt $test_out"
- fi
- fi
- # do nothing. keep looking through more files
- fi
- else
- echo "program passed $in"
- fi
- else
- echo "No corresponding output found for $in"
- fi
- done
- # remove all temp files
- sleep 1
- find . -name "temp[0-9]*.txt" -exec rm {} +
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement