summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTakashi Kokubun <takashikkbn@gmail.com>2025-10-08 20:53:31 -0700
committerTakashi Kokubun <takashikkbn@gmail.com>2025-10-08 21:09:49 -0700
commit438ea7d69ebc4c485b606e0a8d6cf20a446f2596 (patch)
tree64730eeda66a416efea1d80e2c69ee2b7e552743
parent6922e969f1441ded72d1595397ae50687944827d (diff)
test_commit_email.rb: Test the content of an email
-rw-r--r--tool/test/test_commit_email.rb52
1 files changed, 41 insertions, 11 deletions
diff --git a/tool/test/test_commit_email.rb b/tool/test/test_commit_email.rb
index 7b258734d0..38fa60394e 100644
--- a/tool/test/test_commit_email.rb
+++ b/tool/test/test_commit_email.rb
@@ -11,15 +11,16 @@ class TestCommitEmail < Test::Unit::TestCase
git('init', '--initial-branch=master')
git('config', 'user.name', 'Jóhän Grübél')
git('config', 'user.email', 'johan@example.com')
- git('commit', '--allow-empty', '-m', 'New repository initialized by cvs2svn.')
- git('commit', '--allow-empty', '-m', 'Initial revision')
- git('commit', '--allow-empty', '-m', 'version 1.0.0')
+ env = { 'GIT_AUTHOR_DATE' => '2025-10-08T12:00:00Z' }
+ git('commit', '--allow-empty', '-m', 'New repository initialized by cvs2svn.', env:)
+ git('commit', '--allow-empty', '-m', 'Initial revision', env:)
+ git('commit', '--allow-empty', '-m', 'version 1.0.0', env:)
end
@sendmail = File.join(Dir.mktmpdir, 'sendmail')
File.write(@sendmail, <<~SENDMAIL)
#!/usr/bin/env ruby
- p ARGV
+ puts "---"
puts STDIN.read
SENDMAIL
FileUtils.chmod(0755, @sendmail)
@@ -27,18 +28,47 @@ class TestCommitEmail < Test::Unit::TestCase
@commit_email = File.expand_path('../../tool/commit-email.rb', __dir__)
end
- # Just testing an exit status :p
- # TODO: prepare something in test/fixtures/xxx and test output
- def test_successful_run
+ def test_sendmail_encoding
Dir.chdir(@ruby) do
+ before_rev = git('rev-parse', 'HEAD^').chomp
+ long_rev = git('rev-parse', 'HEAD').chomp
+ short_rev = long_rev[0...10]
+
+ env = {
+ 'SENDMAIL' => @sendmail,
+ }.merge!(gem_env)
out, _, status = EnvUtil.invoke_ruby([
{ 'SENDMAIL' => @sendmail }.merge!(gem_env),
@commit_email, './', 'cvs-admin@ruby-lang.org',
- git('rev-parse', 'HEAD^').chomp, git('rev-parse', 'HEAD').chomp, 'refs/heads/master',
+ before_rev, long_rev, 'refs/heads/master',
'--viewer-uri', 'https://github.com/ruby/ruby/commit/',
'--error-to', 'cvs-admin@ruby-lang.org',
], '', true)
- assert_true(status.success?, out)
+
+ assert_true(status.success?)
+ assert_equal(out, <<~EOS)
+ master: #{short_rev} (Jóhän Grübél)
+ ---
+ X-SVN-Author: =?UTF-8?B?SsOzaMOkbiBHcsO8YsOpbA==?=
+ X-SVN-Repository: XXX
+ X-SVN-Revision: #{short_rev}
+ X-SVN-Commit-Id: #{long_rev}
+ Mime-Version: 1.0
+ Content-Type: text/plain; charset=utf-8
+ Content-Transfer-Encoding: quoted-printable
+ From: =?UTF-8?B?SsOzaMOkbiBHcsO8YsOpbA==?= <noreply@ruby-lang.org>
+ To: cvs-admin@ruby-lang.org
+ Subject: #{short_rev} (master): version 1.0.0
+ J=C3=B3h=C3=A4n Gr=C3=BCb=C3=A9l\t2025-10-08 05:00:00 -0700 (Wed, 08 Oct 2=
+ 025)
+
+ New Revision: #{short_rev}
+
+ https://github.com/ruby/ruby/commit/#{short_rev}
+
+ Log:
+ version 1.0.0=
+ EOS
end
end
@@ -50,8 +80,8 @@ class TestCommitEmail < Test::Unit::TestCase
{ 'GEM_PATH' => ENV['BUNDLED_GEM_PATH'], 'GEM_HOME' => ENV['BUNDLED_GEM_HOME'] }
end
- def git(*cmd)
- out, status = Open3.capture2('git', *cmd)
+ def git(*cmd, env: {})
+ out, status = Open3.capture2(env, 'git', *cmd)
unless status.success?
raise "git #{cmd.shelljoin}\n#{out}"
end