aboutsummaryrefslogtreecommitdiffstats
path: root/Library/Homebrew/test/test_formula_spec_selection.rb
blob: a572623d85734595e3e1e5a1603f6f6d11f7ff90 (plain)
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
require 'testing_env'
require 'formula'

class FormulaSpecSelectionTests < Test::Unit::TestCase
  def assert_spec_selected(spec)
    assert_equal @_f.send(spec), @_f.active_spec
  end

  def assert_spec_unset(spec)
    assert_nil @_f.send(spec)
  end

  def test_selects_head_when_requested
    ARGV.stubs(:build_head?).returns(true)

    formula do
      url 'foo-1.0'
      devel { url 'foo-1.1a' }
      head 'foo'
    end

    assert_spec_selected :head
  end

  def test_selects_devel_when_requested
    ARGV.stubs(:build_devel?).returns(true)

    formula do
      url 'foo-1.0'
      devel { url 'foo-1.1a' }
      head 'foo'
    end

    assert_spec_selected :devel
  end

  def test_selects_bottle_when_available
    formula do
      def install_bottle?(*); true; end

      url 'foo-1.0'
      bottle { sha1 TEST_SHA1 => bottle_tag }
    end

    assert_spec_selected :bottle
  end

  def test_selects_stable_by_default
    formula do
      url 'foo-1.0'
      devel { url 'foo-1.1a' }
      head 'foo'
    end

    assert_spec_selected :stable
  end

  def test_selects_stable_when_exclusive
    formula do
      url 'foo-1.0'
    end

    assert_spec_selected :stable
  end

  def test_selects_devel_before_head
    formula do
      devel { url 'foo-1.1a' }
      head 'foo'
    end

    assert_spec_selected :devel
  end

  def test_selects_devel_when_exclusive
    formula do
      devel { url 'foo-1.1a' }
    end

    assert_spec_selected :devel
  end

  def test_selects_head_when_exclusive
    formula do
      head 'foo'
    end

    assert_spec_selected :head
  end

  def test_incomplete_spec_not_selected
    formula do
      sha1 TEST_SHA1
      version '1.0'
      head 'foo'
    end

    assert_spec_selected :head
  end

  def test_incomplete_stable_not_set
    formula do
      sha1 TEST_SHA1
      devel { url 'foo-1.1a' }
      head 'foo'
    end

    assert_spec_unset :stable
    assert_spec_selected :devel
  end

  def test_incomplete_devel_not_set
    formula do
      url 'foo-1.0'
      devel { version '1.1a' }
      head 'foo'
    end

    assert_spec_unset :devel
    assert_spec_selected :stable
  end

  def test_incomplete_bottle_not_set
    formula do
      url 'foo-1.0'
      bottle { sha1 TEST_SHA1 => :some_nonexistent_thing }
    end

    assert_spec_unset :bottle
    assert_spec_selected :stable
  end
end