aboutsummaryrefslogtreecommitdiffstats
path: root/Library/Homebrew/test
diff options
context:
space:
mode:
Diffstat (limited to 'Library/Homebrew/test')
-rw-r--r--Library/Homebrew/test/fixtures/updater_fixture.yaml2
-rw-r--r--Library/Homebrew/test/test_update_report.rb105
2 files changed, 59 insertions, 48 deletions
diff --git a/Library/Homebrew/test/fixtures/updater_fixture.yaml b/Library/Homebrew/test/fixtures/updater_fixture.yaml
index b12f9d447..6f7547570 100644
--- a/Library/Homebrew/test/fixtures/updater_fixture.yaml
+++ b/Library/Homebrew/test/fixtures/updater_fixture.yaml
@@ -40,6 +40,8 @@ update_git_diff_output_with_changed_filetype: |
D Library/Formula/libgsasl.rb
M Library/Homebrew/cmd/update.rb
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: |
R100 git.rb Formula/git.rb
R100 lua.rb Formula/lua.rb
diff --git a/Library/Homebrew/test/test_update_report.rb b/Library/Homebrew/test/test_update_report.rb
index 6f3d70afa..1c96ba105 100644
--- a/Library/Homebrew/test/test_update_report.rb
+++ b/Library/Homebrew/test/test_update_report.rb
@@ -5,37 +5,13 @@ require "yaml"
class ReportTests < Homebrew::TestCase
class ReporterMock < ::Reporter
- attr_accessor :diff, :expected, :called
-
- def initialize(repository)
- repo_var = Reporter.repository_variable(repository)
- ENV["HOMEBREW_UPDATE_BEFORE#{repo_var}"] = "abcdef12"
- ENV["HOMEBREW_UPDATE_AFTER#{repo_var}"] = "abcdef12"
- super
- @outputs = Hash.new { |h, k| h[k] = [] }
- @expected = []
- @called = []
- end
-
- def in_repo_expect(cmd, output = "")
- @expected << cmd
- @outputs[cmd] << output
- end
+ attr_accessor :diff
- 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}>"
+ def initialize(tap, init_rev, cur_rev)
+ @tap = tap
+ ENV["HOMEBREW_UPDATE_BEFORE#{repo_var}"] = init_rev
+ ENV["HOMEBREW_UPDATE_AFTER#{repo_var}"] = cur_rev
+ super(tap)
end
end
@@ -48,8 +24,9 @@ class ReportTests < Homebrew::TestCase
end
def setup
- @updater = ReporterMock.new(HOMEBREW_REPOSITORY)
- @report = Report.new
+ @tap = CoreFormulaRepository.new
+ @reporter = ReporterMock.new(@tap, "12345678", "abcdef12")
+ @hub = ReporterHub.new
end
def teardown
@@ -59,48 +36,80 @@ class ReportTests < Homebrew::TestCase
def perform_update(fixture_name = "")
Formulary.stubs(:factory).returns(stub(:pkg_version => "1.0"))
FormulaVersions.stubs(:new).returns(stub(:formula_at_revision => "2.0"))
- @updater.diff = fixture(fixture_name)
- @report.update(@updater.report)
- assert_equal @updater.expected, @updater.called
+ @reporter.diff = fixture(fixture_name)
+ @hub.add(@reporter) if @reporter.updated?
+ end
+
+ def test_update_report_without_revision_var
+ assert_raises(Reporter::ReporterRevisionUnsetError) { ReporterMock.new(@tap, nil, nil) }
end
def test_update_homebrew_without_any_changes
perform_update
- assert_empty @report
+ assert_empty @hub
end
def test_update_homebrew_without_formulae_changes
perform_update("update_git_diff_output_without_formulae_changes")
- assert_empty @report.select_formula(:M)
- assert_empty @report.select_formula(:A)
- assert_empty @report.select_formula(:D)
+ assert_empty @hub.select_formula(:M)
+ assert_empty @hub.select_formula(:A)
+ 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
def test_update_homebrew_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
def test_update_homebrew_with_restructured_tap
- repo = HOMEBREW_LIBRARY.join("Taps", "foo", "bar")
- @updater = ReporterMock.new(repo)
- repo.join("Formula").mkpath
+ tap = Tap.new("foo", "bar")
+ @reporter = ReporterMock.new(tap, "12345678", "abcdef12")
+ tap.path.join("Formula").mkpath
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
def test_update_homebrew_simulate_homebrew_php_restructuring
- repo = HOMEBREW_LIBRARY.join("Taps", "foo", "bar")
- @updater = ReporterMock.new(repo)
- repo.join("Formula").mkpath
+ tap = Tap.new("foo", "bar")
+ @reporter = ReporterMock.new(tap, "12345678", "abcdef12")
+ tap.path.join("Formula").mkpath
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
def test_update_homebrew_with_tap_formulae_changes
- repo = HOMEBREW_LIBRARY.join("Taps", "foo", "bar")
- @updater = ReporterMock.new(repo)
- repo.join("Formula").mkpath
+ tap = Tap.new("foo", "bar")
+ @reporter = ReporterMock.new(tap, "12345678", "abcdef12")
+ tap.path.join("Formula").mkpath
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