1
0
Fork 0
mirror of https://github.com/ruby/ruby.git synced 2022-11-09 12:17:21 -05:00
ruby--ruby/test/optparse/test_reqarg.rb
nagachika 5d4bfaccab merge revision(s) ab3cb29bd9:
Avoid defining the same test class in multiple files

	Should fix issues with parallel testing sometimes not running all
	tests.

	This should be viewed skipping whitespace changes.

	Fixes [Bug #18731]
	---
	 test/-ext-/bignum/test_big2str.rb        |  38 +-
	 test/-ext-/bignum/test_bigzero.rb        |  20 +-
	 test/-ext-/bignum/test_div.rb            |  38 +-
	 test/-ext-/bignum/test_mul.rb            | 260 ++++++------
	 test/-ext-/bignum/test_pack.rb           | 653 +++++++++++++++----------------
	 test/-ext-/bignum/test_str2big.rb        |  52 ++-
	 test/-ext-/funcall/test_funcall.rb       |  11 -
	 test/-ext-/funcall/test_passing_block.rb |   5 +
	 test/date/test_date_ractor.rb            |   2 +-
	 test/fileutils/clobber.rb                |   5 +-
	 test/fileutils/test_dryrun.rb            |   2 +-
	 test/fileutils/test_nowrite.rb           |   2 +-
	 test/fileutils/test_verbose.rb           |   2 +-
	 test/fileutils/visibility_tests.rb       |   5 +-
	 test/mkmf/base.rb                        | 225 ++++++-----
	 test/mkmf/test_config.rb                 |  16 +-
	 test/mkmf/test_constant.rb               |  56 ++-
	 test/mkmf/test_convertible.rb            |  48 ++-
	 test/mkmf/test_egrep_cpp.rb              |  14 +-
	 test/mkmf/test_find_executable.rb        |  82 ++--
	 test/mkmf/test_flags.rb                  |  92 +++--
	 test/mkmf/test_framework.rb              |  70 ++--
	 test/mkmf/test_have_func.rb              |  18 +-
	 test/mkmf/test_have_library.rb           |  84 ++--
	 test/mkmf/test_have_macro.rb             |  46 ++-
	 test/mkmf/test_install.rb                |  38 +-
	 test/mkmf/test_libs.rb                   | 156 ++++----
	 test/mkmf/test_mkmf.rb                   |  14 +-
	 test/mkmf/test_pkg_config.rb             |  98 +++--
	 test/mkmf/test_signedness.rb             |  38 +-
	 test/mkmf/test_sizeof.rb                 |  74 ++--
	 test/optparse/test_acceptable.rb         |   2 +-
	 test/optparse/test_autoconf.rb           |   4 +-
	 test/optparse/test_bash_completion.rb    |   4 +-
	 test/optparse/test_cclass.rb             |   2 +-
	 test/optparse/test_did_you_mean.rb       |   2 +-
	 test/optparse/test_getopts.rb            |   4 +-
	 test/optparse/test_kwargs.rb             |   4 +-
	 test/optparse/test_noarg.rb              |   6 +-
	 test/optparse/test_optarg.rb             |   2 +-
	 test/optparse/test_placearg.rb           |   2 +-
	 test/optparse/test_reqarg.rb             |  10 +-
	 test/optparse/test_summary.rb            |   2 +-
	 test/optparse/test_zsh_completion.rb     |   4 +-
	 test/ruby/enc/test_emoji_breaks.rb       | 207 +++++-----
	 test/ruby/enc/test_grapheme_breaks.rb    | 115 +++---
	 test/ruby/test_inlinecache.rb            |   2 +-
	 47 files changed, 1280 insertions(+), 1356 deletions(-)
	 delete mode 100644 test/-ext-/funcall/test_funcall.rb
2022-10-21 13:36:03 +09:00

95 lines
3 KiB
Ruby

# frozen_string_literal: false
require_relative 'test_optparse'
module TestOptionParserReqArg
def setup
super
@opt.def_option "--with_underscore=VAL" do |x| @flag = x end
@opt.def_option "--with-hyphen=VAL" do |x| @flag = x end
end
class Def1 < TestOptionParser
include TestOptionParserReqArg
def setup
super
@opt.def_option("-xVAL") {|x| @flag = x}
@opt.def_option("--option=VAL") {|x| @flag = x}
@opt.def_option("--regexp=REGEXP", Regexp) {|x| @reopt = x}
@reopt = nil
end
end
class Def2 < TestOptionParser
include TestOptionParserReqArg
def setup
super
@opt.def_option("-x", "--option=VAL") {|x| @flag = x}
end
end
class Def3 < TestOptionParser
include TestOptionParserReqArg
def setup
super
@opt.def_option("--option=VAL", "-x") {|x| @flag = x}
end
end
class Def4 < TestOptionParser
include TestOptionParserReqArg
def setup
super
@opt.def_option("-xVAL", "--option=VAL") {|x| @flag = x}
end
end
def test_short
assert_raise(OptionParser::MissingArgument) {@opt.parse!(%w"-x")}
assert_equal(%w"", no_error {@opt.parse!(%w"-x foo")})
assert_equal("foo", @flag)
assert_equal(%w"", no_error {@opt.parse!(%w"-xbar")})
assert_equal("bar", @flag)
assert_equal(%w"", no_error {@opt.parse!(%w"-x=")})
assert_equal("=", @flag)
end
def test_abbrev
assert_raise(OptionParser::MissingArgument) {@opt.parse!(%w"-o")}
assert_equal(%w"", no_error {@opt.parse!(%w"-o foo")})
assert_equal("foo", @flag)
assert_equal(%w"", no_error {@opt.parse!(%w"-obar")})
assert_equal("bar", @flag)
assert_equal(%w"", no_error {@opt.parse!(%w"-o=")})
assert_equal("=", @flag)
end
def test_long
assert_raise(OptionParser::MissingArgument) {@opt.parse!(%w"--opt")}
assert_equal(%w"", no_error {@opt.parse!(%w"--opt foo")})
assert_equal("foo", @flag)
assert_equal(%w"foo", no_error {@opt.parse!(%w"--opt= foo")})
assert_equal("", @flag)
assert_equal(%w"", no_error {@opt.parse!(%w"--opt=foo")})
assert_equal("foo", @flag)
end
def test_hyphenize
assert_equal(%w"", no_error {@opt.parse!(%w"--with_underscore foo1")})
assert_equal("foo1", @flag)
assert_equal(%w"", no_error {@opt.parse!(%w"--with-underscore foo2")})
assert_equal("foo2", @flag)
assert_equal(%w"", no_error {@opt.parse!(%w"--with-hyphen foo3")})
assert_equal("foo3", @flag)
assert_equal(%w"", no_error {@opt.parse!(%w"--with_hyphen foo4")})
assert_equal("foo4", @flag)
end
class TestOptionParser::WithPattern < TestOptionParser
def test_pattern
pat = num = nil
@opt.def_option("--pattern=VAL", /(\w+)(?:\s*:\s*(\w+))?/) {|x, y, z| pat = [x, y, z]}
@opt.def_option("-T NUM", /\A[1-4]\z/) {|n| num = n}
no_error {@opt.parse!(%w"--pattern=key:val")}
assert_equal(%w"key:val key val", pat, '[ruby-list:45645]')
no_error {@opt.parse!(%w"-T 4")}
assert_equal("4", num, '[ruby-dev:37514]')
end
end
end