blob: 60b427e22bb99fa628cda7939185fb280d2e92c9 [file] [log] [blame]
Gavin Howard926d2be2018-03-30 11:52:51 -06001#! /bin/sh
Gavin Howard64f113c2018-09-25 09:38:57 -06002#
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 Howard85d68e32018-02-15 14:28:50 -070016
Gavin Howardd43ae752018-09-06 19:36:18 -060017set -e
18
Gavin Howard164620e2018-02-21 19:00:45 -070019script="$0"
20
21testdir=$(dirname "$script")
22
Gavin Howard9c4ce072018-10-03 13:50:46 -060023if [ "$#" -lt 2 ]; then
24 echo "usage: $0 dir test [bc [bc_args...]]"
Gavin Howardd568b652018-02-22 11:22:21 -070025 echo "valid tests are:"
26 echo ""
27 cat "$testdir/all.txt"
28 echo ""
29 exit 1
30fi
31
Gavin Howard9c4ce072018-10-03 13:50:46 -060032d="$1"
33shift
34
Gavin Howard5f3edec2018-03-12 15:34:59 -060035t="$1"
Gavin Howard9c4ce072018-10-03 13:50:46 -060036name="$testdir/$d/$t.txt"
37results="$testdir/$d/${t}_results.txt"
Gavin Howard85d68e32018-02-15 14:28:50 -070038shift
39
Gavin Howardd568b652018-02-22 11:22:21 -070040if [ "$#" -gt 0 ]; then
Gavin Howard9c4ce072018-10-03 13:50:46 -060041 exe="$1"
Gavin Howardd568b652018-02-22 11:22:21 -070042 shift
43else
Gavin Howard9c4ce072018-10-03 13:50:46 -060044 exe="$testdir/../$d"
Gavin Howardd568b652018-02-22 11:22:21 -070045fi
Gavin Howard85d68e32018-02-15 14:28:50 -070046
Gavin Howardd43ae752018-09-06 19:36:18 -060047out="$testdir/../.log_test.txt"
Gavin Howard85d68e32018-02-15 14:28:50 -070048
Gavin Howard9c4ce072018-10-03 13:50:46 -060049if [ "$d" = "bc" ]; then
50 options="-lq"
51 halt="halt"
52else
Gavin Howard36a42432018-10-04 14:26:56 -060053 options="-x"
Gavin Howard9c4ce072018-10-03 13:50:46 -060054 halt="q"
55fi
56
Gavin Howard31690622018-08-30 09:56:37 -060057if [ ! -f "$name" ]; then
Gavin Howard9c4ce072018-10-03 13:50:46 -060058 echo "Generating $d $t..."
59 "$testdir/$d/scripts/$t.$d" > "$name"
Gavin Howard5f3edec2018-03-12 15:34:59 -060060fi
61
Gavin Howard31690622018-08-30 09:56:37 -060062if [ ! -f "$results" ]; then
Gavin Howard9c4ce072018-10-03 13:50:46 -060063 echo "Generating $d $t results..."
64 echo "halt" | $d $options "$name" > "$results"
Gavin Howard31690622018-08-30 09:56:37 -060065fi
Gavin Howardacbd69b2018-08-29 11:35:25 -060066
Gavin Howard9c4ce072018-10-03 13:50:46 -060067echo "Running $d $t..."
Gavin Howard31690622018-08-30 09:56:37 -060068
Gavin Howard9c4ce072018-10-03 13:50:46 -060069echo "$halt" | "$exe" "$@" $options "$name" > "$out"
Gavin Howard31690622018-08-30 09:56:37 -060070
71diff "$results" "$out"
Gavin Howard9aaa3b22018-03-17 21:44:34 -060072
Gavin Howardd43ae752018-09-06 19:36:18 -060073rm -rf "$out"
74