Class: Reap::Test

Inherits:
Task
  • Object
show all
Defined in:
lib/reap/task/test.rb

Overview

Test Task

The Reap test task runs each test in it’s own proccess, making for purer test facility.

NOTE This works well enough but it is a tad delicate. It actually marshals test results across stdout->stdin shell pipe. One consequence of this is that you can’t send debug info to stdout (including #p and #puts). This, hopefully can be remedied in the future.

Defined Under Namespace

Classes: TestResults

Constant Summary

Constants inherited from Task

Reap::Task::RUBY

Instance Method Summary collapse

Methods inherited from Task

#ask, #execute, inherited, #initialize, #initiate, master, #master, #provide_setup_rb, #section, section_required, section_required?, #section_required?, #sh, #task, task_attr, #task_desc, task_desc, #task_help, task_help, task_list, #task_name, task_name, #tell, #use_subsection, verify?

Constructor Details

This class inherits a constructor from Reap::Task

Instance Method Details

#runObject

Run testing task.



59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
# File 'lib/reap/task/test.rb', line 59

def run

  # setup

  tst.files    ||= [ 'test/*/**/*.rb', 'test/**/tc*.rb', 'test/**/test*.rb', 'test/**/*test.rb' ]
  tst.requires ||= []

  tst.live ||= false
  tst.libs ||= [] #['./lib']

  # interal use

  @results = TestResults.new
  @errors = []
  @failures = []

  # Get test files

  test_libs = tst.libs.join(':')
  test_files = FileList.new
  test_files.include(*tst.files)
  test_files.uniq!

  if test_files.empty?
    tell "No test files found."
    return
  end

  #tell "Reap is shelling out work to Ruby's Test Suite..."

  pbar = Console::ProgressBar.new( 'Testing', test_files.size )

  # Run tests
  # (why arn't these unique to begin with?)
  test_files.each do |test_file|
    pbar.inc
    #$stdout << '.'; $stdout.flush

    if ! File.file?( test_file )
      r = nil
    else
      r = fork_test( test_file )
    end
    unless r.passed?
      @errors << r.instance_variable_get('@errors')
      @failures << r.instance_variable_get('@failures')
    end
    @results << r

    #ruby %{-r"test/unit" "#{f}"}
  end

  pbar.finish

  # Don't know why empty arrays get in them yet, but...
  @failures.reject! { |e| e == [] }
  @errors.reject! { |e| e == [] }

  # Display failures
  puts
  puts %{FAILURES:#{@failures.empty? ? ' []' : ''}}
  @failures.reverse.each { |fails|
    fails.reverse.each { |failure|
      puts
      puts %{  - test      : #{failure.test_name}}
      puts %{    location  : #{failure.location}}
      if failure.message.index("\n")
        puts %{    message   : >}
        puts failure.message.tabto(6)
      else
        puts %{    message   : #{failure.message}}
      end
    }
  }

  # Display errors
  puts
  puts %{ERRORS:#{@errors.empty? ? ' []' : ''}}
  @errors.reverse.each { |errs|
    errs.reverse.each { |err|
      puts
      puts %{  - test      : #{err.test_name}}
      puts %{    message   : #{err.exception.message}}
      puts %{    backtrace :}
      err.exception.backtrace[0...-1].each { |bt| puts %Q{      - #{bt}} }
    }
  }

  # Display final results
  puts
  puts @results
  puts

  # old way (don't work right)
  #puts %Q{ ruby %{-I#{test_libs} -e0 -r"test/unit" \\\n#{test_reqs}#{test_opts}} } if $DEBUG
  #ruby %{-I#{test_libs} -e0 -r"test/unit" \\\n#{test_reqs}#{test_opts}}
  #ruby %{-e0 -r"test/unit" \\\n#{test_reqs}#{test_opts}}
end