3 TOP_DIR=$(cd $(dirname $0)/.. && pwd)
4 TOP_BUILDDIR="$abs_top_builddir"
5 [ -z "$TOP_BUILDDIR" ] && TOP_BUILDDIR="$TOP_DIR"
6 TOP_SRCDIR="$abs_top_srcdir"
7 [ -z "$TOP_SRCDIR" ] && TOP_SRCDIR="$TOP_DIR"
9 TEST_DIR="$TOP_SRCDIR/tests"
11 export PATH="$TOP_BUILDDIR/src:${PATH}"
13 export AUGEAS_ROOT="$TOP_BUILDDIR/build/test-augtool"
14 export AUGEAS_LENS_LIB="$TOP_SRCDIR/lenses"
17 type gsed >/dev/null 2>&1 && GSED=gsed
20 [ -z "$failed" ] && echo FAIL
26 # Without args, run all tests
27 if [ $# -eq 0 ] ; then
28 args="$TEST_DIR/test-augtool/*.sh"
38 printf "%-40s ... " $(basename $tst .sh)
40 # Read in test variables. The variables we understand are
41 # echo - echo augtool commands if set to some value
42 # commands - the commands to send to augtool
43 # lens - the lens to use
44 # file - the file that should be changed
45 # diff - the expected diff
46 # refresh - print diff in a form suitable for cut and paste
47 # into the test file if set to some value
49 unset echo commands lens file diff refresh
52 # Setup test root from root/
53 [ -d "$AUGEAS_ROOT" ] && rm -rf "$AUGEAS_ROOT"
54 dest_dir="$AUGEAS_ROOT"$(dirname $file)
56 cp -p "$TEST_DIR"/root/$file $dest_dir
58 [ -n "$echo" ] && echo="-e"
60 commands="set /augeas/load/Test/lens $lens
61 set /augeas/load/Test/incl $file
66 echo "$commands" | augtool $echo --nostdinc --noautoload -n || fail "augtool failed"
68 abs_file="$AUGEAS_ROOT$file"
69 if [ ! -f "${abs_file}.augnew" ]; then
70 fail "Expected file $file.augnew"
72 safe_augeas_root=$(printf "%s\n" "$AUGEAS_ROOT" | sed 's/[][\.*^$(){}?+|/]/\\&/g')
73 act=$(diff -u "$abs_file" "${abs_file}.augnew" \
74 | $GSED -r -e "s/^ $//;s!^(---|\+\+\+) ${safe_augeas_root}($file(\.augnew)?)(.*)\$!\1 \2!;s/\\t/\\\\t/g")
76 if [ "$act" != "$diff" ] ; then
80 other_files=$(find "$AUGEAS_ROOT" -name \*.augnew | grep -v "$abs_file.augnew")
81 [ -n "$other_files" ] && fail "Unexpected file(s) $other_files"
82 [ -z "$failed" ] && echo OK