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