# t160 --- rcsdiff
#
# Copyright (C) 2010-2012 Thien-Thi Nguyen
#
# This program 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 3 of
# the License, or (at your option) any later version.
#
# This program 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 this program.  If not, see <http://www.gnu.org/licenses/>.

. $srcdir/common
. $srcdir/common-kn
split_std_out_err no
prep_b_comparison
minusk=

##
# Check that rcsdiff produces expected output and exit value.
##

cou ()
{
    # $1 -- STEM in fake/b.d/STEM.cou
    cp -f `bundled_commav b.d/$1.cou` $w
}

ev ()
{
    # $1 -- exit value, one of: 0, 1, 2
    # $2+ -- args for rcsdiff
    n=$1 ; shift
    args="$@"
    $hey echo "** $n: $minusk $args"

    rcsdiff $minusk $args $v 1> $actual
    exval=$?
    test x$n = x$exval \
        || problem "rcsdiff exit val not $n for: $args"
}

compare ()
{
    # $1 -- title
    # $2 -- contents of $expected
    echo "$2" | sed '1d;s/|$//' > $expected
    normalize_b_and_diff "$1"
}

$hey echo '                                        -*- org -*-'

##
# * For nonexistent files or revisions, check for exit value 2.
##

$hey echo '* simple problematic'
ev 2 nosuch
ev 2 $wd/nosuch
ev 2 -rnosuch -rnosuch
ev 2 $w

$hey echo '* bad revision'
ev 2 -r -r2
ev 2 -r2 -r
ev 2 -r1.6.2 -r
ev 2 -r -r1.6.2

##
# * The HEAD revision should be the same as the HEAD revision.
##

$hey echo '* b HEAD / b HEAD'
ev 0 -r -r
ev 0 -r1.6.1.2 -r1.6.1.2
ev 0 -r -r1.6.1.2
ev 0 -r1.6.1.2 -r

##
# * Check different revisions that have the same contents with
#   various -kSUBST, with SUBST one of: kv, kvl, k, o, b, v.
##

$hey echo '* different revisions but same text (w/ various -kSUBST)'

xsame ()
{
    # $1 -- SUBST for -kSUBST
    minusk="-k$1"
    ev 0 -r1.1.1.1 -r1.1.1.2
}

xsame kv
xsame kvl
xsame k
xsame o
xsame b
xsame v

##
# * Spot check a few known differences.
##

$hey echo '* b known differerences'

minusk=-kk

xdiff ()
{
    # $1 -- rev1
    # $2 -- rev2
    # $3 -- contents of $expected
    rev1=$1
    rev2=$2
    echo "$3" | sed '1d;s/|$//' > $expected

    ev 1 -r$rev1 -r$rev2
    normalize_b_and_diff "-r$rev1 -r$rev2"
}

xdiff '' '1.6.1.1' '
1c1|
< wow, rcs!$Revision$YES! HMMM THIS SHOULD BE NAMED "ZOW"!|
---|
> wow, rcs!$Revision$YES! HMMM|
14,16d13|
< ;; Revision 1.6.1.2  2010/10/21 22:48:48  ttn|
< ;; Add a name.|
< ;;|'

xdiff '' '1.1.1.7' '
1c1|
< wow, rcs!$Revision$YES! HMMM THIS SHOULD BE NAMED "ZOW"!|
---|
> $Author$|
3,37c3,33|
< ;; $Author$|
< ;; $Date$|
< ;; $Header$|
< ;; $Id$|
< ;; $Locker$|
< ;; $Name$|
< ;; $RCSfile$|
< ;; $Revision$|
< ;; $Source$|
< ;; $State$|
< ;; $Log$|
< ;; Revision 1.6.1.2  2010/10/21 22:48:48  ttn|
< ;; Add a name.|
< ;;|
< ;; Revision 1.6.1.1  2010/05/05 12:18:30  ttn|
< ;; This should in theory go to 1.6.1.1.|
< ;;|
< ;; Revision 1.6  2010/04/12 12:16:58  ttn|
< ;; Add $Revision with pre and suffix.|
< ;;|
< ;; Revision 1.5  2010/03/30 09:46:50  ttn|
< ;; Add text after Log block.|
< ;;|
< ;; Revision 1.4  2010/03/30 09:46:24  zurg|
< ;; Add "earthlings".|
< ;;|
< ;; Revision 1.3  2010/03/30 09:45:42  zurg|
< ;; Add "greetings".|
< ;;|
< ;; Revision 1.2  2010/03/30 09:45:02  ttn|
< ;; Add empty headers.|
< ;;|
< ;; Here is some trailing text|
< greetings|
< earthlings|
---|
> $Date$|
> |
> $Header$|
> |
> $Id$|
> |
> $Locker$|
> |
> /*|
>  * $Log$|
>  * Revision 1.1.1.7  2010/03/28 16:04:26  ttn|
>  * Replace last line with "z".|
>  *|
>  * Revision 1.1.1.6  2010/03/18 06:22:00  ttn|
>  * Surround Log kw with C-style comment.|
>  *|
>  * Revision 1.1.1.5  2010/03/18 06:21:03  ttn|
>  * WOW is 1.1.1.5! (+ sorted kw)|
>  * |
>  */|
> |
> $Name$|
> |
> $RCSfile$|
> |
> $Revision$|
> |
> $Source$|
> |
> $State$|
> z|'

xdiff '' '1.9' '
1,2c1,2|
< wow, rcs!$Revision$YES! HMMM THIS SHOULD BE NAMED "ZOW"!|
< |
---|
> wow, rcs!$Revision$YES!$1$2$3$RevisionZ$Nym:42$|
> z|
14,15c14,15|
< ;; Revision 1.6.1.2  2010/10/21 22:48:48  ttn|
< ;; Add a name.|
---|
> ;; Revision 1.9  2010/04/18 09:39:02  ttn|
> ;; Minor change, plus set state.|
17,18c17,21|
< ;; Revision 1.6.1.1  2010/05/05 12:18:30  ttn|
< ;; This should in theory go to 1.6.1.1.|
---|
> ;; Revision 1.8  2010/04/12 13:23:04  ttn|
> ;; Add even more keyword weirdness.|
> ;;|
> ;; Revision 1.7  2010/04/12 13:20:50  ttn|
> ;; Add more keyword weirdness.|'

##
# * (if using GNU diff) check long options passthrough
##
$hey echo '* long options passthrough'
if diff --help | grep -e '--unified' ; then
    must 'cp `bundled_commav two` $wd/two,v'
    rcsdiff --unified -r4.20 -r4.21 $wd/two > $wd/rcsdiff.out \
        && problem 'rcsdiff did not exit w/ non-zero status'
    cat > $wd/expected <<EOF
--- t160.d/two	2010/10/02 16:41:32	4.20
+++ t160.d/two	2010/10/02 16:41:32	4.21
@@ -1 +1,2 @@
 nonempty
+morejunk
EOF
    diff $wd/rcsdiff.out $wd/expected > $wd/diff.out
    noiselessness_rules $wd/diff.out 'rcsdiff produced the wrong output'
else
    $hey echo '(skipped)'
fi

exit 0

# t160 ends here
