test_update_report: fix test
Closes Homebrew/homebrew#48546. Signed-off-by: Xu Cheng <xucheng@me.com>
This commit is contained in:
parent
239c860863
commit
79a01a47cc
@ -40,6 +40,8 @@ update_git_diff_output_with_changed_filetype: |
|
|||||||
D Library/Formula/libgsasl.rb
|
D Library/Formula/libgsasl.rb
|
||||||
M Library/Homebrew/cmd/update.rb
|
M Library/Homebrew/cmd/update.rb
|
||||||
M SUPPORTERS.md
|
M SUPPORTERS.md
|
||||||
|
update_git_diff_output_with_formula_rename: |
|
||||||
|
R100 Library/Formula/cv.rb Library/Formula/progress.rb
|
||||||
update_git_diff_output_with_restructured_tap: |
|
update_git_diff_output_with_restructured_tap: |
|
||||||
R100 git.rb Formula/git.rb
|
R100 git.rb Formula/git.rb
|
||||||
R100 lua.rb Formula/lua.rb
|
R100 lua.rb Formula/lua.rb
|
||||||
|
@ -5,37 +5,13 @@ require "yaml"
|
|||||||
|
|
||||||
class ReportTests < Homebrew::TestCase
|
class ReportTests < Homebrew::TestCase
|
||||||
class ReporterMock < ::Reporter
|
class ReporterMock < ::Reporter
|
||||||
attr_accessor :diff, :expected, :called
|
attr_accessor :diff
|
||||||
|
|
||||||
def initialize(repository)
|
def initialize(tap, init_rev, cur_rev)
|
||||||
repo_var = Reporter.repository_variable(repository)
|
@tap = tap
|
||||||
ENV["HOMEBREW_UPDATE_BEFORE#{repo_var}"] = "abcdef12"
|
ENV["HOMEBREW_UPDATE_BEFORE#{repo_var}"] = init_rev
|
||||||
ENV["HOMEBREW_UPDATE_AFTER#{repo_var}"] = "abcdef12"
|
ENV["HOMEBREW_UPDATE_AFTER#{repo_var}"] = cur_rev
|
||||||
super
|
super(tap)
|
||||||
@outputs = Hash.new { |h, k| h[k] = [] }
|
|
||||||
@expected = []
|
|
||||||
@called = []
|
|
||||||
end
|
|
||||||
|
|
||||||
def in_repo_expect(cmd, output = "")
|
|
||||||
@expected << cmd
|
|
||||||
@outputs[cmd] << output
|
|
||||||
end
|
|
||||||
|
|
||||||
def `(*args)
|
|
||||||
cmd = args.join(" ")
|
|
||||||
if @expected.include?(cmd) && !@outputs[cmd].empty?
|
|
||||||
@called << cmd
|
|
||||||
@outputs[cmd].shift
|
|
||||||
else
|
|
||||||
raise "#{inspect} unexpectedly called backticks: `#{cmd}`"
|
|
||||||
end
|
|
||||||
end
|
|
||||||
alias_method :safe_system, :`
|
|
||||||
alias_method :system, :`
|
|
||||||
|
|
||||||
def inspect
|
|
||||||
"#<#{self.class.name}>"
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
@ -48,8 +24,9 @@ class ReportTests < Homebrew::TestCase
|
|||||||
end
|
end
|
||||||
|
|
||||||
def setup
|
def setup
|
||||||
@updater = ReporterMock.new(HOMEBREW_REPOSITORY)
|
@tap = CoreFormulaRepository.new
|
||||||
@report = Report.new
|
@reporter = ReporterMock.new(@tap, "12345678", "abcdef12")
|
||||||
|
@hub = ReporterHub.new
|
||||||
end
|
end
|
||||||
|
|
||||||
def teardown
|
def teardown
|
||||||
@ -59,48 +36,80 @@ class ReportTests < Homebrew::TestCase
|
|||||||
def perform_update(fixture_name = "")
|
def perform_update(fixture_name = "")
|
||||||
Formulary.stubs(:factory).returns(stub(:pkg_version => "1.0"))
|
Formulary.stubs(:factory).returns(stub(:pkg_version => "1.0"))
|
||||||
FormulaVersions.stubs(:new).returns(stub(:formula_at_revision => "2.0"))
|
FormulaVersions.stubs(:new).returns(stub(:formula_at_revision => "2.0"))
|
||||||
@updater.diff = fixture(fixture_name)
|
@reporter.diff = fixture(fixture_name)
|
||||||
@report.update(@updater.report)
|
@hub.add(@reporter) if @reporter.updated?
|
||||||
assert_equal @updater.expected, @updater.called
|
end
|
||||||
|
|
||||||
|
def test_update_report_without_revision_var
|
||||||
|
assert_raises(Reporter::ReporterRevisionUnsetError) { ReporterMock.new(@tap, nil, nil) }
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_update_homebrew_without_any_changes
|
def test_update_homebrew_without_any_changes
|
||||||
perform_update
|
perform_update
|
||||||
assert_empty @report
|
assert_empty @hub
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_update_homebrew_without_formulae_changes
|
def test_update_homebrew_without_formulae_changes
|
||||||
perform_update("update_git_diff_output_without_formulae_changes")
|
perform_update("update_git_diff_output_without_formulae_changes")
|
||||||
assert_empty @report.select_formula(:M)
|
assert_empty @hub.select_formula(:M)
|
||||||
assert_empty @report.select_formula(:A)
|
assert_empty @hub.select_formula(:A)
|
||||||
assert_empty @report.select_formula(:D)
|
assert_empty @hub.select_formula(:D)
|
||||||
|
end
|
||||||
|
|
||||||
|
def test_update_homebrew_with_formulae_changes
|
||||||
|
perform_update("update_git_diff_output_with_formulae_changes")
|
||||||
|
assert_equal %w[xar yajl], @hub.select_formula(:M)
|
||||||
|
assert_equal %w[antiword bash-completion ddrescue dict lua], @hub.select_formula(:A)
|
||||||
|
end
|
||||||
|
|
||||||
|
def test_update_homebrew_with_removed_formulae
|
||||||
|
perform_update("update_git_diff_output_with_removed_formulae")
|
||||||
|
assert_equal %w[libgsasl], @hub.select_formula(:D)
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_update_homebrew_with_changed_filetype
|
def test_update_homebrew_with_changed_filetype
|
||||||
perform_update("update_git_diff_output_with_changed_filetype")
|
perform_update("update_git_diff_output_with_changed_filetype")
|
||||||
|
assert_equal %w[elixir], @hub.select_formula(:M)
|
||||||
|
assert_equal %w[libbson], @hub.select_formula(:A)
|
||||||
|
assert_equal %w[libgsasl], @hub.select_formula(:D)
|
||||||
|
end
|
||||||
|
|
||||||
|
def test_update_homebrew_with_formula_rename
|
||||||
|
@tap.stubs(:formula_renames).returns("cv" => "progress")
|
||||||
|
perform_update("update_git_diff_output_with_formula_rename")
|
||||||
|
assert_empty @hub.select_formula(:A)
|
||||||
|
assert_empty @hub.select_formula(:D)
|
||||||
|
assert_equal [["cv", "progress"]], @hub.select_formula(:R)
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_update_homebrew_with_restructured_tap
|
def test_update_homebrew_with_restructured_tap
|
||||||
repo = HOMEBREW_LIBRARY.join("Taps", "foo", "bar")
|
tap = Tap.new("foo", "bar")
|
||||||
@updater = ReporterMock.new(repo)
|
@reporter = ReporterMock.new(tap, "12345678", "abcdef12")
|
||||||
repo.join("Formula").mkpath
|
tap.path.join("Formula").mkpath
|
||||||
|
|
||||||
perform_update("update_git_diff_output_with_restructured_tap")
|
perform_update("update_git_diff_output_with_restructured_tap")
|
||||||
|
assert_equal %w[foo/bar/git foo/bar/lua], @hub.select_formula(:A)
|
||||||
|
assert_empty @hub.select_formula(:D)
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_update_homebrew_simulate_homebrew_php_restructuring
|
def test_update_homebrew_simulate_homebrew_php_restructuring
|
||||||
repo = HOMEBREW_LIBRARY.join("Taps", "foo", "bar")
|
tap = Tap.new("foo", "bar")
|
||||||
@updater = ReporterMock.new(repo)
|
@reporter = ReporterMock.new(tap, "12345678", "abcdef12")
|
||||||
repo.join("Formula").mkpath
|
tap.path.join("Formula").mkpath
|
||||||
|
|
||||||
perform_update("update_git_diff_simulate_homebrew_php_restructuring")
|
perform_update("update_git_diff_simulate_homebrew_php_restructuring")
|
||||||
|
assert_empty @hub.select_formula(:A)
|
||||||
|
assert_equal %w[foo/bar/git foo/bar/lua], @hub.select_formula(:D)
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_update_homebrew_with_tap_formulae_changes
|
def test_update_homebrew_with_tap_formulae_changes
|
||||||
repo = HOMEBREW_LIBRARY.join("Taps", "foo", "bar")
|
tap = Tap.new("foo", "bar")
|
||||||
@updater = ReporterMock.new(repo)
|
@reporter = ReporterMock.new(tap, "12345678", "abcdef12")
|
||||||
repo.join("Formula").mkpath
|
tap.path.join("Formula").mkpath
|
||||||
|
|
||||||
perform_update("update_git_diff_output_with_tap_formulae_changes")
|
perform_update("update_git_diff_output_with_tap_formulae_changes")
|
||||||
|
assert_equal %w[foo/bar/lua], @hub.select_formula(:A)
|
||||||
|
assert_equal %w[foo/bar/git], @hub.select_formula(:M)
|
||||||
|
assert_empty @hub.select_formula(:D)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
Loading…
x
Reference in New Issue
Block a user