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