Skip to contentSkip to conversation

t0000: do not use export X=Y

PATCH In review Torsten Bögershausen 3 participants 10 messages Jun 15, 2016

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 t0000: do not use export X=Y

The shell syntax "export X=Y A=B" is not understood by all shells.

---
 t/t0000-basic.sh | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
t/t0000-basic.sh +2 -1
index 5c32288..10be52b 100755
@@ -53,7 +53,8 @@ run_sub_test_lib_test () {
 		# Pretend we're a test harness.  This prevents
 		# test-lib from writing the counts to a file that will
 		# later be summarized, showing spurious "failed" tests
-		export HARNESS_ACTIVE=t &&
+		HARNESS_ACTIVE=t &&
+		export HARNESS_ACTIVE &&
 		cd "$name" &&
 		cat >"$name.sh" <<-EOF &&
 		#!$SHELL_PATH
Signature · 1 line
1.8.3
#1 lore raw
Quoted 12 lines · Torsten Bögershausen

The shell syntax "export X=Y A=B" is not understood by all shells.

---
 t/t0000-basic.sh | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
t/t0000-basic.sh +0 -0
index 5c32288..10be52b 100755

t/t0000-basic.sh run_sub_test_lib_test () { · line 60

Quoted 9 lines
t/t0000-basic.sh +2 -1
@@ -53,7 +53,8 @@ run_sub_test_lib_test () {
 		# Pretend we're a test harness.  This prevents
 		# test-lib from writing the counts to a file that will
 		# later be summarized, showing spurious "failed" tests
-		export HARNESS_ACTIVE=t &&
+		HARNESS_ACTIVE=t &&
+		export HARNESS_ACTIVE &&
 		cd "$name" &&
 		cat >"$name.sh" <<-EOF &&
 		#!$SHELL_PATH

Ack. Sorry for breaking this -- I suppose test-lint would have caught me out?

Signature · 2 lines
Thomas Rast
trast@{inf,student}.ethz.ch
#2 lore raw
Quoted 18 lines · Thomas Rast
Quoted 16 lines · Torsten Bögershausen

The shell syntax "export X=Y A=B" is not understood by all shells.

---
 t/t0000-basic.sh | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
t/t0000-basic.sh +0 -1
index 5c32288..10be52b 100755
@@ -53,7 +53,8 @@ run_sub_test_lib_test () {
 		# Pretend we're a test harness.  This prevents
 		# test-lib from writing the counts to a file that will
 		# later be summarized, showing spurious "failed" tests
-		export HARNESS_ACTIVE=t &&
Quoted 8 lines

t/t0000-basic.sh run_sub_test_lib_test () { · line 60

Quoted 5 lines
t/t0000-basic.sh +2 -0
+		HARNESS_ACTIVE=t &&
+		export HARNESS_ACTIVE &&
 		cd "$name" &&
 		cat >"$name.sh" <<-EOF &&
 		#!$SHELL_PATH

Ack. Sorry for breaking this -- I suppose test-lint would have caught me out?

Or I should have. Thanks for catching.

#3 lore raw

PATCH 1/2 t9902: fix 'test A == B' to use = operator

In reply to Thomas Rast

The == operator as an alias to = is not POSIX. This doesn't actually matter for the execution of the script, because it only runs when the shell is bash. However, it trips up test-lint, so it's nicer to use the standard form.

---
 t/t9902-completion.sh | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
t/t9902-completion.sh +1 -1
index d9e3103..272a071 100755
@@ -69,7 +69,7 @@ run_completion ()
 	local -a COMPREPLY _words
 	local _cword
 	_words=( $1 )
-	test "${1: -1}" == ' ' && _words+=('')
+	test "${1: -1}" = ' ' && _words+=('')
 	(( _cword = ${#_words[@]} - 1 ))
 	__git_wrap__git_main && print_comp
 }
Signature · 1 line
1.8.3.2.947.g0347b11
#4 lore raw

PATCH 2/2 test-lint: detect 'export FOO=bar'

Some shells do not understand the one-line construct, and instead need

FOO=bar &&
export FOO

Detect this in the test-lint target.

---

Quoted 1 line · I wrote:

Torsten Bögershausen <[email protected]> writes:

[...]

Quoted 3 lines
Quoted 3 lines
(quoted diff) +2 -1
-		export HARNESS_ACTIVE=t &&
+		HARNESS_ACTIVE=t &&
+		export HARNESS_ACTIVE &&

[...]

Quoted 2 lines

Ack. Sorry for breaking this -- I suppose test-lint would have caught me out?

Well, no, not yet.

 t/check-non-portable-shell.pl | 1 +
 1 file changed, 1 insertion(+)
t/check-non-portable-shell.pl +1 -0
index 8b5a71d..45971f4 100755
@@ -21,6 +21,7 @@ while (<>) {
 	/^\s*declare\s+/ and err 'arrays/declare not portable';
 	/^\s*[^#]\s*which\s/ and err 'which is not portable (please use type)';
 	/test\s+[^=]*==/ and err '"test a == b" is not portable (please use =)';
+	/^\s*export\s+[^=]*=/ and err '"export FOO=bar" is not portable (please use FOO=bar && export FOO)';
 	# this resets our $. for each file
 	close ARGV if eof;
 }
Signature · 1 line
1.8.3.2.947.g0347b11
#5 lore raw

Re: [PATCH 2/2] test-lint: detect 'export FOO=bar'

Quoted 14 lines · Thomas Rast

Some shells do not understand the one-line construct, and instead need

FOO=bar &&
export FOO

Detect this in the test-lint target.

---

Quoted 1 line · I wrote:

Torsten Bögershausen <[email protected]> writes:

[...]

Quoted 8 lines
Quoted 3 lines
Quoted 3 lines
(quoted diff) +2 -1
-		export HARNESS_ACTIVE=t &&
+		HARNESS_ACTIVE=t &&
+		export HARNESS_ACTIVE &&

[...]

Quoted 2 lines

Ack. Sorry for breaking this -- I suppose test-lint would have caught me out?

Well, no, not yet.

Thanks for working on this

Quoted 10 lines

 t/check-non-portable-shell.pl | 1 +
 1 file changed, 1 insertion(+)
t/check-non-portable-shell.pl +0 -0
index 8b5a71d..45971f4 100755

t/check-non-portable-shell.pl while (<>) { · line 24

Quoted 4 lines
t/check-non-portable-shell.pl +1 -0
@@ -21,6 +21,7 @@ while (<>) {
 	/^\s*declare\s+/ and err 'arrays/declare not portable';
 	/^\s*[^#]\s*which\s/ and err 'which is not portable (please use type)';
 	/test\s+[^=]*==/ and err '"test a == b" is not portable (please use =)';
+	/^\s*export\s+[^=]*=/ and err '"export FOO=bar" is not portable (please use FOO=bar && export FOO)';

I have a slightly tighter reg exp in my tree, but credits should go to Thomas:

/^\s*export\s+\S+=\S+/

/Torsten

#8 lore raw

Re: [PATCH 1/2] t9902: fix 'test A == B' to use = operator

In reply to Thomas Rast
Quoted 4 lines · Thomas Rast

The == operator as an alias to = is not POSIX. This doesn't actually matter for the execution of the script, because it only runs when the shell is bash. However, it trips up test-lint, so it's nicer to use the standard form.

OK, my knee-jerk reaction was "this is only for bash" as you said, but the test-lint part I agree with.

But then test-lint _ought_ to also catch the use of "local" in the ideal world, so perhaps in the longer term we would need to treat this bash-only script differently from others anyway???

Quoted 19 lines
---
 t/t9902-completion.sh | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
t/t9902-completion.sh +1 -1
index d9e3103..272a071 100755
@@ -69,7 +69,7 @@ run_completion ()
 	local -a COMPREPLY _words
 	local _cword
 	_words=( $1 )
-	test "${1: -1}" == ' ' && _words+=('')
+	test "${1: -1}" = ' ' && _words+=('')
 	(( _cword = ${#_words[@]} - 1 ))
 	__git_wrap__git_main && print_comp
 }
#6 lore raw

Re: [PATCH 2/2] test-lint: detect 'export FOO=bar'

In reply to Torsten Bögershausen
Quoted 4 lines · Torsten Bögershausen

t/check-non-portable-shell.pl while (<>) { · line 24

Quoted 1 line
t/check-non-portable-shell.pl +1 -0
+	/^\s*export\s+[^=]*=/ and err '"export FOO=bar" is not portable (please use FOO=bar && export FOO)';

I have a slightly tighter reg exp in my tree, but credits should go to Thomas:

/^\s*export\s+\S+=\S+/

Hmm, is that correct? I would expect shells that have problems with 'export FOO=bar' to also fail on 'export FOO=' (i.e. set to empty string and export).

Signature · 2 lines
Thomas Rast
trast@{inf,student}.ethz.ch
#7 lore raw

Re: [PATCH 2/2] test-lint: detect 'export FOO=bar'

Quoted 11 lines · Thomas Rast
Quoted 4 lines · Torsten Bögershausen

t/check-non-portable-shell.pl while (<>) { · line 24

Quoted 1 line
t/check-non-portable-shell.pl +1 -0
+	/^\s*export\s+[^=]*=/ and err '"export FOO=bar" is not portable (please use FOO=bar && export FOO)';

I have a slightly tighter reg exp in my tree, but credits should go to Thomas:

/^\s*export\s+\S+=\S+/

Hmm, is that correct? I would expect shells that have problems with 'export FOO=bar' to also fail on 'export FOO=' (i.e. set to empty string and export).

Good point, thanks

#9 lore raw

Re: [PATCH 1/2] t9902: fix 'test A == B' to use = operator

In reply to Junio C Hamano
Quoted 7 lines · Junio C Hamano
Quoted 4 lines · Thomas Rast

The == operator as an alias to = is not POSIX. This doesn't actually matter for the execution of the script, because it only runs when the shell is bash. However, it trips up test-lint, so it's nicer to use the standard form.

Quoted 6 lines

OK, my knee-jerk reaction was "this is only for bash" as you said, but the test-lint part I agree with.

But then test-lint _ought_ to also catch the use of "local" in the ideal world, so perhaps in the longer term we would need to treat this bash-only script differently from others anyway???

True. I didn't really think about wider implications; I just noticed that there was an easy-to-fix complaint from test-lint :-)

Signature · 2 lines
Thomas Rast
trast@{inf,student}.ethz.ch