Bump to 1.14.1
[platform/upstream/augeas.git] / tests / test-save-empty.sh
1 #!/bin/sh
2
3 # Test that we report an error when writing to nonexistent dirs
4 # but that we do create new files correctly
5
6 save_hosts() {
7 opts="--nostdinc -r $ROOT -I $abs_top_srcdir/lenses"
8 (augtool $opts | grep ^/augeas) <<EOF
9 set /files/etc/hosts/1/ipaddr 127.0.0.1
10 set /files/etc/hosts/1/canonical localhost
11 save
12 print /augeas/files/etc/hosts/error
13 EOF
14 }
15
16 expected_errors() {
17 cat <<EOF
18 /augeas/files/etc/hosts/error = "mk_augtemp"
19 /augeas/files/etc/hosts/error/message = "No such file or directory"
20 EOF
21 }
22
23 ROOT=$abs_top_builddir/build/test-save-empty
24 HOSTS=$ROOT/etc/hosts
25
26 rm -rf $ROOT
27 mkdir -p $ROOT
28 ACTUAL=$(save_hosts)
29 EXPECTED=$(expected_errors)
30
31 if [ "$ACTUAL" != "$EXPECTED" ]
32 then
33     echo "No error on missing /etc directory:"
34     echo "$ACTUAL"
35     exit 1
36 fi
37
38 mkdir -p $ROOT/etc
39 ACTUAL=$(save_hosts)
40 if [ -n "$ACTUAL" ] ; then
41     echo "Error creating file:"
42     echo $ACTUAL
43     exit 1
44 fi
45
46 if [ ! -f $HOSTS ] ; then
47     echo "File ${HOSTS} was not created"
48     exit 1
49 fi
50
51 printf '127.0.0.1\tlocalhost\n' > $HOSTS.expected
52
53 if ! cmp $HOSTS $HOSTS.expected > /dev/null 2>&1 ; then
54     echo "Contents of $HOSTS are incorrect"
55     exit 1
56 fi