git@vger.kernel.org mailing list mirror (one of many)
 help / color / mirror / code / Atom feed
* [PATCH 1/1] tests: Allow customization of how say_color() prints
@ 2012-12-15 19:12 Ramsay Jones
  2012-12-16  6:34 ` Junio C Hamano
  0 siblings, 1 reply; 4+ messages in thread
From: Ramsay Jones @ 2012-12-15 19:12 UTC (permalink / raw)
  To: Junio C Hamano; +Cc: GIT Mailing-list


Since commit 7bc0911d ("test-lib: Fix say_color () not to interpret
\a\b\c in the message", 11-10-2012), the "--no-color" version of
say_color() has been using the (bash builtin) printf function, rather
than echo, to print the testsuite output. Due to an intermittent (and
rare) failure of the printf builtin function on some older versions
of cygwin, this leads to several (currently 7) test failures.

In order the fix the test failures, we provide a means to customize
the function used by say_color() to print the output. The function
is customized using GIT_TEST_PRINT[_LN] variables, which are set by
default to keep the current behaviour unchanged, but may used from
(say) the config.mak file to re-instate the use of echo. This could
be done by adding the following to config.mak:

    GIT_TEST_PRINT=echo -nE
    GIT_TEST_PRINT_LN=echo -E
    export GIT_TEST_PRINT GIT_TEST_PRINT_LN

Note that the GIT_TEST_PRINT variable is used in the "--color" version
of say_color(), and does not provide the line termination character.
In contrast, the GIT_TEST_PRINT_LN variable is used by the "--no-color"
version of say_color() and does provide the line termination.

Signed-off-by: Ramsay Jones <ramsay@ramsay1.demon.co.uk>
---
 Makefile      |  6 ++++++
 t/test-lib.sh | 13 +++++++++++--
 2 files changed, 17 insertions(+), 2 deletions(-)

diff --git a/Makefile b/Makefile
index 736ecd4..4f7803e 100644
--- a/Makefile
+++ b/Makefile
@@ -2603,6 +2603,12 @@ GIT-BUILD-OPTIONS: FORCE
 ifdef GIT_TEST_OPTS
 	@echo GIT_TEST_OPTS=\''$(subst ','\'',$(subst ','\'',$(GIT_TEST_OPTS)))'\' >>$@
 endif
+ifdef GIT_TEST_PRINT
+	@echo GIT_TEST_PRINT=\''$(subst ','\'',$(subst ','\'',$(GIT_TEST_PRINT)))'\' >>$@
+endif
+ifdef GIT_TEST_PRINT_LN
+	@echo GIT_TEST_PRINT_LN=\''$(subst ','\'',$(subst ','\'',$(GIT_TEST_PRINT_LN)))'\' >>$@
+endif
 ifdef GIT_TEST_CMP
 	@echo GIT_TEST_CMP=\''$(subst ','\'',$(subst ','\'',$(GIT_TEST_CMP)))'\' >>$@
 endif
diff --git a/t/test-lib.sh b/t/test-lib.sh
index f50f834..9dcf3c1 100644
--- a/t/test-lib.sh
+++ b/t/test-lib.sh
@@ -202,6 +202,15 @@ do
 	esac
 done
 
+if test -z "$GIT_TEST_PRINT"
+then
+	GIT_TEST_PRINT="printf %s"
+fi
+if test -z "$GIT_TEST_PRINT_LN"
+then
+	GIT_TEST_PRINT_LN="printf %s\n"
+fi
+
 if test -n "$color"
 then
 	say_color () {
@@ -221,7 +230,7 @@ then
 			test -n "$quiet" && return;;
 		esac
 		shift
-		printf "%s" "$*"
+		$GIT_TEST_PRINT "$*"
 		tput sgr0
 		echo
 		)
@@ -230,7 +239,7 @@ else
 	say_color() {
 		test -z "$1" && test -n "$quiet" && return
 		shift
-		printf "%s\n" "$*"
+		$GIT_TEST_PRINT_LN "$*"
 	}
 fi
 
-- 
1.8.0

^ permalink raw reply related	[flat|nested] 4+ messages in thread

* Re: [PATCH 1/1] tests: Allow customization of how say_color() prints
  2012-12-15 19:12 [PATCH 1/1] tests: Allow customization of how say_color() prints Ramsay Jones
@ 2012-12-16  6:34 ` Junio C Hamano
  2012-12-17 22:31   ` Ramsay Jones
  0 siblings, 1 reply; 4+ messages in thread
From: Junio C Hamano @ 2012-12-16  6:34 UTC (permalink / raw)
  To: Ramsay Jones; +Cc: GIT Mailing-list

Ramsay Jones <ramsay@ramsay1.demon.co.uk> writes:

> diff --git a/t/test-lib.sh b/t/test-lib.sh
> index f50f834..9dcf3c1 100644
> --- a/t/test-lib.sh
> +++ b/t/test-lib.sh
> @@ -202,6 +202,15 @@ do
>  	esac
>  done
>  
> +if test -z "$GIT_TEST_PRINT"
> +then
> +	GIT_TEST_PRINT="printf %s"
> +fi
> +if test -z "$GIT_TEST_PRINT_LN"
> +then
> +	GIT_TEST_PRINT_LN="printf %s\n"
> +fi
> +
>  if test -n "$color"
>  then
>  	say_color () {
> @@ -221,7 +230,7 @@ then
>  			test -n "$quiet" && return;;
>  		esac
>  		shift
> -		printf "%s" "$*"
> +		$GIT_TEST_PRINT "$*"
>  		tput sgr0
>  		echo
>  		)
> @@ -230,7 +239,7 @@ else
>  	say_color() {
>  		test -z "$1" && test -n "$quiet" && return
>  		shift
> -		printf "%s\n" "$*"
> +		$GIT_TEST_PRINT_LN "$*"
>  	}
>  fi

As you said, this is ugly and also unwieldy in that I do not see an
easy way for a platform/builder to define something that needs to
pass a parameter with $IFS in it in these two variables.

Why does your printf die in the first place???

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH 1/1] tests: Allow customization of how say_color() prints
  2012-12-16  6:34 ` Junio C Hamano
@ 2012-12-17 22:31   ` Ramsay Jones
  2012-12-18  1:42     ` Junio C Hamano
  0 siblings, 1 reply; 4+ messages in thread
From: Ramsay Jones @ 2012-12-17 22:31 UTC (permalink / raw)
  To: Junio C Hamano; +Cc: GIT Mailing-list

Junio C Hamano wrote:
> Ramsay Jones <ramsay@ramsay1.demon.co.uk> writes:
> 
>> diff --git a/t/test-lib.sh b/t/test-lib.sh
>> index f50f834..9dcf3c1 100644
>> --- a/t/test-lib.sh
>> +++ b/t/test-lib.sh
>> @@ -202,6 +202,15 @@ do
>>  	esac
>>  done
>>  
>> +if test -z "$GIT_TEST_PRINT"
>> +then
>> +	GIT_TEST_PRINT="printf %s"
>> +fi
>> +if test -z "$GIT_TEST_PRINT_LN"
>> +then
>> +	GIT_TEST_PRINT_LN="printf %s\n"
>> +fi
>> +
>>  if test -n "$color"
>>  then
>>  	say_color () {
>> @@ -221,7 +230,7 @@ then
>>  			test -n "$quiet" && return;;
>>  		esac
>>  		shift
>> -		printf "%s" "$*"
>> +		$GIT_TEST_PRINT "$*"
>>  		tput sgr0
>>  		echo
>>  		)
>> @@ -230,7 +239,7 @@ else
>>  	say_color() {
>>  		test -z "$1" && test -n "$quiet" && return
>>  		shift
>> -		printf "%s\n" "$*"
>> +		$GIT_TEST_PRINT_LN "$*"
>>  	}
>>  fi
> 
> As you said, this is ugly and also unwieldy in that I do not see an
> easy way for a platform/builder to define something that needs to
> pass a parameter with $IFS in it in these two variables.

Yes, I spent 10 minutes trying to decide if I should send this patch
at all ... (ie how much public humiliation could I take :-D )

> Why does your printf die in the first place???

I really don't know. I'm not sure I will ever know. A couple of years
ago, when I was trying to debug the (harmless) "--color" spew, I found
(via google, etc) numerous accounts of similar problems, with various
workarounds for specific problems. One such account claimed that the
cause of the problem was an official "fix" from Microsoft (as part of
a service pack) which worked just fine on Windows Vista (and later) but
had this known side-effect on XP. Since it fixed the problem it was
intended to fix, even on XP, and the unfortunate "side-effect" on XP
should be quite rare, they decided to apply it on XP anyway. :(

Hmm, on reflection, it would probably be best if you just drop this patch.
I can keep it locally and apply it on top of any branch I want to test.
(Actually, it would be easier to simply revert commit 7bc0911d.)

Sorry for wasting your time.

ATB,
Ramsay Jones

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH 1/1] tests: Allow customization of how say_color() prints
  2012-12-17 22:31   ` Ramsay Jones
@ 2012-12-18  1:42     ` Junio C Hamano
  0 siblings, 0 replies; 4+ messages in thread
From: Junio C Hamano @ 2012-12-18  1:42 UTC (permalink / raw)
  To: Ramsay Jones; +Cc: GIT Mailing-list

Ramsay Jones <ramsay@ramsay1.demon.co.uk> writes:

> Junio C Hamano wrote:
> ...
>> Why does your printf die in the first place???
>
> I really don't know. ...
>
> Sorry for wasting your time.

Not a waste. I was hoping somebody (not necessarily you) may be able
to come up with a cleaner solution.  Unfortunately it hasn't
happened (yet), but discussing issues on the list is often not a
waste.

We could introduce git_test_print and git_test_println shell
functions that default to the current "printf", and let the users
override these by including a custom scriptllet from t/test-lib.sh,
or something.

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2012-12-18  1:42 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2012-12-15 19:12 [PATCH 1/1] tests: Allow customization of how say_color() prints Ramsay Jones
2012-12-16  6:34 ` Junio C Hamano
2012-12-17 22:31   ` Ramsay Jones
2012-12-18  1:42     ` Junio C Hamano

Code repositories for project(s) associated with this public inbox

	https://80x24.org/mirrors/git.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).