class Drntest::TestLoader

Public Class Methods

new(config, test_path) click to toggle source
# File lib/drntest/test-loader.rb, line 25
def initialize(config, test_path)
  @config = config
  @test_path = test_path
end

Public Instance Methods

load() click to toggle source
# File lib/drntest/test-loader.rb, line 30
def load
  load_test_file(@test_path)
end

Private Instance Methods

load_test_file(path) click to toggle source
# File lib/drntest/test-loader.rb, line 41
def load_test_file(path)
  parser = Yajl::Parser.new
  operations = []
  parser.on_parse_complete = lambda do |operation|
    operations << operation
  end
  data = ""
  Pathname(path).open do |input|
    input.each_line do |line|
      data << line
      case line.chomp
      when /\A\#\@([^\s]+)/
        type = $1
        options = Shellwords.split($POSTMATCH.strip)
        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
        else
          operations << directive
        end
      when /\A\#/
        # comment
      else
        begin
          parser << line
        rescue Yajl::ParseError => error
          JSONLoader.report_error(path, data, error)
          raise error
        end
      end
    end
  end
  operations
end
normalize_directive_type(type) click to toggle source
# File lib/drntest/test-loader.rb, line 109
def normalize_directive_type(type)
  type.gsub("-", "_").to_sym
end
parse_directive(type, options) click to toggle source
# File lib/drntest/test-loader.rb, line 82
def parse_directive(type, options)
  case normalize_directive_type(type)
  when :include
    IncludeDirective.new(options.first)
  when :enable_logging
    EnableLoggingDirective.new
  when :disable_logging
    DisableLoggingDirective.new
  when :omit
    OmitDirective.new(options.first)
  when :require_catalog_version
    RequireCatalogVersionDirective.new(Integer(options.first))
  when :enable_completion
    EnableCompletionDirective.new
  when :disable_completion
    DisableCompletionDirective.new
  when :enable_validation
    EnableValidationDirective.new
  when :disable_validation
    DisableValidationDirective.new
  when :subscribe_until
    SubscribeUntil.new(options)
  else
    UnknownDirective.new(type, options)
  end
end
resolve_relative_path(path) click to toggle source
# File lib/drntest/test-loader.rb, line 35
def resolve_relative_path(path)
  path = path.to_s
  path = path[2..-1] if path[0..1] == "./"
  Pathname(path).expand_path(@config.base_path)
end