1#!/usr/local/bin/bash
2# ===========================================================================
3#
4#                            PUBLIC DOMAIN NOTICE
5#               National Center for Biotechnology Information
6#
7#  This software/database is a "United States Government Work" under the
8#  terms of the United States Copyright Act.  It was written as part of
9#  the author's official duties as a United States Government employee and
10#  thus cannot be copyrighted.  This software/database is freely available
11#  to the public for use. The National Library of Medicine and the U.S.
12#  Government have not placed any restriction on its use or reproduction.
13#
14#  Although all reasonable efforts have been taken to ensure the accuracy
15#  and reliability of the software and data, the NLM and the U.S.
16#  Government do not and cannot warrant the performance or results that
17#  may be obtained by using this software or data. The NLM and the U.S.
18#  Government disclaim all warranties, express or implied, including
19#  warranties of performance, merchantability or fitness for any particular
20#  purpose.
21#
22#  Please cite the author in any work or product based on this material.
23#
24# ===========================================================================
25SHKRIPT=`basename $0`
26
27EXECUTABLE=$1
28
29
30DEBMO=`echo $2 | grep -- "-DNDEBUG" >/dev/null 2>&2 || echo "Y"`
31if [ -z "$DEBMO" ]
32then
33    DEBMO=N
34    echo "## TESTING RELEASE VERSION"
35else
36    echo "## TESTING DEBUG VERSION"
37fi
38
39
40usage ()
41{
42    cat <<EOF >&2
43
44Syntax: $SHKRIPT executable
45
46Where:
47
48    executable - path to executable to test
49
50EOF
51}
52
53
54if [ -z "$EXECUTABLE" ]
55then
56    echo ERROR: invalid parameters  >&2
57    echo
58    usage
59    exit 1
60fi
61
62if [ ! -x "$EXECUTABLE" ]
63then
64	echo ERROR: can not stat executable '$EXECUTABLE' >&2
65	exit 1
66fi
67
68###
69##  Test 1 : help contans parameter in help string
70###
71echo "## 1. Testing argument existence in help string"
72CMD="$EXECUTABLE -h"
73if [ "$DEBMO" == "Y" ]
74then
75    RET=`eval $CMD | ( grep -- "--append_output" >/dev/null 2>&1 && echo GOOD )`
76else
77    RET=`eval $CMD | ( grep -- "--append_output" >/dev/null 2>&1 || echo GOOD )`
78fi
79
80if [ "$RET" != "GOOD" ]
81then
82    echo "## <<== FAILED"
83    exit 2
84else
85    echo "## <<== PASSED"
86fi
87
88###
89##  Test 2 : help does not contans parameter name
90###
91echo "## 2. Testing argument absence in help string"
92CMD="$EXECUTABLE -h jojoba"
93RET=`eval $CMD | ( grep -- "--append_output" >/dev/null 2>&1 || echo GOOD )`
94if [ "$RET" != "GOOD" ]
95then
96    echo "## <<== FAILED"
97    exit 2
98else
99    echo "## <<== PASSED"
100fi
101
102###
103##  Test 3 : append output true
104###
105echo "## 3. Testing --append_output argument is true"
106CMD="$EXECUTABLE --append_output"
107RET=`eval $CMD | ( grep -- "APPEND_MODE: Y" >/dev/null 2>&1 && echo GOOD )`
108if [ "$RET" != "GOOD" ]
109then
110    echo "## <<== FAILED"
111    exit 2
112else
113    echo "## <<== PASSED"
114fi
115
116###
117##  Test 4 : append output false
118###
119echo "## 4. Testing --append_output argument is false"
120CMD="$EXECUTABLE"
121RET=`eval $CMD | ( grep -- "APPEND_MODE: N" >/dev/null 2>&1 && echo GOOD )`
122if [ "$RET" != "GOOD" ]
123then
124    echo "## <<== FAILED"
125    exit 2
126else
127    echo "## <<== PASSED"
128fi
129