Kouhei Sutou
null+****@clear*****
Wed Mar 19 17:01:31 JST 2014
Kouhei Sutou 2014-03-19 17:01:31 +0900 (Wed, 19 Mar 2014) New Revision: ab8b2427b6b8641c41fc4c3d23e49dede9e6c356 https://github.com/droonga/drntest/commit/ab8b2427b6b8641c41fc4c3d23e49dede9e6c356 Message: Simplify error handling on unknown directive Modified files: lib/drntest/directive.rb lib/drntest/test-loader.rb Modified: lib/drntest/directive.rb (+9 -0) =================================================================== --- lib/drntest/directive.rb 2014-03-19 16:58:42 +0900 (2bc95e6) +++ lib/drntest/directive.rb 2014-03-19 17:01:31 +0900 (47f47d6) @@ -17,6 +17,15 @@ module Drntest class Directive end + class UnknownDirective < Directive + attr_reader :type, :options + + def initialize(type, options) + @type = type + @options = options + end + end + class IncludeDirective < Directive attr_reader :path Modified: lib/drntest/test-loader.rb (+8 -5) =================================================================== --- lib/drntest/test-loader.rb 2014-03-19 16:58:42 +0900 (e7f24de) +++ lib/drntest/test-loader.rb 2014-03-19 17:01:31 +0900 (fd44cad) @@ -52,8 +52,12 @@ module Drntest when /\A\#\@([^\s]+)/ type = $1 options = Shellwords.split($POSTMATCH.strip) - directive = parse_directive(type, options, path, input.lineno, line) - if directive.is_a?(IncludeDirective) + directive = parse_directive(type, options) + case directive + when UnknownDirective + raise InputError.new(path, input.lineno, line, + "unknown directive: <#{directive.type}>") + when IncludeDirective included = resolve_relative_path(directive.path) included_operations = load_test_file(included) operations += included_operations @@ -75,7 +79,7 @@ module Drntest operations end - def parse_directive(type, options, path, line_number, content) + def parse_directive(type, options) case normalize_directive_type(type) when :include IncludeDirective.new(value) @@ -86,8 +90,7 @@ module Drntest when :omit OmitDirective.new(options.first) else - raise InputError.new(path, line_number, content, - "unknown directive: <#{type}>") + UnknownDirective.new(type, options) end end -------------- next part -------------- HTML����������������������������...Download