Gavin Howard | 926d2be | 2018-03-30 11:52:51 -0600 | [diff] [blame] | 1 | #! /bin/sh |
Gavin Howard | 64f113c | 2018-09-25 09:38:57 -0600 | [diff] [blame] | 2 | # |
| 3 | # Copyright 2018 Gavin D. Howard |
| 4 | # |
| 5 | # Permission to use, copy, modify, and/or distribute this software for any |
| 6 | # purpose with or without fee is hereby granted. |
| 7 | # |
| 8 | # THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH |
| 9 | # REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY |
| 10 | # AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, |
| 11 | # INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM |
| 12 | # LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR |
| 13 | # OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR |
| 14 | # PERFORMANCE OF THIS SOFTWARE. |
| 15 | # |
Gavin Howard | 85d68e3 | 2018-02-15 14:28:50 -0700 | [diff] [blame] | 16 | |
Gavin Howard | d43ae75 | 2018-09-06 19:36:18 -0600 | [diff] [blame] | 17 | set -e |
| 18 | |
Gavin Howard | 164620e | 2018-02-21 19:00:45 -0700 | [diff] [blame] | 19 | script="$0" |
| 20 | |
| 21 | testdir=$(dirname "$script") |
| 22 | |
Gavin Howard | 9c4ce07 | 2018-10-03 13:50:46 -0600 | [diff] [blame] | 23 | if [ "$#" -lt 2 ]; then |
| 24 | echo "usage: $0 dir test [bc [bc_args...]]" |
Gavin Howard | d568b65 | 2018-02-22 11:22:21 -0700 | [diff] [blame] | 25 | echo "valid tests are:" |
| 26 | echo "" |
| 27 | cat "$testdir/all.txt" |
| 28 | echo "" |
| 29 | exit 1 |
| 30 | fi |
| 31 | |
Gavin Howard | 9c4ce07 | 2018-10-03 13:50:46 -0600 | [diff] [blame] | 32 | d="$1" |
| 33 | shift |
| 34 | |
Gavin Howard | 5f3edec | 2018-03-12 15:34:59 -0600 | [diff] [blame] | 35 | t="$1" |
Gavin Howard | 9c4ce07 | 2018-10-03 13:50:46 -0600 | [diff] [blame] | 36 | name="$testdir/$d/$t.txt" |
| 37 | results="$testdir/$d/${t}_results.txt" |
Gavin Howard | 85d68e3 | 2018-02-15 14:28:50 -0700 | [diff] [blame] | 38 | shift |
| 39 | |
Gavin Howard | d568b65 | 2018-02-22 11:22:21 -0700 | [diff] [blame] | 40 | if [ "$#" -gt 0 ]; then |
Gavin Howard | 9c4ce07 | 2018-10-03 13:50:46 -0600 | [diff] [blame] | 41 | exe="$1" |
Gavin Howard | d568b65 | 2018-02-22 11:22:21 -0700 | [diff] [blame] | 42 | shift |
| 43 | else |
Gavin Howard | 9c4ce07 | 2018-10-03 13:50:46 -0600 | [diff] [blame] | 44 | exe="$testdir/../$d" |
Gavin Howard | d568b65 | 2018-02-22 11:22:21 -0700 | [diff] [blame] | 45 | fi |
Gavin Howard | 85d68e3 | 2018-02-15 14:28:50 -0700 | [diff] [blame] | 46 | |
Gavin Howard | d43ae75 | 2018-09-06 19:36:18 -0600 | [diff] [blame] | 47 | out="$testdir/../.log_test.txt" |
Gavin Howard | 85d68e3 | 2018-02-15 14:28:50 -0700 | [diff] [blame] | 48 | |
Gavin Howard | 9c4ce07 | 2018-10-03 13:50:46 -0600 | [diff] [blame] | 49 | if [ "$d" = "bc" ]; then |
| 50 | options="-lq" |
| 51 | halt="halt" |
| 52 | else |
Gavin Howard | 36a4243 | 2018-10-04 14:26:56 -0600 | [diff] [blame^] | 53 | options="-x" |
Gavin Howard | 9c4ce07 | 2018-10-03 13:50:46 -0600 | [diff] [blame] | 54 | halt="q" |
| 55 | fi |
| 56 | |
Gavin Howard | 3169062 | 2018-08-30 09:56:37 -0600 | [diff] [blame] | 57 | if [ ! -f "$name" ]; then |
Gavin Howard | 9c4ce07 | 2018-10-03 13:50:46 -0600 | [diff] [blame] | 58 | echo "Generating $d $t..." |
| 59 | "$testdir/$d/scripts/$t.$d" > "$name" |
Gavin Howard | 5f3edec | 2018-03-12 15:34:59 -0600 | [diff] [blame] | 60 | fi |
| 61 | |
Gavin Howard | 3169062 | 2018-08-30 09:56:37 -0600 | [diff] [blame] | 62 | if [ ! -f "$results" ]; then |
Gavin Howard | 9c4ce07 | 2018-10-03 13:50:46 -0600 | [diff] [blame] | 63 | echo "Generating $d $t results..." |
| 64 | echo "halt" | $d $options "$name" > "$results" |
Gavin Howard | 3169062 | 2018-08-30 09:56:37 -0600 | [diff] [blame] | 65 | fi |
Gavin Howard | acbd69b | 2018-08-29 11:35:25 -0600 | [diff] [blame] | 66 | |
Gavin Howard | 9c4ce07 | 2018-10-03 13:50:46 -0600 | [diff] [blame] | 67 | echo "Running $d $t..." |
Gavin Howard | 3169062 | 2018-08-30 09:56:37 -0600 | [diff] [blame] | 68 | |
Gavin Howard | 9c4ce07 | 2018-10-03 13:50:46 -0600 | [diff] [blame] | 69 | echo "$halt" | "$exe" "$@" $options "$name" > "$out" |
Gavin Howard | 3169062 | 2018-08-30 09:56:37 -0600 | [diff] [blame] | 70 | |
| 71 | diff "$results" "$out" |
Gavin Howard | 9aaa3b2 | 2018-03-17 21:44:34 -0600 | [diff] [blame] | 72 | |
Gavin Howard | d43ae75 | 2018-09-06 19:36:18 -0600 | [diff] [blame] | 73 | rm -rf "$out" |
| 74 | |