Bump to 1.14.1
[platform/upstream/augeas.git] / tests / test-function-modified.sh
1 #!/bin/sh
2
3 # Test that changing the value of a node causes the function modified() to return true
4
5 root=$abs_top_builddir/build/test-function-modified
6 hosts=$root/etc/hosts
7
8 rm -rf $root
9 mkdir -p $(dirname $hosts)
10
11 cat <<EOF > $hosts
12 127.0.0.1 localhost
13 ::1       localhost6
14 EOF
15
16 touch -r $0 $hosts
17
18 augtool --nostdinc -r $root -I $abs_top_srcdir/lenses > /dev/null <<EOF >$root/output.1
19 set /files/etc/hosts/1/ipaddr 127.0.0.4
20 match /files/etc/hosts//*[modified()]
21 EOF
22
23 [ "$(cat $root/output.1)" = '/files/etc/hosts/1/ipaddr = 127.0.0.4' ] || exit 1
24
25 # An empty value should return true, even if none of the child nodes are modified
26 augtool --nostdinc -r $root -I $abs_top_srcdir/lenses > /dev/null <<EOF >$root/output.2
27 set /files/etc/hosts/1 x
28 set /files/etc/hosts/1
29 match /files/etc/hosts//*[modified()]
30 EOF
31
32 [ "$(cat $root/output.2)" = '/files/etc/hosts/1 = (none)' ] || exit 1
33
34 # Test that changing a value does not change the parent node
35 # Test that adding a new node also marks the (new) parent node.
36 augtool --nostdinc -r $root -I $abs_top_srcdir/lenses > /dev/null <<EOF >$root/output.3
37 set /files/etc/hosts/1/ipaddr 127.1.1.1
38 set /files/etc/hosts/3/ipaddr 127.3.3.3
39 match /files/etc/hosts//*[modified()]
40 EOF
41
42 diff -q $root/output.3  -  <<EOF || exit 1
43 /files/etc/hosts/3 = (none)
44 /files/etc/hosts/1/ipaddr = 127.1.1.1
45 /files/etc/hosts/3/ipaddr = 127.3.3.3
46 EOF
47