{"thread":{"id":"1078","subject":"[PATCH 1/8] Factor out useful test case infrastructure from t/t6001... into t/t6000-lib.sh","startedAt":"2005-07-01T06:46:58Z","lastAt":"2005-07-01T06:46:58Z","messageCount":1,"participants":["Jon Seymour"],"isPatch":true,"patchVersion":1,"patchTotal":8},"messages":[{"id":"5520","messageId":"20050701064658.5069.qmail@blackcubes.dyndns.org","threadId":"1078","inReplyTo":null,"subject":"[PATCH 1/8] Factor out useful test case infrastructure from t/t6001... into t/t6000-lib.sh","fromName":"Jon Seymour","fromEmail":"jon.seymour@gmail.com","sentAt":"2005-07-01T06:46:58Z","receivedAt":"2005-07-01T06:46:58Z","isPatch":true,"sender":{"key":"jon.seymour@gmail.com","avatar":"https://avatars.githubusercontent.com/u/207131?v=4"},"body":"\nFunctions that are useful to other t6xxx testcases are moved into t6000-lib.sh\n\nTo use these functions in a test case, use a test-case pre-amble like:\n\n. ./test-lib.sh\n. ../t6000-lib.sh # t6xxx specific functions\n\nSigned-off-by: Jon Seymour <jon.seymour@gmail.com>\n---\n\n t/t6000-lib.sh                  |  105 +++++++++++++++++++++++++++++++++++++\n t/t6001-rev-list-merge-order.sh |  112 ---------------------------------------\n 2 files changed, 106 insertions(+), 111 deletions(-)\n create mode 100644 t/t6000-lib.sh\n\n127ff5409fda605196f4a237b1c075f3b5b2a0b6\ndiff --git a/t/t6000-lib.sh b/t/t6000-lib.sh\nnew file mode 100644\n--- /dev/null\n+++ b/t/t6000-lib.sh\n@@ -0,0 +1,105 @@\n+[ -d .git/refs/tags ] || mkdir -p .git/refs/tags\n+\n+sed_script=\"\";\n+\n+# Answer the sha1 has associated with the tag. The tag must exist in .git or .git/refs/tags\n+tag()\n+{\n+\t_tag=$1\n+\t[ -f .git/refs/tags/$_tag ] || error \"tag: \\\"$_tag\\\" does not exist\"\n+\tcat .git/refs/tags/$_tag\n+}\n+\n+# Generate a commit using the text specified to make it unique and the tree\n+# named by the tag specified.\n+unique_commit()\n+{\n+\t_text=$1\n+        _tree=$2\n+\tshift 2\n+    \techo $_text | git-commit-tree $(tag $_tree) \"$@\"\n+}\n+\n+# Save the output of a command into the tag specified. Prepend\n+# a substitution script for the tag onto the front of $sed_script\n+save_tag()\n+{\n+\t_tag=$1\t\n+\t[ -n \"$_tag\" ] || error \"usage: save_tag tag commit-args ...\"\n+\tshift 1\n+    \t\"$@\" >.git/refs/tags/$_tag\n+    \tsed_script=\"s/$(tag $_tag)/$_tag/g${sed_script+;}$sed_script\"\n+}\n+\n+# Replace unhelpful sha1 hashses with their symbolic equivalents \n+entag()\n+{\n+\tsed \"$sed_script\"\n+}\n+\n+# Execute a command after first saving, then setting the GIT_AUTHOR_EMAIL\n+# tag to a specified value. Restore the original value on return.\n+as_author()\n+{\n+\t_author=$1\n+\tshift 1\n+        _save=$GIT_AUTHOR_EMAIL\n+\n+\texport GIT_AUTHOR_EMAIL=\"$_author\"\n+\t\"$@\"\n+        export GIT_AUTHOR_EMAIL=\"$_save\"\n+}\n+\n+commit_date()\n+{\n+        _commit=$1\n+\tgit-cat-file commit $_commit | sed -n \"s/^committer .*> \\([0-9]*\\) .*/\\1/p\" \n+}\n+\n+on_committer_date()\n+{\n+    _date=$1\n+    shift 1\n+    GIT_COMMITTER_DATE=$_date \"$@\"\n+}\n+\n+# Execute a command and suppress any error output.\n+hide_error()\n+{\n+\t\"$@\" 2>/dev/null\n+}\n+\n+check_output()\n+{\n+\t_name=$1\n+\tshift 1\n+\tif eval \"$*\" | entag > $_name.actual\n+\tthen\n+\t\tdiff $_name.expected $_name.actual\n+\telse\n+\t\treturn 1;\n+\tfi\n+}\n+\n+# Turn a reasonable test description into a reasonable test name.\n+# All alphanums translated into -'s which are then compressed and stripped\n+# from front and back.\n+name_from_description()\n+{\n+        tr \"'\" '-' | tr '~`!@#$%^&*()_+={}[]|\\;:\"<>,/? ' '-' | tr -s '-' | tr '[A-Z]' '[a-z]' | sed \"s/^-*//;s/-*\\$//\"\n+}\n+\n+\n+# Execute the test described by the first argument, by eval'ing\n+# command line specified in the 2nd argument. Check the status code\n+# is zero and that the output matches the stream read from \n+# stdin.\n+test_output_expect_success()\n+{\t\n+\t_description=$1\n+        _test=$2\n+        [ $# -eq 2 ] || error \"usage: test_output_expect_success description test <<EOF ... EOF\"\n+        _name=$(echo $_description | name_from_description)\n+\tcat > $_name.expected\n+\ttest_expect_success \"$_description\" \"check_output $_name \\\"$_test\\\"\" \n+}\ndiff --git a/t/t6001-rev-list-merge-order.sh b/t/t6001-rev-list-merge-order.sh\n--- a/t/t6001-rev-list-merge-order.sh\n+++ b/t/t6001-rev-list-merge-order.sh\n@@ -6,117 +6,7 @@\n test_description='Tests git-rev-list --merge-order functionality'\n \n . ./test-lib.sh\n-\n-#\n-# TODO: move the following block (upto --- end ...) into testlib.sh\n-#\n-[ -d .git/refs/tags ] || mkdir -p .git/refs/tags\n-\n-sed_script=\"\";\n-\n-# Answer the sha1 has associated with the tag. The tag must exist in .git or .git/refs/tags\n-tag()\n-{\n-\t_tag=$1\n-\t[ -f .git/refs/tags/$_tag ] || error \"tag: \\\"$_tag\\\" does not exist\"\n-\tcat .git/refs/tags/$_tag\n-}\n-\n-# Generate a commit using the text specified to make it unique and the tree\n-# named by the tag specified.\n-unique_commit()\n-{\n-\t_text=$1\n-        _tree=$2\n-\tshift 2\n-    \techo $_text | git-commit-tree $(tag $_tree) \"$@\"\n-}\n-\n-# Save the output of a command into the tag specified. Prepend\n-# a substitution script for the tag onto the front of $sed_script\n-save_tag()\n-{\n-\t_tag=$1\t\n-\t[ -n \"$_tag\" ] || error \"usage: save_tag tag commit-args ...\"\n-\tshift 1\n-    \t\"$@\" >.git/refs/tags/$_tag\n-    \tsed_script=\"s/$(tag $_tag)/$_tag/g${sed_script+;}$sed_script\"\n-}\n-\n-# Replace unhelpful sha1 hashses with their symbolic equivalents \n-entag()\n-{\n-\tsed \"$sed_script\"\n-}\n-\n-# Execute a command after first saving, then setting the GIT_AUTHOR_EMAIL\n-# tag to a specified value. Restore the original value on return.\n-as_author()\n-{\n-\t_author=$1\n-\tshift 1\n-        _save=$GIT_AUTHOR_EMAIL\n-\n-\texport GIT_AUTHOR_EMAIL=\"$_author\"\n-\t\"$@\"\n-        export GIT_AUTHOR_EMAIL=\"$_save\"\n-}\n-\n-commit_date()\n-{\n-        _commit=$1\n-\tgit-cat-file commit $_commit | sed -n \"s/^committer .*> \\([0-9]*\\) .*/\\1/p\" \n-}\n-\n-on_committer_date()\n-{\n-    _date=$1\n-    shift 1\n-    GIT_COMMITTER_DATE=$_date \"$@\"\n-}\n-\n-# Execute a command and suppress any error output.\n-hide_error()\n-{\n-\t\"$@\" 2>/dev/null\n-}\n-\n-check_output()\n-{\n-\t_name=$1\n-\tshift 1\n-\tif eval \"$*\" | entag > $_name.actual\n-\tthen\n-\t\tdiff $_name.expected $_name.actual\n-\telse\n-\t\treturn 1;\n-\tfi\n-}\n-\n-# Turn a reasonable test description into a reasonable test name.\n-# All alphanums translated into -'s which are then compressed and stripped\n-# from front and back.\n-name_from_description()\n-{\n-        tr \"'\" '-' | tr '~`!@#$%^&*()_+={}[]|\\;:\"<>,/? ' '-' | tr -s '-' | tr '[A-Z]' '[a-z]' | sed \"s/^-*//;s/-*\\$//\"\n-}\n-\n-\n-# Execute the test described by the first argument, by eval'ing\n-# command line specified in the 2nd argument. Check the status code\n-# is zero and that the output matches the stream read from \n-# stdin.\n-test_output_expect_success()\n-{\t\n-\t_description=$1\n-        _test=$2\n-        [ $# -eq 2 ] || error \"usage: test_output_expect_success description test <<EOF ... EOF\"\n-        _name=$(echo $_description | name_from_description)\n-\tcat > $_name.expected\n-\ttest_expect_success \"$_description\" \"check_output $_name \\\"$_test\\\"\" \n-}\n-\n-# --- end of stuff to move ---\n+. ../t6000-lib.sh # t6xxx specific functions\n \n # test-case specific test function\n check_adjacency()\n------------\n"}]}