]> git.saurik.com Git - apple/configd.git/blob - common/reference_output.sh
configd-1061.101.1.tar.gz
[apple/configd.git] / common / reference_output.sh
1 #!/bin/sh
2
3 tmpfile=/tmp/test_reference_output$$.txt
4
5 cleanup()
6 {
7 if [ -f "${tmpfile}" ]; then
8 echo removing "${tmpfile}"
9 rm -f "${tmpfile}"
10 fi
11 exit 1
12 }
13
14 trap cleanup 1 2 3 15
15
16 run_program()
17 {
18 program="${1}"
19 filter="${2}"
20 if [ "${filter}" = "" ]; then
21 ${program}
22 else
23 ${program} | ${filter}
24 fi
25 }
26
27 usage()
28 {
29 echo "usage: $0 ( create | test ) <program> <reference_file> [ <filter> ]"
30 exit 1
31 }
32
33 command="${1}"
34 program="${2}"
35 ref_file="${3}"
36 filter="${4}"
37
38 if [ "${ref_file}" = "" ]; then
39 usage "${0}"
40 fi
41
42 if [ "${program}" = "" ]; then
43 usage "${0}"
44 fi
45
46 if [ ! -f "${program}" ]; then
47 echo "program '${program}' doesn't exit"
48 exit 1
49 fi
50 if [ ! -x "${program}" ]; then
51 program="sh ${program}"
52 fi
53 # echo "The program is ${program}"
54
55 if [ ! "${filter}" = "" ]; then
56 if [ ! -f "${filter}" ]; then
57 echo "filter '${filter}' doesn't exit"
58 exit 1
59 fi
60 if [ ! -x "${filter}" ]; then
61 filter="sh ${filter}"
62 fi
63 # echo "The filter is ${filter}"
64 else
65 echo no filter
66 fi
67
68 if [ "${command}" = "create" ]; then
69 run_program "${program}" "${filter}" > "${ref_file}"
70 elif [ "${command}" = "test" ]; then
71 if [ ! -f "${ref_file}" ]; then
72 echo "reference file '${ref_file}' doesn't exist"
73 exit 1
74 fi
75 run_program "${program}" "${filter}" > "${tmpfile}"
76 cmp "${tmpfile}" "${ref_file}"
77 if [ ! $? -eq 0 ]; then
78 echo FAILURE
79 diff "${tmpfile}" "${ref_file}"
80 exit 1
81 fi
82 echo SUCCESS
83 else
84 usage "${0}"
85 fi
86
87 exit 0