1#! /bin/sh
2#
3# Test suite for getlist.
4
5# The count starts at 1 and is updated each time ok is printed.  printcount
6# takes "ok" or "not ok".
7count=1
8printcount () {
9    echo "$1 $count $2"
10    count=`expr $count + 1`
11}
12
13# Takes a file, a grep expression and then arguments for getlist, calls
14# getlist with those arguments, and compares the result from the results of
15# running grep on the file.
16getlist () {
17    file="$1"
18    shift
19    grep="$1"
20    shift
21    grep "$grep" "$file" > wanted
22    $getlist -h localhost -p 11119 "$@" > seen
23    if [ $? = 0 ] && diff wanted seen ; then
24        printcount "ok"
25    else
26        printcount "not ok"
27    fi
28    rm wanted seen
29}
30
31# Find the right directory.
32getlist="../../frontends/getlist"
33dirs='. clients tests/clients'
34for dir in $dirs ; do
35    if [ -r "$dir/server-list" ] ; then
36        cd $dir
37        break
38    fi
39done
40if [ ! -x "$getlist" ] ; then
41    echo 'Could not find getlist' >&2
42    exit 1
43fi
44if [ ! -x 'server-list' ] ; then
45    echo 'Could not find server-list' >&2
46    exit 1
47fi
48
49# Print out the count of tests.
50echo 15
51
52# Point getlist at the appropriate inn.conf file.
53INNCONF=../data/etc/inn.conf; export INNCONF
54
55# Start the daemon.
56./server-list
57
58# Run the tests.
59getlist ../data/db/active .
60getlist ../data/db/active . active
61getlist ../data/db/active . active '*'
62getlist ../data/db/active . active '*' ymx=
63getlist ../data/db/active '\.test ' active '*.test'
64getlist ../data/db/active '\.test ' active '*.test' y
65getlist ../data/db/active '#######' active '*.test' m
66getlist ../data/db/active ' =' active '*' =
67getlist ../data/db/active ' x$' active 'example.*' x
68getlist ../data/db/active ' y$' active '*' y
69getlist ../data/db/newsgroups . newsgroups
70getlist ../data/db/newsgroups . newsgroups '*'
71getlist ../data/db/newsgroups 'config' newsgroups '*.config'
72getlist ../data/db/active.times . active.times
73getlist ../data/db/distributions . distributions
74
75# Kill the server.
76kill `cat pid`
77rm pid
78