From 296d5b8e42361ee5fd8231c41e7abb2a0148c574 Mon Sep 17 00:00:00 2001 From: wl Date: Wed, 15 Dec 2004 06:04:48 +0000 Subject: * gdiffmk.sh: Make sed pattern work with alternate result of GNU diff's -D option, using `!' instead of `not' in #endif comments. (Exit): Use prefix for each emitted message line. * tests/*: New files for testing gdiffmk. * README, gdiffmk.man, gdiffmk.sh: Updated. Minor fixes. --- contrib/gdiffmk/ChangeLog | 15 +++++++- contrib/gdiffmk/README | 50 ++++++++++++++----------- contrib/gdiffmk/gdiffmk.man | 2 +- contrib/gdiffmk/gdiffmk.sh | 20 ++++++---- contrib/gdiffmk/tests/file1 | 11 ++++++ contrib/gdiffmk/tests/file2 | 11 ++++++ contrib/gdiffmk/tests/test_baseline | 17 +++++++++ contrib/gdiffmk/tests/test_baseline6 | 17 +++++++++ contrib/gdiffmk/tests/test_baseline7 | 2 + contrib/gdiffmk/tests/tests.sh | 72 ++++++++++++++++++++++++++++++++++++ 10 files changed, 186 insertions(+), 31 deletions(-) create mode 100644 contrib/gdiffmk/tests/file1 create mode 100644 contrib/gdiffmk/tests/file2 create mode 100644 contrib/gdiffmk/tests/test_baseline create mode 100644 contrib/gdiffmk/tests/test_baseline6 create mode 100644 contrib/gdiffmk/tests/test_baseline7 create mode 100755 contrib/gdiffmk/tests/tests.sh (limited to 'contrib') diff --git a/contrib/gdiffmk/ChangeLog b/contrib/gdiffmk/ChangeLog index a461b440..e8324875 100644 --- a/contrib/gdiffmk/ChangeLog +++ b/contrib/gdiffmk/ChangeLog @@ -1,10 +1,23 @@ +2004-12-14 Werner LEMBERG + + * gdiffmk.sh: Make sed pattern work with alternate result of GNU + diff's -D option, using `!' instead of `not' in #endif comments. + (Exit): Use prefix for each emitted message line. + +2004-12-14 Mike Bianchi + + * tests/*: New files for testing gdiffmk. + + * README, gdiffmk.man, gdiffmk.sh: Updated. + Minor fixes. + 2004-12-13 Mike Bianchi Add `-x' command line option to select a diff program. * gdiffmk.sh: Add code to handle `-x'. Move test for working `diff' down. - Fix sed pattern. + Fix sed pattern -- `.mc *' needs to be followed by `.mc .'. (Usage): Updated. * gdiffmk.man: Updated. diff --git a/contrib/gdiffmk/README b/contrib/gdiffmk/README index 4fd687e1..ff2ce342 100644 --- a/contrib/gdiffmk/README +++ b/contrib/gdiffmk/README @@ -3,35 +3,41 @@ command for troff/nroff documents, with enhancements. It should not be confused with diffmk commands that operate on XML. -The inspiration for this code was a Perl 2 version written in 1989 by Randal L. -Schwartz. Thanks to Werner Lemberg for help in making the package more -portable and fit into the GNU groff source structure. +The inspiration for this code was a Perl 2 version written in 1989 by Randal +L. Schwartz. See -http://www.landfield.com/software/comp.sources.misc/archive-name/volume06/diffmk.p.gz + landfield.com/software/comp.sources.misc/archive-name/volume06/diffmk.p.gz -Gnu diff(1) with the -Dname option does all of the work and sed(1) translates -the output into something groff/troff/nroff can handle. +Thanks to Werner Lemberg for help in making the package more portable and +fit into the GNU groff source structure. + +Gnu diff(1) with the -Dname option does all of the work and sed(1) +translates the output into something groff/troff/nroff can handle. Note the BUGS on the man page. -$Header: /sources/groff/groff/contrib/gdiffmk/README,v 1.1 2004/12/12 20:06:55 wl Exp $ +The `tests' directory contains simple tests. `tests.sh run' runs them and +compares the output against baseline files. Calling `tests.sh' without +argument gives the usage. + +---------------------------------------------------------------------------- -# Copyright (C) 2004 Free Software Foundation, Inc. -# Written by Mike Bianchi > +Copyright (C) 2004 Free Software Foundation, Inc. +Written by Mike Bianchi > -# This file is part of the gdiffmk utility, which is part of groff. +This file is part of the gdiffmk utility, which is part of groff. -# groff is free software; you can redistribute it and/or modify it -# under the terms of the GNU General Public License as published by -# the Free Software Foundation; either version 2, or (at your option) -# any later version. +groff is free software; you can redistribute it and/or modify it +under the terms of the GNU General Public License as published by +the Free Software Foundation; either version 2, or (at your option) +any later version. -# groff is distributed in the hope that it will be useful, but WITHOUT -# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY -# or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public -# License for more details. +groff is distributed in the hope that it will be useful, but WITHOUT +ANY WARRANTY; without even the implied warranty of MERCHANTABILITY +or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public +License for more details. -# You should have received a copy of the GNU General Public License -# along with groff; see the files COPYING and LICENSE in the top -# directory of the groff source. If not, write to the Free Software -# Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +You should have received a copy of the GNU General Public License +along with groff; see the files COPYING and LICENSE in the top +directory of the groff source. If not, write to the Free Software +Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. diff --git a/contrib/gdiffmk/gdiffmk.man b/contrib/gdiffmk/gdiffmk.man index 19bf40d1..a813cf04 100644 --- a/contrib/gdiffmk/gdiffmk.man +++ b/contrib/gdiffmk/gdiffmk.man @@ -134,7 +134,7 @@ Use the command to perform the comparison of .I file1 and -.I file2 . +.IR file2 . In particular, .I diffcmd should accept the diff --git a/contrib/gdiffmk/gdiffmk.sh b/contrib/gdiffmk/gdiffmk.sh index 87bc9c36..4f494412 100644 --- a/contrib/gdiffmk/gdiffmk.sh +++ b/contrib/gdiffmk/gdiffmk.sh @@ -57,7 +57,11 @@ OPTIONS: function Exit { exitcode=$1 shift - echo >&2 "${cmd}: $@" + for arg + do + echo >&2 "${cmd}: $1" + shift + done exit ${exitcode} } @@ -74,11 +78,11 @@ function FileRead { if test ! -e "$2" then - Exit $1 "File \`$2' not found." + Exit $1 "File \`$2' not found." fi if test ! -r "$2" then - Exit $1 "File \`$2' not readable." + Exit $1 "File \`$2' not readable." fi } @@ -101,7 +105,7 @@ function FileCreate { Exit $1 "File \`$2' not created; " \ "Cannot write directory \`$( dirname "$2" )'." fi - Exit $1 "File \`$2' not writeable." + Exit $1 "File \`$2' not writeable." fi } @@ -114,7 +118,9 @@ function WouldClobber { if test "$1" -ef "$3" then - Exit 3 "\`$3' is the same as \`$2' and would be clobbered." + Exit 3 \ + "The $2 and OUTPUT arguments both point to the same file," \ + "\`$1', and it would be overwritten." fi } @@ -241,14 +247,14 @@ diff -D"${label}" -- ${FILE1} ${FILE2} | p d } - /^#ifndef '"${label}"'/,/^#endif \/\* [not ]*'"${label}"'/ { + /^#ifndef '"${label}"'/,/^#endif \/\* [!not ]*'"${label}"'/ { /^#else \/\* '"${label}"'/,/^#endif \/\* '"${label}"'/ { /^#else \/\* '"${label}"'/ s/.*/.mc '"${changemark}"'/ /^#endif \/\* '"${label}"'/ s/.*/.mc/ p d } - /^#endif \/\* not '"${label}"'/ { + /^#endif \/\* \(not\|!\) '"${label}"'/ { s/.*/.mc '"${deletemark}"'/p a\ .mc diff --git a/contrib/gdiffmk/tests/file1 b/contrib/gdiffmk/tests/file1 new file mode 100644 index 00000000..ba6a4be2 --- /dev/null +++ b/contrib/gdiffmk/tests/file1 @@ -0,0 +1,11 @@ +.ll 25 +.pl 20 +.nf +file1 and file2 #1 +file1 only +file1 and file2 #2 +file1 and file2 #3 +file1 only +file1 only +file1 and file2 #4 +file1 and file2 #5 diff --git a/contrib/gdiffmk/tests/file2 b/contrib/gdiffmk/tests/file2 new file mode 100644 index 00000000..54e95eef --- /dev/null +++ b/contrib/gdiffmk/tests/file2 @@ -0,0 +1,11 @@ +.ll 25 +.pl 20 +.nf +file1 and file2 #1 +file2 only +file2 only +file1 and file2 #2 +file2 only +file1 and file2 #3 +file1 and file2 #4 +file1 and file2 #5 diff --git a/contrib/gdiffmk/tests/test_baseline b/contrib/gdiffmk/tests/test_baseline new file mode 100644 index 00000000..6b329926 --- /dev/null +++ b/contrib/gdiffmk/tests/test_baseline @@ -0,0 +1,17 @@ +.ll 25 +.pl 20 +.nf +file1 and file2 #1 +.mc | +file2 only +file2 only +.mc +file1 and file2 #2 +.mc + +file2 only +.mc +file1 and file2 #3 +.mc * +.mc +file1 and file2 #4 +file1 and file2 #5 diff --git a/contrib/gdiffmk/tests/test_baseline6 b/contrib/gdiffmk/tests/test_baseline6 new file mode 100644 index 00000000..3156961b --- /dev/null +++ b/contrib/gdiffmk/tests/test_baseline6 @@ -0,0 +1,17 @@ +.ll 25 +.pl 20 +.nf +file1 and file2 #1 +.mc C +file2 only +file2 only +.mc +file1 and file2 #2 +.mc A +file2 only +.mc +file1 and file2 #3 +.mc D +.mc +file1 and file2 #4 +file1 and file2 #5 diff --git a/contrib/gdiffmk/tests/test_baseline7 b/contrib/gdiffmk/tests/test_baseline7 new file mode 100644 index 00000000..6bee99f5 --- /dev/null +++ b/contrib/gdiffmk/tests/test_baseline7 @@ -0,0 +1,2 @@ +gdiffmk.sh: The FILE2 and OUTPUT arguments both point to the same file, +gdiffmk.sh: `tmp_file7', and it would be overwritten. diff --git a/contrib/gdiffmk/tests/tests.sh b/contrib/gdiffmk/tests/tests.sh new file mode 100755 index 00000000..a13d2f87 --- /dev/null +++ b/contrib/gdiffmk/tests/tests.sh @@ -0,0 +1,72 @@ +#!/bin/sh +# A very simple function test for gdiffmk.sh. + +command=../gdiffmk.sh + +# Test the number of arguments and the first argument. +case $#-$1 in +1-clean ) + rm -fv test_result? tmp_file? + exit 0 + ;; +1-run ) + ;; +* ) + echo >&2 "$0 [ clean | run ] +Run a few simple tests on \`${command}'."' + +clean Remove the test_result? and tmp_file? files. +run Run the tests. +' + exit 255 + ;; +esac + +function TestResult { + if diff $1 $2 + then + echo $2 PASSED + else + echo $2 TEST FAILED '\a' + fi +} + +tmpfile=/tmp/$$ +trap 'rm -f ${tmpfile}' 0 1 2 3 15 + +# 3 file arguments +ResultFile=test_result1 +sh ${command} file1 file2 ${ResultFile} 2>${tmpfile} +cat ${tmpfile} >>${ResultFile} +TestResult test_baseline ${ResultFile} + +# OUTPUT to stdout by default +ResultFile=test_result2 +sh ${command} file1 file2 >${ResultFile} 2>&1 +TestResult test_baseline ${ResultFile} + +# OUTPUT to stdout via - argument +ResultFile=test_result3 +sh ${command} file1 file2 - >${ResultFile} 2>&1 +TestResult test_baseline ${ResultFile} + +# FILE1 from standard input via - argument +ResultFile=test_result4 +sh ${command} - file2 ${ResultFile} 2>&1 +TestResult test_baseline ${ResultFile} + +# FILE2 from standard input via - argument +ResultFile=test_result5 +sh ${command} file1 - ${ResultFile} 2>&1 +TestResult test_baseline ${ResultFile} + +# Different values for addmark, changemark, deletemark +ResultFile=test_result6 +sh ${command} -aA -cC -dD file1 file2 >${ResultFile} 2>&1 +TestResult test_baseline6 ${ResultFile} + +# Test for accidental file overwrite. +ResultFile=test_result7 +cp file2 tmp_file7 +sh ${command} -aA -dD -cC file1 tmp_file7 tmp_file7 >${ResultFile} 2>&1 +TestResult test_baseline7 ${ResultFile} -- cgit v1.2.1