From 8a57f471dcac4074afca8abcf76f9df28dbaeb65 Mon Sep 17 00:00:00 2001 From: BurdetteLamar Date: Sun, 17 Oct 2021 17:45:14 -0500 Subject: [PATCH 01/11] Some tests --- Rakefile | 9 +++- test/test.rb | 12 +++++ test/test_new.rb | 133 +++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 153 insertions(+), 1 deletion(-) create mode 100644 test/test.rb create mode 100644 test/test_new.rb diff --git a/Rakefile b/Rakefile index e33a5d3..a60e899 100644 --- a/Rakefile +++ b/Rakefile @@ -1,3 +1,10 @@ -require "bundler/gem_tasks" +require 'bundler/gem_tasks' +require 'rake/testtask' + +Rake::TestTask.new(:test) do |t| + t.libs << 'test' + t.libs << 'lib' + t.test_files = FileList['test/test_*.rb'] +end task :default => :test diff --git a/test/test.rb b/test/test.rb new file mode 100644 index 0000000..92f4025 --- /dev/null +++ b/test/test.rb @@ -0,0 +1,12 @@ +require 'getoptlong' +opts = GetoptLong.new( + ['--xxx', '-x', '--aaa', '-a', GetoptLong::REQUIRED_ARGUMENT], + ['--yyy', '-y', '--bbb', '-b', GetoptLong::OPTIONAL_ARGUMENT], + ['--zzz', '-z', '--ccc', '-c', GetoptLong::NO_ARGUMENT] +) +opts.each do |opt, arg| + puts "#{opt} => #{arg}" +end + + + diff --git a/test/test_new.rb b/test/test_new.rb new file mode 100644 index 0000000..26adca4 --- /dev/null +++ b/test/test_new.rb @@ -0,0 +1,133 @@ +require 'minitest/autorun' +require 'getoptlong' + +class TestGetoptLong < Minitest::Test + + def setup + # Nothing yet. + end + + def teardown + # Nothing yet. + end + + def test_new_with_no_array + GetoptLong.new + end + + def test_no_options + output = `ruby test/test.rb` + assert_equal(output, '') + end + + def test_required_argument + options = %w[--xxx --xx --x -x --aaa --aa --a -a] + options.each do |option| + output = `ruby test/test.rb #{option} arg` + assert_equal("--xxx => arg\n", output) + end + end + + def test_required_argument_missing + options = %w[--xxx --xx --x -x --aaa --aa --a -a] + options.each do |option| + expected = "option `--xxx' requires an argument (GetoptLong::MissingArgument)" + _, err = capture_subprocess_io do + `ruby test/test.rb --xxx` + end + assert_match(expected, err) + end + end + + def test_optional_argument + options = %w[--yyy --y --y -y --bbb --bb --b -b] + options.each do |option| + output = `ruby test/test.rb #{option} arg` + assert_equal("--yyy => arg\n", output) + end + end + + def test_optional_argument_missing + options = %w[--yyy --y --y -y --bbb --bb --b -b] + options.each do |option| + output = `ruby test/test.rb #{option}` + assert_equal("--yyy => \n", output) + end + end + + def test_no_argument + options = %w[--zzz --zz --z -z --ccc --cc --c -c] + options.each do |option| + output = `ruby test/test.rb #{option}` + assert_equal("--zzz => \n", output) + end + end + + def test_new_with_empty_array + e = assert_raises(ArgumentError) do + GetoptLong.new([]) + end + assert_match(/no argument-flag/, e.message) + end + + def test_new_with_bad_array + e = assert_raises(ArgumentError) do + GetoptLong.new('foo') + end + assert_match(/option list contains non-Array argument/, e.message) + end + + def test_new_with_empty_subarray + e = assert_raises(ArgumentError) do + GetoptLong.new([[]]) + end + assert_match(/no argument-flag/, e.message) + end + + def test_new_with_bad_subarray + e = assert_raises(ArgumentError) do + GetoptLong.new([1]) + end + assert_match(/no option name/, e.message) + end + + def test_new_with_invalid_option + invalid_options = %w[verbose -verbose -- +] + invalid_options.each do |invalid_option| + e = assert_raises(ArgumentError, invalid_option.to_s) do + arguments = [ + [invalid_option, '-v', GetoptLong::NO_ARGUMENT] + ] + GetoptLong.new(*arguments) + end + assert_match(/invalid option/, e.message) + end + end + + def test_new_with_invalid_alias + invalid_aliases = %w[v - -- +] + invalid_aliases.each do |invalid_alias| + e = assert_raises(ArgumentError, invalid_alias.to_s) do + arguments = [ + ['--verbose', invalid_alias, GetoptLong::NO_ARGUMENT] + ] + GetoptLong.new(*arguments) + end + assert_match(/invalid option/, e.message) + end + end + + def test_new_with_invalid_flag + invalid_flags = ['foo'] + invalid_flags.each do |invalid_flag| + e = assert_raises(ArgumentError, invalid_flag.to_s) do + arguments = [ + ['--verbose', '-v', invalid_flag] + ] + GetoptLong.new(*arguments) + end + assert_match(/no argument-flag/, e.message) + end + end + +end From e063b07876d381726d950c5b8f21675ff76bf246 Mon Sep 17 00:00:00 2001 From: BurdetteLamar Date: Mon, 18 Oct 2021 07:06:00 -0500 Subject: [PATCH 02/11] Switch from Minitest to test-unit --- test/test_new.rb | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/test/test_new.rb b/test/test_new.rb index 26adca4..c51e646 100644 --- a/test/test_new.rb +++ b/test/test_new.rb @@ -1,7 +1,7 @@ -require 'minitest/autorun' +require 'test/unit' require 'getoptlong' -class TestGetoptLong < Minitest::Test +class TestGetoptLong < Test::Unit::TestCase def setup # Nothing yet. @@ -28,16 +28,16 @@ def test_required_argument end end - def test_required_argument_missing - options = %w[--xxx --xx --x -x --aaa --aa --a -a] - options.each do |option| - expected = "option `--xxx' requires an argument (GetoptLong::MissingArgument)" - _, err = capture_subprocess_io do - `ruby test/test.rb --xxx` - end - assert_match(expected, err) - end - end + # def test_required_argument_missing + # options = %w[--xxx --xx --x -x --aaa --aa --a -a] + # options.each do |option| + # expected = "option `--xxx' requires an argument (GetoptLong::MissingArgument)" + # _, err = capture_subprocess_io do + # `ruby test/test.rb --xxx` + # end + # assert_match(expected, err) + # end + # end def test_optional_argument options = %w[--yyy --y --y -y --bbb --bb --b -b] From 58f74f0ac152391cbad0524ccb26541839925132 Mon Sep 17 00:00:00 2001 From: BurdetteLamar Date: Mon, 18 Oct 2021 16:31:51 -0500 Subject: [PATCH 03/11] Some tests --- test/test.rb | 5 ++++- test/test_new.rb | 56 +++++++++++++++++++++++++++++++++++++++--------- 2 files changed, 50 insertions(+), 11 deletions(-) diff --git a/test/test.rb b/test/test.rb index 92f4025..3437450 100644 --- a/test/test.rb +++ b/test/test.rb @@ -5,8 +5,11 @@ ['--zzz', '-z', '--ccc', '-c', GetoptLong::NO_ARGUMENT] ) opts.each do |opt, arg| - puts "#{opt} => #{arg}" + puts "#{opt}: #{arg}" end +puts ARGV +puts ARGV.size + diff --git a/test/test_new.rb b/test/test_new.rb index c51e646..279ecf8 100644 --- a/test/test_new.rb +++ b/test/test_new.rb @@ -11,20 +11,44 @@ def teardown # Nothing yet. end + def verify_output(expected, output) + exp_entries = expected.dup + act_entries = output.split("\n") + # Last act_entry is argv size as a string. + argv_size = act_entries.pop.to_i + act_argv = act_entries.pop(argv_size) + # Last exp_entry is an array of expected argv strings. + exp_argv = exp_entries.pop + assert_equal(exp_argv, act_argv, 'ARGV') + assert_equal(exp_entries.size, act_entries.size, 'Entries') + i = 0 + exp_entries.zip(act_entries) do |exp, act| + assert_equal(exp, act, "Entry #{i}") + i += 1 + end + end + def test_new_with_no_array GetoptLong.new end def test_no_options - output = `ruby test/test.rb` - assert_equal(output, '') + output = `ruby test/test.rb foo bar` + expected = [ + %w[foo bar] + ] + verify_output(expected, output) end def test_required_argument + expected = [ + '--xxx: arg', + %w[foo bar] + ] options = %w[--xxx --xx --x -x --aaa --aa --a -a] options.each do |option| - output = `ruby test/test.rb #{option} arg` - assert_equal("--xxx => arg\n", output) + output = `ruby test/test.rb foo #{option} arg bar` + verify_output(expected, output) end end @@ -40,26 +64,38 @@ def test_required_argument # end def test_optional_argument + expected = [ + '--yyy: arg', + %w[foo bar] + ] options = %w[--yyy --y --y -y --bbb --bb --b -b] options.each do |option| - output = `ruby test/test.rb #{option} arg` - assert_equal("--yyy => arg\n", output) + output = `ruby test/test.rb foo bar #{option} arg` + verify_output(expected, output) end end def test_optional_argument_missing + expected = [ + '--yyy: ', + %w[foo bar] + ] options = %w[--yyy --y --y -y --bbb --bb --b -b] options.each do |option| - output = `ruby test/test.rb #{option}` - assert_equal("--yyy => \n", output) + output = `ruby test/test.rb foo bar #{option}` + verify_output(expected, output) end end def test_no_argument + expected = [ + '--zzz: ', + %w[foo bar] + ] options = %w[--zzz --zz --z -z --ccc --cc --c -c] options.each do |option| - output = `ruby test/test.rb #{option}` - assert_equal("--zzz => \n", output) + output = `ruby test/test.rb foo #{option} bar` + verify_output(expected, output) end end From b21bd8f7622c2321751097c697fd1c048a59d10e Mon Sep 17 00:00:00 2001 From: BurdetteLamar Date: Mon, 18 Oct 2021 18:30:45 -0500 Subject: [PATCH 04/11] Some tests --- test/options.rb | 26 ++++++++++++++++++++++++++ test/test.rb | 15 --------------- test/test_new.rb | 29 ++++++++++++++++++++--------- 3 files changed, 46 insertions(+), 24 deletions(-) create mode 100644 test/options.rb delete mode 100644 test/test.rb diff --git a/test/options.rb b/test/options.rb new file mode 100644 index 0000000..4da4142 --- /dev/null +++ b/test/options.rb @@ -0,0 +1,26 @@ +require 'getoptlong' +# This program supports testing. +# A test can execute the program with selected options and arguments, +# then capture and evaluate the output. +# +# The output is: +# +# - One line for each found option. +# - One line for each remaining element in ARGV. +# - The count of ARGV elements. +# (This lets the test know now much of the output is ARGV, +# and how much is options.) +opts = GetoptLong.new( + ['--xxx', '-x', '--aaa', '-a', GetoptLong::REQUIRED_ARGUMENT], + ['--yyy', '-y', '--bbb', '-b', GetoptLong::OPTIONAL_ARGUMENT], + ['--zzz', '-z', '--ccc', '-c', GetoptLong::NO_ARGUMENT] +) +# Write each option and its argument. +opts.each do |opt, arg| + puts "#{opt}: #{arg}" +end +# To keep the parsing simple in the test, +# write each ARGV element on a separate line. +puts ARGV +# The test will need to know how many of them there are. +puts ARGV.size diff --git a/test/test.rb b/test/test.rb deleted file mode 100644 index 3437450..0000000 --- a/test/test.rb +++ /dev/null @@ -1,15 +0,0 @@ -require 'getoptlong' -opts = GetoptLong.new( - ['--xxx', '-x', '--aaa', '-a', GetoptLong::REQUIRED_ARGUMENT], - ['--yyy', '-y', '--bbb', '-b', GetoptLong::OPTIONAL_ARGUMENT], - ['--zzz', '-z', '--ccc', '-c', GetoptLong::NO_ARGUMENT] -) -opts.each do |opt, arg| - puts "#{opt}: #{arg}" -end -puts ARGV -puts ARGV.size - - - - diff --git a/test/test_new.rb b/test/test_new.rb index 279ecf8..9450277 100644 --- a/test/test_new.rb +++ b/test/test_new.rb @@ -11,13 +11,24 @@ def teardown # Nothing yet. end + # The target program is supposed to write: + # + # - One line for each option. + # - One line for each element in ARGV. + # - One line giving the count of ARGV elements. + # + # This is important because the test must know how to compare + # options against options and ARGV elements against ARGV elements. + # def verify_output(expected, output) + # Don't mess with the caller's data. exp_entries = expected.dup - act_entries = output.split("\n") - # Last act_entry is argv size as a string. + act_entries = output.dup.split("\n") + # The last act_entry is ARGV size as a string. + # Get the ARGV elements into act_argv. argv_size = act_entries.pop.to_i act_argv = act_entries.pop(argv_size) - # Last exp_entry is an array of expected argv strings. + # The last exp_entry is an array of expected argv strings. exp_argv = exp_entries.pop assert_equal(exp_argv, act_argv, 'ARGV') assert_equal(exp_entries.size, act_entries.size, 'Entries') @@ -33,7 +44,7 @@ def test_new_with_no_array end def test_no_options - output = `ruby test/test.rb foo bar` + output = `ruby test/options.rb foo bar` expected = [ %w[foo bar] ] @@ -47,7 +58,7 @@ def test_required_argument ] options = %w[--xxx --xx --x -x --aaa --aa --a -a] options.each do |option| - output = `ruby test/test.rb foo #{option} arg bar` + output = `ruby test/options.rb foo #{option} arg bar` verify_output(expected, output) end end @@ -57,7 +68,7 @@ def test_required_argument # options.each do |option| # expected = "option `--xxx' requires an argument (GetoptLong::MissingArgument)" # _, err = capture_subprocess_io do - # `ruby test/test.rb --xxx` + # `ruby test/options.rb --xxx` # end # assert_match(expected, err) # end @@ -70,7 +81,7 @@ def test_optional_argument ] options = %w[--yyy --y --y -y --bbb --bb --b -b] options.each do |option| - output = `ruby test/test.rb foo bar #{option} arg` + output = `ruby test/options.rb foo bar #{option} arg` verify_output(expected, output) end end @@ -82,7 +93,7 @@ def test_optional_argument_missing ] options = %w[--yyy --y --y -y --bbb --bb --b -b] options.each do |option| - output = `ruby test/test.rb foo bar #{option}` + output = `ruby test/options.rb foo bar #{option}` verify_output(expected, output) end end @@ -94,7 +105,7 @@ def test_no_argument ] options = %w[--zzz --zz --z -z --ccc --cc --c -c] options.each do |option| - output = `ruby test/test.rb foo #{option} bar` + output = `ruby test/options.rb foo #{option} bar` verify_output(expected, output) end end From 76c56dc2c16d2abad46e08f2e2a856341f6fd750 Mon Sep 17 00:00:00 2001 From: BurdetteLamar Date: Tue, 19 Oct 2021 07:55:18 -0500 Subject: [PATCH 05/11] Some tests --- test/{options.rb => t.rb} | 0 test/test_new.rb | 12 ++++++------ 2 files changed, 6 insertions(+), 6 deletions(-) rename test/{options.rb => t.rb} (100%) diff --git a/test/options.rb b/test/t.rb similarity index 100% rename from test/options.rb rename to test/t.rb diff --git a/test/test_new.rb b/test/test_new.rb index 9450277..bacd74c 100644 --- a/test/test_new.rb +++ b/test/test_new.rb @@ -44,7 +44,7 @@ def test_new_with_no_array end def test_no_options - output = `ruby test/options.rb foo bar` + output = `ruby test/t.rb foo bar` expected = [ %w[foo bar] ] @@ -58,7 +58,7 @@ def test_required_argument ] options = %w[--xxx --xx --x -x --aaa --aa --a -a] options.each do |option| - output = `ruby test/options.rb foo #{option} arg bar` + output = `ruby test/t.rb foo #{option} arg bar` verify_output(expected, output) end end @@ -68,7 +68,7 @@ def test_required_argument # options.each do |option| # expected = "option `--xxx' requires an argument (GetoptLong::MissingArgument)" # _, err = capture_subprocess_io do - # `ruby test/options.rb --xxx` + # `ruby test/t.rb --xxx` # end # assert_match(expected, err) # end @@ -81,7 +81,7 @@ def test_optional_argument ] options = %w[--yyy --y --y -y --bbb --bb --b -b] options.each do |option| - output = `ruby test/options.rb foo bar #{option} arg` + output = `ruby test/t.rb foo bar #{option} arg` verify_output(expected, output) end end @@ -93,7 +93,7 @@ def test_optional_argument_missing ] options = %w[--yyy --y --y -y --bbb --bb --b -b] options.each do |option| - output = `ruby test/options.rb foo bar #{option}` + output = `ruby test/t.rb foo bar #{option}` verify_output(expected, output) end end @@ -105,7 +105,7 @@ def test_no_argument ] options = %w[--zzz --zz --z -z --ccc --cc --c -c] options.each do |option| - output = `ruby test/options.rb foo #{option} bar` + output = `ruby test/t.rb foo #{option} bar` verify_output(expected, output) end end From 2a8e2a602af2ad69d765ec88bcfdfbd183a2efd8 Mon Sep 17 00:00:00 2001 From: BurdetteLamar Date: Wed, 20 Oct 2021 08:33:17 -0500 Subject: [PATCH 06/11] Some tests --- test/test_new.rb | 102 ++++++++++++++++++++--------------------------- 1 file changed, 44 insertions(+), 58 deletions(-) diff --git a/test/test_new.rb b/test/test_new.rb index bacd74c..7eb6aa9 100644 --- a/test/test_new.rb +++ b/test/test_new.rb @@ -3,40 +3,27 @@ class TestGetoptLong < Test::Unit::TestCase - def setup - # Nothing yet. - end - - def teardown - # Nothing yet. - end - - # The target program is supposed to write: - # - # - One line for each option. - # - One line for each element in ARGV. - # - One line giving the count of ARGV elements. - # - # This is important because the test must know how to compare - # options against options and ARGV elements against ARGV elements. - # - def verify_output(expected, output) - # Don't mess with the caller's data. - exp_entries = expected.dup - act_entries = output.dup.split("\n") - # The last act_entry is ARGV size as a string. - # Get the ARGV elements into act_argv. - argv_size = act_entries.pop.to_i - act_argv = act_entries.pop(argv_size) - # The last exp_entry is an array of expected argv strings. - exp_argv = exp_entries.pop - assert_equal(exp_argv, act_argv, 'ARGV') - assert_equal(exp_entries.size, act_entries.size, 'Entries') - i = 0 - exp_entries.zip(act_entries) do |exp, act| - assert_equal(exp, act, "Entry #{i}") - i += 1 + def verify(test_argv, expected_remaining_argv, expected_options) + # Save ARGV and replace it with a test ARGV. + argv_saved = ARGV + ARGV.replace(test_argv) + # Define options. + opts = GetoptLong.new( + ['--xxx', '-x', '--aaa', '-a', GetoptLong::REQUIRED_ARGUMENT], + ['--yyy', '-y', '--bbb', '-b', GetoptLong::OPTIONAL_ARGUMENT], + ['--zzz', '-z', '--ccc', '-c', GetoptLong::NO_ARGUMENT] + ) + # Gather options. + actual_options = [] + opts.each do |opt, arg| + actual_options << "#{opt}: #{arg}" end + # Save remaining test ARGV and restore original ARGV. + actual_remaining_argv = ARGV + ARGV.replace(argv_saved) + # Assert. + assert_equal(expected_remaining_argv, actual_remaining_argv, 'ARGV') + assert_equal(expected_options, actual_options, 'Options') end def test_new_with_no_array @@ -44,22 +31,21 @@ def test_new_with_no_array end def test_no_options - output = `ruby test/t.rb foo bar` - expected = [ - %w[foo bar] - ] - verify_output(expected, output) + expected_options = [] + expected_argv = %w[foo bar] + argv = %w[foo bar] + verify(argv, expected_argv, expected_options) end def test_required_argument - expected = [ - '--xxx: arg', - %w[foo bar] + expected_options = [ + '--xxx: arg' ] + expected_argv = %w[foo bar] options = %w[--xxx --xx --x -x --aaa --aa --a -a] options.each do |option| - output = `ruby test/t.rb foo #{option} arg bar` - verify_output(expected, output) + argv = ['foo', option, 'arg', 'bar'] + verify(argv, expected_argv, expected_options) end end @@ -75,38 +61,38 @@ def test_required_argument # end def test_optional_argument - expected = [ - '--yyy: arg', - %w[foo bar] + expected_options = [ + '--yyy: arg' ] + expected_argv = %w[foo bar] options = %w[--yyy --y --y -y --bbb --bb --b -b] options.each do |option| - output = `ruby test/t.rb foo bar #{option} arg` - verify_output(expected, output) + argv = ['foo', 'bar', option, 'arg'] + verify(argv, expected_argv, expected_options) end end def test_optional_argument_missing - expected = [ - '--yyy: ', - %w[foo bar] + expected_options = [ + '--yyy: ' ] + expected_argv = %w[foo bar] options = %w[--yyy --y --y -y --bbb --bb --b -b] options.each do |option| - output = `ruby test/t.rb foo bar #{option}` - verify_output(expected, output) + argv = ['foo', 'bar', option] + verify(argv, expected_argv, expected_options) end end def test_no_argument - expected = [ - '--zzz: ', - %w[foo bar] + expected_options = [ + '--zzz: ' ] + expected_argv = %w[foo bar] options = %w[--zzz --zz --z -z --ccc --cc --c -c] options.each do |option| - output = `ruby test/t.rb foo #{option} bar` - verify_output(expected, output) + argv = ['foo', option, 'bar'] + verify(argv, expected_argv, expected_options) end end From 9be4cdd3350606f19e4e3935fd659754f3a6ff00 Mon Sep 17 00:00:00 2001 From: BurdetteLamar Date: Wed, 20 Oct 2021 08:59:40 -0500 Subject: [PATCH 07/11] Some tests --- test/test_new.rb | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/test/test_new.rb b/test/test_new.rb index 7eb6aa9..b066b49 100644 --- a/test/test_new.rb +++ b/test/test_new.rb @@ -49,16 +49,16 @@ def test_required_argument end end - # def test_required_argument_missing - # options = %w[--xxx --xx --x -x --aaa --aa --a -a] - # options.each do |option| - # expected = "option `--xxx' requires an argument (GetoptLong::MissingArgument)" - # _, err = capture_subprocess_io do - # `ruby test/t.rb --xxx` - # end - # assert_match(expected, err) - # end - # end + def test_required_argument_missing + options = %w[--xxx --xx --x -x --aaa --aa --a -a] + options.each do |option| + argv = [option] + e = assert_raises(GetoptLong::MissingArgument) do + verify(argv, [], []) + end + assert_match('requires an argument', e.message) + end + end def test_optional_argument expected_options = [ From 821d32d3bbfe7e2f172c72c1a56da8f597892041 Mon Sep 17 00:00:00 2001 From: BurdetteLamar Date: Wed, 20 Oct 2021 10:47:23 -0500 Subject: [PATCH 08/11] Some tests --- test/t.rb | 26 -------------------------- 1 file changed, 26 deletions(-) delete mode 100644 test/t.rb diff --git a/test/t.rb b/test/t.rb deleted file mode 100644 index 4da4142..0000000 --- a/test/t.rb +++ /dev/null @@ -1,26 +0,0 @@ -require 'getoptlong' -# This program supports testing. -# A test can execute the program with selected options and arguments, -# then capture and evaluate the output. -# -# The output is: -# -# - One line for each found option. -# - One line for each remaining element in ARGV. -# - The count of ARGV elements. -# (This lets the test know now much of the output is ARGV, -# and how much is options.) -opts = GetoptLong.new( - ['--xxx', '-x', '--aaa', '-a', GetoptLong::REQUIRED_ARGUMENT], - ['--yyy', '-y', '--bbb', '-b', GetoptLong::OPTIONAL_ARGUMENT], - ['--zzz', '-z', '--ccc', '-c', GetoptLong::NO_ARGUMENT] -) -# Write each option and its argument. -opts.each do |opt, arg| - puts "#{opt}: #{arg}" -end -# To keep the parsing simple in the test, -# write each ARGV element on a separate line. -puts ARGV -# The test will need to know how many of them there are. -puts ARGV.size From dbd177646c2329d5bd1c9d7417ee117fefb2ea3e Mon Sep 17 00:00:00 2001 From: BurdetteLamar Date: Fri, 22 Oct 2021 18:57:36 -0500 Subject: [PATCH 09/11] Some tests --- test/{test_new.rb => test_getoptlong.rb} | 4 ---- 1 file changed, 4 deletions(-) rename test/{test_new.rb => test_getoptlong.rb} (98%) diff --git a/test/test_new.rb b/test/test_getoptlong.rb similarity index 98% rename from test/test_new.rb rename to test/test_getoptlong.rb index b066b49..386ada7 100644 --- a/test/test_new.rb +++ b/test/test_getoptlong.rb @@ -26,10 +26,6 @@ def verify(test_argv, expected_remaining_argv, expected_options) assert_equal(expected_options, actual_options, 'Options') end - def test_new_with_no_array - GetoptLong.new - end - def test_no_options expected_options = [] expected_argv = %w[foo bar] From 500cff59fd6b636c38866b094bcc104823f032e5 Mon Sep 17 00:00:00 2001 From: BurdetteLamar Date: Fri, 22 Oct 2021 19:32:24 -0500 Subject: [PATCH 10/11] Some tests --- test/test_getoptlong.rb | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/test/test_getoptlong.rb b/test/test_getoptlong.rb index 386ada7..f7ed87a 100644 --- a/test/test_getoptlong.rb +++ b/test/test_getoptlong.rb @@ -49,7 +49,7 @@ def test_required_argument_missing options = %w[--xxx --xx --x -x --aaa --aa --a -a] options.each do |option| argv = [option] - e = assert_raises(GetoptLong::MissingArgument) do + e = assert_raise(GetoptLong::MissingArgument) do verify(argv, [], []) end assert_match('requires an argument', e.message) @@ -93,28 +93,28 @@ def test_no_argument end def test_new_with_empty_array - e = assert_raises(ArgumentError) do + e = assert_raise(ArgumentError) do GetoptLong.new([]) end assert_match(/no argument-flag/, e.message) end def test_new_with_bad_array - e = assert_raises(ArgumentError) do + e = assert_raise(ArgumentError) do GetoptLong.new('foo') end assert_match(/option list contains non-Array argument/, e.message) end def test_new_with_empty_subarray - e = assert_raises(ArgumentError) do + e = assert_raise(ArgumentError) do GetoptLong.new([[]]) end assert_match(/no argument-flag/, e.message) end def test_new_with_bad_subarray - e = assert_raises(ArgumentError) do + e = assert_raise(ArgumentError) do GetoptLong.new([1]) end assert_match(/no option name/, e.message) @@ -123,7 +123,7 @@ def test_new_with_bad_subarray def test_new_with_invalid_option invalid_options = %w[verbose -verbose -- +] invalid_options.each do |invalid_option| - e = assert_raises(ArgumentError, invalid_option.to_s) do + e = assert_raise(ArgumentError, invalid_option.to_s) do arguments = [ [invalid_option, '-v', GetoptLong::NO_ARGUMENT] ] @@ -136,7 +136,7 @@ def test_new_with_invalid_option def test_new_with_invalid_alias invalid_aliases = %w[v - -- +] invalid_aliases.each do |invalid_alias| - e = assert_raises(ArgumentError, invalid_alias.to_s) do + e = assert_raise(ArgumentError, invalid_alias.to_s) do arguments = [ ['--verbose', invalid_alias, GetoptLong::NO_ARGUMENT] ] @@ -149,7 +149,7 @@ def test_new_with_invalid_alias def test_new_with_invalid_flag invalid_flags = ['foo'] invalid_flags.each do |invalid_flag| - e = assert_raises(ArgumentError, invalid_flag.to_s) do + e = assert_raise(ArgumentError, invalid_flag.to_s) do arguments = [ ['--verbose', '-v', invalid_flag] ] From e105d81d842d6d68b659cb64b72b620fa19d3d30 Mon Sep 17 00:00:00 2001 From: BurdetteLamar Date: Mon, 25 Oct 2021 07:09:09 -0500 Subject: [PATCH 11/11] Some tests --- test/test_getoptlong.rb | 1 + 1 file changed, 1 insertion(+) diff --git a/test/test_getoptlong.rb b/test/test_getoptlong.rb index f7ed87a..f3f0812 100644 --- a/test/test_getoptlong.rb +++ b/test/test_getoptlong.rb @@ -13,6 +13,7 @@ def verify(test_argv, expected_remaining_argv, expected_options) ['--yyy', '-y', '--bbb', '-b', GetoptLong::OPTIONAL_ARGUMENT], ['--zzz', '-z', '--ccc', '-c', GetoptLong::NO_ARGUMENT] ) + opts.quiet = true # Gather options. actual_options = [] opts.each do |opt, arg|