# [PATCH 2/3] t/t7811-grep-open.sh: ensure fake "less" is made executable

4 messages from 2010-06-21 to 2010-06-21. Participants: Brandon Casey, Junio C Hamano.
Thread: https://gitlist.dev/t/24157

## Brandon Casey, 2010-06-21 17:37

Subject: [PATCH 1/3] t/lib-pager.sh: remove unnecessary '^' from 'expr' regular expression
Message-ID: <__CrpvAIIX9lgHHkBLHB9fuuN7Rspzl7LFSDSwXwVCT6rYs_YOUHNMf7JZQbKaPHRl6AjsJ9dx8@cipher.nrlssc.navy.mil>
URL: https://gitlist.dev/e/__CrpvAIIX9lgHHkBLHB9fuuN7Rspzl7LFSDSwXwVCT6rYs_YOUHNMf7JZQbKaPHRl6AjsJ9dx8%40cipher.nrlssc.navy.mil

```
From: Brandon Casey <drafnel@gmail.com>

Regular expressions matched by 'expr' have an implicit '^' at the beginning
of them and so are anchored to the beginning of the string.  Using the '^'
character to mean "match at the beginning", is redundant and could produce
the wrong result if 'expr' implementations interpret the '^' as a literal
'^'.  Additionally, GNU expr 5.97 complains like this:

   expr: warning: unportable BRE: `^[a-z][a-z]*$': using `^' as the first character of the basic regular expression is not portable; it is being ignored

Signed-off-by: Brandon Casey <casey@nrlssc.navy.mil>
---
 t/lib-pager.sh |    2 +-
 1 files changed, 1 insertions(+), 1 deletions(-)

diff --git a/t/lib-pager.sh b/t/lib-pager.sh
index f8c6025..ba03eab 100644
--- a/t/lib-pager.sh
+++ b/t/lib-pager.sh
@@ -9,7 +9,7 @@ test_expect_success 'determine default pager' '
 	test -n "$less"
 '
 
-if expr "$less" : '^[a-z][a-z]*$' >/dev/null
+if expr "$less" : '[a-z][a-z]*$' >/dev/null
 then
 	test_set_prereq SIMPLEPAGER
 fi
-- 
1.6.6.2

```

## Brandon Casey, 2010-06-21 17:37

Subject: [PATCH 2/3] t/t7811-grep-open.sh: ensure fake "less" is made executable
Message-ID: <__CrpvAIIX9lgHHkBLHB9a3UByh6vEB5nG8C7-bzzaY-zhXjKlkZfsB4GNmQRsIYGu10jf-0sjU@cipher.nrlssc.navy.mil>
URL: https://gitlist.dev/e/__CrpvAIIX9lgHHkBLHB9a3UByh6vEB5nG8C7-bzzaY-zhXjKlkZfsB4GNmQRsIYGu10jf-0sjU%40cipher.nrlssc.navy.mil
In-Reply-To: <__CrpvAIIX9lgHHkBLHB9fuuN7Rspzl7LFSDSwXwVCT6rYs_YOUHNMf7JZQbKaPHRl6AjsJ9dx8@cipher.nrlssc.navy.mil>

```
From: Brandon Casey <drafnel@gmail.com>

The fake "less" script was not being made executable.  This can cause the
tests that follow to fail.  This failure is not apparent on platforms which
have DEFAULT_PAGER set to the string "less", since lib-pager.sh will have
set the $less variable to "less" and the SIMPLEPAGER prerequisite will have
been set, and so the "less" script will have already been created properly
and made executable in test 2 'git grep -O'.  On platforms which set
DEFAULT_PAGER to something like "more", no such script will have been
previously created, and tests 7 and 8 will fail.

So, add a call to chmod to make the fake "less" script executable.

Signed-off-by: Brandon Casey <casey@nrlssc.navy.mil>
---
 t/t7811-grep-open.sh |    3 ++-
 1 files changed, 2 insertions(+), 1 deletions(-)

diff --git a/t/t7811-grep-open.sh b/t/t7811-grep-open.sh
index 8db4fc8..2e5c701 100755
--- a/t/t7811-grep-open.sh
+++ b/t/t7811-grep-open.sh
@@ -84,10 +84,11 @@ test_expect_success 'git grep -O --no-index' '
 '
 
 test_expect_success 'setup: fake "less"' '
-	cat >less <<-\EOF
+	cat >less <<-\EOF &&
 	#!/bin/sh
 	printf "%s\n" "$@" >actual
 	EOF
+	chmod +x less
 '
 
 test_expect_success 'git grep -O jumps to line in less' '
-- 
1.6.6.2

```

## Brandon Casey, 2010-06-21 17:37

Subject: [PATCH 3/3] t/t7811-grep-open.sh: remove broken/redundant creation of fake "less" script
Message-ID: <__CrpvAIIX9lgHHkBLHB9XDHAxBXxWdeEjxUzFD8IDsCriIMGC3nkCjyvNdGPppHV_Yf_CyEmg8@cipher.nrlssc.navy.mil>
URL: https://gitlist.dev/e/__CrpvAIIX9lgHHkBLHB9XDHAxBXxWdeEjxUzFD8IDsCriIMGC3nkCjyvNdGPppHV_Yf_CyEmg8%40cipher.nrlssc.navy.mil
In-Reply-To: <__CrpvAIIX9lgHHkBLHB9fuuN7Rspzl7LFSDSwXwVCT6rYs_YOUHNMf7JZQbKaPHRl6AjsJ9dx8@cipher.nrlssc.navy.mil>

```
From: Brandon Casey <drafnel@gmail.com>

The fake "less" script was already created in a previous test titled
'setup: fake "less"', so it is redundant.  Additionally, it is broken since
the redirection of 'cat' is to a file named 'less', but the chmod operates
on the file named by the $less variable which may not contain the value
'less'.

So, just remove this code, and rely on the creation of the fake "less"
script performed earlier within the test script.

Signed-off-by: Brandon Casey <casey@nrlssc.navy.mil>
---
 t/t7811-grep-open.sh |    5 -----
 1 files changed, 0 insertions(+), 5 deletions(-)

diff --git a/t/t7811-grep-open.sh b/t/t7811-grep-open.sh
index 2e5c701..c110441 100755
--- a/t/t7811-grep-open.sh
+++ b/t/t7811-grep-open.sh
@@ -109,11 +109,6 @@ test_expect_success 'git grep -O jumps to line in less' '
 
 test_expect_success 'modified file' '
 	rm -f actual &&
-	cat >less <<-\EOF &&
-	#!/bin/sh
-	printf "%s\n" "$@" >actual
-	EOF
-	chmod +x $less &&
 	cat >expect <<-\EOF &&
 	+/*enum grep_pat_token
 	grep.h
-- 
1.6.6.2

```

## Junio C Hamano, 2010-06-21 18:11

Subject: Re: [PATCH 1/3] t/lib-pager.sh: remove unnecessary '^' from 'expr' regular expression
Message-ID: <7vd3vki7d7.fsf@alter.siamese.dyndns.org>
URL: https://gitlist.dev/e/7vd3vki7d7.fsf%40alter.siamese.dyndns.org
In-Reply-To: <__CrpvAIIX9lgHHkBLHB9fuuN7Rspzl7LFSDSwXwVCT6rYs_YOUHNMf7JZQbKaPHRl6AjsJ9dx8@cipher.nrlssc.navy.mil>

```
Brandon Casey <casey@nrlssc.navy.mil> writes:

> From: Brandon Casey <drafnel@gmail.com>
>
> Regular expressions matched by 'expr' have an implicit '^' at the beginning
> of them and so are anchored to the beginning of the string.

Oh, of course; I should have caught this earlier.

$ git grep -n -e 'expr .*: .*['\''"]^'
t/lib-pager.sh:12:if expr "$less" : '^[a-z][a-z]*$' >/dev/null
t/t7005-editor.sh:16:if ! expr "$vi" : '^[a-z]*$' >/dev/null
t/t7006-pager.sh:113:   ! expr "$firstline" : "^[a-zA-Z]" >/dev/null

I'll fix the other two; thanks.

```
