diff options
author | makoto kuwata <kwa@kuwata-lab.com> | 2009-02-07 09:10:01 +0000 |
---|---|---|
committer | makoto kuwata <kwa@kuwata-lab.com> | 2009-02-07 09:10:01 +0000 |
commit | 10fe426fc39b65f979cef34a758ecd206f25a61d (patch) | |
tree | 504cf1eb725375e408ea916a12e264addc95fded | |
parent | 694d19941e8e52f290f3cb5e6c2afbffba796d5c (diff) | |
download | erubis-10fe426fc39b65f979cef34a758ecd206f25a61d.tar.gz |
- [bugfix] report argument name when option argument is missing
- [bugfix] enhacner class name was not reported when not found (Ruby 1.9.1)
- [change] add _error_test() to 'test-main.rb'
-rw-r--r-- | ChangeLog.txt | 5 | ||||
-rw-r--r-- | lib/erubis/main.rb | 5 | ||||
-rw-r--r-- | test/test-main.rb | 39 |
3 files changed, 29 insertions, 20 deletions
diff --git a/ChangeLog.txt b/ChangeLog.txt index b70e4ec..68e62e1 100644 --- a/ChangeLog.txt +++ b/ChangeLog.txt @@ -2,6 +2,11 @@ .?lastupdate: $Date$ .?version: $Rev$ +: Rev.122 (2009-02-07) + .- [bugfix] report argument name when option argument is missing + .- [bugfix] enhacner class name was not reported when not found (Ruby 1.9.1) + .- [change] add _error_test() to 'test-main.rb' + : Rev.121 (2009-02-07) .- [change] change '#!/usr/bin/ruby' to '#!/usr/bin/env ruby' in 'bin/erubis' .- [bugfix] change 'optchar.chr' to 'optchar' in 'main.rb'. diff --git a/lib/erubis/main.rb b/lib/erubis/main.rb index 58084d8..34f1091 100644 --- a/lib/erubis/main.rb +++ b/lib/erubis/main.rb @@ -326,7 +326,7 @@ module Erubis elsif arg_required.include?(optchar) arg = optstr.empty? ? argv.shift : optstr unless arg - mesg = "-#{optchar}: #{@option_args[optchar]} required." + mesg = "-#{optchar}: #{@option_names[optchar]} required." raise CommandOptionError.new(mesg) end options[optchar] = arg @@ -395,7 +395,8 @@ module Erubis enhancers = [] shortname = nil begin - enhancer_names.split(/,/).each do |shortname| + enhancer_names.split(/,/).each do |name| + shortname = name enhancers << Erubis.const_get("#{shortname}Enhancer") end rescue NameError diff --git a/test/test-main.rb b/test/test-main.rb index dab8006..5db3f52 100644 --- a/test/test-main.rb +++ b/test/test-main.rb @@ -152,17 +152,8 @@ END end File.open(@filename, 'w') { |f| f.write(@input) } if @filename begin - #if @options.is_a?(Array) - # command = "ruby #{$script} #{@options.join(' ')} #{@filename}" - #else - # command = "ruby #{$script} #{@options} #{@filename}" - #end - #output = `#{command}` - if @options.is_a?(Array) - argv = @options + [ @filename ] - else - argv = "#{@options} #{@filename}".split - end + argv = @options.is_a?(Array) ? @options.dup : @options.split + argv << @filename if @filename $stdout = output = StringWriter.new Erubis::Main.new.execute(argv) ensure @@ -172,6 +163,12 @@ END assert_text_equal(@expected, output) end + def _error_test(errclass, errmsg) + ex = assert_raise(errclass) { _test() } + assert_equal(errmsg, ex.message) + end + + def test_help # -h @options = '-h' m = Erubis::Main.new @@ -242,7 +239,7 @@ END -:7: syntax error, unexpected $end, expecting ')' END errmsgs << <<'END' -7: syntax error, unexpected $end, expecting keyword_end or keyword_endfor +7: syntax error, unexpected $end, expecting keyword_end END else errmsgs << <<'END' @@ -620,24 +617,30 @@ END def test_invalid_option # -1 (invalid option) @input = INPUT @options = '-1' - ex = assert_raise(Erubis::CommandOptionError) { _test() } - assert_equal("-1: unknown option.", ex.message) + _error_test(Erubis::CommandOptionError, "-1: unknown option.") end def test_invalid_enhancer # -E hoge @options = '-E hoge' errmsg = "hoge: no such Enhancer (try '-h' to show all enhancers)." - ex = assert_raise(Erubis::CommandOptionError) { _test() } - assert_equal(errmsg, ex.message) + _error_test(Erubis::CommandOptionError, errmsg) end def test_invalid_lang # -l hoge @options = '-l hoge' errmsg = "-l hoge: invalid language name (class Erubis::Ehoge not found)." - ex = assert_raise(Erubis::CommandOptionError) { _test() } - assert_equal(errmsg, ex.message) + _error_test(Erubis::CommandOptionError, errmsg) + end + + + def test_missing_argument # -E + @filename = false + @options = '-E' + _error_test(Erubis::CommandOptionError, "-E: enhancers required.") + @options = '-l' + _error_test(Erubis::CommandOptionError, "-l: lang required.") end |