From 6219bb22ba213ff75ca9cb8aa0d4debd28c34f21 Mon Sep 17 00:00:00 2001 From: Junio C Hamano Date: Mon, 9 Jun 2014 12:23:30 -0700 Subject: test: turn EXPENSIVE into a lazy prerequisite Two test scripts (t0021 and t5551) had copy & paste code to set EXPENSIVE prerequisite. Use the test_lazy_prereq helper to define them in the common t/test-lib.sh. Signed-off-by: Junio C Hamano --- t/t0021-conversion.sh | 2 -- t/t5551-http-fetch.sh | 2 -- t/test-lib.sh | 4 ++++ 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/t/t0021-conversion.sh b/t/t0021-conversion.sh index b92e6cb046..f890c54d13 100755 --- a/t/t0021-conversion.sh +++ b/t/t0021-conversion.sh @@ -190,8 +190,6 @@ test_expect_success 'required filter clean failure' ' test_must_fail git add test.fc ' -test -n "$GIT_TEST_LONG" && test_set_prereq EXPENSIVE - test_expect_success EXPENSIVE 'filter large file' ' git config filter.largefile.smudge cat && git config filter.largefile.clean cat && diff --git a/t/t5551-http-fetch.sh b/t/t5551-http-fetch.sh index afb439e09c..d69739337b 100755 --- a/t/t5551-http-fetch.sh +++ b/t/t5551-http-fetch.sh @@ -214,8 +214,6 @@ test_expect_success 'cookies stored in http.cookiefile when http.savecookies set test_cmp expect_cookies.txt cookies_tail.txt ' -test -n "$GIT_TEST_LONG" && test_set_prereq EXPENSIVE - test_expect_success EXPENSIVE 'create 50,000 tags in the repo' ' ( cd "$HTTPD_DOCUMENT_ROOT_PATH/repo.git" && diff --git a/t/test-lib.sh b/t/test-lib.sh index b25249ec4c..d70d05e1cb 100644 --- a/t/test-lib.sh +++ b/t/test-lib.sh @@ -855,6 +855,10 @@ test_lazy_prereq AUTOIDENT ' git var GIT_AUTHOR_IDENT ' +test_lazy_prereq EXPENSIVE ' + test -n "$GIT_TEST_LONG" +' + # When the tests are run as root, permission tests will report that # things are writable when they shouldn't be. test -w / || test_set_prereq SANITY -- cgit v1.2.3 From e1ecd9e3c8f800e3eab908df3e9fc4e166fca394 Mon Sep 17 00:00:00 2001 From: Junio C Hamano Date: Mon, 9 Jun 2014 13:54:25 -0700 Subject: test: turn USR_BIN_TIME into a lazy prerequisite Two test scripts (t3302 and t3419) had copy & paste code to set USR_BIN_TIME prerequisite. Use the test_lazy_prereq helper to define them in the common t/test-lib.sh. Signed-off-by: Junio C Hamano --- t/t3302-notes-index-expensive.sh | 1 - t/t3419-rebase-patch-id.sh | 1 - t/test-lib.sh | 4 ++++ 3 files changed, 4 insertions(+), 2 deletions(-) diff --git a/t/t3302-notes-index-expensive.sh b/t/t3302-notes-index-expensive.sh index e35d7811ac..dc706abe5c 100755 --- a/t/t3302-notes-index-expensive.sh +++ b/t/t3302-notes-index-expensive.sh @@ -9,7 +9,6 @@ test_description='Test commit notes index (expensive!)' test_set_prereq NOT_EXPENSIVE test -n "$GIT_NOTES_TIMING_TESTS" && test_set_prereq EXPENSIVE -test -x /usr/bin/time && test_set_prereq USR_BIN_TIME create_repo () { number_of_commits=$1 diff --git a/t/t3419-rebase-patch-id.sh b/t/t3419-rebase-patch-id.sh index e70ac10a0c..08e30b30f4 100755 --- a/t/t3419-rebase-patch-id.sh +++ b/t/t3419-rebase-patch-id.sh @@ -6,7 +6,6 @@ test_description='git rebase - test patch id computation' test_set_prereq NOT_EXPENSIVE test -n "$GIT_PATCHID_TIMING_TESTS" && test_set_prereq EXPENSIVE -test -x /usr/bin/time && test_set_prereq USR_BIN_TIME count() { diff --git a/t/test-lib.sh b/t/test-lib.sh index d70d05e1cb..884c57c30b 100644 --- a/t/test-lib.sh +++ b/t/test-lib.sh @@ -859,6 +859,10 @@ test_lazy_prereq EXPENSIVE ' test -n "$GIT_TEST_LONG" ' +test_lazy_prereq USR_BIN_TIME ' + test -x /usr/bin/time +' + # When the tests are run as root, permission tests will report that # things are writable when they shouldn't be. test -w / || test_set_prereq SANITY -- cgit v1.2.3 From ac2803b9625a9c38c1595f22da8f160969ed9625 Mon Sep 17 00:00:00 2001 From: Junio C Hamano Date: Mon, 9 Jun 2014 13:21:59 -0700 Subject: t3302: coding style updates Use "<<-END_OF_HERE_TEXT" to push the contents of here-text to the right in order to show the loop structure better. Use write_script when writing a script to be run. Use "test" (not "[ ... ]") and avoid unnecessary ";" in the middle of a line. Signed-off-by: Junio C Hamano --- t/t3302-notes-index-expensive.sh | 90 +++++++++++++++++++++------------------- 1 file changed, 47 insertions(+), 43 deletions(-) diff --git a/t/t3302-notes-index-expensive.sh b/t/t3302-notes-index-expensive.sh index dc706abe5c..aa9dbd770f 100755 --- a/t/t3302-notes-index-expensive.sh +++ b/t/t3302-notes-index-expensive.sh @@ -16,43 +16,43 @@ create_repo () { test -d .git || { git init && ( - while [ $nr -lt $number_of_commits ]; do + while test $nr -lt $number_of_commits + do nr=$(($nr+1)) mark=$(($nr+$nr)) notemark=$(($mark+1)) test_tick && - cat < $GIT_COMMITTER_DATE -data <> note_commit + cat <<-INPUT_END && + commit refs/heads/master + mark :$mark + committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE + data <>note_commit done && test_tick && - cat < $GIT_COMMITTER_DATE -data < $GIT_COMMITTER_DATE + data < output && + git log | grep "^ " >output && i=$count && - while [ $i -gt 0 ]; do + while test $i -gt 0 + do echo " commit #$i" && echo " note for commit #$i" && - i=$(($i-1)); - done > expect && + i=$(($i-1)) + done >expect && test_cmp expect output } -cat > time_notes << \EOF +write_script time_notes <<\EOF mode=$1 i=1 - while [ $i -lt $2 ]; do + while test $i -lt $2 + do case $1 in no-notes) - GIT_NOTES_REF=non-existing; export GIT_NOTES_REF - ;; + GIT_NOTES_REF=non-existing + export GIT_NOTES_REF + ;; notes) unset GIT_NOTES_REF - ;; + ;; esac - git log >/dev/null + git log i=$(($i+1)) - done + done >/dev/null EOF time_notes () { for mode in no-notes notes do echo $mode - /usr/bin/time "$SHELL_PATH" ../time_notes $mode $1 + /usr/bin/time ../time_notes $mode $1 done } @@ -118,7 +121,8 @@ do_tests () { } do_tests NOT_EXPENSIVE 10 -for count in 100 1000 10000; do +for count in 100 1000 10000 +do do_tests EXPENSIVE $count done -- cgit v1.2.3 From f23b1d06e5a7a162a7cfc5281b10580e7e3d23d6 Mon Sep 17 00:00:00 2001 From: Junio C Hamano Date: Mon, 9 Jun 2014 13:36:54 -0700 Subject: t3302: do not chdir around in the primary test process These days^Wyears we strive to do stuff in subdirectories inside subshells to avoid mistakes. Signed-off-by: Junio C Hamano --- t/t3302-notes-index-expensive.sh | 27 ++++++++++++++++++--------- 1 file changed, 18 insertions(+), 9 deletions(-) diff --git a/t/t3302-notes-index-expensive.sh b/t/t3302-notes-index-expensive.sh index aa9dbd770f..7712cf3993 100755 --- a/t/t3302-notes-index-expensive.sh +++ b/t/t3302-notes-index-expensive.sh @@ -106,18 +106,27 @@ do_tests () { pr=$1 count=$2 - test_expect_success $pr 'setup / mkdir' ' - mkdir $count && - cd $count + test_expect_success $pr "setup $count" ' + mkdir "$count" && + ( + cd "$count" && + create_repo "$count" + ) ' - test_expect_success $pr "setup $count" "create_repo $count" - - test_expect_success $pr 'notes work' "test_notes $count" - - test_expect_success USR_BIN_TIME,$pr 'notes timing with /usr/bin/time' "time_notes 100" + test_expect_success $pr 'notes work' ' + ( + cd "$count" && + test_notes "$count" + ) + ' - test_expect_success $pr 'teardown / cd ..' 'cd ..' + test_expect_success USR_BIN_TIME,$pr 'notes timing with /usr/bin/time' ' + ( + cd "$count" && + time_notes 100 + ) + ' } do_tests NOT_EXPENSIVE 10 -- cgit v1.2.3 From 19c8c4a9b70a5c896d2c88250d7f209970fdf8d0 Mon Sep 17 00:00:00 2001 From: Junio C Hamano Date: Mon, 9 Jun 2014 13:43:19 -0700 Subject: t3302: drop unnecessary NOT_EXPENSIVE pseudo-prerequisite This was only necessary because do_tests helper the script defines took its parameters in a wrong order. Just pass an empty string (or not passing the optional EXPENSIVE prerequisite) when running the test with a light-weight set of parameters and have the shell do the right thing when parsing test_expect_success helper. Signed-off-by: Junio C Hamano --- t/t3302-notes-index-expensive.sh | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/t/t3302-notes-index-expensive.sh b/t/t3302-notes-index-expensive.sh index 7712cf3993..8d44e04354 100755 --- a/t/t3302-notes-index-expensive.sh +++ b/t/t3302-notes-index-expensive.sh @@ -7,7 +7,6 @@ test_description='Test commit notes index (expensive!)' . ./test-lib.sh -test_set_prereq NOT_EXPENSIVE test -n "$GIT_NOTES_TIMING_TESTS" && test_set_prereq EXPENSIVE create_repo () { @@ -103,8 +102,7 @@ time_notes () { } do_tests () { - pr=$1 - count=$2 + count=$1 pr=${2-} test_expect_success $pr "setup $count" ' mkdir "$count" && @@ -121,7 +119,7 @@ do_tests () { ) ' - test_expect_success USR_BIN_TIME,$pr 'notes timing with /usr/bin/time' ' + test_expect_success "USR_BIN_TIME${pr:+,$pr}" 'notes timing with /usr/bin/time' ' ( cd "$count" && time_notes 100 @@ -129,10 +127,10 @@ do_tests () { ' } -do_tests NOT_EXPENSIVE 10 +do_tests 10 for count in 100 1000 10000 do - do_tests EXPENSIVE $count + do_tests "$count" EXPENSIVE done test_done -- cgit v1.2.3 From b687cd6aba394bba34ad9fb70aa33cd5cfcebc6c Mon Sep 17 00:00:00 2001 From: Junio C Hamano Date: Mon, 9 Jun 2014 14:03:10 -0700 Subject: t3419: drop unnecessary NOT_EXPENSIVE pseudo-prerequisite This was only necessary because do_tests helper the script defines took its parameters in a wrong order. Just pass an empty string (or not passing the optional EXPENSIVE prerequisite) when running the test with a light-weight set of parameters and have the shell do the right thing when parsing test_expect_success helper. Also update coding style while we are at it. Signed-off-by: Junio C Hamano --- t/t3419-rebase-patch-id.sh | 22 ++++++++-------------- 1 file changed, 8 insertions(+), 14 deletions(-) diff --git a/t/t3419-rebase-patch-id.sh b/t/t3419-rebase-patch-id.sh index 08e30b30f4..9292b499f3 100755 --- a/t/t3419-rebase-patch-id.sh +++ b/t/t3419-rebase-patch-id.sh @@ -4,11 +4,9 @@ test_description='git rebase - test patch id computation' . ./test-lib.sh -test_set_prereq NOT_EXPENSIVE test -n "$GIT_PATCHID_TIMING_TESTS" && test_set_prereq EXPENSIVE -count() -{ +count () { i=0 while test $i -lt $1 do @@ -17,8 +15,7 @@ count() done } -scramble() -{ +scramble () { i=0 while read x do @@ -27,12 +24,11 @@ scramble() echo "$x" fi i=$((($i+1) % 10)) - done < "$1" > "$1.new" + done <"$1" >"$1.new" mv -f "$1.new" "$1" } -run() -{ +run () { echo \$ "$@" /usr/bin/time "$@" >/dev/null } @@ -42,10 +38,8 @@ test_expect_success 'setup' ' git tag root ' -do_tests() -{ - pr=$1 - nlines=$2 +do_tests () { + nlines=$1 pr=${2-} test_expect_success $pr "setup: $nlines lines" " rm -f .gitattributes && @@ -102,7 +96,7 @@ do_tests() " } -do_tests NOT_EXPENSIVE 500 -do_tests EXPENSIVE 50000 +do_tests 500 +do_tests 50000 EXPENSIVE test_done -- cgit v1.2.3