File: runner.sh

package info (click to toggle)
awesome 4.3-8.1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 6,468 kB
  • sloc: ansic: 14,508; sh: 526; makefile: 46
file content (57 lines) | stat: -rwxr-xr-x 1,301 bytes parent folder | download | duplicates (4)
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
#!/bin/sh
# Todo: Give this shell script a sane calling convention. Right now it has a
# file containing the expected output as first argument and just executes
# everything else.

set -ue

# Cleanup on errors / aborting
cleanup() {
    rm -rf "$file_stderr" "$file_stdout" || true
}
trap "cleanup" 0 2 3 15

file_stdout=$(mktemp)
file_stderr=$(mktemp)

expected_output=$1
shift

# Run the command that we were given
exit_code=0
"$@" > ${file_stdout} 2> ${file_stderr} || exit_code=$?

# If exit code is not zero or anything was produced on stderr...
if [ $exit_code -ne 0 -o -s "${file_stderr}" ]
then
    echo "Result: ${exit_code}"
    if [ -s "${file_stdout}" ]
    then
        echo "Output:"
        cat "${file_stdout}"
    fi
    if [ -s "${file_stderr}" ]
    then
        echo "Error:"
        cat "${file_stderr}"
    fi
    exit 1
fi

# Automatically add the output for new examples
if [ ! -e "${expected_output}" ]
then
    cp "${file_stdout}" "${expected_output}"
fi

# Check if we got the output we wanted
if ! cmp --silent "${file_stdout}" "${expected_output}"
then
    echo "Expected text from ${expected_output}, but got:"
    diff -u "${expected_output}" "${file_stdout}" || true
    exit 1
fi

exit 0

# vim: filetype=sh:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:textwidth=80