Imported Upstream version 1.22.3
[platform/upstream/groff.git] / contrib / gdiffmk / tests / runtests.in
1 #! /bin/sh
2 #
3 #       A very simple function test for gdiffmk.sh.
4 #
5 # Copyright (C) 2004, 2005, 2009 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 srcdir=@srcdir@
25
26 command=../gdiffmk
27
28 #       Test the number of arguments and the first argument.
29 case $#-$1 in
30 1-clean )
31         rm -fv result* tmp_file*
32         exit 0
33         ;;
34 1-run )
35         ;;
36 * )
37         echo >&2 "$0 [ clean | run ]
38 Run a few simple tests on \`${command}'."'
39
40 clean   Remove the result? and tmp_file? files.
41 run     Run the tests.
42 '
43         exit 255
44         ;;
45 esac
46
47 function TestResult {
48         if cmp -s $1 $2
49         then
50                 echo $2 PASSED
51         else
52                 echo ''
53                 echo $2 TEST FAILED
54                 diff $1 $2
55                 echo ''
56         fi
57 }
58
59 tmpfile=/tmp/$$
60 trap 'rm -f ${tmpfile}' 0 1 2 3 15
61
62 #       Run tests.
63
64 #       3 file arguments
65 ResultFile=result.1
66 ${command}  ${srcdir}/file1  ${srcdir}/file2 ${ResultFile} 2>${tmpfile}
67 cat ${tmpfile} >>${ResultFile}
68 TestResult ${srcdir}/baseline ${ResultFile}
69
70 #       OUTPUT to stdout by default
71 ResultFile=result.2
72 ${command}  ${srcdir}/file1  ${srcdir}/file2  >${ResultFile} 2>&1
73 TestResult ${srcdir}/baseline ${ResultFile}
74
75 #       OUTPUT to stdout via  -  argument
76 ResultFile=result.3
77 ${command}  ${srcdir}/file1  ${srcdir}/file2 - >${ResultFile} 2>&1
78 TestResult ${srcdir}/baseline ${ResultFile}
79
80 #       FILE1 from standard input via  -  argument
81 ResultFile=result.4
82 ${command}  - ${srcdir}/file2 <${srcdir}/file1  >${ResultFile} 2>&1
83 TestResult ${srcdir}/baseline ${ResultFile}
84
85 #       FILE2 from standard input via  -  argument
86 ResultFile=result.5
87 ${command}  ${srcdir}/file1 - <${srcdir}/file2  >${ResultFile} 2>&1
88 TestResult ${srcdir}/baseline ${ResultFile}
89
90 #       Different values for addmark, changemark, deletemark
91 ResultFile=result.6
92 ${command}  -aA -cC -dD  ${srcdir}/file1 ${srcdir}/file2  >${ResultFile} 2>&1
93 TestResult ${srcdir}/baseline.6 ${ResultFile}
94
95 #       Test for accidental file overwrite.
96 ResultFile=result.7
97 cp ${srcdir}/file2 tmp_file.7
98 ${command}  -aA -dD -cC  ${srcdir}/file1 tmp_file.7  tmp_file.7 \
99                                                         >${ResultFile} 2>&1
100 TestResult ${srcdir}/baseline.7 ${ResultFile}
101
102 #       Test -D option
103 ResultFile=result.8
104 ${command}  -D  ${srcdir}/file1 ${srcdir}/file2 >${ResultFile} 2>&1
105 TestResult ${srcdir}/baseline.8 ${ResultFile}
106
107 #       Test -D  and  -M  options
108 ResultFile=result.9
109 ${command}  -D  -M '<<<<' '>>>>'                                \
110                         ${srcdir}/file1 ${srcdir}/file2 >${ResultFile} 2>&1
111 TestResult ${srcdir}/baseline.9 ${ResultFile}
112
113 #       Test -D  and  -B  options
114 ResultFile=result.10
115 ${command}  -D  -B  ${srcdir}/file1 ${srcdir}/file2 >${ResultFile} 2>&1
116 TestResult ${srcdir}/baseline.10 ${ResultFile}
117
118 #       EOF