3 # Test manipulating the save flags in /augeas/save
5 root=$abs_top_builddir/build/test-save-mode
7 augopts="--nostdinc -r $root -I $abs_top_srcdir/lenses"
12 augtool $augopts "$@" > /dev/null
14 if [ "x$exp" = ok -a $status -ne 0 ] ; then
17 elif [ "x$exp" = fail -a $status -eq 0 ] ; then
18 echo "augtool succeeded but should have failed"
24 exp="/files/etc/hosts/1/ipaddr = $1"
25 act=$(augtool $augopts get /files/etc/hosts/1/ipaddr)
27 if [ "$act" != "$exp" ] ; then
28 printf "Expected: %s\n" "$exp"
29 printf "Actual : %s\n" "$act"
34 assert_file_exists() {
35 if [ ! -f "$1" ] ; then
36 echo "File $1 does not exist, but should"
41 assert_file_exists_not() {
43 echo "File $1 exists, but should not"
51 mkdir -p $(dirname $hosts)
57 setup "No /augeas/save"
58 run_augtool fail <<EOF
59 set /files/etc/hosts/1/ipaddr 127.0.0.2
63 assert_ipaddr 127.0.0.1
65 setup "Invalid /augeas/save"
66 run_augtool fail <<EOF
67 set /files/etc/hosts/1/ipaddr 127.0.0.2
68 set /augeas/save "not a valid flag"
71 assert_ipaddr 127.0.0.1
74 run_augtool fail <<EOF
75 set /files/etc/hosts/1/ipaddr 127.0.0.2
79 assert_ipaddr 127.0.0.1
80 assert_file_exists_not $hosts.augnew
81 assert_file_exists_not $hosts.augsave
85 set /files/etc/hosts/1/ipaddr 127.0.0.2
86 set /augeas/save newfile
89 assert_ipaddr 127.0.0.1
90 assert_file_exists $hosts.augnew
91 assert_file_exists_not $hosts.augsave
95 set /files/etc/hosts/1/ipaddr 127.0.0.2
96 set /augeas/save overwrite
99 assert_ipaddr 127.0.0.2
100 assert_file_exists_not $hosts.augnew
101 assert_file_exists_not $hosts.augsave
105 set /files/etc/hosts/1/ipaddr 127.0.0.2
106 set /augeas/save backup
109 assert_ipaddr 127.0.0.2
110 assert_file_exists_not $hosts.augnew
111 assert_file_exists $hosts.augsave
114 augopts="${augopts} --autosave"
118 set /files/etc/hosts/1/ipaddr 127.0.0.2
120 assert_ipaddr 127.0.0.2
121 assert_file_exists_not $hosts.augnew
122 assert_file_exists_not $hosts.augsave
124 setup "autosave command line"
125 run_augtool ok set /files/etc/hosts/1/ipaddr 127.0.0.2
126 assert_ipaddr 127.0.0.2
127 assert_file_exists_not $hosts.augnew
128 assert_file_exists_not $hosts.augsave