Class: Toe::Test

Inherits:
Tap::Task
  • Object
show all
Includes:
Tap::Utils
Defined in:
lib/toe/test.rb

Overview

:startdoc::task a testing task

The Tap version of Rake::TestTask, shamelessly adapted from the original. The default test command is:

% ruby -w -Ilib -e 'ARGV.each{|f| load f}' TEST_FILES...

Where the test files are all files matching ‘test/*/_test.rb’. The options can be used to specify other options, lib paths, globs, filters, and even multiple interpreters.

Instance Method Summary collapse

Instance Method Details

#load_codeObject

Code to load the test files, by default a simple one-liner:

-e 'ARGV.each{|f| load f}'


45
46
47
# File 'lib/toe/test.rb', line 45

def load_code
  "-e 'ARGV.each{|f| load f}'"
end

#process(*args) ⇒ Object



49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
# File 'lib/toe/test.rb', line 49

def process(*args)

  # construct the command options
  options = [load_code]
  opts.each {|opt|  options << (opt[0] == ?- ? opt : "-#{opt}") }
  libs.each {|path| options << "-I\"#{File.expand_path(path)}\"" }
  options = options.join(" ")
  
  # select test files
  files = globs.collect do |glob|
    Dir.glob(glob).select do |path|
      File.file?(path) && path =~ filter
    end
  end.flatten!
  
  if files.empty?
    log :warn, "no files found for: #{globs.inspect}", Logger::WARN
  end
  
  files.collect! {|path| "\"#{path}\""}
  files = [files.join(' ')] unless iterate
  
  # launch each test
  files.each do |path|
    cmds.each do |cmd|
      sh(cmd, options, path)
    end
  end
end

#sh(*cmd) ⇒ Object



79
80
81
82
# File 'lib/toe/test.rb', line 79

def sh(*cmd)
  log :sh, cmd.join(' ')
  super
end