File: test_autoconf.rb

package info (click to toggle)
ruby2.3 2.3.3-1%2Bdeb9u8
  • links: PTS, VCS
  • area: main
  • in suites: stretch
  • size: 65,344 kB
  • sloc: ruby: 639,947; ansic: 317,772; xml: 25,445; yacc: 9,068; javascript: 6,648; lisp: 2,568; tcl: 949; makefile: 623; sh: 533; perl: 62; sed: 53; python: 47; awk: 36; asm: 35
file content (64 lines) | stat: -rw-r--r-- 1,696 bytes parent folder | download | duplicates (2)
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
# frozen_string_literal: false
require 'test/unit'
require 'optparse/ac'

class TestOptionParser < Test::Unit::TestCase; end

class TestOptionParser::AutoConf < Test::Unit::TestCase
  def setup
    @opt = OptionParser::AC.new
    @foo = @bar = self.class
    @opt.ac_arg_enable("foo", "foo option") {|x| @foo = x}
    @opt.ac_arg_disable("bar", "bar option") {|x| @bar = x}
    @opt.ac_arg_with("zot", "zot option") {|x| @zot = x}
  end

  class DummyOutput < String
    alias write <<
  end
  def no_error(*args)
    $stderr, stderr = DummyOutput.new, $stderr
    assert_nothing_raised(*args) {return yield}
  ensure
    stderr, $stderr = $stderr, stderr
    $!.backtrace.delete_if {|e| /\A#{Regexp.quote(__FILE__)}:#{__LINE__-2}/o =~ e} if $!
    assert_empty(stderr)
  end

  def test_enable
    @opt.parse!(%w"--enable-foo")
    assert_equal(true, @foo)
    @opt.parse!(%w"--enable-bar")
    assert_equal(true, @bar)
  end

  def test_disable
    @opt.parse!(%w"--disable-foo")
    assert_equal(false, @foo)
    @opt.parse!(%w"--disable-bar")
    assert_equal(false, @bar)
  end

  def test_with
    @opt.parse!(%w"--with-zot=foobar")
    assert_equal("foobar", @zot)
    @opt.parse!(%w"--without-zot")
    assert_nil(@zot)
  end

  def test_without
    @opt.parse!(%w"--without-zot")
    assert_nil(@zot)
    assert_raise(OptionParser::NeedlessArgument) {@opt.parse!(%w"--without-zot=foobar")}
  end

  def test_help
    help = @opt.help
    assert_match(/--enable-foo/, help)
    assert_match(/--disable-bar/, help)
    assert_match(/--with-zot/, help)
    assert_not_match(/--disable-foo/, help)
    assert_not_match(/--enable-bar/, help)
    assert_not_match(/--without/, help)
  end
end