[Groonga-commit] droonga/drntest at ed71bea [master] Simplify error message for unknown directive case

Back to archive index

Kouhei Sutou null+****@clear*****
Wed Mar 19 16:54:25 JST 2014


Kouhei Sutou	2014-03-19 16:54:25 +0900 (Wed, 19 Mar 2014)

  New Revision: ed71bea0408bde6d80cf52b3e1c7acdd80f86875
  https://github.com/droonga/drntest/commit/ed71bea0408bde6d80cf52b3e1c7acdd80f86875

  Message:
    Simplify error message for unknown directive case

  Added files:
    lib/drntest/input-error.rb
  Modified files:
    lib/drntest/test-loader.rb
    lib/drntest/test-runner.rb

  Added: lib/drntest/input-error.rb (+26 -0) 100644
===================================================================
--- /dev/null
+++ lib/drntest/input-error.rb    2014-03-19 16:54:25 +0900 (507f9e1)
@@ -0,0 +1,26 @@
+# Copyright (C) 2014  Droonga Project
+#
+# This program is free software: you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation, either version 3 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program.  If not, see <http://www.gnu.org/licenses/>.
+
+module Drntest
+  class InputError < StandardError
+    attr_reader :file, :line_number, :content
+    def initialize(file, line_number, content, message)
+      @file = file
+      @line_number = line_number
+      @content = content
+      super("#{message}: #{@file}:#{@line_number}: #{@content}")
+    end
+  end
+end

  Modified: lib/drntest/test-loader.rb (+8 -4)
===================================================================
--- lib/drntest/test-loader.rb    2014-03-19 16:36:21 +0900 (66c62e0)
+++ lib/drntest/test-loader.rb    2014-03-19 16:54:25 +0900 (cc11c97)
@@ -15,6 +15,7 @@
 
 require "drntest/json-loader"
 require "drntest/directive"
+require "drntest/input-error"
 
 module Drntest
   class TestLoader
@@ -41,13 +42,14 @@ module Drntest
         operations << operation
       end
       data = ""
-      Pathname(path).read.each_line do |line|
+      Pathname(path).open do |input|
+        input.each_line do |line|
         data << line
         case line.chomp
         when /\A\#\@([^\s]+)(?:\s+(.+))?\z/
           type = $1
           value = $2
-          directive = parse_directive(type, value)
+          directive = parse_directive(type, value, path, input.lineno, line)
           if directive.is_a?(IncludeDirective)
             included = resolve_relative_path(directive.path)
             included_operations = load_test_file(included)
@@ -66,10 +68,11 @@ module Drntest
           end
         end
       end
+      end
       operations
     end
 
-    def parse_directive(type, value)
+    def parse_directive(type, value, path, line_number, content)
       case normalize_directive_type(type)
       when :include
         IncludeDirective.new(value)
@@ -80,7 +83,8 @@ module Drntest
       when :omit
         OmitDirective.new(value)
       else
-        raise "unknown directive: #{type}"
+        raise InputError.new(path, line_number, content,
+                             "unknown directive: <#{type}>")
       end
     end
 

  Modified: lib/drntest/test-runner.rb (+7 -2)
===================================================================
--- lib/drntest/test-runner.rb    2014-03-19 16:36:21 +0900 (c4ab6ea)
+++ lib/drntest/test-runner.rb    2014-03-19 16:54:25 +0900 (130118f)
@@ -23,6 +23,7 @@ require "drntest/test-results"
 require "drntest/test-executor"
 require "drntest/json-loader"
 require "drntest/engine"
+require "drntest/input-error"
 
 module Drntest
   class TestRunner
@@ -170,8 +171,12 @@ module Drntest
       errors.each_with_index do |error, i|
         puts(mark)
         formatted_nth = "%*d)" % [n_digits, i + 1]
-        puts("#{formatted_nth} #{error.message} (#{error.class})")
-        puts(error.backtrace)
+        if error.is_a?(InputError)
+          puts("#{formatted_nth} #{error.message}")
+        else
+          puts("#{formatted_nth} #{error.message} (#{error.class})")
+          puts(error.backtrace)
+        end
         puts(mark)
       end
     end
-------------- next part --------------
HTML����������������������������...
Download 



More information about the Groonga-commit mailing list
Back to archive index