Merge branch 'cl/t9001-cleanup' into maint
authorJunio C Hamano <gitster@pobox.com>
Thu, 22 Mar 2018 21:24:13 +0000 (14:24 -0700)
committerJunio C Hamano <gitster@pobox.com>
Thu, 22 Mar 2018 21:24:13 +0000 (14:24 -0700)
Test clean-up.

* cl/t9001-cleanup:
t9001: use existing helper in send-email test

1  2 
t/t9001-send-email.sh
diff --combined t/t9001-send-email.sh
index 4d261c2a9c2a8081b07ee8db39d0983f0a470341,f75698016fa90123724e10b507e686e93ae63aea..81869d89133a55b8e2d1fe676ff217636466f66f
@@@ -6,6 -6,12 +6,12 @@@ test_description='git send-email
  # May be altered later in the test
  PREREQ="PERL"
  
+ replace_variable_fields () {
+       sed     -e "s/^\(Date:\).*/\1 DATE-STRING/" \
+               -e "s/^\(Message-Id:\).*/\1 MESSAGE-ID-STRING/" \
+               -e "s/^\(X-Mailer:\).*/\1 X-MAILER-STRING/"
+ }
  test_expect_success $PREREQ 'prepare reference tree' '
        echo "1A quick brown fox jumps over the" >file &&
        echo "lazy dog" >>file &&
@@@ -50,7 -56,7 +56,7 @@@ test_no_confirm () 
                --smtp-server="$(pwd)/fake.sendmail" \
                $@ \
                $patches >stdout &&
 -              test_must_fail grep "Send this email" stdout &&
 +              ! grep "Send this email" stdout &&
                >no_confirm_okay
  }
  
@@@ -149,7 -155,6 +155,7 @@@ cat >expected-cc <<\EO
  !three@example.com!
  !four@example.com!
  !five@example.com!
 +!six@example.com!
  EOF
  "
  
@@@ -160,11 -165,9 +166,11 @@@ test_expect_success $PREREQ 'cc traile
        Test Cc: trailers.
  
        Cc: one@example.com
 -      Cc: <two@example.com> # this is part of the name
 -      Cc: <three@example.com>, <four@example.com> # not.five@example.com
 -      Cc: "Some # Body" <five@example.com> [part.of.name.too]
 +      Cc: <two@example.com> # trailing comments are ignored
 +      Cc: <three@example.com>, <not.four@example.com> one address per line
 +      Cc: "Some # Body" <four@example.com> [ <also.a.comment> ]
 +      Cc: five@example.com # not.six@example.com
 +      Cc: six@example.com, not.seven@example.com
        EOF
        clean_fake_sendmail &&
        git send-email -1 --to=recipient@example.com \
@@@ -296,10 -299,7 +302,7 @@@ test_expect_success $PREREQ 'Show all h
                --bcc=bcc@example.com \
                --in-reply-to="<unique-message-id@example.com>" \
                --smtp-server relay.example.com \
-               $patches |
-       sed     -e "s/^\(Date:\).*/\1 DATE-STRING/" \
-               -e "s/^\(Message-Id:\).*/\1 MESSAGE-ID-STRING/" \
-               -e "s/^\(X-Mailer:\).*/\1 X-MAILER-STRING/" \
+               $patches | replace_variable_fields \
                >actual-show-all-headers &&
        test_cmp expected-show-all-headers actual-show-all-headers
  '
@@@ -554,12 -554,6 +557,6 @@@ Result: O
  EOF
  "
  
- replace_variable_fields () {
-       sed     -e "s/^\(Date:\).*/\1 DATE-STRING/" \
-               -e "s/^\(Message-Id:\).*/\1 MESSAGE-ID-STRING/" \
-               -e "s/^\(X-Mailer:\).*/\1 X-MAILER-STRING/"
- }
  test_suppression () {
        git send-email \
                --dry-run \
@@@ -1266,7 -1260,7 +1263,7 @@@ test_expect_success $PREREQ 'asks abou
        grep email-using-8bit stdout &&
        grep "Which 8bit encoding" stdout &&
        egrep "Content|MIME" msgtxt1 >actual &&
 -      test_cmp actual content-type-decl
 +      test_cmp content-type-decl actual
  '
  
  test_expect_success $PREREQ 'sendemail.8bitEncoding works' '
                        --smtp-server="$(pwd)/fake.sendmail" \
                        email-using-8bit >stdout &&
        egrep "Content|MIME" msgtxt1 >actual &&
 -      test_cmp actual content-type-decl
 +      test_cmp content-type-decl actual
  '
  
  test_expect_success $PREREQ '--8bit-encoding overrides sendemail.8bitEncoding' '
                        --8bit-encoding=UTF-8 \
                        email-using-8bit >stdout &&
        egrep "Content|MIME" msgtxt1 >actual &&
 -      test_cmp actual content-type-decl
 +      test_cmp content-type-decl actual
  '
  
  test_expect_success $PREREQ 'setup expect' '
@@@ -1917,52 -1911,4 +1914,52 @@@ test_expect_success $PREREQ 'leading an
        test_cmp expected-list actual-list
  '
  
 +test_expect_success $PREREQ 'invoke hook' '
 +      mkdir -p .git/hooks &&
 +
 +      write_script .git/hooks/sendemail-validate <<-\EOF &&
 +      # test that we have the correct environment variable, pwd, and
 +      # argument
 +      case "$GIT_DIR" in
 +      *.git)
 +              true
 +              ;;
 +      *)
 +              false
 +              ;;
 +      esac &&
 +      test -f 0001-add-master.patch &&
 +      grep "add master" "$1"
 +      EOF
 +
 +      mkdir subdir &&
 +      (
 +              # Test that it works even if we are not at the root of the
 +              # working tree
 +              cd subdir &&
 +              git send-email \
 +                      --from="Example <nobody@example.com>" \
 +                      --to=nobody@example.com \
 +                      --smtp-server="$(pwd)/../fake.sendmail" \
 +                      ../0001-add-master.patch &&
 +
 +              # Verify error message when a patch is rejected by the hook
 +              sed -e "s/add master/x/" ../0001-add-master.patch >../another.patch &&
 +              git send-email \
 +                      --from="Example <nobody@example.com>" \
 +                      --to=nobody@example.com \
 +                      --smtp-server="$(pwd)/../fake.sendmail" \
 +                      ../another.patch 2>err
 +              test_i18ngrep "rejected by sendemail-validate hook" err
 +      )
 +'
 +
 +test_expect_success $PREREQ 'test that send-email works outside a repo' '
 +      nongit git send-email \
 +              --from="Example <nobody@example.com>" \
 +              --to=nobody@example.com \
 +              --smtp-server="$(pwd)/fake.sendmail" \
 +              "$(pwd)/0001-add-master.patch"
 +'
 +
  test_done