diff options
| author | Steve Kemp <steve@steve.org.uk> | 2012-11-22 11:13:51 +0000 | 
|---|---|---|
| committer | Steve Kemp <steve@steve.org.uk> | 2012-11-22 11:13:51 +0000 | 
| commit | cab345816331ac1e27094ce85b5e595b956e14fb (patch) | |
| tree | 8fb428956622af9be6a8da5637757069a2ba8a12 | |
| parent | 2809f83782773485c166b07c73eefe35a5726b81 (diff) | |
  Moved TestFactory to the custodian-namespace.
| -rwxr-xr-x | bin/custodian-parse-execute | 2 | ||||
| -rw-r--r-- | lib/custodian/testfactory.rb | 106 | 
2 files changed, 56 insertions, 52 deletions
| diff --git a/bin/custodian-parse-execute b/bin/custodian-parse-execute index a99246e..2a75629 100755 --- a/bin/custodian-parse-execute +++ b/bin/custodian-parse-execute @@ -39,7 +39,7 @@ end  # Create the object  #  begin -  c = TestFactory.create( txt ) +  c = Custodian::TestFactory.create( txt )    puts "created object of class type #{c.class}"    puts ".to_s    : #{c.to_s}" diff --git a/lib/custodian/testfactory.rb b/lib/custodian/testfactory.rb index c736ac1..5b2428d 100644 --- a/lib/custodian/testfactory.rb +++ b/lib/custodian/testfactory.rb @@ -13,75 +13,79 @@ require 'json'  # file - or that line encoded as a JSON string.  #  # -class TestFactory +module Custodian -  # -  # The subclasses we have. -  # -  @@subclasses = { } +  class TestFactory -  # -  # Create a test-type object given a line of text from our parser. -  # -  # The line will be like "target must run tcp|ssh|ftp|smtp .." -  # -  # -  def self.create( line ) -      # -    # JSON ? +    # The subclasses we have.      # -    if ( line =~ /^\{(.*)\}$/ ) -      begin -        obj = JSON.parse( line ); -        raise ArgumentError, "JSON object was not a hash" unless obj.kind_of?(Hash) -        line = obj["line"] -        raise ArgumentError, "obj[:line] was nil" unless (!line.nil?) -      rescue =>ex -        raise ArgumentError, "Line did not deserialize from JSON: #{line} - #{ex}" -      end -    end +    @@subclasses = { }      # -    # If this is an obvious protocol test. +    # Create a test-type object given a line of text from our parser.      # -    if ( line =~ /must\s+run\s+(\S+)(\s+|\.|$)/ ) -      test_type = $1.dup -      test_type.chomp!( "." ) +    # The line will be like "target must run tcp|ssh|ftp|smtp .." +    # +    # +    def self.create( line ) + +      # +      # JSON ? +      # +      if ( line =~ /^\{(.*)\}$/ ) +        begin +          obj = JSON.parse( line ); +          raise ArgumentError, "JSON object was not a hash" unless obj.kind_of?(Hash) +          line = obj["line"] +          raise ArgumentError, "obj[:line] was nil" unless (!line.nil?) +        rescue =>ex +          raise ArgumentError, "Line did not deserialize from JSON: #{line} - #{ex}" +        end +      end -      c = @@subclasses[test_type] -      if c -        c.new( line ) + +      # +      # If this is an obvious protocol test. +      # +      if ( line =~ /must\s+run\s+(\S+)(\s+|\.|$)/ ) +        test_type = $1.dup +        test_type.chomp!( "." ) + +        c = @@subclasses[test_type] +        if c +          c.new( line ) +        else +          raise ArgumentError, "Bad test type: #{test_type}" +        end        else -        raise ArgumentError, "Bad test type: #{test_type}" +        raise "Unknown line given - Failed to instantiate a suitable protocol-test."        end -    else -      raise "Unknown line given - Failed to instantiate a suitable protocol-test."      end -  end -  # -  # Register a new test type - this must be called by our derived classes -  # -  def self.register_test_type name -    @@subclasses[name] = self -  end +    # +    # Register a new test type - this must be called by our derived classes +    # +    def self.register_test_type name +      @@subclasses[name] = self +    end -  # -  # Return an array of test-types we know about -  # -  # i.e. Derived classes that have registered themselves. -  # -  # -  def types -    @@subclasses -  end +    # +    # Return an array of test-types we know about +    # +    # i.e. Derived classes that have registered themselves. +    # +    # +    def types +      @@subclasses +    end -end +  end +end | 
