git/list[1] front-page[2] threads[3] people[4] search[5] about
 

[PATCH 1/2] tests: fix unportable "\?" and "\+" regex syntax

From
Ævar Arnfjörð Bjarmason <avarab@gmail.com>
Date
Feb 21, 2019, 19:28 UTC
Message-ID
<20190221192849.6581-2-avarab@gmail.com>
In-Reply-To
<xmqq8sybz7b2.fsf@gitster-ct.c.googlers.com>

Fix widely supported but non-POSIX basic regex syntax introduced in [1] and [2]. On GNU, NetBSD and FreeBSD the following works:

    $ echo xy >f
    $ grep 'xy\?' f; echo $?
    xy
    0

The same goes for "\+". The "?" and "+" syntax is not in the BRE syntax, just in ERE, but on some implementations it can be invoked by prefixing the meta-operator with "\", but not on OpenBSD:

    $ uname -a
    OpenBSD obsd.my.domain 6.2 GENERIC#132 amd64
    $ grep --version
    grep version 0.9
    $ grep 'xy\?' f; echo $?
    1

Let's fix this by moving to ERE syntax instead, where "?" and "+" are universally supported:

    $ grep -E 'xy?' f; echo $?
    xy
    0
1. 2ed5c8e174 ("describe: setup working tree for --dirty", 2019-02-03)
2. c801170b0c ("t6120: test for describe with a bare repository",
   2019-02-03)
Signed-off-by: Ævar Arnfjörð Bjarmason <avarab@gmail.com>
---
 t/t6120-describe.sh | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)
diff --git a/t/t6120-describe.sh b/t/t6120-describe.sh
index ee5b03ee18..2b883d8174 100755
--- a/t/t6120-describe.sh
+++ b/t/t6120-describe.sh
@@ -146,7 +146,7 @@ check_describe A-* HEAD
 test_expect_success 'describe works from outside repo using --git-dir' '
 	git clone --bare "$TRASH_DIRECTORY" "$TRASH_DIRECTORY/bare" &&
 	git --git-dir "$TRASH_DIRECTORY/bare" describe >out &&
-	grep "^A-[1-9][0-9]\?-g[0-9a-f]\+$" out
+	grep -E "^A-[1-9][0-9]?-g[0-9a-f]+$" out
 '
 
 check_describe "A-*[0-9a-f]" --dirty
@@ -156,7 +156,7 @@ test_expect_success 'describe --dirty with --work-tree' '
 		cd "$TEST_DIRECTORY" &&
 		git --git-dir "$TRASH_DIRECTORY/.git" --work-tree "$TRASH_DIRECTORY" describe --dirty >"$TRASH_DIRECTORY/out"
 	) &&
-	grep "^A-[1-9][0-9]\?-g[0-9a-f]\+$" out
+	grep -E "^A-[1-9][0-9]?-g[0-9a-f]+$" out
 '
 
 test_expect_success 'set-up dirty work tree' '
@@ -170,7 +170,7 @@ test_expect_success 'describe --dirty with --work-tree (dirty)' '
 		cd "$TEST_DIRECTORY" &&
 		git --git-dir "$TRASH_DIRECTORY/.git" --work-tree "$TRASH_DIRECTORY" describe --dirty >"$TRASH_DIRECTORY/out"
 	) &&
-	grep "^A-[1-9][0-9]\?-g[0-9a-f]\+-dirty$" out
+	grep -E "^A-[1-9][0-9]?-g[0-9a-f]+-dirty$" out
 '
 
 check_describe "A-*[0-9a-f].mod" --dirty=.mod
@@ -180,7 +180,7 @@ test_expect_success 'describe --dirty=.mod with --work-tree (dirty)' '
 		cd "$TEST_DIRECTORY" &&
 		git --git-dir "$TRASH_DIRECTORY/.git" --work-tree "$TRASH_DIRECTORY" describe --dirty=.mod >"$TRASH_DIRECTORY/out"
 	) &&
-	grep "^A-[1-9][0-9]\?-g[0-9a-f]\+.mod$" out
+	grep -E "^A-[1-9][0-9]?-g[0-9a-f]+.mod$" out
 '
 
 test_expect_success 'describe --dirty HEAD' '
-- 
2.21.0.rc0.258.g878e2cd30e
Previous: Josh SteadmonNext: Junio C Hamano
Message 16 of 25 in “[ANNOUNCE] Git v2.21.0-rc2”
  1. Junio C HamanoFeb 19, 2019
  2. Randall S. BeckerFeb 20, 2019
  3. Junio C HamanoFeb 20, 2019
  4. Johannes SchindelinFeb 20, 2019
  5. Duy NguyenFeb 21, 2019
  6. brian m. carlsonFeb 21, 2019
  7. Duy NguyenFeb 22, 2019
  8. Randall S. BeckerFeb 21, 2019
  9. Junio C HamanoFeb 21, 2019
  10. SZEDER GáborFeb 21, 2019
  11. Randall S. BeckerFeb 21, 2019
  12. Randall S. BeckerFeb 21, 2019
  13. Git for Windows v2.21.0-rc2, was Re: [ANNOUNCE] Git v2.21.0-rc2Johannes Schindelin, Feb 21, 2019
  14. 0/2 BSD portability fixes for 2.21.0-rc2Ævar Arnfjörð Bjarmason, Feb 21, 2019
  15. Josh SteadmonFeb 22, 2019
  16. 1/2 tests: fix unportable "\?" and "\+" regex syntaxÆvar Arnfjörð Bjarmason, Feb 21, 2019
  17. Junio C HamanoFeb 22, 2019
  18. 2/2 commit-graph tests: fix cryptic unportable "dd" invocationÆvar Arnfjörð Bjarmason, Feb 21, 2019
  19. SZEDER GáborFeb 21, 2019
  20. Ævar Arnfjörð BjarmasonFeb 21, 2019
  21. SZEDER GáborFeb 22, 2019
  22. Ævar Arnfjörð BjarmasonFeb 22, 2019
  23. Junio C HamanoFeb 22, 2019
  24. Todd ZullingerFeb 22, 2019
  25. commit-graph tests: fix unportable "dd" invocationJunio C Hamano, Feb 22, 2019

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.