ZenTest 3.0.0 → 3.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -9,7 +9,7 @@ class RailsAutotest < Autotest
9
9
 
10
10
  def initialize # :nodoc:
11
11
  super
12
- @exceptions = %r%(?:^\./(?:db|doc|log|public|script))|(?:.rhtml$)%
12
+ @exceptions = %r%(?:^\./(?:db|doc|log|public|script|vendor/rails))|(?:.rhtml$)%
13
13
  end
14
14
 
15
15
  def map_file_names(updated) # :nodoc:
@@ -21,34 +21,48 @@ class RailsAutotest < Autotest
21
21
 
22
22
  case filename
23
23
  when %r%^test/fixtures/(.*)s.yml% then
24
- model_test = "test/unit/#{$1}_test.rb"
25
- functional_test = "test/functional/#{$1}_controller_test.rb"
26
- model_tests << model_test if File.exists? model_test
27
- functional_tests << functional_test if File.exists? functional_test
24
+ model_tests << "test/unit/#{$1}_test.rb"
25
+ functional_tests << "test/functional/#{$1}_controller_test.rb"
28
26
  when %r%^test/unit/.*rb$% then
29
27
  model_tests << filename
30
28
  when %r%^app/models/(.*)\.rb$% then
31
- model_tests << "test/unit/#{$1}_test.rb"
29
+ test_file = "test/unit/#{$1}_test.rb"
30
+ model_tests << test_file
32
31
  when %r%^test/functional/.*\.rb$% then
33
32
  functional_tests << filename
34
33
  when %r%^app/helpers/application_helper.rb% then
35
34
  functional_tests.push(*Dir['test/functional/*_test.rb'])
36
35
  when %r%^app/helpers/(.*)_helper.rb% then
37
- functional_tests << "test/functional/#{$1}_controller_test.rb"
36
+ test_file = "test/functional/#{$1}_controller_test.rb"
37
+ functional_tests << test_file
38
38
  when %r%^app/controllers/application.rb$% then
39
- functional_tests << "test/functional/dummy_controller_test.rb"
40
- when %r%^app/controllers/(.*)\.rb$% then
41
- functional_tests << "test/functional/#{$1}_test.rb"
39
+ test_file = "test/functional/dummy_controller_test.rb"
40
+ functional_tests << test_file
41
+ when %r%^app/controllers/(.*/)?(.*)\.rb$% then
42
+ test_file = "test/functional/#{$1}#{$2}_test.rb"
43
+ functional_tests << test_file
42
44
  when %r%^app/views/layouts/% then
43
45
  when %r%^app/views/(.*)/% then
44
- functional_tests << "test/functional/#{$1}_controller_test.rb"
46
+ test_file = "test/functional/#{$1}_controller_test.rb"
47
+ functional_tests << test_file
48
+ when %r%^config/routes.rb$% then
49
+ functional_tests.push(*Dir['test/functional/**/*_test.rb'].sort)
50
+ when %r%^test/test_helper.rb$%,
51
+ %r%^config/boot.rb%,
52
+ %r%^config/database.yml%,
53
+ %r%^config/environment.rb%,
54
+ %r%^config/environments/test.rb% then
55
+ model_tests.push(*Dir['test/unit/**/*_test.rb'].sort)
56
+ functional_tests.push(*Dir['test/functional/**/*_test.rb'].sort)
57
+ when %r%^vendor/%, /^Rakefile$/ then
58
+ # ignore standard rails files
45
59
  else
46
- puts "dunno! #{filename}"
60
+ STDERR.puts "Dunno! #{filename}" if $v or $TESTING
47
61
  end
48
62
  end
49
63
 
50
- model_tests.uniq!
51
- functional_tests.uniq!
64
+ model_tests = model_tests.uniq.select { |f| @files.has_key? f }
65
+ functional_tests = functional_tests.uniq.select { |f| @files.has_key? f }
52
66
 
53
67
  return model_tests, functional_tests
54
68
  end
@@ -73,6 +73,9 @@ end
73
73
 
74
74
  class UnitDiff
75
75
 
76
+ WINDOZE = /win32/ =~ RUBY_PLATFORM
77
+ DIFF = (WINDOZE ? 'diff.exe' : 'diff')
78
+
76
79
  ##
77
80
  # Handy wrapper for UnitDiff#unit_diff.
78
81
 
@@ -177,7 +180,7 @@ class UnitDiff
177
180
  diff_flags = $u ? "-u" : $c ? "-c" : ""
178
181
  diff_flags += " -b" if $b
179
182
 
180
- result = `diff #{diff_flags} #{a.path} #{b.path}`
183
+ result = `#{DIFF} #{diff_flags} #{a.path} #{b.path}`
181
184
  if result.empty? then
182
185
  output.push "[no difference--suspect ==]"
183
186
  else
@@ -25,7 +25,7 @@ end
25
25
 
26
26
  class ZenTest
27
27
 
28
- VERSION = '3.0.0'
28
+ VERSION = '3.1.0'
29
29
 
30
30
  if $TESTING then
31
31
  attr_reader :missing_methods
@@ -94,6 +94,7 @@ class ZenTest
94
94
  klass_methods = klass_methods.map { |m| "self." + m }
95
95
  public_methods += klass_methods
96
96
  public_methods -= Kernel.methods unless full
97
+ public_methods -= %w(pretty_print pretty_print_cycle)
97
98
  klassmethods = {}
98
99
  public_methods.each do |meth|
99
100
  puts "# found method #{meth}" if $DEBUG
@@ -282,8 +283,8 @@ class ZenTest
282
283
  '>' => 'gt',
283
284
  '>=' => 'ge',
284
285
  '>>' => 'gt2',
285
- '@+' => 'unary_plus',
286
- '@-' => 'unary_minus',
286
+ '+@' => 'unary_plus',
287
+ '-@' => 'unary_minus',
287
288
  '[]' => 'index',
288
289
  '[]=' => 'index_equals',
289
290
  '^' => 'carat',
File without changes
File without changes
File without changes
File without changes
File without changes
@@ -5,6 +5,8 @@ require 'test/unit'
5
5
 
6
6
  require 'autotest'
7
7
 
8
+ Dir.chdir File.join(File.dirname(__FILE__), "..")
9
+
8
10
  class Autotest
9
11
 
10
12
  attr_accessor :system_responses
@@ -29,133 +31,216 @@ end
29
31
  class TestAutotest < Test::Unit::TestCase
30
32
 
31
33
  def setup
32
- @photo_file = 'test/data/normal/lib/photo.rb'
33
- @photo_test_file = 'test/data/normal/test/test_photo.rb'
34
- @route_test_file = 'test/data/normal/test/test_route.rb'
35
- @user_test_file = 'test/data/normal/test/test_user.rb'
36
- @camelcase_test_file = 'test/data/normal/test/test_camelcase.rb'
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'
37
42
 
38
- util_touch @photo_file, (Time.now - 60)
39
- util_touch @photo_test_file, (Time.now - 60)
40
- util_touch @camelcase_test_file, (Time.now - 60)
43
+ @file_map = {}
44
+
45
+ @all_files = [ @blah_file, @photo_file, @photo_test_file, @route_test_file, @user_test_file, @camelcase_test_file ]
46
+
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)
51
+ end
41
52
 
42
53
  @at = Autotest.new
43
54
  end
44
55
 
45
- def test_failed_test_files_not_updated
46
- klass = 'TestPhoto'
47
- tests = [@user_test_file, @photo_test_file]
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
+ ]
48
63
 
49
- @at.updated? @photo_test_file
64
+ expected = [
65
+ ["'/^(test_a|test_b|test_c)/'", /one/],
66
+ ["'/^(test_d)/'", /two/],
67
+ ]
50
68
 
51
- failed_files = @at.failed_test_files klass, tests
69
+ assert_equal expected,
70
+ @at.consolidate_failures(failed).sort_by { |f,k| k.source }
71
+ end
72
+
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 = []
77
+
78
+ failed_files = @at.failed_test_files(/photo/, tests, updated_files)
52
79
 
53
80
  assert_equal [], failed_files
54
81
  end
55
82
 
56
- def test_failed_test_files_updated
57
- klass = 'TestPhoto'
83
+ # 1 test changes, 1 test runs
84
+ def test_failed_test_files_test_updated
58
85
  tests = [@user_test_file, @photo_test_file]
86
+ updated_files = [@photo_test_file]
59
87
 
60
- @at.updated? @photo_test_file
61
- util_touch @photo_test_file
62
-
63
- failed_files = @at.failed_test_files klass, tests
88
+ failed_files = @at.failed_test_files(/photo/, tests, updated_files)
64
89
 
65
90
  assert_equal [@photo_test_file], failed_files
66
91
  end
67
92
 
68
- def test_failed_test_files_updated_camelcase
69
- klass = 'TestCamelCase'
70
- tests = [@camelcase_test_file]
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]
71
97
 
72
- @at.updated? @camelcase_test_file
73
- util_touch @camelcase_test_file
98
+ failed_files = @at.failed_test_files(/photo/, tests, updated_files)
99
+
100
+ assert_equal [], failed_files
101
+ end
102
+
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]
74
107
 
75
- failed_files = @at.failed_test_files klass, tests
108
+ failed_files = @at.failed_test_files(/camel_?case/, tests, updated_files)
76
109
 
77
110
  assert_equal [@camelcase_test_file], failed_files
78
111
  end
79
112
 
80
- def test_failed_test_files_updated_implementation
81
- klass = 'TestPhoto'
82
- tests = [@user_test_file, @photo_test_file]
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
126
+ end
83
127
 
84
- @at.updated? @photo_file
85
- util_touch @photo_file
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]
86
132
 
87
- failed_files = @at.failed_test_files klass, tests
133
+ failed_files = @at.failed_test_files(/photo/, tests, updated_files)
88
134
 
89
135
  assert_equal [@photo_test_file], failed_files
90
136
  end
91
137
 
92
- def test_map_file_names
93
- @at.files['test/test_autotest.rb'] = Time.at 1
94
- @at.files['lib/autotest.rb'] = Time.at 1
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
95
141
 
96
- file_names = [
97
- 'lib/autotest.rb',
98
- 'lib/auto_test.rb',
99
- 'test/test_autotest.rb',
142
+ failures = [
143
+ ["'/^(test_a|test_b|test_c)/'", /one/],
144
+ ["'/^(test_d)/'", /two/],
100
145
  ]
101
146
 
102
- expected = [
103
- [['test/test_autotest.rb']],
104
- [['test/test_autotest.rb']],
105
- [['test/test_autotest.rb']],
106
- ]
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"
107
154
 
108
- file_names.each_with_index do |name, i|
109
- assert_equal expected[i], @at.map_file_names([name]), "test #{i}, #{name}"
110
- end
155
+ assert_equal expected, @at.failure_report(failures)
156
+ end
157
+
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 }
165
+
166
+ util_test_map_file_names @normal_tests_dir
111
167
  end
112
168
 
113
169
  def test_retest_failed_modified
114
- failed = [['test_route', 'TestPhoto']]
115
- tests = [@photo_test_file]
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
116
179
 
117
- @at.system_responses = [true]
180
+ out, err = util_capture do
181
+ @at.retest_failed failed, tests
182
+ end
118
183
 
119
- util_touch @photo_test_file
184
+ out = out.split $/
120
185
 
121
- out, err = util_capture do
122
- @at.retest_failed failed, tests
186
+ assert_equal "# Waiting for changes", out.shift
187
+ assert_equal "# Rerunning failures: #{@photo_test_file}", out.shift
188
+ assert_equal "+ ruby -Ilib:test #{@photo_test_file} -n test_route | unit_diff -u", out.shift
189
+
190
+ assert_equal true, @at.backtick_responses.empty?
123
191
  end
192
+ end
124
193
 
125
- out = out.split $/
194
+ def test_reset_times
195
+ Dir.chdir @normal_tests_dir do
196
+ @at.updated?(@photo_test_file)
126
197
 
127
- assert_equal "# Rerunning failures: #{@photo_test_file}", out.shift
128
- assert_equal "+ ruby -Ilib:test -S testrb -n test_route #{@photo_test_file}", out.shift
198
+ assert_equal false, @at.updated?(@photo_test_file), 'In @files'
199
+ time = @at.files[@photo_test_file]
129
200
 
130
- assert_equal true, @at.system_responses.empty?
201
+ @at.reset_times
202
+
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
131
206
  end
132
207
 
133
208
  def test_updated_eh
134
- assert_equal true, @at.updated?(@photo_test_file), 'Not in @files'
135
- assert_equal false, @at.updated?(@photo_test_file), 'In @files'
136
- @at.files[@photo_test_file] = Time.at 1
137
- util_touch @photo_test_file
138
- assert_equal true, @at.updated?(@photo_test_file), 'Touched'
209
+ Dir.chdir @normal_tests_dir do
210
+ assert_equal true, @at.updated?(@photo_test_file), 'Not in @files'
211
+ assert_equal false, @at.updated?(@photo_test_file), 'In @files'
212
+ @at.files[@photo_test_file] = Time.at 1
213
+ util_touch @photo_test_file
214
+ assert_equal true, @at.updated?(@photo_test_file), 'Touched'
215
+ end
139
216
  end
140
217
 
141
218
  def test_updated_files
142
- Dir.chdir 'test/data/normal' do
219
+ Dir.chdir @normal_tests_dir do
143
220
  @at.updated_files
144
- end
145
221
 
146
- expected = {
147
- 'lib/photo.rb' => File.stat(@photo_file).mtime,
148
- 'test/test_photo.rb' => File.stat(@photo_test_file).mtime,
149
- 'test/test_route.rb' => File.stat(@route_test_file).mtime,
150
- 'test/test_user.rb' => File.stat(@user_test_file).mtime,
151
- 'test/test_camelcase.rb' => File.stat(@camelcase_test_file).mtime,
152
- }
222
+ expected = Hash[*@all_files.map { |f| [f, File.stat(f).mtime] }.flatten]
153
223
 
154
- assert_equal expected, @at.files
224
+ assert_equal expected, @at.files
155
225
 
156
- util_touch @photo_test_file
226
+ util_touch @photo_test_file
157
227
 
158
- assert_not_equal expected['test_photo.rb'], @at.files
228
+ assert_not_equal expected['test/test_photo.rb'], @at.files
229
+ end
230
+ end
231
+
232
+ def util_add_map(file, *tests)
233
+ tests = [[],[]] if tests.empty?
234
+
235
+ @file_map[file] = tests
236
+ end
237
+
238
+ def util_test_map_file_names(dir)
239
+ Dir.chdir dir do
240
+ @file_map.each do |name, expected|
241
+ assert_equal expected, @at.map_file_names([name.dup]), "test #{name}"
242
+ end
243
+ end
159
244
  end
160
245
 
161
246
  def util_capture
@@ -175,5 +260,6 @@ class TestAutotest < Test::Unit::TestCase
175
260
  def util_touch(file, t = Time.now)
176
261
  File.utime(t, t, file)
177
262
  end
263
+
178
264
  end
179
265
 
@@ -5,50 +5,97 @@ class TestRailsAutotest < TestAutotest
5
5
 
6
6
  def setup
7
7
  super
8
+
8
9
  @at = RailsAutotest.new
10
+
11
+ @rails_tests_dir = 'test/data/rails'
12
+
13
+ @rails_photo_file = 'app/models/photo.rb'
14
+ @rails_unit_tests = [
15
+ 'test/unit/flickr_photo_test.rb',
16
+ 'test/unit/photo_test.rb',
17
+ 'test/unit/route_test.rb',
18
+ ]
19
+
20
+ @rails_functional_tests = [
21
+ 'test/functional/admin/themes_controller_test.rb',
22
+ 'test/functional/dummy_controller_test.rb',
23
+ 'test/functional/route_controller_test.rb',
24
+ ]
25
+
26
+ @rails_all_tests = [@rails_unit_tests, @rails_functional_tests]
27
+ end
28
+
29
+ (instance_methods.sort - Object.instance_methods).each do |meth|
30
+ undef_method meth if meth =~ /^test_failed_test_files/
9
31
  end
10
32
 
11
33
  def test_map_file_names
12
- file_names = [
13
- './app/helpers/application_helper.rb',
14
- './test/fixtures/routes.yml',
15
- './test/unit/photo_test.rb',
16
- './app/models/photo.rb',
17
- './app/controllers/application.rb',
18
- './app/controllers/route_controller.rb',
19
- './app/views/layouts/default.rhtml',
20
- './app/views/route/index.rhtml',
21
- './app/helpers/route_helper.rb',
22
- ]
23
-
24
- expected = [
25
- # ApplicationHelper
26
- [[], ['test/functional/route_controller_test.rb']],
27
- # fixture
28
- [['test/unit/route_test.rb'],
29
- ['test/functional/route_controller_test.rb']],
30
- # test
31
- [['test/unit/photo_test.rb'], []],
32
- # model
33
- [['test/unit/photo_test.rb'], []],
34
- # ApplicationController
35
- [[], ['test/functional/dummy_controller_test.rb']],
36
- # controller
37
- [[], ['test/functional/route_controller_test.rb']],
38
- # layout
39
- [[], []],
40
- # view
41
- [[], ['test/functional/route_controller_test.rb']],
42
- # helper
43
- [[], ['test/functional/route_controller_test.rb']],
44
- ]
45
-
46
- Dir.chdir 'test/data/rails' do
47
- file_names.each_with_index do |name, i|
48
- assert_equal expected[i], @at.map_file_names([name]),
49
- "test #{i}, #{name}"
50
- end
34
+ # controllers
35
+ util_add_map("./app/controllers/admin/themes_controller.rb",
36
+ [], ["test/functional/admin/themes_controller_test.rb"])
37
+ util_add_map("./app/controllers/application.rb",
38
+ [], ["test/functional/dummy_controller_test.rb"])
39
+ util_add_map("./app/controllers/route_controller.rb",
40
+ [], ["test/functional/route_controller_test.rb"])
41
+ util_add_map("./app/controllers/notest_controller.rb")
42
+
43
+ # helpers
44
+ util_add_map("./app/helpers/application_helper.rb",
45
+ [], ["test/functional/dummy_controller_test.rb",
46
+ "test/functional/route_controller_test.rb"])
47
+ util_add_map("./app/helpers/route_helper.rb",
48
+ [], ["test/functional/route_controller_test.rb"])
49
+
50
+ # model
51
+ util_add_map("./app/models/route.rb",
52
+ ["test/unit/route_test.rb"], [])
53
+ util_add_map("./app/models/notest.rb")
54
+
55
+ # views
56
+ util_add_map("./app/views/layouts/default.rhtml")
57
+ util_add_map("./app/views/route/index.rhtml",
58
+ [], ["test/functional/route_controller_test.rb"])
59
+ util_add_map("./app/views/route/xml.rxml",
60
+ [], ["test/functional/route_controller_test.rb"])
61
+ util_add_map("./app/views/shared/notest.rhtml")
62
+
63
+ # tests
64
+ util_add_map("./test/fixtures/routes.yml",
65
+ ["test/unit/route_test.rb"],
66
+ ["test/functional/route_controller_test.rb"])
67
+ util_add_map("./test/functional/admin/themes_controller_test.rb",
68
+ [], ["test/functional/admin/themes_controller_test.rb"])
69
+ util_add_map("./test/functional/route_controller_test.rb",
70
+ [], ["test/functional/route_controller_test.rb"])
71
+
72
+ util_add_map("./test/unit/photo_test.rb",
73
+ ["test/unit/photo_test.rb"], [])
74
+
75
+ util_add_map("./test/test_helper.rb",
76
+ @rails_unit_tests, @rails_functional_tests )
77
+
78
+ # global conf thingies
79
+ util_add_map("./config/boot.rb",
80
+ @rails_unit_tests, @rails_functional_tests )
81
+ util_add_map("./config/database.yml",
82
+ @rails_unit_tests, @rails_functional_tests )
83
+ util_add_map("./config/environment.rb",
84
+ @rails_unit_tests, @rails_functional_tests )
85
+ util_add_map("./config/environments/test.rb",
86
+ @rails_unit_tests, @rails_functional_tests )
87
+ util_add_map("./config/routes.rb",
88
+ [], @rails_functional_tests)
89
+
90
+ # ignored crap
91
+ util_add_map("./vendor/plugins/cartographer/lib/keys.rb")
92
+ util_add_map("./Rakefile")
93
+
94
+ @rails_all_tests.flatten.each do |t|
95
+ @at.files[t] = Time.at(0)
51
96
  end
97
+
98
+ util_test_map_file_names @rails_tests_dir
52
99
  end
53
100
 
54
101
  end