Bump to 1.14.1
[platform/upstream/augeas.git] / tests / test-augmatch.sh
1 #!/bin/sh
2
3 # Tests for augmatch
4
5 TOPDIR=$(cd $(dirname $0)/.. && pwd)
6 [ -n "$abs_top_srcdir" ] || abs_top_srcdir=$TOPDIR
7
8 export AUGEAS_LENS_LIB=$abs_top_srcdir/lenses
9 export AUGEAS_ROOT=$abs_top_srcdir/tests/root
10
11 fail() {
12     echo "failed: $*"
13     exit 1
14 }
15
16 assert_eq() {
17     if [ "$1" != "$2" ]; then
18         shift 2
19         fail $*
20     fi
21 }
22
23 # print the tree for /etc/exports
24 act=$(augmatch /etc/exports)
25 assert_eq 23 $(echo "$act" | wc -l) "t1: expected 23 lines of output"
26
27 # show only the entry for a specific mount
28 act=$(augmatch -m 'dir["/home"]' /etc/exports)
29 assert_eq 9 $(echo "$act" | wc -l) "t2: expected 9 lines of output"
30
31 # show all the clients to which we are exporting /home
32 act=$(augmatch -eom 'dir["/home"]/client' /etc/exports)
33 exp=$(printf "207.46.0.0/16\n192.168.50.2/32\n")
34 assert_eq "$exp" "$act" "t3: expected '$exp'"
35
36 # report errors with exit code 2
37 augmatch -m '**' /etc/exports >/dev/null 2>&1
38 ret=$?
39 assert_eq 2 $ret "t4: expected exit code 2 but got $ret"
40
41 augmatch /etc >/dev/null 2>&1
42 ret=$?
43 assert_eq 2 $ret "t5: expected exit code 2 but got $ret"
44
45 # test --quiet
46 act=$(augmatch -q -m "dir['/local']" /etc/exports)
47 ret=$?
48 assert_eq '' "$act" "t6: expected no output"
49 assert_eq 0 $ret "t6: expected exit code 0 but got $ret"
50
51 act=$(augmatch -q -m "dir['/not_there']" /etc/exports)
52 ret=$?
53 assert_eq '' "$act" "t7: expected no output"
54 assert_eq 1 $ret "t7: expected exit code 1 but got $ret"