Re: [PATCH v4 6/7] trace.c: print env vars in trace_run_command()

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

 



Nguyễn Thái Ngọc Duy  <pclouds@xxxxxxxxx> writes:

> +test_trace() {
> +	local expected="$1"

Style: "test_trace () {" is how we start a shell function.
Portability: we do not use "local".

> +	shift
> +	GIT_TRACE=1 test-run-command "$@" run-command true 2>&1 >/dev/null | \
> +		sed 's/.* run_command: //' >actual &&
> +	echo "$expected true" >expected &&
> +	test_cmp expected actual

Consistency: everybody else in the test script contrasts "actual" vs
"expect" (they happen to be of the same length ;-); don't say
expectED just to be different.

> +}
> +
> +test_expect_success 'GIT_TRACE with environment variables' '
> +	test_trace "abc=1 def=2" env abc=1 env def=2 &&
> +	test_trace "abc=2" env abc env abc=1 env abc=2 &&
> +	test_trace "abc=2" env abc env abc=2 &&
> +	abc=1 test_trace "def=1" env abc=1 env def=1 &&

Portability: "VAR=VAL shell_function args..." does not work
everywhere, unlike "VAR=VAL command args..." that exports the set of
environment variables for just a single shot invocation of the
command.

Running this script with dash fails, even though bash does behave as
you expect.

> +	abc=1 test_trace "def=1" env abc env abc=1 env def=1 &&
> +	test_trace "def=1" env non-exist env def=1 &&
> +	test_trace "abc=2" env abc=1 env abc env abc=2 &&
> +	abc=1 def=2 test_trace "unset abc def;" env abc env def &&
> +	abc=1 def=2 test_trace "unset def; abc=3" env abc env def env abc=3 &&
> +	abc=1 test_trace "unset abc;" env abc=2 env abc
> +'

Taking them together, here is what I'll be queuing on top to make
today's push-out to pass the tests.

Thanks.

diff --git a/t/t0061-run-command.sh b/t/t0061-run-command.sh
index e6208316c3..24c92b6cd7 100755
--- a/t/t0061-run-command.sh
+++ b/t/t0061-run-command.sh
@@ -141,26 +141,41 @@ test_expect_success 'run_command outputs ' '
 	test_cmp expect actual
 '
 
-test_trace() {
-	local expected="$1"
+test_trace () {
+	expect="$1"
 	shift
 	GIT_TRACE=1 test-run-command "$@" run-command true 2>&1 >/dev/null | \
 		sed 's/.* run_command: //' >actual &&
-	echo "$expected true" >expected &&
-	test_cmp expected actual
+	echo "$expect true" >expect &&
+	test_cmp expect actual
 }
 
 test_expect_success 'GIT_TRACE with environment variables' '
 	test_trace "abc=1 def=2" env abc=1 env def=2 &&
 	test_trace "abc=2" env abc env abc=1 env abc=2 &&
 	test_trace "abc=2" env abc env abc=2 &&
-	abc=1 test_trace "def=1" env abc=1 env def=1 &&
-	abc=1 test_trace "def=1" env abc env abc=1 env def=1 &&
+	(
+		abc=1 && export abc &&
+		test_trace "def=1" env abc=1 env def=1
+	) &&
+	(
+		abc=1 && export abc &&
+		test_trace "def=1" env abc env abc=1 env def=1
+	) &&
 	test_trace "def=1" env non-exist env def=1 &&
 	test_trace "abc=2" env abc=1 env abc env abc=2 &&
-	abc=1 def=2 test_trace "unset abc def;" env abc env def &&
-	abc=1 def=2 test_trace "unset def; abc=3" env abc env def env abc=3 &&
-	abc=1 test_trace "unset abc;" env abc=2 env abc
+	(
+		abc=1 def=2 && export abc def &&
+		test_trace "unset abc def;" env abc env def
+	) &&
+	(
+		abc=1 def=2 && export abc def &&
+		test_trace "unset def; abc=3" env abc env def env abc=3
+	) &&
+	(
+		abc=1 && export abc &&
+		test_trace "unset abc;" env abc=2 env abc
+	)
 '
 
 test_done
-- 
2.16.0-rc2-179-g03f5267cd7





[Index of Archives]     [Linux Kernel Development]     [Gcc Help]     [IETF Annouce]     [DCCP]     [Netdev]     [Networking]     [Security]     [V4L]     [Bugtraq]     [Yosemite]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Linux SCSI]     [Fedora Users]

  Powered by Linux