Sha256: d6a74107ea0466d76adaa8fdcce88d108fd51a2e2fb32835cbf3924b6be289aa

Contents?: true

Size: 1.77 KB

Versions: 3

Compression:

Stored size: 1.77 KB

Contents

# frozen_string_literal: false
require 'test/unit'
require 'optparse/ac'

class ::OptionParserAutoConf < Test::Unit::TestCase
  def setup
    @opt = CLI::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 concat
  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_enable_value
    @opt.parse!(%w"--enable-foo=A")
    assert_equal("A", @foo)
    @opt.parse!(%w"--enable-bar=B")
    assert_equal("B", @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(CLI::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

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
cli-option_parser.rb-0.6.0 test/optparse/test_autoconf.rb
cli-option_parser.rb-0.5.3 test/optparse/test_autoconf.rb
cli-option_parser.rb-0.5.2 test/optparse/test_autoconf.rb