Skip to content

Commit 438ea7d

Browse files
committed
test_commit_email.rb: Test the content of an email
1 parent 6922e96 commit 438ea7d

File tree

1 file changed

+41
-11
lines changed

1 file changed

+41
-11
lines changed

tool/test/test_commit_email.rb

Lines changed: 41 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -11,34 +11,64 @@ def setup
1111
git('init', '--initial-branch=master')
1212
git('config', 'user.name', 'Jóhän Grübél')
1313
git('config', 'user.email', 'johan@example.com')
14-
git('commit', '--allow-empty', '-m', 'New repository initialized by cvs2svn.')
15-
git('commit', '--allow-empty', '-m', 'Initial revision')
16-
git('commit', '--allow-empty', '-m', 'version 1.0.0')
14+
env = { 'GIT_AUTHOR_DATE' => '2025-10-08T12:00:00Z' }
15+
git('commit', '--allow-empty', '-m', 'New repository initialized by cvs2svn.', env:)
16+
git('commit', '--allow-empty', '-m', 'Initial revision', env:)
17+
git('commit', '--allow-empty', '-m', 'version 1.0.0', env:)
1718
end
1819

1920
@sendmail = File.join(Dir.mktmpdir, 'sendmail')
2021
File.write(@sendmail, <<~SENDMAIL)
2122
#!/usr/bin/env ruby
22-
p ARGV
23+
puts "---"
2324
puts STDIN.read
2425
SENDMAIL
2526
FileUtils.chmod(0755, @sendmail)
2627

2728
@commit_email = File.expand_path('../../tool/commit-email.rb', __dir__)
2829
end
2930

30-
# Just testing an exit status :p
31-
# TODO: prepare something in test/fixtures/xxx and test output
32-
def test_successful_run
31+
def test_sendmail_encoding
3332
Dir.chdir(@ruby) do
33+
before_rev = git('rev-parse', 'HEAD^').chomp
34+
long_rev = git('rev-parse', 'HEAD').chomp
35+
short_rev = long_rev[0...10]
36+
37+
env = {
38+
'SENDMAIL' => @sendmail,
39+
}.merge!(gem_env)
3440
out, _, status = EnvUtil.invoke_ruby([
3541
{ 'SENDMAIL' => @sendmail }.merge!(gem_env),
3642
@commit_email, './', 'cvs-admin@ruby-lang.org',
37-
git('rev-parse', 'HEAD^').chomp, git('rev-parse', 'HEAD').chomp, 'refs/heads/master',
43+
before_rev, long_rev, 'refs/heads/master',
3844
'--viewer-uri', 'https://github.com/ruby/ruby/commit/',
3945
'--error-to', 'cvs-admin@ruby-lang.org',
4046
], '', true)
41-
assert_true(status.success?, out)
47+
48+
assert_true(status.success?)
49+
assert_equal(out, <<~EOS)
50+
master: #{short_rev} (Jóhän Grübél)
51+
---
52+
X-SVN-Author: =?UTF-8?B?SsOzaMOkbiBHcsO8YsOpbA==?=
53+
X-SVN-Repository: XXX
54+
X-SVN-Revision: #{short_rev}
55+
X-SVN-Commit-Id: #{long_rev}
56+
Mime-Version: 1.0
57+
Content-Type: text/plain; charset=utf-8
58+
Content-Transfer-Encoding: quoted-printable
59+
From: =?UTF-8?B?SsOzaMOkbiBHcsO8YsOpbA==?= <noreply@ruby-lang.org>
60+
To: cvs-admin@ruby-lang.org
61+
Subject: #{short_rev} (master): version 1.0.0
62+
J=C3=B3h=C3=A4n Gr=C3=BCb=C3=A9l\t2025-10-08 05:00:00 -0700 (Wed, 08 Oct 2=
63+
025)
64+
65+
New Revision: #{short_rev}
66+
67+
https://github.com/ruby/ruby/commit/#{short_rev}
68+
69+
Log:
70+
version 1.0.0=
71+
EOS
4272
end
4373
end
4474

@@ -50,8 +80,8 @@ def gem_env
5080
{ 'GEM_PATH' => ENV['BUNDLED_GEM_PATH'], 'GEM_HOME' => ENV['BUNDLED_GEM_HOME'] }
5181
end
5282

53-
def git(*cmd)
54-
out, status = Open3.capture2('git', *cmd)
83+
def git(*cmd, env: {})
84+
out, status = Open3.capture2(env, 'git', *cmd)
5585
unless status.success?
5686
raise "git #{cmd.shelljoin}\n#{out}"
5787
end

0 commit comments

Comments
 (0)