{"thread":{"id":"597","subject":"[PATCH 1/2] Add test suite and an example.","startedAt":"2005-05-13T00:20:34Z","lastAt":"2005-05-13T00:20:34Z","messageCount":1,"participants":["Junio C Hamano"],"isPatch":true,"patchVersion":1,"patchTotal":2},"messages":[{"id":"3218","messageId":"7vk6m4asdp.fsf@assigned-by-dhcp.cox.net","threadId":"597","inReplyTo":null,"subject":"[PATCH 1/2] Add test suite and an example.","fromName":"Junio C Hamano","fromEmail":"junkio@cox.net","sentAt":"2005-05-13T00:20:34Z","receivedAt":"2005-05-13T00:20:34Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"This adds t/ directory to host test suite, a test helper\nlibarary and a basic set of tests that has already helped\nfinding a bug introduced when we added symlink support.\n\nSigned-off-by: Junio C Hamano <junkio@cox.net>\n---\n\n*** Note: please make sure chmod +x t*.sh after applying before committing.\n\nt/t0000-basic.sh |  133 +++++++++++++++++++++++++++++++++++++++++++++++++++++++\nt/test-lib.sh    |  118 ++++++++++++++++++++++++++++++++++++++++++++++++\n2 files changed, 251 insertions(+)\nt/t0000-basic.sh (. --> 100755)\nt/test-lib.sh (. --> 100755)\n\n--- a/t/t0000-basic.sh\n+++ b/t/t0000-basic.sh\n@@ -0,0 +1,133 @@\n+#!/bin/sh\n+#\n+# Copyright (c) 2005 Junio C Hamano\n+#\n+\n+test_description='Test the very basics part #1.\n+\n+The rest of the test suite does not check the basic operation of git\n+plumbing commands to work very carefully.  Their job is to concentrate\n+on tricky features that caused bugs in the past to detect regression.\n+\n+This test runs very basic features, like registering things in cache,\n+writing tree, etc.\n+\n+Note that this test *deliberately* hard-codes many expected object\n+IDs.  When object ID computation changes, like in the previous case of\n+swapping compression and hashing order, the person who is making the\n+modification *should* take notice and update the test vectors here.\n+'\n+. ./test-lib.sh\n+\n+################################################################\n+# init-db has been done in an empty repository.\n+# make sure it is empty.\n+\n+find .git/objects -type f -print >should-be-empty\n+test_expect_success 'cmp -s /dev/null should-be-empty'\n+\n+# also it should have 256 subdirectories.  257 is counting \"objects\"\n+find .git/objects -type d -print >full-of-directories\n+test_expect_success 'test \"$(wc -l full-of-directories | sed -e \"s/ .*//\")\" = 257'\n+\n+################################################################\n+# Basics of the basics\n+\n+# updating a new file without --add should fail.\n+test_expect_failure 'git-update-cache should-be-empty'\n+\n+# and with --add it should succeed, even if it is empty (it used to fail).\n+test_expect_success 'git-update-cache --add should-be-empty'\n+\n+test_expect_success 'tree=$(git-write-tree)'\n+\n+# we know the shape and contents of the tree and know the object ID for it.\n+test_expect_success 'test \"$tree\" = 7bb943559a305bdd6bdee2cef6e5df2413c3d30a'\n+\n+# Removing paths.\n+rm -f should-be-empty full-of-directories\n+test_expect_failure 'git-update-cache should-be-empty'\n+test_expect_success 'git-update-cache --remove should-be-empty'\n+\n+# Empty tree can be written with recent write-tree.\n+test_expect_success 'tree=$(git-write-tree)'\n+test_expect_success 'test \"$tree\" = 4b825dc642cb6eb9a060e54bf8d69288fbee4904'\n+\n+# Various types of objects\n+mkdir path2 path3 path3/subp3\n+for p in path0 path2/file2 path3/file3 path3/subp3/file3\n+do\n+    echo \"hello $p\" >$p\n+    ln -s \"hello $p\" ${p}sym\n+done\n+test_expect_success 'find path* ! -type d -print0 | xargs -0 -r git-update-cache --add'\n+\n+# Show them and see that matches what we expect.\n+test_expect_success 'git-ls-files --stage >current'\n+\n+cat >expected <<\\EOF\n+100644 f87290f8eb2cbbea7857214459a0739927eab154 0 path0\n+120000 15a98433ae33114b085f3eb3bb03b832b3180a01 0 path0sym\n+100644 3feff949ed00a62d9f7af97c15cd8a30595e7ac7 0 path2/file2\n+120000 d8ce161addc5173867a3c3c730924388daedbc38 0 path2/file2sym\n+100644 0aa34cae68d0878578ad119c86ca2b5ed5b28376 0 path3/file3\n+120000 8599103969b43aff7e430efea79ca4636466794f 0 path3/file3sym\n+100644 00fb5908cb97c2564a9783c0c64087333b3b464f 0 path3/subp3/file3\n+120000 6649a1ebe9e9f1c553b66f5a6e74136a07ccc57c 0 path3/subp3/file3sym\n+EOF\n+test_expect_success 'diff current expected'\n+\n+test_expect_success 'tree=$(git-write-tree)'\n+test_expect_success 'test \"$tree\" = 087704a96baf1c2d1c869a8b084481e121c88b5b'\n+\n+test_expect_success 'git-ls-tree $tree >current'\n+cat >expected <<\\EOF\n+100644\tblob\tf87290f8eb2cbbea7857214459a0739927eab154\tpath0\n+120000\tblob\t15a98433ae33114b085f3eb3bb03b832b3180a01\tpath0sym\n+040000\ttree\t58a09c23e2ca152193f2786e06986b7b6712bdbe\tpath2\n+040000\ttree\t21ae8269cacbe57ae09138dcc3a2887f904d02b3\tpath3\n+EOF\n+test_expect_success 'diff current expected'\n+\n+test_expect_success 'git-ls-tree -r $tree >current'\n+cat >expected <<\\EOF\n+100644\tblob\tf87290f8eb2cbbea7857214459a0739927eab154\tpath0\n+120000\tblob\t15a98433ae33114b085f3eb3bb03b832b3180a01\tpath0sym\n+040000\ttree\t58a09c23e2ca152193f2786e06986b7b6712bdbe\tpath2\n+100644\tblob\t3feff949ed00a62d9f7af97c15cd8a30595e7ac7\tpath2/file2\n+120000\tblob\td8ce161addc5173867a3c3c730924388daedbc38\tpath2/file2sym\n+040000\ttree\t21ae8269cacbe57ae09138dcc3a2887f904d02b3\tpath3\n+100644\tblob\t0aa34cae68d0878578ad119c86ca2b5ed5b28376\tpath3/file3\n+120000\tblob\t8599103969b43aff7e430efea79ca4636466794f\tpath3/file3sym\n+040000\ttree\t3c5e5399f3a333eddecce7a9b9465b63f65f51e2\tpath3/subp3\n+100644\tblob\t00fb5908cb97c2564a9783c0c64087333b3b464f\tpath3/subp3/file3\n+120000\tblob\t6649a1ebe9e9f1c553b66f5a6e74136a07ccc57c\tpath3/subp3/file3sym\n+EOF\n+test_expect_success 'diff current expected'\n+\n+################################################################\n+# read-tree followed by write-tree should be idempotent\n+\n+rm .git/index\n+test_expect_success 'git-read-tree $tree &&\n+test -f .git/index &&\n+newtree=$(git-write-tree) &&\n+test \"$newtree\" = \"$tree\"'\n+\n+cat >expected <<\\EOF\n+*100644->100644\tblob\tf87290f8eb2cbbea7857214459a0739927eab154->0000000000000000000000000000000000000000\tpath0\n+*120000->120000\tblob\t15a98433ae33114b085f3eb3bb03b832b3180a01->0000000000000000000000000000000000000000\tpath0sym\n+*100644->100644\tblob\t3feff949ed00a62d9f7af97c15cd8a30595e7ac7->0000000000000000000000000000000000000000\tpath2/file2\n+*120000->120000\tblob\td8ce161addc5173867a3c3c730924388daedbc38->0000000000000000000000000000000000000000\tpath2/file2sym\n+*100644->100644\tblob\t0aa34cae68d0878578ad119c86ca2b5ed5b28376->0000000000000000000000000000000000000000\tpath3/file3\n+*120000->120000\tblob\t8599103969b43aff7e430efea79ca4636466794f->0000000000000000000000000000000000000000\tpath3/file3sym\n+*100644->100644\tblob\t00fb5908cb97c2564a9783c0c64087333b3b464f->0000000000000000000000000000000000000000\tpath3/subp3/file3\n+*120000->120000\tblob\t6649a1ebe9e9f1c553b66f5a6e74136a07ccc57c->0000000000000000000000000000000000000000\tpath3/subp3/file3sym\n+EOF\n+test_expect_success 'git-diff-files >current && cmp -s current expected'\n+\n+test_expect_success 'git-update-cache --refresh'\n+\n+test_expect_success 'git-diff-files >current && cmp -s current /dev/null'\n+\n+test_done\n--- a/t/test-lib.sh\n+++ b/t/test-lib.sh\n@@ -0,0 +1,118 @@\n+#!/bin/sh\n+#\n+# Copyright (c) 2005 Junio C Hamano\n+#\n+\n+# For repeatability, reset the environment to known value.\n+LANG=C\n+TZ=UTC\n+export LANG TZ\n+unset AUTHOR_DATE\n+unset AUTHOR_EMAIL\n+unset AUTHOR_NAME\n+unset COMMIT_AUTHOR_EMAIL\n+unset COMMIT_AUTHOR_NAME\n+unset GIT_ALTERNATE_OBJECT_DIRECTORIES\n+unset GIT_AUTHOR_DATE\n+unset GIT_AUTHOR_EMAIL\n+unset GIT_AUTHOR_NAME\n+unset GIT_COMMITTER_EMAIL\n+unset GIT_COMMITTER_NAME\n+unset GIT_DIFF_OPTS\n+unset GIT_DIR\n+unset GIT_EXTERNAL_DIFF\n+unset GIT_INDEX_FILE\n+unset GIT_OBJECT_DIRECTORY\n+unset SHA1_FILE_DIRECTORIES\n+unset SHA1_FILE_DIRECTORY\n+\n+# Each test should start with something like this, after copyright notices:\n+#\n+# test_description='Description of this test...\n+# This test checks if command xyzzy does the right thing...\n+# '\n+# . ./test-lib.sh\n+\n+error () {\n+\techo >&2 \"* error: $*\"\n+\texit 1\n+}\n+\n+say () {\n+\techo \"* $*\"\n+}\n+\n+case \"${test_description}\" in\n+'')\n+\terror \"test script did not set test_description.\" ;;\n+esac\n+\n+while case \"$#\" in 0) break;; esac\n+do\n+\tcase \"$1\" in\n+\t-d|--d|--de|--deb|--debu|--debug)\n+\t\tdebug=t; shift ;;\n+\t-h|--h|--he|--hel|--help)\n+\t\tsay \"$test_description\"\n+\t\texit 0\n+\t\t;;\n+\t*)\n+\t\tbreak ;;\n+\tesac\n+done\n+test_failure=0\n+\n+test_debug () {\n+\tcase \"$debug\" in '') ;; ?*) eval \"$*\" ;; esac\n+}\n+\n+test_ok () {\n+\tsay \"$@\"\n+}\n+\n+test_failure () {\n+\tsay \"***BAD*** $@\"\n+\ttest_failure=1;\n+}\n+\n+test_expect_failure () {\n+\tsay \"expecting failure: $1\"\n+\teval \"$1\"\n+\tcase $? in\n+\t0)\ttest_failure \"did not fail as expected.\" ;;\n+\t*) \ttest_ok \"failed as expected.\" ;;\n+\tesac\n+}\n+\n+test_expect_success () {\n+\tsay \"expecting success: $1\"\n+\teval \"$1\"\n+\tcase $? in\n+\t0) \ttest_ok \"succeeded as expected.\" ;;\n+\t*)\ttest_failure \"did not succeed as expected.\" ;;\n+\tesac\n+}\n+\n+test_done () {\n+\tcase \"$test_failure\" in\n+\t0)\t\n+\t\t# we could:\n+\t\t# cd .. && rm -fr trash\n+\t\t# but that means we forbid any tests that use their own\n+\t\t# subdirectory from calling test_done without coming back\n+\t\t# to where they started from.\n+\t\texit 0 ;;\n+\t*)\texit 1 ;;\n+\tesac\n+}\n+\n+# Test the binaries we have just built.  The tests are kept in\n+# t/ subdirectory and are run in trash subdirectory.\n+PATH=$(pwd)/..:$PATH\n+\n+# Test repository\n+test=trash\n+rm -fr \"$test\"\n+mkdir \"$test\"\n+cd \"$test\"\n+git-init-db 2>/dev/null || error \"cannot run git-init-db\"\n------------------------------------------------\n\n"}]}