ZenTest 3.2.0 → 3.3.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (50) hide show
  1. data/History.txt +21 -0
  2. data/Manifest.txt +8 -24
  3. data/Rakefile +32 -8
  4. data/bin/autotest +4 -1
  5. data/bin/multiruby +20 -6
  6. data/bin/ruby_fork +6 -0
  7. data/bin/ruby_fork_client +6 -0
  8. data/example_dot_autotest.rb +148 -0
  9. data/lib/autotest.rb +201 -254
  10. data/lib/rails_autotest.rb +48 -110
  11. data/lib/ruby_fork.rb +178 -0
  12. data/lib/test/rails.rb +2 -2
  13. data/lib/test/rails/controller_test_case.rb +1 -1
  14. data/lib/test/rails/helper_test_case.rb +60 -0
  15. data/lib/test/rails/pp_html_document.rb +74 -0
  16. data/lib/test/rails/rake_tasks.rb +13 -12
  17. data/lib/test/rails/view_test_case.rb +2 -2
  18. data/lib/test/zentest_assertions.rb +39 -0
  19. data/lib/unit_diff.rb +6 -3
  20. data/lib/zentest.rb +1 -1
  21. data/test/test_autotest.rb +160 -208
  22. data/test/test_rails_autotest.rb +115 -138
  23. data/test/test_ruby_fork.rb +172 -0
  24. data/test/test_unit_diff.rb +69 -1
  25. data/test/test_zentest_assertions.rb +66 -0
  26. metadata +13 -27
  27. data/test/data/normal/lib/.#photo.rb +0 -0
  28. data/test/data/normal/lib/blah.rb +0 -0
  29. data/test/data/normal/lib/photo.rb +0 -0
  30. data/test/data/normal/test/#test_photo.rb# +0 -0
  31. data/test/data/normal/test/test_camelcase.rb +0 -0
  32. data/test/data/normal/test/test_photo.rb +0 -0
  33. data/test/data/normal/test/test_route.rb +0 -0
  34. data/test/data/normal/test/test_user.rb +0 -0
  35. data/test/data/rails/app/controllers/admin/theme_controller.rb +0 -0
  36. data/test/data/rails/app/controllers/route_controller.rb +0 -0
  37. data/test/data/rails/app/models/flickr_photo.rb +0 -0
  38. data/test/data/rails/app/models/route.rb +0 -0
  39. data/test/data/rails/app/views/route/index.rhtml +0 -0
  40. data/test/data/rails/config/environment.rb +0 -0
  41. data/test/data/rails/config/routes.rb +0 -0
  42. data/test/data/rails/test/controllers/route_controller_test.rb +0 -0
  43. data/test/data/rails/test/fixtures/routes.yml +0 -0
  44. data/test/data/rails/test/functional/admin/themes_controller_test.rb +0 -0
  45. data/test/data/rails/test/functional/dummy_controller_test.rb +0 -0
  46. data/test/data/rails/test/functional/route_controller_test.rb +0 -0
  47. data/test/data/rails/test/unit/flickr_photo_test.rb +0 -0
  48. data/test/data/rails/test/unit/photo_test.rb +0 -0
  49. data/test/data/rails/test/unit/route_test.rb +0 -0
  50. data/test/data/rails/test/views/route_view_test.rb +0 -0
@@ -1,25 +1,25 @@
1
1
  require 'code_statistics'
2
2
 
3
- namespace :test do
4
- desc 'Run the view tests in test/views'
5
- Rake::TestTask.new :views => [ 'db:test:prepare' ] do |t|
3
+ def define_test_task(test_type)
4
+ desc "Run the #{test_type} tests in test/#{test_type}s"
5
+ Rake::TestTask.new "#{test_type}s" => [ 'db:test:prepare' ] do |t|
6
6
  t.libs << 'test'
7
- t.pattern = 'test/views/**/*_test.rb'
7
+ t.pattern = "test/#{test_type}s/**/*_test.rb"
8
8
  t.verbose = true
9
9
  end
10
+ end
10
11
 
11
- desc 'Run the controller tests in test/controllers'
12
- Rake::TestTask.new :controllers => [ 'db:test:prepare' ] do |t|
13
- t.libs << 'test'
14
- t.pattern = 'test/controllers/**/*_test.rb'
15
- t.verbose = true
16
- end
12
+ namespace :test do
13
+ define_test_task 'helper'
14
+ define_test_task 'view'
15
+ define_test_task 'controller'
17
16
  end
18
17
 
19
18
  desc 'Run all tests'
20
19
  task :test => %w[
21
20
  test:units
22
21
  test:controllers
22
+ test:helpers
23
23
  test:views
24
24
  test:functionals
25
25
  test:integration
@@ -32,6 +32,7 @@ dirs = [
32
32
  %w[Components components],
33
33
  %w[Controllers app/controllers],
34
34
  %w[Controller\ tests test/controllers],
35
+ %w[Helper\ tests test/helpers],
35
36
  %w[View\ tests test/views],
36
37
  %w[Functional\ tests test/functional],
37
38
  %w[Integration\ tests test/integration],
@@ -44,6 +45,6 @@ dirs = dirs.select { |name, dir| File.directory? dir }
44
45
 
45
46
  STATS_DIRECTORIES.replace dirs
46
47
 
47
- CodeStatistics::TEST_TYPES << 'View tests'
48
- CodeStatistics::TEST_TYPES << 'Controller tests'
48
+ new_test_types = ['Controller tests', 'Helper tests', 'View tests']
49
+ CodeStatistics::TEST_TYPES.push(*new_test_types)
49
50
 
@@ -71,8 +71,8 @@
71
71
  # @request.request_uri = '/foo'
72
72
  # assigns[:action_title] = 'Hello & Goodbye'
73
73
  #
74
- # # Render an empty string with the 'default' layout.
75
- # render :text => '', :layout => 'default'
74
+ # # Render an empty string with the 'application' layout.
75
+ # render :text => '', :layout => 'application'
76
76
  #
77
77
  # # Assert content just like a regular view test.
78
78
  # assert_links_to '/', 'Home'
@@ -17,6 +17,14 @@ module Test::Unit::Assertions
17
17
 
18
18
  alias deny_equal assert_not_equal
19
19
 
20
+ ##
21
+ # Asserts that +obj+ responds to #empty? and #empty? returns true.
22
+
23
+ def assert_empty(obj)
24
+ assert_respond_to obj, :empty?
25
+ assert_equal true, obj.empty?
26
+ end
27
+
20
28
  ##
21
29
  # Asserts that +obj+ responds to #empty? and #empty? returns false.
22
30
 
@@ -42,5 +50,36 @@ module Test::Unit::Assertions
42
50
  assert_equal false, obj.include?(item), message
43
51
  end
44
52
 
53
+ ##
54
+ # Captures $stdout and $stderr to StringIO objects and returns them.
55
+ # Restores $stdout and $stderr when done.
56
+ #
57
+ # Usage:
58
+ # def test_puts
59
+ # out, err = capture do
60
+ # puts 'hi'
61
+ # STDERR.puts 'bye!'
62
+ # end
63
+ # assert_equal "hi\n", out.string
64
+ # assert_equal "bye!\n", err.string
65
+ # end
66
+
67
+ def util_capture
68
+ require 'stringio'
69
+ orig_stdout = $stdout.dup
70
+ orig_stderr = $stderr.dup
71
+ captured_stdout = StringIO.new
72
+ captured_stderr = StringIO.new
73
+ $stdout = captured_stdout
74
+ $stderr = captured_stderr
75
+ yield
76
+ captured_stdout.rewind
77
+ captured_stderr.rewind
78
+ return captured_stdout, captured_stderr
79
+ ensure
80
+ $stdout = orig_stdout
81
+ $stderr = orig_stderr
82
+ end
83
+
45
84
  end
46
85
 
data/lib/unit_diff.rb CHANGED
@@ -28,7 +28,7 @@ def temp_file(data)
28
28
  data = data.map { |l| '%3d) %s' % [count+=1, l] } if $l
29
29
  data = data.join('')
30
30
  # unescape newlines, strip <> from entire string
31
- data = data.gsub(/\\n/, "\n").gsub(/\A</m, '').gsub(/>\Z/m, '').gsub(/0x[a-f0-9]+/m, '0xXXXXXX')
31
+ data = data.gsub(/\\n/, "\n").gsub(/0x[a-f0-9]+/m, '0xXXXXXX') + "\n"
32
32
  temp.print data
33
33
  temp.puts unless data =~ /\n\Z/m
34
34
  temp.flush
@@ -80,6 +80,7 @@ class UnitDiff
80
80
  # Handy wrapper for UnitDiff#unit_diff.
81
81
 
82
82
  def self.unit_diff(input)
83
+ trap 'INT' do exit 1 end
83
84
  ud = UnitDiff.new
84
85
  ud.unit_diff(input)
85
86
  end
@@ -193,8 +194,10 @@ class UnitDiff
193
194
  end
194
195
  end
195
196
 
196
- footer.shift if footer.first.strip.empty?
197
- output.push footer.compact.map {|line| line.strip}.join("\n")
197
+ if footer then
198
+ footer.shift if footer.first.strip.empty?
199
+ output.push footer.compact.map {|line| line.strip}.join("\n")
200
+ end
198
201
 
199
202
  return output.flatten.join("\n")
200
203
  end
data/lib/zentest.rb CHANGED
@@ -71,7 +71,7 @@ end
71
71
 
72
72
  class ZenTest
73
73
 
74
- VERSION = '3.2.0'
74
+ VERSION = '3.3.0'
75
75
 
76
76
  if $TESTING then
77
77
  attr_reader :missing_methods
@@ -1,269 +1,221 @@
1
+ #!/usr/local/bin/ruby -w
2
+
1
3
  $TESTING = true
2
4
 
5
+ require 'test/unit/testcase'
6
+ require 'test/unit' if $0 == __FILE__
3
7
  require 'stringio'
4
- require 'test/unit'
5
-
6
8
  require 'autotest'
7
9
 
8
- Dir.chdir File.join(File.dirname(__FILE__), "..")
9
-
10
- class Autotest
11
-
12
- attr_accessor :system_responses
13
- attr_reader :files
14
-
15
- def system(cmd)
16
- @system_responses ||= []
17
- raise 'Out of system responses' if @system_responses.empty?
18
- return @system_responses.shift
19
- end
20
-
21
- attr_accessor :backtick_responses
22
-
23
- def `(cmd) # ` appeases emacs
24
- @backtick_responses ||= []
25
- raise 'Out of backtick responses' if @backtick_responses.empty?
26
- return @backtick_responses.shift
27
- end
28
-
29
- end
10
+ # NOT TESTED:
11
+ # class_run
12
+ # add_sigint_handler
13
+ # all_good
14
+ # get_to_green
15
+ # reset
16
+ # ruby
17
+ # run
18
+ # run_tests
30
19
 
31
20
  class TestAutotest < Test::Unit::TestCase
32
-
33
21
  def setup
34
- @normal_tests_dir = 'test/data/normal'
35
-
36
- @blah_file = 'lib/blah.rb'
37
- @photo_file = 'lib/photo.rb'
38
- @photo_test_file = 'test/test_photo.rb'
39
- @route_test_file = 'test/test_route.rb'
40
- @user_test_file = 'test/test_user.rb'
41
- @camelcase_test_file = 'test/test_camelcase.rb'
22
+ @test_class = 'TestBlah'
23
+ @test = 'test/test_blah.rb'
24
+ @impl = 'lib/blah.rb'
42
25
 
43
- @file_map = {}
26
+ @a = Object.const_get(self.class.name[4..-1]).new
27
+ @a.output = StringIO.new
28
+ @a.files.clear
29
+ @a.files[@impl] = Time.at(1)
30
+ @a.files[@test] = Time.at(2)
31
+ @a.last_mtime = Time.at(2)
32
+ end
44
33
 
45
- @all_files = [ @blah_file, @photo_file, @photo_test_file, @route_test_file, @user_test_file, @camelcase_test_file ]
34
+ def test_hooks
35
+ @a.instance_variable_set :@reset1, false
36
+ @a.instance_variable_set :@reset2, false
37
+ @a.instance_variable_set :@reset3, false
46
38
 
47
- Dir.chdir @normal_tests_dir do
48
- util_touch @photo_file, (Time.now - 60)
49
- util_touch @photo_test_file, (Time.now - 60)
50
- util_touch @camelcase_test_file, (Time.now - 60)
39
+ Autotest.add_hook(:reset) do |at|
40
+ at.instance_variable_set :@reset1, true
51
41
  end
52
42
 
53
- @at = Autotest.new
54
- end
55
-
56
- def test_consolidate_failures
57
- failed = [
58
- %w[test_a TestOne],
59
- %w[test_b TestOne],
60
- %w[test_c TestOne],
61
- %w[test_d TestTwo],
62
- ]
63
-
64
- expected = [
65
- ["'/^(test_a|test_b|test_c)$/'", /one/],
66
- ["'/^(test_d)$/'", /two/],
67
- ]
68
-
69
- assert_equal expected,
70
- @at.consolidate_failures(failed).sort_by { |f,k| k.source }
71
- end
43
+ Autotest.add_hook(:reset) do |at|
44
+ at.instance_variable_set :@reset2, true
45
+ end
72
46
 
73
- # 0 files update, 0 run
74
- def test_failed_test_files_no_updates
75
- tests = [@user_test_file, @photo_test_file]
76
- updated_files = []
47
+ Autotest.add_hook(:reset) do |at|
48
+ at.instance_variable_set :@reset3, true
49
+ end
77
50
 
78
- failed_files = @at.failed_test_files(/photo/, tests, updated_files)
51
+ @a.reset
79
52
 
80
- assert_equal [], failed_files
53
+ assert @a.instance_variable_get(:@reset1), "Hook1 should work on reset"
54
+ assert @a.instance_variable_get(:@reset2), "Hook2 should work on reset"
55
+ assert @a.instance_variable_get(:@reset3), "Hook3 should work on reset"
81
56
  end
82
57
 
83
- # 1 test changes, 1 test runs
84
- def test_failed_test_files_test_updated
85
- tests = [@user_test_file, @photo_test_file]
86
- updated_files = [@photo_test_file]
58
+ # TODO BUG /usr/local/bin/ruby -I.:lib:test test/test_rails_autotest.rb -n "/^(test_hooks)$/" | unit_diff -u; /usr/local/bin/ruby -I.:lib:test test/test_autotest.rb -n "/^(test_hooks|test_hooks)$/" | unit_diff -u
87
59
 
88
- failed_files = @at.failed_test_files(/photo/, tests, updated_files)
60
+ def test_consolidate_failures_experiment
61
+ @a.files.clear
62
+ @a.files['lib/autotest.rb'] = Time.at(1)
63
+ @a.files['test/test_autotest.rb'] = Time.at(2)
89
64
 
90
- assert_equal [@photo_test_file], failed_files
65
+ input = [['test_fail1', 'TestAutotest'], ['test_fail2', 'TestAutotest'], ['test_error1', 'TestAutotest'], ['test_error2', 'TestAutotest']]
66
+ result = @a.consolidate_failures input
67
+ expected = { 'test/test_autotest.rb' => %w( test_fail1 test_fail2 test_error1 test_error2 ) }
68
+ assert_equal expected, result
91
69
  end
92
70
 
93
- # non-matching test class changed, 0 test runs
94
- def test_failed_test_files_unrelated_test_updated
95
- tests = [@user_test_file, @photo_test_file]
96
- updated_files = [@user_test_file]
97
-
98
- failed_files = @at.failed_test_files(/photo/, tests, updated_files)
99
-
100
- assert_equal [], failed_files
71
+ def test_consolidate_failures_green
72
+ result = @a.consolidate_failures([])
73
+ expected = {}
74
+ assert_equal expected, result
101
75
  end
102
76
 
103
- # tests handling of camelcase test matching
104
- def test_failed_test_files_camelcase_updated
105
- tests = [@camelcase_test_file]
106
- updated_files = [@camelcase_test_file]
107
-
108
- failed_files = @at.failed_test_files(/camel_?case/, tests, updated_files)
109
-
110
- assert_equal [@camelcase_test_file], failed_files
77
+ def test_consolidate_failures_multiple_matches
78
+ @a.files['test/test_blah_again.rb'] = Time.at(42)
79
+ result = @a.consolidate_failures([['test_unmatched', @test_class]])
80
+ expected = {}
81
+ assert_equal expected, result
82
+ expected = "multiple files matched class TestBlah [\"test/test_blah.rb\", \"test/test_blah_again.rb\"].\n"
83
+ assert_equal expected, @a.output.string
111
84
  end
112
85
 
113
- # running back to back with different classes should give updates for each
114
- # class.
115
- def test_failed_test_files_implementation_updated_both
116
- tests = [@photo_test_file, @user_test_file]
117
- updated_files = [@blah_file]
118
-
119
- failed_files = @at.failed_test_files(/photo/, tests, updated_files)
120
-
121
- assert_equal [@photo_test_file], failed_files
122
-
123
- failed_files = @at.failed_test_files(/user/, tests, updated_files)
124
-
125
- assert_equal [@user_test_file], failed_files
86
+ def test_consolidate_failures_no_match
87
+ result = @a.consolidate_failures([['test_blah1', @test_class], ['test_blah2', @test_class], ['test_blah1', 'TestUnknown']])
88
+ expected = {@test => ['test_blah1', 'test_blah2']}
89
+ assert_equal expected, result
90
+ expected = "Unable to map class TestUnknown to a file\n"
91
+ assert_equal expected, @a.output.string
126
92
  end
127
93
 
128
- # "general" file changes, run all failures + mapped file
129
- def test_failed_test_files_implementation_updated
130
- tests = [@user_test_file, @photo_test_file]
131
- updated_files = [@blah_file]
132
-
133
- failed_files = @at.failed_test_files(/photo/, tests, updated_files)
134
-
135
- assert_equal [@photo_test_file], failed_files
94
+ def test_consolidate_failures_red
95
+ result = @a.consolidate_failures([['test_blah1', @test_class], ['test_blah2', @test_class]])
96
+ expected = {@test => ['test_blah1', 'test_blah2']}
97
+ assert_equal expected, result
136
98
  end
137
99
 
138
- def test_failure_report
139
- @at.files['test/test_one.rb'] = Time.at 0
140
- @at.files['test/test_two.rb'] = Time.at 0
100
+ # TODO: lots of filename edgecases for find_files_to_test
141
101
 
142
- failures = [
143
- ["'/^(test_a|test_b|test_c)/'", /one/],
144
- ["'/^(test_d)/'", /two/],
145
- ]
102
+ def test_find_files_to_test
103
+ @a.last_mtime = Time.at(0)
104
+ assert @a.find_files_to_test(@a.files)
146
105
 
147
- expected = "# failures remain in 2 files:
148
- # test/test_one.rb:
149
- # test_a
150
- # test_b
151
- # test_c
152
- # test/test_two.rb:
153
- # test_d"
154
-
155
- assert_equal expected, @at.failure_report(failures)
106
+ @a.last_mtime = @a.files.values.sort.last + 1
107
+ assert ! @a.find_files_to_test(@a.files)
156
108
  end
157
109
 
158
- def test_map_file_names
159
- util_add_map('lib/untested.rb', [])
160
- util_add_map('lib/autotest.rb', ['test/test_autotest.rb'])
161
- util_add_map('lib/auto_test.rb', ['test/test_autotest.rb'])
162
- util_add_map('test/test_autotest.rb', ['test/test_autotest.rb'])
163
-
164
- @file_map.keys.each { |file| @at.files[file] = Time.at 0 }
110
+ def test_find_files_to_test_dunno
111
+ empty = {}
165
112
 
166
- util_test_map_file_names @normal_tests_dir
113
+ files = { "fooby.rb" => Time.at(42) }
114
+ assert @a.find_files_to_test(files) # we find fooby,
115
+ assert_equal empty, @a.files_to_test # but it isn't something to test
116
+ assert_equal "Dunno! fooby.rb\n", @a.output.string
167
117
  end
168
118
 
169
- def test_retest_failed_modified
170
- Dir.chdir @normal_tests_dir do
171
- @all_files.each do |f| @at.updated? f; end
172
-
173
- failed = [['test_route', /photo/]]
174
- tests = [@photo_test_file]
175
-
176
- @at.backtick_responses = ['1 tests, 1 assertions, 0 failures, 0 errors']
177
-
178
- util_touch @photo_test_file
179
-
180
- out, err = util_capture do
181
- @at.retest_failed failed, tests
182
- end
183
-
184
- out = out.split $/
185
-
186
- assert_equal "# Waiting for changes", out.shift
187
- assert_equal "# Rerunning failures: #{@photo_test_file}", out.shift
188
- assert_equal "+ #{@at.ruby} -Ilib:test #{@photo_test_file} -n test_route | unit_diff -u", out.shift
119
+ def test_flunk
120
+ flunk
121
+ end
189
122
 
190
- assert_equal true, @at.backtick_responses.empty?
191
- end
123
+ def test_find_files_to_test_lib
124
+ # ensure we add test_blah.rb when blah.rb updates
125
+ util_find_files_to_test(@impl, @test => [])
192
126
  end
193
127
 
194
- def test_reset_times
195
- Dir.chdir @normal_tests_dir do
196
- @at.updated?(@photo_test_file)
128
+ def test_find_files_to_test_no_change
129
+ empty = {}
197
130
 
198
- assert_equal false, @at.updated?(@photo_test_file), 'In @files'
199
- time = @at.files[@photo_test_file]
131
+ # ensure world is virginal
132
+ assert_equal empty, @a.files_to_test
200
133
 
201
- @at.reset_times
134
+ # ensure we do nothing when nothing changes...
135
+ files = { @impl => @a.files[@impl] } # same time
136
+ assert ! @a.find_files_to_test(files)
137
+ assert_equal empty, @a.files_to_test
138
+ assert_equal "", @a.output.string
202
139
 
203
- assert_not_equal time, @at.files[@photo_test_file]
204
- assert_equal true, @at.updated?(@photo_test_file), 'Time reset to 0'
205
- end
140
+ files = { @impl => @a.files[@impl] } # same time
141
+ assert(! @a.find_files_to_test(files))
142
+ assert_equal empty, @a.files_to_test
143
+ assert_equal "", @a.output.string
206
144
  end
207
145
 
208
- def test_ruby
209
- this_ruby = File.join(Config::CONFIG['bindir'],
210
- Config::CONFIG['ruby_install_name'])
211
- assert_equal this_ruby, @at.ruby
146
+ def test_find_files_to_test_test
147
+ # ensure we add test_blah.rb when test_blah.rb itself updates
148
+ util_find_files_to_test(@test, @test => [])
212
149
  end
213
150
 
214
- def test_updated_eh
215
- Dir.chdir @normal_tests_dir do
216
- assert_equal true, @at.updated?(@photo_test_file), 'Not in @files'
217
- assert_equal false, @at.updated?(@photo_test_file), 'In @files'
218
- @at.files[@photo_test_file] = Time.at 1
219
- util_touch @photo_test_file
220
- assert_equal true, @at.updated?(@photo_test_file), 'Touched'
221
- end
222
- end
151
+ def test_handle_results
152
+ @a.files_to_test.clear
153
+ @a.files.clear
154
+ @a.files['lib/autotest.rb'] = Time.at(1)
155
+ @a.files['test/test_autotest.rb'] = Time.at(2)
156
+ empty = {}
157
+ assert_equal empty, @a.files_to_test, "must start empty"
223
158
 
224
- def test_updated_files
225
- Dir.chdir @normal_tests_dir do
226
- @at.updated_files
159
+ s1 = "Loaded suite -e
160
+ Started
161
+ ............
162
+ Finished in 0.001655 seconds.
227
163
 
228
- expected = Hash[*@all_files.map { |f| [f, File.stat(f).mtime] }.flatten]
164
+ 12 tests, 18 assertions, 0 failures, 0 errors
165
+ "
229
166
 
230
- assert_equal expected, @at.files
167
+ @a.handle_results(s1)
168
+ assert_equal empty, @a.files_to_test, "must stay empty"
231
169
 
232
- util_touch @photo_test_file
170
+ s2 = "
171
+ 1) Failure:
172
+ test_fail1(TestAutotest) [./test/test_autotest.rb:59]:
173
+ 2) Failure:
174
+ test_fail2(TestAutotest) [./test/test_autotest.rb:59]:
175
+ 3) Error:
176
+ test_error1(TestAutotest):
177
+ 3) Error:
178
+ test_error2(TestAutotest):
179
+ "
233
180
 
234
- assert_not_equal expected['test/test_photo.rb'], @at.files
235
- end
236
- end
181
+ @a.handle_results(s2)
182
+ expected = { "test/test_autotest.rb" => %w( test_fail1 test_fail2 test_error1 test_error2 ) }
183
+ assert_equal expected, @a.files_to_test
237
184
 
238
- def util_add_map(file, *tests)
239
- @file_map[file] = tests
185
+ @a.handle_results(s1)
186
+ assert_equal empty, @a.files_to_test
240
187
  end
241
188
 
242
- def util_test_map_file_names(dir)
243
- Dir.chdir dir do
244
- @file_map.each do |name, expected|
245
- assert_equal expected, @at.map_file_names([name.dup]), "test #{name}"
246
- end
247
- end
248
- end
189
+ def test_make_test_cmd
190
+ ruby_cmd = Config::CONFIG['ruby_install_name']
191
+ f = {
192
+ @test => [],
193
+ 'test/test_fooby.rb' => [ 'test_something1', 'test_something2' ]
194
+ }
195
+ expected = [ "/usr/local/bin/#{ruby_cmd} -I.:lib:test -rtest/unit -e \"%w[#{@test}].each { |f| load f }\" | unit_diff -u",
196
+ "/usr/local/bin/#{ruby_cmd} -I.:lib:test test/test_fooby.rb -n \"/^(test_something1|test_something2)$/\" | unit_diff -u" ].join("; ")
249
197
 
250
- def util_capture
251
- old_stdout = $stdout
252
- old_stderr = $stderr
253
- out = StringIO.new
254
- err = StringIO.new
255
- $stdout = out
256
- $stderr = err
257
- yield
258
- return out.string, err.string
259
- ensure
260
- $stdout = old_stdout
261
- $stderr = old_stderr
198
+ result = @a.make_test_cmd f
199
+ assert_equal expected, result
262
200
  end
263
201
 
264
- def util_touch(file, t = Time.now)
265
- File.utime(t, t, file)
202
+ def test_tests_for_file
203
+ assert_equal [@test], @a.tests_for_file(@impl)
204
+ assert_equal [@test], @a.tests_for_file(@test)
205
+
206
+ assert_equal ['test/test_unknown.rb'], @a.tests_for_file('test/test_unknown.rb')
207
+ assert_equal [], @a.tests_for_file('lib/unknown.rb')
208
+ assert_equal [], @a.tests_for_file('unknown.rb')
209
+ assert_equal [], @a.tests_for_file('test_unknown.rb')
266
210
  end
267
211
 
268
- end
212
+ def util_find_files_to_test(f, expected)
213
+ t = @a.last_mtime + 1
214
+ files = { f => t }
269
215
 
216
+ assert @a.find_files_to_test(files)
217
+ assert_equal expected, @a.files_to_test
218
+ assert_equal t, @a.files[f]
219
+ assert_equal "", @a.output.string
220
+ end
221
+ end