1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
  | 
require "testing_env"
require "cmd/update-report"
require "formula_versions"
require "yaml"
class ReportTests < Homebrew::TestCase
  class ReporterMock < ::Reporter
    attr_accessor :diff
    def initialize(tap)
      @tap = tap
      ENV["HOMEBREW_UPDATE_BEFORE#{repo_var}"] = "12345678"
      ENV["HOMEBREW_UPDATE_AFTER#{repo_var}"] = "abcdef12"
      super(tap)
    end
  end
  def fixture(name)
    self.class.fixture_data[name] || ""
  end
  def self.fixture_data
    @fixture_data ||= YAML.load_file("#{TEST_DIRECTORY}/fixtures/updater_fixture.yaml")
  end
  def setup
    @tap = CoreTap.new
    @reporter = ReporterMock.new(@tap)
    @hub = ReporterHub.new
  end
  def perform_update(fixture_name = "")
    Formulary.stubs(:factory).returns(stub(:pkg_version => "1.0"))
    FormulaVersions.stubs(:new).returns(stub(:formula_at_revision => "2.0"))
    @reporter.diff = fixture(fixture_name)
    @hub.add(@reporter) if @reporter.updated?
  end
  def test_update_report_without_revision_var
    ENV.delete_if { |k, _v| k.start_with? "HOMEBREW_UPDATE" }
    assert_raises(Reporter::ReporterRevisionUnsetError) { Reporter.new(@tap) }
  end
  def test_update_homebrew_without_any_changes
    perform_update
    assert_empty @hub
  end
  def test_update_homebrew_without_formulae_changes
    perform_update("update_git_diff_output_without_formulae_changes")
    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
    tap = Tap.new("foo", "bar")
    @reporter = ReporterMock.new(tap)
    tap.path.join("Formula").mkpath
    perform_update("update_git_diff_output_with_restructured_tap")
    assert_empty @hub.select_formula(:A)
    assert_empty @hub.select_formula(:D)
    assert_empty @hub.select_formula(:R)
  ensure
    tap.path.parent.rmtree
  end
  def test_update_homebrew_with_formula_rename_and_restructuring
    tap = Tap.new("foo", "bar")
    @reporter = ReporterMock.new(tap)
    tap.path.join("Formula").mkpath
    tap.stubs(:formula_renames).returns("xchat" => "xchat2")
    perform_update("update_git_diff_output_with_formula_rename_and_restructuring")
    assert_empty @hub.select_formula(:A)
    assert_empty @hub.select_formula(:D)
    assert_equal [%w[foo/bar/xchat foo/bar/xchat2]], @hub.select_formula(:R)
  ensure
    tap.path.parent.rmtree
  end
  def test_update_homebrew_simulate_homebrew_php_restructuring
    tap = Tap.new("foo", "bar")
    @reporter = ReporterMock.new(tap)
    tap.path.join("Formula").mkpath
    perform_update("update_git_diff_simulate_homebrew_php_restructuring")
    assert_empty @hub.select_formula(:A)
    assert_empty @hub.select_formula(:D)
    assert_empty @hub.select_formula(:R)
  ensure
    tap.path.parent.rmtree
  end
  def test_update_homebrew_with_tap_formulae_changes
    tap = Tap.new("foo", "bar")
    @reporter = ReporterMock.new(tap)
    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)
  ensure
    tap.path.parent.rmtree
  end
end
  |