projects/06/test/run-tests.sh
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 |
#!/bin/sh # tests for project 6 - assembler script_location="$(dirname "$0")" now="$(date +%s)" test_dir="out-$now" tests_setup() { cd "$script_location" # cd to script's containing directory so paths work mkdir -p "$test_dir" echo "Test setup complete." } tests_teardown() { rm -f "$test_dir"/* rmdir "$test_dir" } # $1 - first file, $2 - second file assert_files_equal() { files_diff="$(diff "$1" "$2")" if [ "$files_diff" = "" ]; then echo "PASS" else echo "FAIL" #echo -e "---------------- diff output: ----------------\n$files_diff" echo -e "---------------- diff output: ----------------\ndiff $1 $2" echo -e "$files_diff" fi } # $1 - path/to/assembler executable, $2 - input assembly file, # $3 - output file, $4 - test vector file (known correct output) run_test_compare_out() { "$1" "$2" "$3" # run program w/ test args assert_files_equal "$3" "$4" # ensure file contents are the same } # $1 - path/to/assembler executable run_tests() { echo "Testing under assembler $1" # test calls below (comment to disable individual unit tests) echo "================ Testing Add.asm (no symbols) =================" run_test_compare_out "$1" add/Add.asm "$test_dir"/Add.hack add/Add.hack echo "================ Testing MaxL.asm (no symbols) =================" run_test_compare_out "$1" max/MaxL.asm "$test_dir"/MaxL.hack max/MaxL.hack echo "================ Testing Max.asm =================" run_test_compare_out "$1" max/Max.asm "$test_dir"/Max.hack max/Max.hack echo "================ Testing Rect.asm =================" run_test_compare_out "$1" rect/Rect.asm "$test_dir"/Rect.hack rect/Rect.hack echo "================ Testing RectL.asm (no symbols) =================" run_test_compare_out "$1" rect/RectL.asm "$test_dir"/RectL.hack rect/RectL.hack echo "================ Testing Pong.asm =================" run_test_compare_out "$1" pong/Pong.asm "$test_dir"/Pong.hack pong/Pong.hack echo "================ Testing PongL.asm (no symbols) =================" run_test_compare_out "$1" pong/PongL.asm "$test_dir"/PongL.hack pong/PongL.hack } tests_setup # for each assembler executable run_tests ../bin/n2tasm1 #run_tests ../bin/n2tasm2 echo "==============================================" tests_teardown |