git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [RFC]  test-lib.sh: preprocess to use PERL_PATH
@ 2012-06-23  5:04 Torsten Bögershausen
  2012-06-23  5:22 ` Junio C Hamano
  0 siblings, 1 reply; 5+ messages in thread
From: Torsten Bögershausen @ 2012-06-23  5:04 UTC (permalink / raw)
  To: git; +Cc: tboegi

All test cases found in t/*.sh must include test-lib instead of test-lib.sh

Replace the inclusion of GIT-BUILD-OPTIONS with definitions that are filled in
during preprocessing.

The new test-lib doesn't need to to open GIT-BUILD-OPTIONS for each
test script, which speeds up the execution a bit.

Signed-off-by: Torsten Bögershausen <tboegi@web.de>
---

Note: The diff of all files in t/* is not here in this patch - the mail seems not to got through when I add
all the diffs here.

So this patch is incomplete and should show the idea.

I ran the following script to do the changes:
sedmulti.sh t/*
(where sedmulti.sh is below:)

====================
#!/bin/sh

if [ $# -lt 3 ]; then
  echo "usage sedmulti <fromtext> <totext> filename ..." >&2
        exit 1;
fi

fromtext=$1;
shift;
totext=$1;
shift;

for f in "$@"; do
  echo sed -ire "s%$fromtext%$totext%g" $f
  sed -ire "s%$fromtext%$totext%g" $f
done
===================


 .gitignore    |    1 +
 Makefile      |    4 ++++
 t/README      |    8 ++++----
 t/test-lib.sh |   11 ++++++++---
 4 files changed, 17 insertions(+), 7 deletions(-)

diff --git a/.gitignore b/.gitignore
index bf66648..62c60ce 100644
--- a/.gitignore
+++ b/.gitignore
@@ -192,6 +192,7 @@
 /test-sigchain
 /test-subprocess
 /test-svn-fe
+t/test-lib
 /common-cmds.h
 *.tar.gz
 *.dsc
diff --git a/Makefile b/Makefile
index 0914133..d540ab6 100644
--- a/Makefile
+++ b/Makefile
@@ -442,6 +442,7 @@ SCRIPT_LIB += git-rebase--interactive
 SCRIPT_LIB += git-rebase--merge
 SCRIPT_LIB += git-sh-setup
 SCRIPT_LIB += git-sh-i18n
+SCRIPT_LIB += t/test-lib
 
 SCRIPT_PERL += git-add--interactive.perl
 SCRIPT_PERL += git-difftool.perl
@@ -2018,6 +2019,9 @@ sed -e '1s|#!.*/sh|#!$(SHELL_PATH_SQ)|' \
     -e 's|@@LOCALEDIR@@|$(localedir_SQ)|g' \
     -e 's/@@NO_CURL@@/$(NO_CURL)/g' \
     -e 's/@@USE_GETTEXT_SCHEME@@/$(USE_GETTEXT_SCHEME)/g' \
+    -e 's|@@PERL_PATH@@|$(PERL_PATH)|g' \
+    -e 's|@@PYTHON_PATH@@|$(PYTHON_PATH)|g' \
+    -e 's|@@TAR@@|$(TAR)|g' \
     -e $(BROKEN_PATH_FIX) \
     $@.sh >$@+
 endef
diff --git a/t/README b/t/README
index 4c3ea25..fa23726 100644
--- a/t/README
+++ b/t/README
@@ -203,7 +203,7 @@ the top-level test script, never name the file to match the above
 pattern.  The Makefile here considers all such files as the
 top-level test script and tries to run all of them.  Care is
 especially needed if you are creating a common test library
-file, similar to test-lib.sh, because such a library file may
+file, similar to test-lib, because such a library file may
 not be suitable for standalone execution.
 
 
@@ -225,13 +225,13 @@ assignment to variable 'test_description', like this:
 	and tries to run git-ls-files with option --frotz.'
 
 
-Source 'test-lib.sh'
+Source 'test-lib'
 --------------------
 
 After assigning test_description, the test script should source
-test-lib.sh like this:
+test-lib like this:
 
-	. ./test-lib.sh
+	. ./test-lib
 
 This test harness library does the following things:
 
diff --git a/t/test-lib.sh b/t/test-lib.sh
index 9e2b711..306fcd9 100644
--- a/t/test-lib.sh
+++ b/t/test-lib.sh
@@ -46,7 +46,7 @@ EDITOR=:
 # /usr/xpg4/bin/sh and /bin/ksh to bail out.  So keep the unsets
 # deriving from the command substitution clustered with the other
 # ones.
-unset VISUAL EMAIL LANGUAGE COLUMNS $(perl -e '
+unset VISUAL EMAIL LANGUAGE COLUMNS $(@@PERL_PATH@@ -e '
 	my @env = keys %ENV;
 	my $ok = join("|", qw(
 		TRACE
@@ -107,7 +107,7 @@ export _x05 _x40 _z40 LF
 # test_description='Description of this test...
 # This test checks if command xyzzy does the right thing...
 # '
-# . ./test-lib.sh
+# . ./test-lib
 [ "x$ORIGINAL_TERM" != "xdumb" ] && (
 		TERM=$ORIGINAL_TERM &&
 		export TERM &&
@@ -492,7 +492,12 @@ GIT_CONFIG_NOSYSTEM=1
 GIT_ATTR_NOSYSTEM=1
 export PATH GIT_EXEC_PATH GIT_TEMPLATE_DIR GIT_CONFIG_NOSYSTEM GIT_ATTR_NOSYSTEM
 
-. "$GIT_BUILD_DIR"/GIT-BUILD-OPTIONS
+SHELL_PATH='@SHELL_PATH@'
+PERL_PATH='@@PERL_PATH@@'
+DIFF='@@DIFF@@'
+PYTHON_PATH='@@PYTHON_PATH@@'
+TAR='@@TAR@@'
+export PERL_PATH 
 
 if test -z "$GIT_TEST_CMP"
 then
-- 
1.7.9.1.3.gd6f4c.dirty

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

* Re: [RFC]  test-lib.sh: preprocess to use PERL_PATH
  2012-06-23  5:04 [RFC] test-lib.sh: preprocess to use PERL_PATH Torsten Bögershausen
@ 2012-06-23  5:22 ` Junio C Hamano
  2012-06-23  5:26   ` Torsten Bögershausen
  0 siblings, 1 reply; 5+ messages in thread
From: Junio C Hamano @ 2012-06-23  5:22 UTC (permalink / raw)
  To: Torsten Bögershausen; +Cc: git

Torsten Bögershausen <tboegi@web.de> writes:

> All test cases found in t/*.sh must include test-lib instead of test-lib.sh

Please don't.  That is too much churning for too little gain, I am afraid.

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

* Re: [RFC]  test-lib.sh: preprocess to use PERL_PATH
  2012-06-23  5:22 ` Junio C Hamano
@ 2012-06-23  5:26   ` Torsten Bögershausen
  2012-06-23  6:18     ` Junio C Hamano
  0 siblings, 1 reply; 5+ messages in thread
From: Torsten Bögershausen @ 2012-06-23  5:26 UTC (permalink / raw)
  To: Junio C Hamano; +Cc: git, Torsten Bögershausen

On 23.06.12 07:22, Junio C Hamano wrote:
> Torsten Bögershausen <tboegi@web.de> writes:
>
>> All test cases found in t/*.sh must include test-lib instead of test-lib.sh
> Please don't.  That is too much churning for too little gain, I am afraid.
Ok, would it be better to rename

t/test-lib.sh -> t/test-lib.sh.sh

and let the Makefile generate t/test-lib.sh?

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

* Re: [RFC]  test-lib.sh: preprocess to use PERL_PATH
  2012-06-23  5:26   ` Torsten Bögershausen
@ 2012-06-23  6:18     ` Junio C Hamano
  2012-06-23 13:11       ` Torsten Bögershausen
  0 siblings, 1 reply; 5+ messages in thread
From: Junio C Hamano @ 2012-06-23  6:18 UTC (permalink / raw)
  To: Torsten Bögershausen; +Cc: git

Torsten Bögershausen <tboegi@web.de> writes:

> On 23.06.12 07:22, Junio C Hamano wrote:
>> Torsten Bögershausen <tboegi@web.de> writes:
>>
>>> All test cases found in t/*.sh must include test-lib instead of test-lib.sh
>> Please don't.  That is too much churning for too little gain, I am afraid.
> Ok, would it be better to rename
>
> t/test-lib.sh -> t/test-lib.sh.sh
>
> and let the Makefile generate t/test-lib.sh?

It isn't as bad as the patch posted, but not very much.

There are number of a lot lower impact options before you
contemplate such a large change, given that there is only one
invocation of bare "perl" before GIT-BUILD-OPTIONS is dot-sourced.

 (1) Perhaps that use does not have any portability issues, and we
     can leave it as-is, with a comment to forbid people from
     turning into "$PERL_PATH" and be done with it?

 (2) Perhaps that use can be rewritten in such a way that it does
     not have to be done with perl in the first place?

 (3) Perhaps what that use of perl does can be delayed until we
     dot-source GIT-BUILD-OPTIONS and have $PERL_PATH defined, in
     which case we can move that use to a later position (and we can
     turn that sole use of perl into "$PERL_PATH")?

 (3) Perhaps what test-lib.sh does before it dot-sources
     GIT-BUILD-OPTIONS does not be affected if we dot-sourced
     GIT-BUILD-OPTIONS a lot earlier (and we can turn that sole use
     of perl into "$PERL_PATH")?


For example (this is not tested at all, nor I did not think it
through), a patch that moves the definition of TEST_DIRECTORY which
GIT_BUILD_DIR depends on higher, so that we can dot-source the file
a lot earlier, may look like this.


 t/test-lib.sh | 43 ++++++++++++++++++++++---------------------
 1 file changed, 22 insertions(+), 21 deletions(-)

diff --git a/t/test-lib.sh b/t/test-lib.sh
index 9e2b711..f3e7cf9 100644
--- a/t/test-lib.sh
+++ b/t/test-lib.sh
@@ -34,6 +34,26 @@ esac
 # Keep the original TERM for say_color
 ORIGINAL_TERM=$TERM
 
+# Test the binaries we have just built.  The tests are kept in
+# t/ subdirectory and are run in 'trash directory' subdirectory.
+if test -z "$TEST_DIRECTORY"
+then
+	# We allow tests to override this, in case they want to run tests
+	# outside of t/, e.g. for running tests on the test library
+	# itself.
+	TEST_DIRECTORY=$(pwd)
+fi
+if test -z "$TEST_OUTPUT_DIRECTORY"
+then
+	# Similarly, override this to store the test-results subdir
+	# elsewhere
+	TEST_OUTPUT_DIRECTORY=$TEST_DIRECTORY
+fi
+GIT_BUILD_DIR="$TEST_DIRECTORY"/..
+
+. "$GIT_BUILD_DIR"/GIT-BUILD-OPTIONS
+export PERL_PATH SHELL_PATH
+
 # For repeatability, reset the environment to known value.
 LANG=C
 LC_ALL=C
@@ -46,7 +66,7 @@ EDITOR=:
 # /usr/xpg4/bin/sh and /bin/ksh to bail out.  So keep the unsets
 # deriving from the command substitution clustered with the other
 # ones.
-unset VISUAL EMAIL LANGUAGE COLUMNS $(perl -e '
+unset VISUAL EMAIL LANGUAGE COLUMNS $("$PERL_PATH" -e '
 	my @env = keys %ENV;
 	my $ok = join("|", qw(
 		TRACE
@@ -229,7 +249,7 @@ trap 'die' EXIT
 
 # The user-facing functions are loaded from a separate file so that
 # test_perf subshells can have them too
-. "${TEST_DIRECTORY:-.}"/test-lib-functions.sh
+. "$TEST_DIRECTORY/test-lib-functions.sh"
 
 # You are not expected to call test_ok_ and test_failure_ directly, use
 # the text_expect_* functions instead.
@@ -380,23 +400,6 @@ test_done () {
 	esac
 }
 
-# Test the binaries we have just built.  The tests are kept in
-# t/ subdirectory and are run in 'trash directory' subdirectory.
-if test -z "$TEST_DIRECTORY"
-then
-	# We allow tests to override this, in case they want to run tests
-	# outside of t/, e.g. for running tests on the test library
-	# itself.
-	TEST_DIRECTORY=$(pwd)
-fi
-if test -z "$TEST_OUTPUT_DIRECTORY"
-then
-	# Similarly, override this to store the test-results subdir
-	# elsewhere
-	TEST_OUTPUT_DIRECTORY=$TEST_DIRECTORY
-fi
-GIT_BUILD_DIR="$TEST_DIRECTORY"/..
-
 if test -n "$valgrind"
 then
 	make_symlink () {
@@ -492,8 +495,6 @@ GIT_CONFIG_NOSYSTEM=1
 GIT_ATTR_NOSYSTEM=1
 export PATH GIT_EXEC_PATH GIT_TEMPLATE_DIR GIT_CONFIG_NOSYSTEM GIT_ATTR_NOSYSTEM
 
-. "$GIT_BUILD_DIR"/GIT-BUILD-OPTIONS
-
 if test -z "$GIT_TEST_CMP"
 then
 	if test -n "$GIT_TEST_CMP_USE_COPIED_CONTEXT"

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

* Re: [RFC]  test-lib.sh: preprocess to use PERL_PATH
  2012-06-23  6:18     ` Junio C Hamano
@ 2012-06-23 13:11       ` Torsten Bögershausen
  0 siblings, 0 replies; 5+ messages in thread
From: Torsten Bögershausen @ 2012-06-23 13:11 UTC (permalink / raw)
  To: Junio C Hamano; +Cc: git, Torsten Bögershausen

On 23.06.12 08:18, Junio C Hamano wrote:
> Torsten Bögershausen <tboegi@web.de> writes:
>
>> On 23.06.12 07:22, Junio C Hamano wrote:
>>> Torsten Bögershausen <tboegi@web.de> writes:
>>>
>>>> All test cases found in t/*.sh must include test-lib instead of test-lib.sh
>>> Please don't.  That is too much churning for too little gain, I am afraid.
>> Ok, would it be better to rename
>>
>> t/test-lib.sh -> t/test-lib.sh.sh
>>
>> and let the Makefile generate t/test-lib.sh?
> It isn't as bad as the patch posted, but not very much.
>
> There are number of a lot lower impact options before you
> contemplate such a large change, given that there is only one
> invocation of bare "perl" before GIT-BUILD-OPTIONS is dot-sourced.
>
>  (1) Perhaps that use does not have any portability issues, and we
>      can leave it as-is, with a comment to forbid people from
>      turning into "$PERL_PATH" and be done with it?
>
>  (2) Perhaps that use can be rewritten in such a way that it does
>      not have to be done with perl in the first place?
>
>  (3) Perhaps what that use of perl does can be delayed until we
>      dot-source GIT-BUILD-OPTIONS and have $PERL_PATH defined, in
>      which case we can move that use to a later position (and we can
>      turn that sole use of perl into "$PERL_PATH")?
>
>  (3) Perhaps what test-lib.sh does before it dot-sources
>      GIT-BUILD-OPTIONS does not be affected if we dot-sourced
>      GIT-BUILD-OPTIONS a lot earlier (and we can turn that sole use
>      of perl into "$PERL_PATH")?
>
>
> For example (this is not tested at all, nor I did not think it
> through), a patch that moves the definition of TEST_DIRECTORY which
> GIT_BUILD_DIR depends on higher, so that we can dot-source the file
> a lot earlier, may look like this.
>
>
>  t/test-lib.sh | 43 ++++++++++++++++++++++---------------------
>  1 file changed, 22 insertions(+), 21 deletions(-)
>
> diff --git a/t/test-lib.sh b/t/test-lib.sh
> index 9e2b711..f3e7cf9 100644
> --- a/t/test-lib.sh
> +++ b/t/test-lib.sh
> @@ -34,6 +34,26 @@ esac
>  # Keep the original TERM for say_color
>  ORIGINAL_TERM=$TERM
>  
> +# Test the binaries we have just built.  The tests are kept in
> +# t/ subdirectory and are run in 'trash directory' subdirectory.
> +if test -z "$TEST_DIRECTORY"
> +then
> +	# We allow tests to override this, in case they want to run tests
> +	# outside of t/, e.g. for running tests on the test library
> +	# itself.
> +	TEST_DIRECTORY=$(pwd)
> +fi
> +if test -z "$TEST_OUTPUT_DIRECTORY"
> +then
> +	# Similarly, override this to store the test-results subdir
> +	# elsewhere
> +	TEST_OUTPUT_DIRECTORY=$TEST_DIRECTORY
> +fi
> +GIT_BUILD_DIR="$TEST_DIRECTORY"/..
> +
> +. "$GIT_BUILD_DIR"/GIT-BUILD-OPTIONS
> +export PERL_PATH SHELL_PATH
> +
>  # For repeatability, reset the environment to known value.
>  LANG=C
>  LC_ALL=C
> @@ -46,7 +66,7 @@ EDITOR=:
>  # /usr/xpg4/bin/sh and /bin/ksh to bail out.  So keep the unsets
>  # deriving from the command substitution clustered with the other
>  # ones.
> -unset VISUAL EMAIL LANGUAGE COLUMNS $(perl -e '
> +unset VISUAL EMAIL LANGUAGE COLUMNS $("$PERL_PATH" -e '
>  	my @env = keys %ENV;
>  	my $ok = join("|", qw(
>  		TRACE
> @@ -229,7 +249,7 @@ trap 'die' EXIT
>  
>  # The user-facing functions are loaded from a separate file so that
>  # test_perf subshells can have them too
> -. "${TEST_DIRECTORY:-.}"/test-lib-functions.sh
> +. "$TEST_DIRECTORY/test-lib-functions.sh"
>  
>  # You are not expected to call test_ok_ and test_failure_ directly, use
>  # the text_expect_* functions instead.
> @@ -380,23 +400,6 @@ test_done () {
>  	esac
>  }
>  
> -# Test the binaries we have just built.  The tests are kept in
> -# t/ subdirectory and are run in 'trash directory' subdirectory.
> -if test -z "$TEST_DIRECTORY"
> -then
> -	# We allow tests to override this, in case they want to run tests
> -	# outside of t/, e.g. for running tests on the test library
> -	# itself.
> -	TEST_DIRECTORY=$(pwd)
> -fi
> -if test -z "$TEST_OUTPUT_DIRECTORY"
> -then
> -	# Similarly, override this to store the test-results subdir
> -	# elsewhere
> -	TEST_OUTPUT_DIRECTORY=$TEST_DIRECTORY
> -fi
> -GIT_BUILD_DIR="$TEST_DIRECTORY"/..
> -
>  if test -n "$valgrind"
>  then
>  	make_symlink () {
> @@ -492,8 +495,6 @@ GIT_CONFIG_NOSYSTEM=1
>  GIT_ATTR_NOSYSTEM=1
>  export PATH GIT_EXEC_PATH GIT_TEMPLATE_DIR GIT_CONFIG_NOSYSTEM GIT_ATTR_NOSYSTEM
>  
> -. "$GIT_BUILD_DIR"/GIT-BUILD-OPTIONS
> -
>  if test -z "$GIT_TEST_CMP"
>  then
>  	if test -n "$GIT_TEST_CMP_USE_COPIED_CONTEXT"
Excellent!
Thanks: enjoyed & tested OK both on

457f08c4777b552ad35 (where t4030 was broken when testing here)

and

>commit 9746b046e5651aa7277a0b853819e2d076d403c6
>Date:   Fri Jun 22 22:20:27 2012 -0700

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

end of thread, other threads:[~2012-06-23 13:11 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2012-06-23  5:04 [RFC] test-lib.sh: preprocess to use PERL_PATH Torsten Bögershausen
2012-06-23  5:22 ` Junio C Hamano
2012-06-23  5:26   ` Torsten Bögershausen
2012-06-23  6:18     ` Junio C Hamano
2012-06-23 13:11       ` Torsten Bögershausen

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 NNTP newsgroup(s).