blob: e02c7040e2155505ec62c0de118c6759f3f46d30 (
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
 | require 'testing_env'
require 'extend/ARGV'
class ArgvExtensionTests < Homebrew::TestCase
  def setup
    @argv = [].extend(HomebrewArgvExtension)
  end
  def test_argv_formulae
    @argv.unshift 'mxcl'
    assert_raises(FormulaUnavailableError) { @argv.formulae }
  end
  def test_argv_casks
    @argv.unshift 'mxcl'
    assert_equal [], @argv.casks
  end
  def test_argv_kegs
    keg = HOMEBREW_CELLAR + "mxcl/10.0"
    keg.mkpath
    @argv << 'mxcl'
    assert_equal 1, @argv.kegs.length
  ensure
    keg.parent.rmtree
  end
  def test_argv_named
    @argv << "foo" << "--debug" << "-v"
    assert_equal %w[foo], @argv.named
  end
  def test_options_only
    @argv << "--foo" << "-vds" << "a" << "b" << "cdefg"
    assert_equal %w[--foo -vds], @argv.options_only
  end
  def test_flags_only
    @argv << "--foo" << "-vds" << "a" << "b" << "cdefg"
    assert_equal %w[--foo], @argv.flags_only
  end
  def test_empty_argv
    assert_empty @argv.named
    assert_empty @argv.kegs
    assert_empty @argv.formulae
    assert_empty @argv
  end
  def test_switch?
    @argv << "-ns" << "-i" << "--bar"
    %w{n s i}.each { |s| assert @argv.switch?(s) }
    %w{b ns bar --bar -n}.each { |s| assert !@argv.switch?(s) }
  end
  def test_flag?
    @argv << "--foo" << "-bq" << "--bar"
    assert @argv.flag?("--foo")
    assert @argv.flag?("--bar")
    assert @argv.flag?("--baz")
    assert @argv.flag?("--qux")
    assert !@argv.flag?("--frotz")
    assert !@argv.flag?("--debug")
  end
end
 |