[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: init.sh compare function
From: |
Bruno Haible |
Subject: |
Re: init.sh compare function |
Date: |
Tue, 22 Nov 2011 01:57:16 +0100 |
User-agent: |
KMail/1.13.6 (Linux/2.6.37.6-0.5-desktop; KDE/4.6.0; x86_64; ; ) |
[dropping bug-grep from CC]
> > --- a/tests/init.sh
> > +++ b/tests/init.sh
> > @@ -221,11 +221,35 @@ export MALLOC_PERTURB_
> > # a partition, or to undo any other global state changes.
> > cleanup_ () { :; }
> >
> > +# Arrange not to let diff or cmp operate on /dev/null,
> > +# since on some systems (at least OSF/1 5.1), that doesn't work.
I like the idea, but as a person who often looks at failing tests and
interprets the output I have two comments:
1) I would find it useful if, despite recognizing /dev/null as a special
case, the output format would stay the same or nearly the same.
When I see a line "+foo bar" or "-foo bar", possibly preceded by a diff
hunk, I know that the program produced or did not produce a line
containing "foo bar". Whereas when I see a line "foo bar" I think of
output that went to stdout of stderr and which should have been piped
away.
2) I would also find it useful to mention in comments that compare
function is meant to be called as in
compare expected_output actual_output
and not the opposite.
Why? Because a "+" indicates something that was added, whereas "-"
indicates something that was removed or missing. Most often the
program's actual output is wrong, not the expected output.
If you call
compare actual_output expected_output
then extraneous lines come out as "-line" and omitted ones come out as
"+line", which is counter-intuitive.
Whereas if you call
compare expected_output actual_output
then extraneous lines come out as "+line" and omitted ones come out as
"-line".
Yes I know it would take some work to revisit all coreutils and grep
tests that use 'compare', but that is not an urgent task.
> > +# When one argument is /dev/null and the other is not empty,
> > +# cat the nonempty file to stderr and return 1.
> > +# Otherwise, return 0.
> > +compare_dev_null_ ()
> > +{
> > + test $# = 2 || return 2
> > +
> > + if test "x$1" = x/dev/null; then
> > + set dummy "$2" "$1"; shift
> > + fi
> > +
> > + test "x$2" = x/dev/null || return 2
> > +
> > + test -s "$1" || return 0
> > +
> > + cat - "$1" <<EOF >&2
> > +Unexpected contents of $1:
> > +EOF
So here I would emit a fake hunk header and then either
sed 's/^/+/' "$1"
or
sed 's/^/-/' "$1"
Bruno
--
In memoriam Ricardo Flores Magón
<http://en.wikipedia.org/wiki/Ricardo_Flores_Magón>