[Groonga-commit] groonga/groonga-test [master] Support error handling

Back to archive index

null+****@clear***** null+****@clear*****
2012年 3月 5日 (月) 18:27:43 JST


Kouhei Sutou	2012-03-05 18:27:43 +0900 (Mon, 05 Mar 2012)

  New Revision: a2bde97d41a43093bd5fd1b9715faa8ba6ed61a8

  Log:
    Support error handling

  Modified files:
    bin/groonga-test

  Modified: bin/groonga-test (+49 -6)
===================================================================
--- bin/groonga-test    2012-03-05 17:52:25 +0900 (4405257)
+++ bin/groonga-test    2012-03-05 18:27:43 +0900 (d7c30e5)
@@ -185,8 +185,31 @@ class GroongaTester
       attr_accessor :logging, :result
       def initialize
         @logging = true
+        @n_nested = 0
         @result = []
       end
+
+      def execute
+        @n_nested += 1
+        yield
+      ensure
+        @n_nested -= 1
+      end
+
+      def top_level?
+        @n_nested == 1
+      end
+    end
+
+    class Error < StandardError
+    end
+
+    class NotExist < Error
+      attr_reader :path
+      def initialize(path)
+        @path = path
+        super("<#{path}> doesn't exist.")
+      end
     end
 
     def initialize(groonga, context=nil)
@@ -197,12 +220,24 @@ class GroongaTester
     end
 
     def execute(script_path)
-      script_path.open("r:ascii-8bit") do |script_file|
-        script_file.each_line do |line|
-          if @loading
-            execute_line_on_loading(line)
-          else
-            execute_line_with_continuation_line_support(line)
+      unless script_path.exist?
+        raise NotExist.new(script_path)
+      end
+
+      @context.execute do
+        script_path.open("r:ascii-8bit") do |script_file|
+          script_file.each_line do |line|
+            begin
+              if @loading
+                execute_line_on_loading(line)
+              else
+                execute_line_with_continuation_line_support(line)
+              end
+            rescue Error
+              line_info = "#{script_path}:#{script_file.lineno}:#{line.chomp}"
+              log_error("#{line_info}: #{$!.message}")
+              raise unles****@conte*****_level?
+            end
           end
         end
       end
@@ -297,6 +332,10 @@ class GroongaTester
     def log(tag, content)
       return unles****@conte*****
       return if content.empty?
+      log_force(tag, content)
+    end
+
+    def log_force(tag, content)
       @context.result << [tag, content]
     end
 
@@ -307,6 +346,10 @@ class GroongaTester
     def log_output(content)
       log(:output, content)
     end
+
+    def log_error(content)
+      log_force(:error, content)
+    end
   end
 
   class Reporter




Groonga-commit メーリングリストの案内
Back to archive index