diff --git a/script/texdoclib-cli.tlu b/script/texdoclib-cli.tlu index b5a98bf..79c2026 100644 --- a/script/texdoclib-cli.tlu +++ b/script/texdoclib-cli.tlu @@ -106,14 +106,14 @@ local function parse_options() end for i, o in ipairs(C.options) do - if k == o["short"] or k == o["long"] then + if k == o['short'] or k == o['long'] then k = i break end end option = C.options[k] - if option['group'] == 'action' then + if option ~= nil and option['group'] == 'action' then if option['long'] == 'just-view' then return true, 'view', cl_config elseif option['long'] == 'print-completion' then @@ -121,7 +121,7 @@ local function parse_options() else return true, option['long'], cl_config end - elseif option['group'] then + elseif option~=nil and option['group'] then if option['type'] == 'boolean' then option['action'](cl_config, curr_arg) elseif option['type'] == 'string' then diff --git a/spec/misc/errors_spec.rb b/spec/misc/errors_spec.rb index afe8d44..3a8591c 100644 --- a/spec/misc/errors_spec.rb +++ b/spec/misc/errors_spec.rb @@ -3,34 +3,6 @@ RSpec.describe "Errors", :type => :aruba do include_context "messages" - context "running without any option nor argument" do - before(:each) { run_texdoc } - - it 'should result in the "no action" error' do - expect(last_command_started).to have_exit_status(2) - expect(stderr).to include(error_line "No action specified.") - expect(stderr).to include(error_line msg_usage) - end - end - - context "missing arguments for Option -d" do - before(:each) { run_texdoc "-d" } - - it 'should result in a getopt parser error' do - expect(last_command_started).to have_exit_status(1) - expect(stderr).to include(error_line "Option -d requires an argument.") - end - end - - context "missing arguments for Option -c" do - before(:each) { run_texdoc "-c" } - - it 'should result in a getopt parser error' do - expect(last_command_started).to have_exit_status(1) - expect(stderr).to include(error_line "Option -c requires an argument.") - end - end - context "when any document for input cannot be found" do let(:nonexist_pkg) { "never_never_existing_package_foooooooooo" } diff --git a/spec/misc/getopt_spec.rb b/spec/misc/getopt_spec.rb index 02b4e30..83a6b7e 100644 --- a/spec/misc/getopt_spec.rb +++ b/spec/misc/getopt_spec.rb @@ -110,4 +110,42 @@ debug_line "search", "Searching documents for pattern \"-texlive-en\"") end end + + # error cases + context "running without any option nor argument" do + before(:each) { run_texdoc } + + it 'should result in the "no action" error' do + expect(last_command_started).to have_exit_status(2) + expect(stderr).to include(error_line "No action specified.") + expect(stderr).to include(error_line msg_usage) + end + end + + context "missing arguments for Option -d" do + before(:each) { run_texdoc "-d" } + + it "should result in a getopt parser error" do + expect(last_command_started).to have_exit_status(1) + expect(stderr).to include(error_line "Option -d requires an argument.") + end + end + + context "missing arguments for Option -c" do + before(:each) { run_texdoc "-c" } + + it "should result in a getopt parser error" do + expect(last_command_started).to have_exit_status(1) + expect(stderr).to include(error_line "Option -c requires an argument.") + end + end + + context "given an unknown option" do + before(:each) { run_texdoc "-x" } + + it "should result in a getopt parser error" do + expect(last_command_started).to have_exit_status(2) + expect(stderr).to include(error_line "unknown option: -x") + end + end end