bug-grep
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: tests/yesno.sh, kinds of line (matching/non-matching, selected/rejec


From: Julian Foad
Subject: Re: tests/yesno.sh, kinds of line (matching/non-matching, selected/rejected)
Date: Sun, 13 Nov 2005 23:46:09 +0000
User-agent: Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.7.8) Gecko/20050511

Charles Levert wrote:
* On Sunday 2005-11-13 at 18:44:57 +0000, Julian Foad wrote:

Test #28: { ../src/grep -F -n -b -m 2 -v -C 1 -o yes; echo "?$?"; sed

We'll discuss the interaction between "-v" and "-o" separately.

Test #28 still involves a context line (albeit
here a matching one, since -v), so whatever
decision is made for the other two tests should
equally apply here (regarding -C/-m).

Well, the decision made about -C/-m _affects_ this test but is not the only consideration, because of the additional "-v".

As for -C/-v/-o and the warning issue, I think
we do disagree.  With -o, I see a line-group
(including selected and context lines) as a
pool of _printable_ content, i.e., lines to scan
for -o parts.  Hence, I see no special case or
need for a warning then, and I see the group
separator remaining.   -C/-v/-o means "find all
matching parts in the vicinity of a non-matching
line (or lines) and collect them as a group".

Yikes. There's some kind of logic to that line of reasoning, but it strikes me as very arcane. I have never thought of wanting such output. I can't imagine any meaningful use for it. Sorry. That logic involves Grep doing two different kinds of search (conceptually, not just implementation-wise which it currently does anyway). That effect is much better and more flexibly obtained with two successive Greps: "grep -C -v | grep -o".

I think "-v" and "-o" are mutually exclusive:

  -v: "show only the lines that have no matches"
      (possibly with a few lines of context)

  -o: "show only the matches"
(it would make some kind of logical sense to show possibly a few _characters_ of context around each match, but nobody has asked for that)

I'm greatly in favour of options having orthogonal meanings as much as possible, but I it is unreasonable here. It is far better to disallow certain combinations (which can then be given meanings in the future if it becomes desirable) than to give them a meaning now just because we can (and then have to support that meaning forever even though it is not useful).

Hey, there's another example of keeping it free of unneeded functionality and future-proof: we don't support context lines with "-o". If we were to make "-C" work with "-o" in some arbitrary line-based way now, we'd lock ourselves out of the possibility of making it show the specified number of _characters_ if and when people do start to expect that. (I'd never thought of that "characters of context" idea until now, and I don't know if it will ever be wanted, and don't suggest we even consider implementing it, but it illustrates a point.)


That means those "4/..." tests are wrong.

Since yesno.sh specializes in exactly this
kind of issues, should we now just remove those
from foad1.sh?  Or do still they do something
for anchors that nothing else does?

Their original purpose, as I mentioned, was to check that Grep doesn't crash. The appropriate way to do this would be to change them to not check the output; one of the other test files may have a more appropriate framework for doing that.

- Julian




reply via email to

[Prev in Thread] Current Thread [Next in Thread]