{"thread":{"id":"8601","subject":"[StGIT PATCH] Update test-lib.sh from current git.","startedAt":"2007-06-14T21:15:27Z","lastAt":"2007-06-14T21:15:27Z","messageCount":1,"participants":["Yann Dirson"],"isPatch":true,"patchVersion":1,"patchTotal":null},"messages":[{"id":"45092","messageId":"20070614211527.7877.62502.stgit@gandelf.nowhere.earth","threadId":"8601","inReplyTo":null,"subject":"[StGIT PATCH] Update test-lib.sh from current git.","fromName":"Yann Dirson","fromEmail":"ydirson@altern.org","sentAt":"2007-06-14T21:15:27Z","receivedAt":"2007-06-14T21:15:27Z","isPatch":true,"sender":{"key":"ydirson@altern.org","avatar":"https://avatars.githubusercontent.com/u/1190950?v=4"},"body":"Updated with changes to git up to rev\n664368886781b7c070233c002597b84628eec571, including:\n\n* GIT_SKIP_TESTS support, useful to run the testsuite bypassing tests\nknown to fail\n* test_tick utility function to forge realistic commit dates\n* deprecation of git-init-db in favor of git-init\n* more environment safety cleanups\n\nSigned-off-by: Yann Dirson <ydirson@altern.org>\n---\n\n t/test-lib.sh |  128 ++++++++++++++++++++++++++++++++++++++++++++++++---------\n 1 files changed, 107 insertions(+), 21 deletions(-)\n\ndiff --git a/t/test-lib.sh b/t/test-lib.sh\nold mode 100755\nnew mode 100644\nindex d50a3ba..4bb00fb\n--- a/t/test-lib.sh\n+++ b/t/test-lib.sh\n@@ -10,11 +10,14 @@ LC_ALL=C\n PAGER=cat\n TZ=UTC\n export LANG LC_ALL PAGER TZ\n+EDITOR=:\n+VISUAL=:\n unset AUTHOR_DATE\n unset AUTHOR_EMAIL\n unset AUTHOR_NAME\n unset COMMIT_AUTHOR_EMAIL\n unset COMMIT_AUTHOR_NAME\n+unset EMAIL\n unset GIT_ALTERNATE_OBJECT_DIRECTORIES\n unset GIT_AUTHOR_DATE\n #GIT_AUTHOR_EMAIL=author@example.com\n@@ -29,8 +32,24 @@ unset GIT_INDEX_FILE\n unset GIT_OBJECT_DIRECTORY\n unset SHA1_FILE_DIRECTORIES\n unset SHA1_FILE_DIRECTORY\n+GIT_MERGE_VERBOSITY=5\n+export GIT_MERGE_VERBOSITY\n export GIT_AUTHOR_EMAIL GIT_AUTHOR_NAME\n export GIT_COMMITTER_EMAIL GIT_COMMITTER_NAME\n+export EDITOR VISUAL\n+\n+# Protect ourselves from common misconfiguration to export\n+# CDPATH into the environment\n+unset CDPATH\n+\n+case $(echo $GIT_TRACE |tr \"[A-Z]\" \"[a-z]\") in\n+\t1|2|true)\n+\t\techo \"* warning: Some tests will not work if GIT_TRACE\" \\\n+\t\t\t\"is set as to trace on STDERR ! *\"\n+\t\techo \"* warning: Please set GIT_TRACE to something\" \\\n+\t\t\t\"other than 1, 2 or true ! *\"\n+\t\t;;\n+esac\n \n # Each test should start with something like this, after copyright notices:\n #\n@@ -83,6 +102,17 @@ test_count=0\n \n trap 'echo >&5 \"FATAL: Unexpected exit with code $?\"; exit 1' exit\n \n+test_tick () {\n+\tif test -z \"${test_tick+set}\"\n+\tthen\n+\t\ttest_tick=1112911993\n+\telse\n+\t\ttest_tick=$(($test_tick + 60))\n+\tfi\n+\tGIT_COMMITTER_DATE=\"$test_tick -0700\"\n+\tGIT_AUTHOR_DATE=\"$test_tick -0700\"\n+\texport GIT_COMMITTER_DATE GIT_AUTHOR_DATE\n+}\n \n # You are not expected to call test_ok_ and test_failure_ directly, use\n # the text_expect_* functions instead.\n@@ -112,43 +142,79 @@ test_run_ () {\n \treturn 0\n }\n \n+test_skip () {\n+\tthis_test=$(expr \"./$0\" : '.*/\\(t[0-9]*\\)-[^/]*$')\n+\tthis_test=\"$this_test.$(expr \"$test_count\" + 1)\"\n+\tto_skip=\n+\tfor skp in $GIT_SKIP_TESTS\n+\tdo\n+\t\tcase \"$this_test\" in\n+\t\t$skp)\n+\t\t\tto_skip=t\n+\t\tesac\n+\tdone\n+\tcase \"$to_skip\" in\n+\tt)\n+\t\tsay >&3 \"skipping test: $@\"\n+\t\ttest_count=$(expr \"$test_count\" + 1)\n+\t\tsay \"skip $test_count: $1\"\n+\t\t: true\n+\t\t;;\n+\t*)\n+\t\tfalse\n+\t\t;;\n+\tesac\n+}\n+\n test_expect_failure () {\n \ttest \"$#\" = 2 ||\n \terror \"bug in the test script: not 2 parameters to test-expect-failure\"\n-\tsay >&3 \"expecting failure: $2\"\n-\ttest_run_ \"$2\"\n-\tif [ \"$?\" = 0 -a \"$eval_ret\" != 0 ]\n+\tif ! test_skip \"$@\"\n \tthen\n-\t\ttest_ok_ \"$1\"\n-\telse\n-\t\ttest_failure_ \"$@\"\n+\t\tsay >&3 \"expecting failure: $2\"\n+\t\ttest_run_ \"$2\"\n+\t\tif [ \"$?\" = 0 -a \"$eval_ret\" != 0 -a \"$eval_ret\" -lt 129 ]\n+\t\tthen\n+\t\t\ttest_ok_ \"$1\"\n+\t\telse\n+\t\t\ttest_failure_ \"$@\"\n+\t\tfi\n \tfi\n+\techo >&3 \"\"\n }\n \n test_expect_success () {\n \ttest \"$#\" = 2 ||\n \terror \"bug in the test script: not 2 parameters to test-expect-success\"\n-\tsay >&3 \"expecting success: $2\"\n-\ttest_run_ \"$2\"\n-\tif [ \"$?\" = 0 -a \"$eval_ret\" = 0 ]\n+\tif ! test_skip \"$@\"\n \tthen\n-\t\ttest_ok_ \"$1\"\n-\telse\n-\t\ttest_failure_ \"$@\"\n+\t\tsay >&3 \"expecting success: $2\"\n+\t\ttest_run_ \"$2\"\n+\t\tif [ \"$?\" = 0 -a \"$eval_ret\" = 0 ]\n+\t\tthen\n+\t\t\ttest_ok_ \"$1\"\n+\t\telse\n+\t\t\ttest_failure_ \"$@\"\n+\t\tfi\n \tfi\n+\techo >&3 \"\"\n }\n \n test_expect_code () {\n \ttest \"$#\" = 3 ||\n \terror \"bug in the test script: not 3 parameters to test-expect-code\"\n-\tsay >&3 \"expecting exit code $1: $3\"\n-\ttest_run_ \"$3\"\n-\tif [ \"$?\" = 0 -a \"$eval_ret\" = \"$1\" ]\n+\tif ! test_skip \"$@\"\n \tthen\n-\t\ttest_ok_ \"$2\"\n-\telse\n-\t\ttest_failure_ \"$@\"\n+\t\tsay >&3 \"expecting exit code $1: $3\"\n+\t\ttest_run_ \"$3\"\n+\t\tif [ \"$?\" = 0 -a \"$eval_ret\" = \"$1\" ]\n+\t\tthen\n+\t\t\ttest_ok_ \"$2\"\n+\t\telse\n+\t\t\ttest_failure_ \"$@\"\n+\t\tfi\n \tfi\n+\techo >&3 \"\"\n }\n \n # Most tests can use the created repository, but some amy need to create more.\n@@ -160,8 +226,8 @@ test_create_repo () {\n \trepo=\"$1\"\n \tmkdir \"$repo\"\n \tcd \"$repo\" || error \"Cannot setup test environment\"\n-\tgit-init-db >&3 2>&4 ||\n-\terror \"cannot run git-init-db -- have you installed git-core?\"\n+\tgit-init >/dev/null 2>&1 ||\n+\terror \"cannot run git-init -- have you installed git-core?\"\n \tmv .git/hooks .git/hooks-disabled\n \techo \"empty start\" |\n \tgit-commit-tree `git-write-tree` >.git/refs/heads/master 2>&4 ||\n@@ -195,7 +261,8 @@ test_done () {\n # t/ subdirectory and are run in trash subdirectory.\n PATH=$(pwd)/..:$PATH\n HOME=$(pwd)/trash\n-export PATH HOME\n+GIT_CONFIG=.git/config\n+export PATH HOME GIT_CONFIG\n \n \n # Test repository\n@@ -203,3 +270,22 @@ test=trash\n rm -fr \"$test\"\n test_create_repo $test\n cd \"$test\"\n+\n+this_test=$(expr \"./$0\" : '.*/\\(t[0-9]*\\)-[^/]*$')\n+for skp in $GIT_SKIP_TESTS\n+do\n+\tto_skip=\n+\tfor skp in $GIT_SKIP_TESTS\n+\tdo\n+\t\tcase \"$this_test\" in\n+\t\t$skp)\n+\t\t\tto_skip=t\n+\t\tesac\n+\tdone\n+\tcase \"$to_skip\" in\n+\tt)\n+\t\tsay >&3 \"skipping test $this_test altogether\"\n+\t\tsay \"skip all tests in $this_test\"\n+\t\ttest_done\n+\tesac\n+done\n"}]}