From f17e9fbbe919bc1f4ecaa35a9cb0869a5ec47fc0 Mon Sep 17 00:00:00 2001 From: Johannes Sixt Date: Wed, 11 Mar 2009 21:17:26 +0100 Subject: test-lib: Work around incompatible sort and find on Windows If the PATH lists the Windows system directories before the MSYS directories, Windows's own incompatible sort and find commands would be picked up. We implement these commands as functions and call the real tools by absolute path. Signed-off-by: Johannes Sixt --- t/test-lib.sh | 13 +++++++++++++ 1 file changed, 13 insertions(+) (limited to 't/test-lib.sh') diff --git a/t/test-lib.sh b/t/test-lib.sh index 638cca41e3..4eda5aba4b 100644 --- a/t/test-lib.sh +++ b/t/test-lib.sh @@ -635,3 +635,16 @@ do test_done esac done + +# Fix some commands on Windows +case $(uname -s) in +*MINGW*) + # Windows has its own (incompatible) sort and find + sort () { + /usr/bin/sort "$@" + } + find () { + /usr/bin/find "$@" + } + ;; +esac -- cgit v1.2.3 From 5397ea314f612eaaacfb13d978319afd2c724817 Mon Sep 17 00:00:00 2001 From: Johannes Sixt Date: Sat, 14 Mar 2009 22:21:27 +0100 Subject: test-lib: Work around missing sum on Windows t1002-read-tree-m-u-2way.sh uses 'sum', but it does not rely on the exact form of the sum, only that it is a hash digest. Therefore, we can sneak in 'md5sum' under the name 'sum'. Signed-off-by: Johannes Sixt --- t/test-lib.sh | 3 +++ 1 file changed, 3 insertions(+) (limited to 't/test-lib.sh') diff --git a/t/test-lib.sh b/t/test-lib.sh index 4eda5aba4b..4720b9a92b 100644 --- a/t/test-lib.sh +++ b/t/test-lib.sh @@ -646,5 +646,8 @@ case $(uname -s) in find () { /usr/bin/find "$@" } + sum () { + md5sum "$@" + } ;; esac -- cgit v1.2.3 From 4114156ae959a8ecfea62213df35fd8f778d9c4e Mon Sep 17 00:00:00 2001 From: Johannes Sixt Date: Fri, 13 Mar 2009 23:35:24 +0100 Subject: Tests on Windows: $(pwd) must return Windows-style paths Many tests pass $(pwd) in some form to git and later test that the output of git contains the correct value of $(pwd). For example, the test of 'git remote show' sets up a remote that contains $(pwd) and then the expected result must contain $(pwd). Again, MSYS-bash's path mangling kicks in: Plain $(pwd) uses the MSYS style absolute path /c/path/to/git. The test case would write this name into the 'expect' file. But when git is invoked, MSYS-bash converts this name to the Windows style path c:/path/to/git, and git would produce this form in the result; the test would fail. We fix this by passing -W to bash's pwd that produces the Windows-style path. There are a two cases that need an accompanying change: - In t1504 the value of $(pwd) becomes part of a path list. In this case, the lone 'c' in something like /foo:c:/path/to/git:/bar inhibits MSYS-bashes path mangling; IOW in this case we want the /c/path/to/git form to allow path mangling. We use $PWD instead of $(pwd), which always has the latter form. - In t6200, $(pwd) - the Windows style path - must be used to construct the expected result because that is the path form that git sees. (The change in the test itself is just for consistency: 'git fetch' always sees the Windows-style path, with or without the change.) Signed-off-by: Johannes Sixt --- t/test-lib.sh | 4 ++++ 1 file changed, 4 insertions(+) (limited to 't/test-lib.sh') diff --git a/t/test-lib.sh b/t/test-lib.sh index 4720b9a92b..0a0696abc9 100644 --- a/t/test-lib.sh +++ b/t/test-lib.sh @@ -649,5 +649,9 @@ case $(uname -s) in sum () { md5sum "$@" } + # git sees Windows-style pwd + pwd () { + builtin pwd -W + } ;; esac -- cgit v1.2.3 From a7bb394037e1c32d47d0b04da025bdbe2eb78d66 Mon Sep 17 00:00:00 2001 From: Johannes Sixt Date: Sun, 1 Mar 2009 21:04:46 +0100 Subject: test-lib: Infrastructure to test and check for prerequisites Some tests can be run only if a particular prerequisite is available. For example, some tests require that an UTF-8 locale is available. Here we introduce functions that are used in this way: 1. Insert code that checks whether the prerequisite is available. If it is, call test_set_prereq with an arbitrary tag name that subsequently can be used to check for the prerequisite: case $LANG in *.utf-8) test_set_prereq UTF8 ;; esac 2. In the calls to test_expect_success pass the tag name: test_expect_success UTF8 '...description...' '...tests...' 3. There is an auxiliary predicate that can be used anywhere to test for a prerequisite explicitly: if test_have_prereq UTF8 then ...code to be skipped if prerequisite is not available... fi Signed-off-by: Johannes Sixt --- t/test-lib.sh | 44 +++++++++++++++++++++++++++++++++++++++----- 1 file changed, 39 insertions(+), 5 deletions(-) (limited to 't/test-lib.sh') diff --git a/t/test-lib.sh b/t/test-lib.sh index 0a0696abc9..3c65cfe1ab 100644 --- a/t/test-lib.sh +++ b/t/test-lib.sh @@ -247,6 +247,31 @@ test_chmod () { git update-index --add "--chmod=$@" } +# Use test_set_prereq to tell that a particular prerequisite is available. +# The prerequisite can later be checked for in two ways: +# +# - Explicitly using test_have_prereq. +# +# - Implicitly by specifying the prerequisite tag in the calls to +# test_expect_{success,failure,code}. +# +# The single parameter is the prerequisite tag (a simple word, in all +# capital letters by convention). + +test_set_prereq () { + satisfied="$satisfied$1 " +} +satisfied=" " + +test_have_prereq () { + case $satisfied in + *" $1 "*) + : yes, have it ;; + *) + ! : nope ;; + esac +} + # You are not expected to call test_ok_ and test_failure_ directly, use # the text_expect_* functions instead. @@ -293,6 +318,11 @@ test_skip () { to_skip=t esac done + if test -z "$to_skip" && test -n "$prereq" && + ! test_have_prereq "$prereq" + then + to_skip=t + fi case "$to_skip" in t) say_color skip >&3 "skipping test: $@" @@ -306,8 +336,9 @@ test_skip () { } test_expect_failure () { + test "$#" = 3 && { prereq=$1; shift; } || prereq= test "$#" = 2 || - error "bug in the test script: not 2 parameters to test-expect-failure" + error "bug in the test script: not 2 or 3 parameters to test-expect-failure" if ! test_skip "$@" then say >&3 "checking known breakage: $2" @@ -323,8 +354,9 @@ test_expect_failure () { } test_expect_success () { + test "$#" = 3 && { prereq=$1; shift; } || prereq= test "$#" = 2 || - error "bug in the test script: not 2 parameters to test-expect-success" + error "bug in the test script: not 2 or 3 parameters to test-expect-success" if ! test_skip "$@" then say >&3 "expecting success: $2" @@ -340,8 +372,9 @@ test_expect_success () { } test_expect_code () { + test "$#" = 4 && { prereq=$1; shift; } || prereq= test "$#" = 3 || - error "bug in the test script: not 3 parameters to test-expect-code" + error "bug in the test script: not 3 or 4 parameters to test-expect-code" if ! test_skip "$@" then say >&3 "expecting exit code $1: $3" @@ -365,8 +398,9 @@ test_expect_code () { # Usage: test_external description command arguments... # Example: test_external 'Perl API' perl ../path/to/test.pl test_external () { - test "$#" -eq 3 || - error >&5 "bug in the test script: not 3 parameters to test_external" + test "$#" = 4 && { prereq=$1; shift; } || prereq= + test "$#" = 3 || + error >&5 "bug in the test script: not 3 or 4 parameters to test_external" descr="$1" shift if ! test_skip "$descr" "$@" -- cgit v1.2.3 From 704a3143d5ba0709727430154ef3dad600aad4de Mon Sep 17 00:00:00 2001 From: Johannes Sixt Date: Wed, 4 Mar 2009 22:38:24 +0100 Subject: Use prerequisite tags to skip tests that depend on symbolic links Many tests depend on that symbolic links work. This introduces a check that sets the prerequisite tag SYMLINKS if the file system supports symbolic links. Since so many tests have to check for this prerequisite, we do the check in test-lib.sh, so that we don't need to repeat the test in many scripts. To check for 'ln -s' failures, you can use a FAT partition on Linux: $ mkdosfs -C git-on-fat 1000000 $ sudo mount -o loop,uid=j6t,gid=users,shortname=winnt git-on-fat /mnt Clone git to /mnt and $ GIT_SKIP_TESTS='t0001.1[34] t0010 t1301 t403[34] t4129.[47] t5701.7 t7701.3 t9100 t9101.26 t9119 t9124.[67] t9200.10 t9600.6' \ make test (These additionally skipped tests depend on POSIX permissions that FAT on Linux does not provide.) Signed-off-by: Johannes Sixt --- t/test-lib.sh | 4 ++++ 1 file changed, 4 insertions(+) (limited to 't/test-lib.sh') diff --git a/t/test-lib.sh b/t/test-lib.sh index 3c65cfe1ab..5337e89202 100644 --- a/t/test-lib.sh +++ b/t/test-lib.sh @@ -689,3 +689,7 @@ case $(uname -s) in } ;; esac + +# test whether the filesystem supports symbolic links +ln -s x y 2>/dev/null && test -h y 2>/dev/null && test_set_prereq SYMLINKS +rm -f y -- cgit v1.2.3 From ee9fb68c392cc76cf2a56762eb1c0712ae722f08 Mon Sep 17 00:00:00 2001 From: Johannes Sixt Date: Fri, 13 Mar 2009 22:55:27 +0100 Subject: Skip tests that require a filesystem that obeys POSIX permissions Signed-off-by: Johannes Sixt --- t/test-lib.sh | 4 ++++ 1 file changed, 4 insertions(+) (limited to 't/test-lib.sh') diff --git a/t/test-lib.sh b/t/test-lib.sh index 5337e89202..f134e73566 100644 --- a/t/test-lib.sh +++ b/t/test-lib.sh @@ -687,6 +687,10 @@ case $(uname -s) in pwd () { builtin pwd -W } + # no POSIX permissions + ;; +*) + test_set_prereq POSIXPERM ;; esac -- cgit v1.2.3 From 6fd1106aa4f921dd8e80895ed837072adfd665f1 Mon Sep 17 00:00:00 2001 From: Johannes Sixt Date: Fri, 13 Mar 2009 23:00:15 +0100 Subject: t3700: Skip a test with backslashes in pathspec The test verifies that glob special characters can be escaped with backslashes. In particular, the string fo\[ou\]bar is given to git. On Windows, this does not work because backslashes are first of all directory separators, and first thing git does with a pathspec from the command line is to convert backslashes to forward slashes. Signed-off-by: Johannes Sixt --- t/test-lib.sh | 2 ++ 1 file changed, 2 insertions(+) (limited to 't/test-lib.sh') diff --git a/t/test-lib.sh b/t/test-lib.sh index f134e73566..b4b626e837 100644 --- a/t/test-lib.sh +++ b/t/test-lib.sh @@ -688,9 +688,11 @@ case $(uname -s) in builtin pwd -W } # no POSIX permissions + # backslashes in pathspec are converted to '/' ;; *) test_set_prereq POSIXPERM + test_set_prereq BSLASHPSPEC ;; esac -- cgit v1.2.3