# test suite failures because cmp behaves oddly

3 messages from 2007-02-17 to 2007-02-17. Participants: Johannes Sixt, Junio C Hamano, Johannes Schindelin.
Thread: https://gitlist.dev/t/6862

## Johannes Sixt, 2007-02-17 21:25

Subject: test suite failures because cmp behaves oddly
Message-ID: <200702172225.12758.johannes.sixt@telecom.at>
URL: https://gitlist.dev/e/200702172225.12758.johannes.sixt%40telecom.at

```
Does anyone know how 'cmp' can signal success when its output is redirected 
to /dev/null, even if the compared files are different?

$ cmp M.sum actual7.sum; echo $?
M.sum actual7.sum differ: char 20, line 2
1
$ cmp M.sum actual7.sum > /dev/null; echo $?
0
$ bash --version
GNU bash, version 3.1.17(1)-release (i586-suse-linux)
$ cmp --version
cmp (GNU diffutils) 2.8.7
[...]

Due to this behavior I see reproducible failures in the test suite, unless the 
tests are run in --verbose mode:

$ make GIT_TEST_OPTS=-i t1002-read-tree-m-u-2way.sh
*** t1002-read-tree-m-u-2way.sh ***
*   ok 1: setup
*   ok 2: 1, 2, 3 - no carry forward
*   ok 3: 4 - carry forward local addition.
*   ok 4: 5 - carry forward local addition.
*   ok 5: 6 - local addition already has the same.
* FAIL 6: 7 - local addition already has the same.
        rm -f .git/index nitfol bozbar rezrov frotz &&
             git-read-tree --reset -u $treeH &&
             echo frotz >frotz &&
             git-update-index --add frotz &&
             echo frotz frotz >frotz &&
             git-read-tree -m -u $treeH $treeM &&
             git-ls-files --stage >7.out &&
             diff -U0 M.out 7.out &&
             check_cache_at frotz dirty &&
             sum bozbar frotz nitfol >actual7.sum &&
             if cmp M.sum actual7.sum; then false; else :; fi &&
             : dirty index should have prevented -u from checking it out. &&
             echo frotz frotz >frotz1 &&
             diff frotz frotz1 &&
             rm -f frotz1
make: *** [t1002-read-tree-m-u-2way.sh] Error 1


Has anyone seen something like this?

-- Hannes

```

## Junio C Hamano, 2007-02-17 23:03

Subject: Re: test suite failures because cmp behaves oddly
Message-ID: <7v3b54s7y3.fsf@assigned-by-dhcp.cox.net>
URL: https://gitlist.dev/e/7v3b54s7y3.fsf%40assigned-by-dhcp.cox.net
In-Reply-To: <200702172225.12758.johannes.sixt@telecom.at>

```
Johannes Sixt <johannes.sixt@telecom.at> writes:

> Does anyone know how 'cmp' can signal success when its output is redirected 
> to /dev/null, even if the compared files are different?
>
> $ cmp M.sum actual7.sum; echo $?
> M.sum actual7.sum differ: char 20, line 2
> 1
> $ cmp M.sum actual7.sum > /dev/null; echo $?
> 0
> ...
> Has anyone seen something like this?

I vaguely recall this reported long time ago from one of the
regulars on the list, but googling or gmane search came up
empty.

```

## Johannes Schindelin, 2007-02-17 23:16

Subject: Re: test suite failures because cmp behaves oddly
Message-ID: <Pine.LNX.4.63.0702180015470.22628@wbgn013.biozentrum.uni-wuerzburg.de>
URL: https://gitlist.dev/e/Pine.LNX.4.63.0702180015470.22628%40wbgn013.biozentrum.uni-wuerzburg.de
In-Reply-To: <7v3b54s7y3.fsf@assigned-by-dhcp.cox.net>

```
Hi,

On Sat, 17 Feb 2007, Junio C Hamano wrote:

> Johannes Sixt <johannes.sixt@telecom.at> writes:
> 
> > Does anyone know how 'cmp' can signal success when its output is redirected 
> > to /dev/null, even if the compared files are different?
> >
> > $ cmp M.sum actual7.sum; echo $?
> > M.sum actual7.sum differ: char 20, line 2
> > 1
> > $ cmp M.sum actual7.sum > /dev/null; echo $?
> > 0
> > ...
> > Has anyone seen something like this?
> 
> I vaguely recall this reported long time ago from one of the
> regulars on the list, but googling or gmane search came up
> empty.

Was me. AFAIR it was fixed in CVS.

Ciao,
Dscho

```
