diff options
author | Junio C Hamano <gitster@pobox.com> | 2010-11-17 15:01:00 -0800 |
---|---|---|
committer | Junio C Hamano <gitster@pobox.com> | 2010-11-17 15:01:00 -0800 |
commit | 0510480510b181216d565ebcedea471d50c200b1 (patch) | |
tree | bf7beeb2fc8eca0e3692aedd15d9589b3de8ea86 /t | |
parent | ba0254cb32537b7a7e92854a51256475ee83cdda (diff) | |
parent | d7c411b71d727600d2f031fec9723873ae93c1c7 (diff) | |
download | git-0510480510b181216d565ebcedea471d50c200b1.tar.gz git-0510480510b181216d565ebcedea471d50c200b1.tar.xz |
Merge branch 'jk/push-progress'
* jk/push-progress:
push: pass --progress down to git-pack-objects
t5523-push-upstream: test progress messages
t5523-push-upstream: add function to ensure fresh upstream repo
test_terminal: ensure redirections work reliably
test_terminal: catch use without TTY prerequisite
test-lib: allow test code to check the list of declared prerequisites
tests: test terminal output to both stdout and stderr
tests: factor out terminal handling from t7006
Diffstat (limited to 't')
-rw-r--r-- | t/lib-terminal.sh | 19 | ||||
-rwxr-xr-x | t/t5523-push-upstream.sh | 44 | ||||
-rwxr-xr-x | t/t7006-pager.sh | 38 | ||||
-rw-r--r-- | t/test-lib.sh | 26 | ||||
-rwxr-xr-x | t/test-terminal.perl (renamed from t/t7006/test-terminal.perl) | 31 |
5 files changed, 107 insertions, 51 deletions
diff --git a/t/lib-terminal.sh b/t/lib-terminal.sh new file mode 100644 index 000000000..c383b57ed --- /dev/null +++ b/t/lib-terminal.sh @@ -0,0 +1,19 @@ +#!/bin/sh + +test_expect_success 'set up terminal for tests' ' + if + test_have_prereq PERL && + "$PERL_PATH" "$TEST_DIRECTORY"/test-terminal.perl \ + sh -c "test -t 1 && test -t 2" + then + test_set_prereq TTY && + test_terminal () { + if ! test_declared_prereq TTY + then + echo >&4 "test_terminal: need to declare TTY prerequisite" + return 127 + fi + "$PERL_PATH" "$TEST_DIRECTORY"/test-terminal.perl "$@" + } + fi +' diff --git a/t/t5523-push-upstream.sh b/t/t5523-push-upstream.sh index 00da70763..c229fe68f 100755 --- a/t/t5523-push-upstream.sh +++ b/t/t5523-push-upstream.sh @@ -2,9 +2,14 @@ test_description='push with --set-upstream' . ./test-lib.sh +. "$TEST_DIRECTORY"/lib-terminal.sh + +ensure_fresh_upstream() { + rm -rf parent && git init --bare parent +} test_expect_success 'setup bare parent' ' - git init --bare parent && + ensure_fresh_upstream && git remote add upstream parent ' @@ -66,4 +71,41 @@ test_expect_success 'push -u HEAD' ' check_config headbranch upstream refs/heads/headbranch ' +test_expect_success TTY 'progress messages go to tty' ' + ensure_fresh_upstream && + + test_terminal git push -u upstream master >out 2>err && + grep "Writing objects" err +' + +test_expect_success 'progress messages do not go to non-tty' ' + ensure_fresh_upstream && + + # skip progress messages, since stderr is non-tty + git push -u upstream master >out 2>err && + ! grep "Writing objects" err +' + +test_expect_success 'progress messages go to non-tty (forced)' ' + ensure_fresh_upstream && + + # force progress messages to stderr, even though it is non-tty + git push -u --progress upstream master >out 2>err && + grep "Writing objects" err +' + +test_expect_success TTY 'push -q suppresses progress' ' + ensure_fresh_upstream && + + test_terminal git push -u -q upstream master >out 2>err && + ! grep "Writing objects" err +' + +test_expect_failure TTY 'push --no-progress suppresses progress' ' + ensure_fresh_upstream && + + test_terminal git push -u --no-progress upstream master >out 2>err && + ! grep "Writing objects" err +' + test_done diff --git a/t/t7006-pager.sh b/t/t7006-pager.sh index fb744e3c4..5641b5955 100755 --- a/t/t7006-pager.sh +++ b/t/t7006-pager.sh @@ -4,42 +4,13 @@ test_description='Test automatic use of a pager.' . ./test-lib.sh . "$TEST_DIRECTORY"/lib-pager.sh +. "$TEST_DIRECTORY"/lib-terminal.sh cleanup_fail() { echo >&2 cleanup failed (exit 1) } -test_expect_success 'set up terminal for tests' ' - rm -f stdout_is_tty || - cleanup_fail && - - if test -t 1 - then - >stdout_is_tty - elif - test_have_prereq PERL && - "$PERL_PATH" "$TEST_DIRECTORY"/t7006/test-terminal.perl \ - sh -c "test -t 1" - then - >test_terminal_works - fi -' - -if test -e stdout_is_tty -then - test_terminal() { "$@"; } - test_set_prereq TTY -elif test -e test_terminal_works -then - test_terminal() { - "$PERL_PATH" "$TEST_DIRECTORY"/t7006/test-terminal.perl "$@" - } - test_set_prereq TTY -else - say "# no usable terminal, so skipping some tests" -fi - test_expect_success 'setup' ' unset GIT_PAGER GIT_PAGER_IN_USE; test_might_fail git config --unset core.pager && @@ -213,11 +184,6 @@ test_expect_success 'color when writing to a file intended for a pager' ' colorful colorful.log ' -if test_have_prereq SIMPLEPAGER && test_have_prereq TTY -then - test_set_prereq SIMPLEPAGERTTY -fi - # Use this helper to make it easy for the caller of your # terminal-using function to specify whether it should fail. # If you write @@ -253,7 +219,7 @@ parse_args() { test_default_pager() { parse_args "$@" - $test_expectation SIMPLEPAGERTTY "$cmd - default pager is used by default" " + $test_expectation SIMPLEPAGER,TTY "$cmd - default pager is used by default" " unset PAGER GIT_PAGER; test_might_fail git config --unset core.pager && rm -f default_pager_used || diff --git a/t/test-lib.sh b/t/test-lib.sh index bbe79e0fc..744f4364c 100644 --- a/t/test-lib.sh +++ b/t/test-lib.sh @@ -366,6 +366,15 @@ test_have_prereq () { test $total_prereq = $ok_prereq } +test_declared_prereq () { + case ",$test_prereq," in + *,$1,*) + return 0 + ;; + esac + return 1 +} + # You are not expected to call test_ok_ and test_failure_ directly, use # the text_expect_* functions instead. @@ -418,17 +427,17 @@ test_skip () { break esac done - if test -z "$to_skip" && test -n "$prereq" && - ! test_have_prereq "$prereq" + if test -z "$to_skip" && test -n "$test_prereq" && + ! test_have_prereq "$test_prereq" then to_skip=t fi case "$to_skip" in t) of_prereq= - if test "$missing_prereq" != "$prereq" + if test "$missing_prereq" != "$test_prereq" then - of_prereq=" of $prereq" + of_prereq=" of $test_prereq" fi say_color skip >&3 "skipping test: $@" @@ -442,9 +451,10 @@ test_skip () { } test_expect_failure () { - test "$#" = 3 && { prereq=$1; shift; } || prereq= + test "$#" = 3 && { test_prereq=$1; shift; } || test_prereq= test "$#" = 2 || error "bug in the test script: not 2 or 3 parameters to test-expect-failure" + export test_prereq if ! test_skip "$@" then say >&3 "checking known breakage: $2" @@ -460,9 +470,10 @@ test_expect_failure () { } test_expect_success () { - test "$#" = 3 && { prereq=$1; shift; } || prereq= + test "$#" = 3 && { test_prereq=$1; shift; } || test_prereq= test "$#" = 2 || error "bug in the test script: not 2 or 3 parameters to test-expect-success" + export test_prereq if ! test_skip "$@" then say >&3 "expecting success: $2" @@ -504,11 +515,12 @@ test_expect_code () { # Usage: test_external description command arguments... # Example: test_external 'Perl API' perl ../path/to/test.pl test_external () { - test "$#" = 4 && { prereq=$1; shift; } || prereq= + test "$#" = 4 && { test_prereq=$1; shift; } || test_prereq= test "$#" = 3 || error >&5 "bug in the test script: not 3 or 4 parameters to test_external" descr="$1" shift + export test_prereq if ! test_skip "$descr" "$@" then # Announce the script to reduce confusion about the diff --git a/t/t7006/test-terminal.perl b/t/test-terminal.perl index 6b5f22ae4..ee01eb957 100755 --- a/t/t7006/test-terminal.perl +++ b/t/test-terminal.perl @@ -5,14 +5,15 @@ use warnings; use IO::Pty; use File::Copy; -# Run @$argv in the background with stdout redirected to $out. +# Run @$argv in the background with stdio redirected to $out and $err. sub start_child { - my ($argv, $out) = @_; + my ($argv, $out, $err) = @_; my $pid = fork; if (not defined $pid) { die "fork failed: $!" } elsif ($pid == 0) { open STDOUT, ">&", $out; + open STDERR, ">&", $err; close $out; exec(@$argv) or die "cannot exec '$argv->[0]': $!" } @@ -48,12 +49,28 @@ sub xsendfile { copy($in, $out, 4096) or $!{EIO} or die "cannot copy from child: $!"; } +sub copy_stdio { + my ($out, $err) = @_; + my $pid = fork; + defined $pid or die "fork failed: $!"; + if (!$pid) { + close($out); + xsendfile(\*STDERR, $err); + exit 0; + } + close($err); + xsendfile(\*STDOUT, $out); + finish_child($pid) == 0 + or exit 1; +} + if ($#ARGV < 1) { die "usage: test-terminal program args"; } -my $master = new IO::Pty; -my $slave = $master->slave; -my $pid = start_child(\@ARGV, $slave); -close $slave; -xsendfile(\*STDOUT, $master); +my $master_out = new IO::Pty; +my $master_err = new IO::Pty; +my $pid = start_child(\@ARGV, $master_out->slave, $master_err->slave); +close $master_out->slave; +close $master_err->slave; +copy_stdio($master_out, $master_err); exit(finish_child($pid)); |