summaryrefslogtreecommitdiff
path: root/test/optparse/test_autoconf.rb
diff options
context:
space:
mode:
authornobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2012-04-02 04:25:14 +0000
committernobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2012-04-02 04:25:14 +0000
commita59bfa76e51cb3ddf41fe15c239d3872b73a1e85 (patch)
tree54d4ac6667adaf2b46c1a8337e0d9b74912a6131 /test/optparse/test_autoconf.rb
parent38b8afcf5a4abfc5d8319bcb30a239668eccfb9f (diff)
* lib/optparse/ac.rb: autoconf-like options.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@35214 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'test/optparse/test_autoconf.rb')
-rw-r--r--test/optparse/test_autoconf.rb63
1 files changed, 63 insertions, 0 deletions
diff --git a/test/optparse/test_autoconf.rb b/test/optparse/test_autoconf.rb
new file mode 100644
index 0000000..cb9c938
--- /dev/null
+++ b/test/optparse/test_autoconf.rb
@@ -0,0 +1,63 @@
+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