bug-grep
[Top][All Lists]
Advanced

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

Re: [bug-grep] patch #3477 overview: Tests for --only-matching


From: Julian Foad
Subject: Re: [bug-grep] patch #3477 overview: Tests for --only-matching
Date: Thu, 24 Feb 2005 17:17:44 +0000
User-agent: Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.8a6) Gecko/20050111

Charles Levert wrote:
Tony Abou-Assaleh wrote:
I don't think this script has anything bash-specific in it.

Excellent.

I would probably just

  -- replace /bin/bash by /bin/sh

Of course.

  -- replace ${GREP=...} by ${GREP:=...}

Hmm. The former is used throughout our test scripts, but I can't find any documentation on what it means. I think the latter, assigning a default value, is what we want in all our scripts. That can be a separate patch when you or somebody confirms it.

  -- remove OPTS=... and replace $OPTS by -o "$@" to keep
     the "$@" magic.

Good idea.

Here's another test:

  grep_o_test "word/" "wordword/" "\<word"

Since the format is INPUT OUTPUT PATTERN, I assume you mean

  grep_o_test "wordword/" "word/" "\<word"

Good idea.  Thanks.

Updated version attached. May I check this in to our development version of Grep? I know we wouldn't want to have failing tests in a released version, but I hope this will help and encourage us to fix the bugs. If we had a way of specifying these as "expected to fail", that would be the thing to do.

- Julian
Index: tests/Makefile.am
===================================================================
RCS file: /cvsroot/grep/grep/tests/Makefile.am,v
retrieving revision 1.7
diff -u -3 -p -d -r1.7 Makefile.am
--- tests/Makefile.am   7 Mar 2001 04:11:27 -0000       1.7
+++ tests/Makefile.am   28 Oct 2004 12:19:26 -0000
@@ -3,7 +3,7 @@
 address@hidden@
 
 TESTS = warning.sh khadafy.sh spencer1.sh bre.sh ere.sh \
-        status.sh empty.sh options.sh backref.sh file.sh
+        status.sh empty.sh options.sh backref.sh file.sh grep-o.sh
 EXTRA_DIST = $(TESTS) \
              khadafy.lines khadafy.regexp \
              spencer1.awk spencer1.tests \
--- /dev/null   2003-09-23 18:59:22.000000000 +0100
+++ tests/grep-o.sh     2004-10-28 13:10:00.000000000 +0100
@@ -0,0 +1,45 @@
+#!/bin/bash
+# Test "--only-matching" ("-o") option of GNU Grep
+: ${GREP=../src/grep}
+
+VERBOSE=  # empty or "1"
+failures=0
+
+# grep_o_test EXPECTED_OUTPUT INPUT PATTERN [OPTION...]
+# Run "grep -o" with the given INPUT, PATTERN and OPTIONs, and check that
+# the output is EXPECTED_OUTPUT.
+# "/" represents a newline within EXPECTED_OUTPUT and INPUT.
+function grep_o_test()
+{
+  EXPECT="$1"
+  INPUT="$2"
+  PATTERN=$3
+  shift 3
+  OPTS="-o $@"
+  OUTPUT=`echo -n "$INPUT" | tr "/" "\n" | $GREP $OPTS "$PATTERN" | tr "\n" 
"/"`
+  if test "$OUTPUT" != "$EXPECT" || test "$VERBOSE" == "1"; then
+    echo "Testing:  $GREP $OPTS \"$PATTERN\""
+    echo "  input:  \"$INPUT\""
+    echo "  output: \"$OUTPUT\""
+  fi
+  if test "$OUTPUT" != "$EXPECT"; then
+    echo "  expect: \"$EXPECT\""
+    echo "FAIL"
+    failures=1
+  fi
+}
+
+# "-o" with "-i" should output an exact copy of the matching input text.
+grep_o_test "Word/word/WORD/" "WordA/wordB/WORDC/" "Word" -i
+grep_o_test "Word/word/WORD/" "WordA/wordB/WORDC/" "word" -i
+grep_o_test "Word/word/WORD/" "WordA/wordB/WORDC/" "WORD" -i
+
+# Should display the line number (-n) or file name (-H) of every match,
+# not just of the first match on each input line.
+grep_o_test "1:wA/1:wB/2:wC/" "wA wB/wC/" "w." -n
+grep_o_test "(standard input):wA/(standard input):wB/" "wA wB/" "w." -H
+
+# End of a previous match should not match a "start of line" expression.
+grep_o_test "word_/" "word_word/" "^word_*"
+
+exit $failures

reply via email to

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