[Groonga-commit] droonga/drntest at f276da4 [master] Create directive objects

Back to archive index

Kouhei Sutou null+****@clear*****
Wed Mar 19 16:36:21 JST 2014


Kouhei Sutou	2014-03-19 16:36:21 +0900 (Wed, 19 Mar 2014)

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

  Message:
    Create directive objects

  Modified files:
    lib/drntest/directive.rb
    lib/drntest/test-executor.rb
    lib/drntest/test-loader.rb

  Modified: lib/drntest/directive.rb (+18 -7)
===================================================================
--- lib/drntest/directive.rb    2014-03-19 16:26:46 +0900 (2eefcce)
+++ lib/drntest/directive.rb    2014-03-19 16:36:21 +0900 (2bc95e6)
@@ -15,16 +15,27 @@
 
 module Drntest
   class Directive
-    attr_reader :type, :value
+  end
+
+  class IncludeDirective < Directive
+    attr_reader :path
 
-    def initialize(type, value)
-      @type = normalize_type(type)
-      @value = value
+    def initialize(path)
+      @path = path
     end
+  end
+
+  class EnableLoggingDirective < Directive
+  end
+
+  class DisableLoggingDirective < Directive
+  end
+
+  class OmitDirective < Directive
+    attr_reader :message
 
-    private
-    def normalize_type(type)
-      type.gsub("-", "_").to_sym
+    def initialize(message)
+      @message = message
     end
   end
 end

  Modified: lib/drntest/test-executor.rb (+5 -5)
===================================================================
--- lib/drntest/test-executor.rb    2014-03-19 16:26:46 +0900 (e8f86e3)
+++ lib/drntest/test-executor.rb    2014-03-19 16:36:21 +0900 (d2cac89)
@@ -74,14 +74,14 @@ module Drntest
 
       private
       def execute_directive(directive)
-        case directive.type
-        when :enable_logging
+        case directive
+        when EnableLoggingDirective
           @logging = true
           consume_requests
-        when :disable_logging
+        when DisableLoggingDirective
           @logging = false
-        when :omit
-          @results.omit(directive.value)
+        when OmitDirective
+          @results.omit(directive.message)
           abort_execution
         end
       end

  Modified: lib/drntest/test-loader.rb (+22 -3)
===================================================================
--- lib/drntest/test-loader.rb    2014-03-19 16:26:46 +0900 (c73cb73)
+++ lib/drntest/test-loader.rb    2014-03-19 16:36:21 +0900 (66c62e0)
@@ -47,9 +47,9 @@ module Drntest
         when /\A\#\@([^\s]+)(?:\s+(.+))?\z/
           type = $1
           value = $2
-          directive = Directive.new(type, value)
-          if directive.type == :include
-            included = resolve_relative_path(directive.value)
+          directive = parse_directive(type, value)
+          if directive.is_a?(IncludeDirective)
+            included = resolve_relative_path(directive.path)
             included_operations = load_test_file(included)
             operations += included_operations
           else
@@ -68,5 +68,24 @@ module Drntest
       end
       operations
     end
+
+    def parse_directive(type, value)
+      case normalize_directive_type(type)
+      when :include
+        IncludeDirective.new(value)
+      when :enable_logging
+        EnableLoggingDirective.new
+      when :disable_logging
+        DisableLoggingDirective.new
+      when :omit
+        OmitDirective.new(value)
+      else
+        raise "unknown directive: #{type}"
+      end
+    end
+
+    def normalize_directive_type(type)
+      type.gsub("-", "_").to_sym
+    end
   end
 end
-------------- next part --------------
HTML����������������������������...
Download 



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