Imported Upstream version 1.22.3
[platform/upstream/groff.git] / contrib / gdiffmk / tests / runtests.sh
1 #! /bin/sh
2 #
3 #       A very simple function test for gdiffmk.sh.
4 #
5 # Copyright (C) 2004-2018 Free Software Foundation, Inc.
6 # Written by Mike Bianchi <MBianchi@Foveal.com <mailto:MBianchi@Foveal.com>>
7
8 # This file is part of the gdiffmk utility, which is part of groff.
9
10 # groff is free software; you can redistribute it and/or modify it
11 # under the terms of the GNU General Public License as published by
12 # the Free Software Foundation, either version 3 of the License, or
13 # (at your option) any later version.
14
15 # groff is distributed in the hope that it will be useful, but WITHOUT
16 # ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
17 # or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public
18 # License for more details.
19
20 # You should have received a copy of the GNU General Public License
21 # along with this program.  If not, see <http://www.gnu.org/licenses/>.
22 # This file is part of GNU gdiffmk.
23
24 # abs_top_srcdir and abs_top_builddir are set by AM_TESTS_ENVIRONMENT
25 # (defined in Makefile.am) when running make check
26
27 srcdir=${abs_top_srcdir}/contrib/gdiffmk/tests
28
29 command=${abs_top_builddir}/gdiffmk
30
31 #       Test the number of arguments and the first argument.
32 case "$#-$1" in
33 1-clean )
34         rm -fv result* tmp_file*
35         exit 0
36         ;;
37 1-run )
38         ;;
39 * )
40         echo >&2 "$0 [ clean | run ]
41 Run a few simple tests on '${command}'."'
42
43 clean   Remove the result? and tmp_file? files.
44 run     Run the tests.
45 '
46         exit 255
47         ;;
48 esac
49
50 exit_code=0     #  Success
51 failure_count=0
52 TestResult () {
53         if cmp -s $1 $2
54         then
55                 echo $2 PASSED
56         else
57                 echo ''
58                 echo $2 TEST FAILED
59                 diff $1 $2
60                 echo ''
61                 exit_code=1     #  Failure
62                 failure_count=`expr ${failure_count} + 1`
63         fi
64 }
65
66 tmpfile=/tmp/$$
67 trap 'rm -f ${tmpfile}' 0 1 2 3 15
68
69 #       Run tests.
70
71 #       3 file arguments
72 ResultFile=result.1
73 ${command}  ${srcdir}/file1  ${srcdir}/file2 ${ResultFile} 2>${tmpfile}
74 cat ${tmpfile} >>${ResultFile}
75 TestResult ${srcdir}/baseline ${ResultFile}
76
77
78 #       OUTPUT to stdout by default
79 ResultFile=result.2
80 ${command}  ${srcdir}/file1  ${srcdir}/file2  >${ResultFile} 2>&1
81 TestResult ${srcdir}/baseline ${ResultFile}
82
83
84 #       OUTPUT to stdout via  -  argument
85 ResultFile=result.3
86 ${command}  ${srcdir}/file1  ${srcdir}/file2 - >${ResultFile} 2>&1
87 TestResult ${srcdir}/baseline ${ResultFile}
88
89
90 #       FILE1 from standard input via  -  argument
91 ResultFile=result.4
92 ${command}  - ${srcdir}/file2 <${srcdir}/file1  >${ResultFile} 2>&1
93 TestResult ${srcdir}/baseline ${ResultFile}
94
95
96 #       FILE2 from standard input via  -  argument
97 ResultFile=result.5
98 ${command}  ${srcdir}/file1 - <${srcdir}/file2  >${ResultFile} 2>&1
99 TestResult ${srcdir}/baseline ${ResultFile}
100
101
102 #       Different values for addmark, changemark, deletemark
103 ResultFile=result.6
104 ${command}  -aA -cC -dD  ${srcdir}/file1 ${srcdir}/file2  >${ResultFile} 2>&1
105 TestResult ${srcdir}/baseline.6 ${ResultFile}
106
107
108 #       Different values for addmark, changemark, deletemark
109 #       Alternate format of -a -c and -d flag arguments
110 ResultFile=result.6a
111 ${command}  -a A -c C -d D  ${srcdir}/file1 ${srcdir}/file2  >${ResultFile} 2>&1
112 TestResult ${srcdir}/baseline.6a ${ResultFile}
113
114
115 #       Test for accidental file overwrite.
116 ResultFile=result.7
117 cp ${srcdir}/file2 tmp_file.7
118 ${command}  -aA -dD -cC  ${srcdir}/file1 tmp_file.7  tmp_file.7 \
119                                                         >${ResultFile} 2>&1
120 TestResult ${srcdir}/baseline.7 ${ResultFile}
121
122
123 #       Test -D option
124 ResultFile=result.8
125 ${command}  -D  ${srcdir}/file1 ${srcdir}/file2 >${ResultFile} 2>&1
126 TestResult ${srcdir}/baseline.8 ${ResultFile}
127
128
129 #       Test -D  and  -M  options
130 ResultFile=result.9
131 ${command}  -D  -M '<<<<' '>>>>'                                \
132                         ${srcdir}/file1 ${srcdir}/file2 >${ResultFile} 2>&1
133 TestResult ${srcdir}/baseline.9 ${ResultFile}
134
135
136 #       Test -D  and  -M  options
137 #       Alternate format of -M argument.
138 ResultFile=result.9a
139 ${command}  -D  -M'<<<<' '>>>>'                         \
140                         ${srcdir}/file1 ${srcdir}/file2 >${ResultFile} 2>&1
141 TestResult ${srcdir}/baseline.9a ${ResultFile}
142
143
144 #       Test -D  and  -B  options
145 ResultFile=result.10
146 ${command}  -D  -B  ${srcdir}/file1 ${srcdir}/file2 >${ResultFile} 2>&1
147 TestResult ${srcdir}/baseline.10 ${ResultFile}
148
149
150 echo failure_count ${failure_count}
151
152 exit ${exit_code}
153
154 #       EOF