[PATCH] test-lib-functions: avoid non POSIX ERE in test_dir_is_empty()

Subsystems: the rest

STALE1808d

3 messages, 2 authors, 2021-08-26 · open the first message on its own page

[PATCH] test-lib-functions: avoid non POSIX ERE in test_dir_is_empty()

From: Carlo Marcelo Arenas Belón <hidden>
Date: 2021-08-26 03:18:29

0be7d9b73d (test-lib: add test_dir_is_empty(), 2014-06-19) uses an
ERE through the egrep tool (which is not POSIX) using an ? operator
that isn't either.

replace invocation with two equivalent simpler BRE instead.

Signed-off-by: Carlo Marcelo Arenas Belón <redacted>
---
 t/test-lib-functions.sh | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/t/test-lib-functions.sh b/t/test-lib-functions.sh
index e28411bb75..2803c97df3 100644
--- a/t/test-lib-functions.sh
+++ b/t/test-lib-functions.sh
@@ -790,7 +790,7 @@ test_path_exists () {
 test_dir_is_empty () {
 	test "$#" -ne 1 && BUG "1 param"
 	test_path_is_dir "$1" &&
-	if test -n "$(ls -a1 "$1" | egrep -v '^\.\.?$')"
+	if test -n "$(ls -a1 "$1" | grep -v '^\.$' | grep -v '^\.\.$')"
 	then
 		echo "Directory '$1' is not empty, it contains:"
 		ls -la "$1"
-- 
2.33.0.481.g26d3bed244

Re: [PATCH] test-lib-functions: avoid non POSIX ERE in test_dir_is_empty()

From: Taylor Blau <hidden>
Date: 2021-08-26 04:24:17

On Wed, Aug 25, 2021 at 08:17:10PM -0700, Carlo Marcelo Arenas Belón wrote:
quoted hunk
0be7d9b73d (test-lib: add test_dir_is_empty(), 2014-06-19) uses an
ERE through the egrep tool (which is not POSIX) using an ? operator
that isn't either.

replace invocation with two equivalent simpler BRE instead.

Signed-off-by: Carlo Marcelo Arenas Belón <redacted>
---
 t/test-lib-functions.sh | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/t/test-lib-functions.sh b/t/test-lib-functions.sh
index e28411bb75..2803c97df3 100644
--- a/t/test-lib-functions.sh
+++ b/t/test-lib-functions.sh
@@ -790,7 +790,7 @@ test_path_exists () {
 test_dir_is_empty () {
 	test "$#" -ne 1 && BUG "1 param"
 	test_path_is_dir "$1" &&
-	if test -n "$(ls -a1 "$1" | egrep -v '^\.\.?$')"
+	if test -n "$(ls -a1 "$1" | grep -v '^\.$' | grep -v '^\.\.$')"
This replacement is correct, but I'm not sure that I necessarily find it
simpler. If we really are concerned about egrep usage, then

    if test -n "$(find "$1" | grep -v '^\.$')"

would suffice. But it looks like we are fairly OK with egrep in t (`git
grep 'egrep' -- t | wc -l` turns up 19 matches), so I'm not sure the
change is necessary in the first place.

Thanks,
Taylor

Re: [PATCH] test-lib-functions: avoid non POSIX ERE in test_dir_is_empty()

From: Carlo Arenas <hidden>
Date: 2021-08-26 06:28:53

On Wed, Aug 25, 2021 at 9:24 PM Taylor Blau [off-list ref] wrote:
On Wed, Aug 25, 2021 at 08:17:10PM -0700, Carlo Marcelo Arenas Belón wrote:
quoted
diff --git a/t/test-lib-functions.sh b/t/test-lib-functions.sh
index e28411bb75..2803c97df3 100644
--- a/t/test-lib-functions.sh
+++ b/t/test-lib-functions.sh
@@ -790,7 +790,7 @@ test_path_exists () {
 test_dir_is_empty () {
      test "$#" -ne 1 && BUG "1 param"
      test_path_is_dir "$1" &&
-     if test -n "$(ls -a1 "$1" | egrep -v '^\.\.?$')"
+     if test -n "$(ls -a1 "$1" | grep -v '^\.$' | grep -v '^\.\.$')"
This replacement is correct, but I'm not sure that I necessarily find it
simpler. If we really are concerned about egrep usage, then

    if test -n "$(find "$1" | grep -v '^\.$')"
Interesting idea; if having a much simpler expression is so important
then we could do instead [^.], since all use cases will be covered
(nobody is going to create a three dotted file to workaround a test
IMHO)
But it looks like we are fairly OK with egrep in t (`git
grep 'egrep' -- t | wc -l` turns up 19 matches), so I'm not sure the
change is necessary in the first place.
egrep (and also fgrep, which we intentionally support because it is
missing from some ancient AIX system[1]) will be removed in the
next[2] release of GNU grep.

Carlo

[1] 87539416fd (tests: grep portability fixes, 2008-09-30)
[2] https://git.savannah.gnu.org/cgit/grep.git/commit/?id=a9515624709865d480e3142fd959bccd1c9372d1
Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help