diff options
Diffstat (limited to 'tool')
-rwxr-xr-x | tool/sync_default_gems.rb | 5 | ||||
-rwxr-xr-x | tool/test/test_sync_default_gems.rb | 55 |
2 files changed, 60 insertions, 0 deletions
diff --git a/tool/sync_default_gems.rb b/tool/sync_default_gems.rb index 06852cccbe..98894f52f4 100755 --- a/tool/sync_default_gems.rb +++ b/tool/sync_default_gems.rb @@ -3,8 +3,12 @@ # See `tool/sync_default_gems.rb --help` for how to use this. require 'fileutils' + +module SyncDefaultGems include FileUtils +module_function + REPOSITORIES = { rubygems: 'rubygems/rubygems', rdoc: 'ruby/rdoc', @@ -726,4 +730,5 @@ else else sync_default_gems(gem) end +end if $0 == __FILE__ end diff --git a/tool/test/test_sync_default_gems.rb b/tool/test/test_sync_default_gems.rb new file mode 100755 index 0000000000..7e6a6d830e --- /dev/null +++ b/tool/test/test_sync_default_gems.rb @@ -0,0 +1,55 @@ +#!/usr/bin/ruby +require 'test/unit' +require 'stringio' +require_relative '../sync_default_gems' + +module Test_SyncDefaultGems + class TestMessageFilter < Test::Unit::TestCase + def assert_message_filter(expected, trailers, input, repo = "ruby/test", sha = "0123456789") + subject, *expected = expected + expected = [ + "[#{repo}] #{subject}\n", + *expected.map {_1+"\n"}, + "\n", + "https://github.com/#{repo}/commit/#{sha[0, 10]}\n", + ] + if trailers + expected << "\n" + expected.concat(trailers.map {_1+"\n"}) + end + + out, err = capture_output do + SyncDefaultGems.message_filter(repo, sha, input: StringIO.new(input, "r")) + end + + all_assertions do |a| + a.for("error") {assert_empty err} + a.for("result") {assert_pattern_list(expected, out)} + end + end + + def test_subject_only + expected = [ + "initial commit", + ] + assert_message_filter(expected, nil, "initial commit") + end + + def test_link_in_parenthesis + expected = [ + "fix (https://github.com/ruby/test/pull/1)", + ] + assert_message_filter(expected, nil, "fix (#1)") + end + + def test_co_authored_by + expected = [ + "commit something", + ] + trailers = [ + "Co-Authored-By: git <git@ruby-lang.org>", + ] + assert_message_filter(expected, trailers, [expected, "", trailers, ""].join("\n")) + end + end +end |