Subject: [PATCH 3/3] send-email: test compose functionality

From: Jeff King <[email-masked]>
Date: Mon, 21 Jan 2008 22:29:05 -0500

This is just a basic sanity check that --compose works at
all. Unfortunately, we have to add a --no-confirm-send
option to git-send-email to make this work, since it
otherwise unconditionally tries to talk to the terminal.

Signed-off-by: Jeff King <[email-masked]>
---
Note that the change to git-send-email depends textually on Gustaf's
fix (actually, on my suggested version). I am not happy with adding the
--no-confirm-send option, but there just isn't any way to avoid the
readline call with the existing code short of providing a dummy perl
module in the test harness.

 git-send-email.perl   |   16 ++++++++++------
 t/t9001-send-email.sh |   27 +++++++++++++++++++++++++++
 2 files changed, 37 insertions(+), 6 deletions(-)

diff --git a/git-send-email.perl b/git-send-email.perl
index df1c833..f265a82 100755
--- a/git-send-email.perl
+++ b/git-send-email.perl
@@ -180,6 +180,7 @@ my ($thread, $chain_reply_to, $suppress_from, $signed_off_cc, $cc_cmd);
 my ($smtp_server, $smtp_server_port, $smtp_authuser, $smtp_authpass, $smtp_ssl);
 my ($identity, $aliasfiletype, @alias_files, @smtp_host_parts);
 my ($no_validate);
+my ($no_confirm_send);
 
 my %config_bool_settings = (
     "thread" => [\$thread, 1],
@@ -226,6 +227,7 @@ my $rc = GetOptions("sender|from=s" => \$sender,
 		    "envelope-sender=s" => \$envelope_sender,
 		    "thread!" => \$thread,
 		    "no-validate" => \$no_validate,
+		    "no-confirm-send" => \$no_confirm_send,
 	 );
 
 unless ($rc) {
@@ -453,13 +455,15 @@ EOT
 	close(C);
 	close(C2);
 
-	do {
-		$_ = $term->readline("Send this email? (y|n) ");
-	} while (!defined $_);
+	if (!$no_confirm_send) {
+		do {
+			$_ = $term->readline("Send this email? (y|n) ");
+		} while (!defined $_);
 
-	if (uc substr($_,0,1) ne 'Y') {
-		cleanup_compose_files();
-		exit(0);
+		if (uc substr($_,0,1) ne 'Y') {
+			cleanup_compose_files();
+			exit(0);
+		}
 	}
 
 	unshift @files, "$compose_filename.final";
diff --git a/t/t9001-send-email.sh b/t/t9001-send-email.sh
index dd0c395..b1e9de5 100755
--- a/t/t9001-send-email.sh
+++ b/t/t9001-send-email.sh
@@ -114,4 +114,31 @@ test_expect_success 'allow long lines with --no-validate' '
 		2>errors
 '
 
+test_expect_success 'setup fake editor' '
+	(echo "#!/bin/sh" &&
+	 echo "echo fake edit >>\$1"
+	) >fake-editor &&
+	chmod +x fake-editor
+'
+
+test_expect_success '--compose works' '
+	clean_fake_sendmail &&
+	GIT_EDITOR=$(pwd)/fake-editor \
+	git send-email \
+		--compose --subject foo --no-confirm-send \
+		--from="Example <[email-masked]>" \
+		--to=[email-masked] \
+		--smtp-server="$(pwd)/fake.sendmail" \
+		$patches \
+		2>errors
+'
+
+test_expect_success 'first message is compose text' '
+	grep "^fake edit" msgtxt1
+'
+
+test_expect_success 'second message is patch' '
+	grep "Subject:.*Second" msgtxt2
+'
+
 test_done
-- 
1.5.4.rc3.1130.gd9718-dirty