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