fhicl-expand_test.sh
Go to the documentation of this file.
1 #!/bin/bash
2 
3 TEST_PGM=fhicl-expand
4 TEST_ARGS="--lookup-policy=nonabsolute"
5 WORKDIR=`mktemp -d ${TMPDIR:-/tmp}/${TEST_PGM}.XXXXXXXXXX`
6 [[ -n "$WORKDIR" ]] && [[ -d "$WORKDIR" ]] || [[ -w "$WORKDIR" ]] || exit 1
7 
8 # Clean up if we're not debugging.
9 [[ -z "$DEBUG" ]] && trap "[[ -d \"$WORKDIR\" ]] && rm -rf \"$WORKDIR\"" EXIT
10 
11 OUTPUT_FILE=${WORKDIR}/out.txt
12 
13 export FHICL_FILE_PATH="$WORKDIR"
14 
15 rm -rf ${OUTPUT_FILE}
16 ${TEST_PGM} ${TEST_ARGS} > ${OUTPUT_FILE} <<EOF
17 EOF
18 STATUS=$?
19 [[ ${STATUS} ]] || exit ${STATUS}
20 [[ -r ${OUTPUT_FILE} ]] || exit 11
21 [[ ! -s ${OUTPUT_FILE} ]] || exit 12
22 
23 rm -rf ${OUTPUT_FILE}
24 ${TEST_PGM} ${TEST_ARGS} - > ${OUTPUT_FILE} <<EOF
25 hello
26 EOF
27 STATUS=$?
28 [[ ${STATUS} ]] || exit ${STATUS}
29 [[ -r ${OUTPUT_FILE} ]] || exit 21
30 [[ -s ${OUTPUT_FILE} ]] || exit 22
31 
32 rm -rf ${OUTPUT_FILE}
33 ${TEST_PGM} ${TEST_ARGS} a b c > ${OUTPUT_FILE}
34 STATUS=$?
35 [[ ${STATUS} == 3 ]] || exit ${STATUS}
36 
37 rm -rf ${OUTPUT_FILE}
38 F1=${WORKDIR}/F1.txt
39 F2=${WORKDIR}/F2.txt
40 F3=${WORKDIR}/F3.txt
41 FEXPECTED=${WORKDIR}/expected.txt
42 cat - > ${F1} <<EOF
43 hello
44 EOF
45 cat - > ${F2} <<EOF
46 #include "${F1}"
47 there
48 EOF
49 cat - > ${F3} <<EOF
50 #include "${F2}"
51 moo
52 oink
53 EOF
54 cat - > ${FEXPECTED} <<EOF
55 hello
56 there
57 moo
58 oink
59 EOF
60 ${TEST_PGM} ${TEST_ARGS} ${F3} > ${OUTPUT_FILE}
61 STATUS=$?
62 [[ ${STATUS} ]] || exit ${STATUS}
63 cmp ${FEXPECTED} ${OUTPUT_FILE} || exit 31
64 
65 exit 0