ZenTest 3.10.0 → 3.11.0

Sign up to get free protection for your applications and to get access to all the features.
data/History.txt CHANGED
@@ -1,3 +1,37 @@
1
+ === 3.11.0 / 2008-10-22
2
+
3
+ * 19 minor enhancements:
4
+
5
+ * Added :updated hook, gets list of updated files before running tests.
6
+ * Added autotest/restart.rb - restarts autotest if .autotest updated.
7
+ * Added better help to multiruby.
8
+ * Added dummy build command to multiruby_setup.
9
+ * Added git support.
10
+ * Added rbx:ln:$dir and rbx:git:current.
11
+ * Added rubygems:merge as a nice little hack to share rubygems setups.
12
+ * Added svn tag updating (eg will svn sw from mri 1.8.6 222 to 1.8.6 231).
13
+ * Autotest hooks now take *args as well as instance of autotest.
14
+ * Made it possible to have manually specified tags.
15
+ * Made multiruby a little more self-repairing wrt symlinks and build dirs.
16
+ * Refactored into mri_latest_tag(v).
17
+ * Refactored unit_diff to make it a bit easier to use as a library.
18
+ * Refactored zentest mapping main methods into munge/unmunge.
19
+ * Removed rubinius specific symlink hacks, now fully supported.
20
+ * mri:svn:releases figures out all the latest patch levels.
21
+ * multiruby_setup clean now checks for rakefile first, since rbx has both. :(
22
+ * multiruby_setup help now exits instead of building.
23
+ * multiruby_setup list and clean now exit
24
+
25
+ * 2 bug fixes:
26
+
27
+ * ZenTestMapping converts operator prefixes to operators only when an _ follows.
28
+ * Apparently Tempfile.open doesn't return it's last value. fixed.
29
+
30
+ * 2 bug fixes:
31
+
32
+ * Fixed bug in mri:svn:branch:xxx with svn dir name.
33
+ * multiruby_setup rm now smarter about tarballs.
34
+
1
35
  === 3.10.0 / 2008-06-17
2
36
 
3
37
  * 1 major enhancement:
data/Manifest.txt CHANGED
@@ -36,6 +36,7 @@ lib/autotest/pretty.rb
36
36
  lib/autotest/rails.rb
37
37
  lib/autotest/rcov.rb
38
38
  lib/autotest/redgreen.rb
39
+ lib/autotest/restart.rb
39
40
  lib/autotest/screen.rb
40
41
  lib/autotest/shame.rb
41
42
  lib/autotest/snarl.rb
data/bin/multiruby_setup CHANGED
@@ -4,43 +4,62 @@ require 'multiruby'
4
4
 
5
5
  ARGV << "help" if ARGV.empty?
6
6
 
7
+ Dir.chdir Multiruby.root_dir
8
+ Multiruby.setup_dirs(false)
9
+
7
10
  ARGV.each do |spec|
8
11
  case spec
9
12
  when "-h", "help" then
10
13
  Multiruby.help
14
+ exit 0
11
15
  when "list" then
12
16
  Multiruby.list
17
+ exit 0
18
+ when "build" then
19
+ # do nothing
13
20
  when /rm:(.*)/ then
14
21
  Multiruby.rm $1
15
22
  when "clean" then
16
23
  Multiruby.clean
24
+ exit 0
17
25
  when "update" then
18
26
  Multiruby.update
19
27
  when "update:rubygems" then
20
28
  Multiruby.update_rubygems
29
+ when "rubygems:merge" then
30
+ Multiruby.merge_rubygems
21
31
  when "mri:svn:current" then
22
32
  ARGV << "mri:svn:releases" << "mri:svn:branches"
23
33
  when "mri:svn:releases" then
24
34
  Multiruby::TAGS.each do |v|
25
- ARGV << "mri:svn:#{v}"
35
+ latest = Multiruby.mri_latest_tag v
36
+ abort "Can't find tag #{v}" unless latest
37
+ ARGV << "mri:svn:tag:#{latest}:mri_rel_#{v}"
26
38
  end
27
39
  when "mri:svn:branches" then
28
40
  Multiruby::BRANCHES.each do |v|
29
- ARGV << "mri:svn:#{v}"
41
+ ARGV << "mri:svn:branch:#{v}"
30
42
  end
31
43
  when /mri:svn:branch:(.*)/ then
32
- ver = $1
44
+ dir = ver = $1
33
45
  ver = "branches/ruby_#{ver}" unless ver == "trunk"
34
46
 
35
- Multiruby.svn_co "#{Multiruby::MRI_SVN}/#{ver}", "mri_#{ver}"
47
+ Multiruby.svn_co "#{Multiruby::MRI_SVN}/#{ver}", "mri_#{dir}"
48
+ when /mri:svn:tag:(.*):(.*)/ then
49
+ ver, dir = $1, $2
50
+
51
+ Multiruby.svn_co "#{Multiruby::MRI_SVN}/tags/#{ver}", dir
36
52
  when /mri:svn:tag:(.*)/ then
37
53
  ver = $1
38
- latest = Multiruby.tags.grep(/#{ver}/).last
39
54
 
40
- Multiruby.svn_co "#{Multiruby::MRI_SVN}/tags/#{latest}", "mri_rel_#{ver}"
55
+ ARGV << "mri:svn:tag:#{ver}:#{ver}"
41
56
  when /mri:tar:(.*)/ then
42
57
  v = $1
43
58
  Multiruby.fetch_tar v
59
+ when /rbx:ln:(.*)/ then
60
+ Multiruby.rbx_ln $1
61
+ when /rbx:git:current/ then
62
+ Multiruby.git_clone "#{Multiruby::RBX_GIT}/code", "rubinius"
44
63
  else
45
64
  warn "unknown spec #{spec}"
46
65
  end
@@ -14,9 +14,11 @@
14
14
  # require 'autotest/menu'
15
15
  # require 'autotest/migrate'
16
16
  # require 'autotest/notify'
17
+ # require 'autotest/once'
17
18
  # require 'autotest/pretty'
18
19
  # require 'autotest/rcov'
19
20
  # require 'autotest/redgreen'
21
+ # require 'autotest/restart'
20
22
  # require 'autotest/screen'
21
23
  # require 'autotest/shame'
22
24
  # require 'autotest/snarl'
@@ -31,12 +33,13 @@
31
33
  # Autotest::EmailNotify.recipients = o
32
34
  # Autotest::EmailNotify.use_svn = o
33
35
  # Autotest::EmailNotify.report_every_run = o
34
- # Autotest::Growl.growl title, msg, pri = 0
36
+ # Autotest::Growl.growl title, msg, pri = 0, img = nil
35
37
  # Autotest::JabberNotify.recipients = o
36
38
  # Autotest::JabberNotify.account = o
37
39
  # Autotest::JabberNotify.password = o
38
40
  # Autotest::JabberNotify.use_svn = o
39
41
  # Autotest::JabberNotify.report_every_run = o
42
+ # Autotest::RCov.command = o
40
43
  # Autotest::RCov.pattern = o
41
44
  # Autotest::Shame.chat_app = o
42
45
  # Autotest::Snarl.snarl title, msg, ico = nil
@@ -6,7 +6,7 @@
6
6
  module Autotest::Fixtures
7
7
  Autotest.add_hook :initialize do |at|
8
8
  at.test_mappings['^test/fixtures/(.*)s.yml'] = proc { |filename, matches|
9
- at.files_matching /test\/\w+\/#{matches[1]}(_\w+)?.*_test.rb$/
9
+ at.files_matching(/test\/\w+\/#{matches[1]}(_\w+)?.*_test.rb$/)
10
10
  }
11
11
  end
12
12
  end
@@ -0,0 +1,11 @@
1
+ module Autotest::Restart
2
+ Autotest.add_hook :updated do |at, *args|
3
+ if args.flatten.include? ".autotest" then
4
+ warn "Detected change to .autotest, restarting"
5
+ cmd = "autotest"
6
+ cmd << " -v" if $v
7
+
8
+ exec cmd
9
+ end
10
+ end
11
+ end
data/lib/autotest.rb CHANGED
@@ -29,10 +29,13 @@ $TESTING = false unless defined? $TESTING
29
29
  # Autotest.add_hook hook_name { |autotest| ... }
30
30
  #
31
31
  # The available hooks are: initialize, run, run_command, ran_command,
32
- # red, green, all_good, reset, interrupt, and quit.
32
+ # red, green, updated, all_good, reset, interrupt, and quit.
33
33
  #
34
34
  # See example_dot_autotest.rb for more details.
35
35
  #
36
+ # If a hook returns a true value, it signals to autotest that the hook
37
+ # was handled and should not continue executing hooks.
38
+ #
36
39
  # Naming:
37
40
  #
38
41
  # Autotest uses a simple naming scheme to figure out how to map
@@ -377,7 +380,9 @@ class Autotest
377
380
  def find_files_to_test(files=find_files)
378
381
  updated = files.select { |filename, mtime| self.last_mtime < mtime }
379
382
 
380
- p updated if $v unless updated.empty? or self.last_mtime.to_i == 0
383
+ p updated if $v unless updated.empty? || self.last_mtime.to_i == 0
384
+
385
+ hook :updated, updated unless updated.empty? || self.last_mtime.to_i == 0
381
386
 
382
387
  updated.map { |f,m| test_files_for(f) }.flatten.uniq.each do |filename|
383
388
  self.files_to_test[filename] # creates key with default value
@@ -507,7 +512,8 @@ class Autotest
507
512
 
508
513
  result = result.nil? ? [] : Array(result.last.call(filename, $~))
509
514
 
510
- output.puts "Dunno! #{filename}" if ($v or $TESTING) and result.empty?
515
+ output.puts "No tests matched #{filename}" if
516
+ ($v or $TESTING) and result.empty?
511
517
 
512
518
  result.sort.uniq.select { |f| known_files[f] }
513
519
  end
@@ -624,7 +630,7 @@ class Autotest
624
630
  # until one returns true. Returns false if no hook handled the
625
631
  # event.
626
632
 
627
- def hook(name)
633
+ def hook(name, *args)
628
634
  deprecated = {
629
635
  # none currently
630
636
  }
@@ -634,7 +640,7 @@ class Autotest
634
640
  end
635
641
 
636
642
  HOOKS[name].any? do |plugin|
637
- plugin[self]
643
+ plugin[self, *args]
638
644
  end
639
645
  end
640
646
 
data/lib/multiruby.rb CHANGED
@@ -12,6 +12,7 @@ require 'open-uri'
12
12
  # list - print installed versions.
13
13
  # update - update svn builds.
14
14
  # update:rubygems - update rubygems and nuke install dirs.
15
+ # rubygems:merge - symlink all rubygem dirs to one dir.
15
16
  # rm:$version - remove a particular version.
16
17
  # clean - clean scm build dirs and remove non-scm build dirs.
17
18
  #
@@ -23,6 +24,8 @@ require 'open-uri'
23
24
  # mri:svn:branch:$branch - install a specific $branch of mri from svn.
24
25
  # mri:svn:tag:$tag - install a specific $tag of mri from svn.
25
26
  # mri:tar:$version - install a specific $version of mri from tarball.
27
+ # rbx:ln:$dir - symlink your rbx $dir
28
+ # rbx:git:current - install rbx from git
26
29
  #
27
30
  # NOTES:
28
31
  #
@@ -30,9 +33,18 @@ require 'open-uri'
30
33
  # * I'll get to adding support for other implementations soon.
31
34
  #
32
35
  module Multiruby
33
- MRI_SVN = "http://svn.ruby-lang.org/repos/ruby"
34
- TAGS = %w( 1_8_6 1_8_7 1_9 ).map { |v| "tag:#{v}" }
35
- BRANCHES = %w(1_8 1_8_6 1_8_7 trunk).map { |v| "branch:#{v}" }
36
+ MRI_SVN = "http://svn.ruby-lang.org/repos/ruby"
37
+ RBX_GIT = "git://git.rubini.us"
38
+
39
+ TAGS = %w( 1_8_6 1_8_7 1_9 )
40
+ BRANCHES = %w(1_8 1_8_6 1_8_7 trunk)
41
+
42
+ HELP = []
43
+
44
+ File.readlines(__FILE__).each do |line|
45
+ next unless line =~ /^#( |$)/
46
+ HELP << line.sub(/^# ?/, '')
47
+ end
36
48
 
37
49
  def self.build_and_install
38
50
  root_dir = self.root_dir
@@ -56,20 +68,26 @@ module Multiruby
56
68
 
57
69
  unless test ?d, inst_dir then
58
70
  unless test ?d, build_dir then
59
- puts "creating #{inst_dir}"
60
- Dir.mkdir inst_dir
61
- run "tar zxf #{tarball}"
71
+ if test ?d, tarball then
72
+ dir = File.basename tarball
73
+ FileUtils.ln_sf "../versions/#{dir}", "../build/#{dir}"
74
+ else
75
+ puts "creating #{inst_dir}"
76
+ Dir.mkdir inst_dir
77
+ run "tar zxf #{tarball}"
78
+ end
62
79
  end
63
80
  Dir.chdir build_dir do
64
81
  puts "building and installing #{version}"
65
- run "autoconf" unless test ?f, "configure"
66
- FileUtils.rm_r "ext/readline" if test ?d, "ext/readline"
67
- run "./configure --prefix #{inst_dir} &> log.configure" unless test ?f, "Makefile"
68
- run "nice make -j4 &> log.build"
69
- run "make install &> log.install"
70
- build_dir = Dir.pwd
71
-
72
- if rubygem_tarball and version !~ /1[._-]9|trunk/ then
82
+ if test ?f, "configure.in" then
83
+ gnu_utils_build inst_dir
84
+ elsif test ?f, "Rakefile" then
85
+ rake_build inst_dir
86
+ else
87
+ raise "dunno how to build"
88
+ end
89
+
90
+ if rubygem_tarball and version !~ /1[._-]9|mri_trunk|rubinius/ then
73
91
  rubygems = File.basename rubygem_tarball, ".tgz"
74
92
  run "tar zxf #{rubygem_tarball}" unless test ?d, rubygems
75
93
 
@@ -81,11 +99,6 @@ module Multiruby
81
99
  end
82
100
  end
83
101
  end
84
-
85
- # pick up rubinius - allows for simple symlinks to your build dir
86
- self.in_install_dir do
87
- versions.push(*Dir["rubinius*"])
88
- end
89
102
  end
90
103
 
91
104
  versions
@@ -95,10 +108,10 @@ module Multiruby
95
108
  self.each_scm_build_dir do |style|
96
109
  case style
97
110
  when :svn, :git then
98
- if File.exist? "Makefile" then
99
- system "make clean"
100
- elsif File.exist? "Rakefile" then
101
- system "rake clean"
111
+ if File.exist? "Rakefile" then
112
+ run "rake clean"
113
+ elsif File.exist? "Makefile" then
114
+ run "make clean"
102
115
  end
103
116
  else
104
117
  FileUtils.rm_rf Dir.pwd
@@ -122,13 +135,15 @@ module Multiruby
122
135
  end
123
136
  end
124
137
 
125
- def self.extract_latest_version url
138
+ def self.extract_latest_version url, matching=nil
126
139
  file = URI.parse(url).read
127
140
  versions = file.scan(/href="(ruby.*tar.gz)"/).flatten.reject { |s|
128
141
  s =~ /preview/
129
142
  }.sort_by { |s|
130
143
  s.split(/\D+/).map { |i| i.to_i }
131
- }.flatten.last
144
+ }.flatten
145
+ versions = versions.grep(/#{Regexp.escape(matching)}/) if matching
146
+ versions.last
132
147
  end
133
148
 
134
149
  def self.fetch_tar v
@@ -137,8 +152,10 @@ module Multiruby
137
152
 
138
153
  in_versions_dir do
139
154
  warn " Determining latest version for #{v}"
140
- base = extract_latest_version("#{base_url}/#{v}/")
141
- url = File.join base_url, v, base
155
+ ver = v[/\d+\.\d+/]
156
+ base = extract_latest_version("#{base_url}/#{ver}/", v)
157
+ abort "Could not determine release for #{v}" unless base
158
+ url = File.join base_url, ver, base
142
159
  warn " Fetching #{base} via HTTP... this might take a while."
143
160
  open(url) do |f|
144
161
  File.open base, 'w' do |out|
@@ -148,13 +165,29 @@ module Multiruby
148
165
  end
149
166
  end
150
167
 
151
- def self.help
152
- File.readlines(__FILE__).each do |line|
153
- next unless line =~ /^#( |$)/
154
- puts line.sub(/^# ?/, '')
168
+ def self.git_clone url, dir
169
+ Multiruby.in_versions_dir do
170
+ Multiruby.run "git clone #{url} #{dir}" unless File.directory? dir
171
+ FileUtils.ln_sf "../versions/#{dir}", "../build/#{dir}"
155
172
  end
156
173
  end
157
174
 
175
+ def self.gnu_utils_build inst_dir
176
+ run "autoconf" unless test ?f, "configure"
177
+ run "./configure --prefix #{inst_dir} &> log.configure" unless test ?f, "Makefile"
178
+ run "nice make -j4 &> log.build"
179
+ run "make install &> log.install"
180
+ end
181
+
182
+ def self.rake_build inst_dir
183
+ run "rake &> log.build"
184
+ FileUtils.ln_sf "../build/#{File.basename Dir.pwd}", inst_dir
185
+ end
186
+
187
+ def self.help
188
+ puts HELP.join
189
+ end
190
+
158
191
  def self.in_build_dir
159
192
  Dir.chdir File.join(self.root_dir, "build") do
160
193
  yield
@@ -194,10 +227,38 @@ module Multiruby
194
227
  end
195
228
  end
196
229
 
230
+ def self.merge_rubygems
231
+ in_install_dir do
232
+ gems = Dir["*/lib/ruby/gems"]
233
+
234
+ unless test ?d, "../gems" then
235
+ FileUtils.mv gems.first, ".."
236
+ end
237
+
238
+ gems.each do |d|
239
+ FileUtils.rm_rf d
240
+ FileUtils.ln_sf "../../../../gems", d
241
+ end
242
+ end
243
+ end
244
+
245
+ def self.mri_latest_tag v
246
+ Multiruby.tags.grep(/#{v}/).last
247
+ end
248
+
249
+ def self.rbx_ln dir
250
+ dir = File.expand_path dir
251
+ Multiruby.in_versions_dir do
252
+ FileUtils.ln_sf dir, "rubinius"
253
+ FileUtils.ln_sf "../versions/rubinius", "../install/rubinius"
254
+ end
255
+ end
256
+
197
257
  def self.rm name
198
258
  Multiruby.in_root_dir do
199
259
  FileUtils.rm_rf Dir["*/#{name}"]
200
- File.unlink "versions/ruby-#{name}.tar.gz"
260
+ f = "versions/ruby-#{name}.tar.gz"
261
+ File.unlink f if test ?f, f
201
262
  end
202
263
  end
203
264
 
@@ -218,12 +279,12 @@ module Multiruby
218
279
  raise "ERROR: Command failed with exit code #{$?}" unless system cmd
219
280
  end
220
281
 
221
- def self.setup_dirs
282
+ def self.setup_dirs(download = true)
222
283
  %w(build install versions tmp).each do |dir|
223
284
  unless test ?d, dir then
224
285
  puts "creating #{dir}"
225
286
  Dir.mkdir dir
226
- if dir == "versions" then
287
+ if dir == "versions" && download then
227
288
  warn " Downloading initial ruby tarballs to ~/.multiruby/versions:"
228
289
  %w(1.8 1.9).each do |v|
229
290
  self.fetch_tar v
@@ -238,7 +299,7 @@ module Multiruby
238
299
  def self.svn_co url, dir
239
300
  Multiruby.in_versions_dir do
240
301
  Multiruby.run "svn co #{url} #{dir}" unless File.directory? dir
241
- FileUtils.ln_s "../versions/#{dir}", "../build/#{dir}"
302
+ FileUtils.ln_sf "../versions/#{dir}", "../build/#{dir}"
242
303
  end
243
304
  end
244
305
 
@@ -246,7 +307,7 @@ module Multiruby
246
307
  tags = nil
247
308
  Multiruby.in_tmp_dir do
248
309
  cache = "svn.tag.cache"
249
- File.unlink cache if Time.now - File.mtime(cache) > 86400 rescue nil
310
+ File.unlink cache if Time.now - File.mtime(cache) > 3600 rescue nil
250
311
 
251
312
  File.open cache, "w" do |f|
252
313
  f.write `svn ls #{MRI_SVN}/tags/`
@@ -264,23 +325,56 @@ module Multiruby
264
325
  # figure out latest tag on that name and svn sw to it trunk and
265
326
  # others will just svn update
266
327
 
328
+ clean = []
329
+
267
330
  self.each_scm_build_dir do |style|
331
+ dir = File.basename(Dir.pwd)
332
+ warn dir
333
+
268
334
  case style
269
335
  when :svn then
270
- dir = File.basename(Dir.pwd)
271
- warn dir
272
336
  case dir
273
337
  when /mri_\d/ then
274
338
  system "svn cleanup" # just in case
275
- FileUtils.rm_rf "../install/#{dir}" if `svn up` =~ /^[ADUCG] /
276
- when /tag/
277
- warn "don't know how to update tags: #{dir}"
278
- # url = `svn info`[/^URL: (.*)/, 1]
339
+ svn_up = `svn up`
340
+ in_build_dir do
341
+ if svn_up =~ /^[ADUCG] / then
342
+ clean << dir
343
+ else
344
+ warn " no update"
345
+ end
346
+ FileUtils.ln_sf "../build/#{dir}", "../versions/#{dir}"
347
+ end
348
+ when /mri_rel_(.+)/ then
349
+ ver = $1
350
+ url = `svn info`[/^URL: (.*)/, 1]
351
+ latest = self.mri_latest_tag(ver).chomp('/')
352
+ new_url = File.join(File.dirname(url), latest)
353
+ if new_url != url then
354
+ run "svn sw #{new_url}"
355
+ clean << dir
356
+ else
357
+ warn " no update"
358
+ end
359
+ else
360
+ warn " update in this svn dir not supported yet: #{dir}"
361
+ end
362
+ when :git then
363
+ case dir
364
+ when /rubinius/ then
365
+ run "rake git:update build" # minor cheat by building here
279
366
  else
280
- warn "don't know how to update: #{dir}"
367
+ warn " update in this git dir not supported yet: #{dir}"
281
368
  end
282
369
  else
283
- warn "update in non-svn dir not supported yet: #{dir}"
370
+ warn " update in non-svn dir not supported yet: #{dir}"
371
+ end
372
+ end
373
+
374
+ in_install_dir do
375
+ clean.each do |dir|
376
+ warn "removing install/#{dir}"
377
+ FileUtils.rm_rf dir
284
378
  end
285
379
  end
286
380
  end
@@ -299,5 +393,9 @@ module Multiruby
299
393
  f.write URI.parse(url+file).read
300
394
  end
301
395
  end
396
+
397
+ Multiruby.in_install_dir do
398
+ FileUtils.rm_rf Dir["*"]
399
+ end
302
400
  end
303
401
  end
data/lib/unit_diff.rb CHANGED
@@ -199,31 +199,7 @@ class UnitDiff
199
199
  output.push prefix.compact.map {|line| line.strip}.join("\n")
200
200
 
201
201
  if butwas then
202
- Tempfile.open("expect") do |a|
203
- a.write(massage(expect))
204
- a.rewind
205
- Tempfile.open("butwas") do |b|
206
- b.write(massage(butwas))
207
- b.rewind
208
-
209
- diff_flags = $u ? "-u" : $c ? "-c" : ""
210
- diff_flags += " -b" if $b
211
-
212
- result = `#{DIFF} #{diff_flags} #{a.path} #{b.path}`
213
- if result.empty? then
214
- output.push "[no difference--suspect ==]"
215
- else
216
- output.push result.split(/\n/)
217
- end
218
-
219
- if $k then
220
- warn "moving #{a.path} to #{a.path}.keep"
221
- File.rename a.path, a.path + ".keep"
222
- warn "moving #{b.path} to #{b.path}.keep"
223
- File.rename b.path, b.path + ".keep"
224
- end
225
- end
226
- end
202
+ output.push self.diff(expect, butwas)
227
203
 
228
204
  output.push result_footer
229
205
  output.push ''
@@ -240,6 +216,38 @@ class UnitDiff
240
216
  return output.flatten.join("\n")
241
217
  end
242
218
 
219
+ def diff expect, butwas
220
+ output = nil
221
+
222
+ Tempfile.open("expect") do |a|
223
+ a.write(massage(expect))
224
+ a.rewind
225
+ Tempfile.open("butwas") do |b|
226
+ b.write(massage(butwas))
227
+ b.rewind
228
+
229
+ diff_flags = $u ? "-u" : $c ? "-c" : ""
230
+ diff_flags += " -b" if $b
231
+
232
+ result = `#{DIFF} #{diff_flags} #{a.path} #{b.path}`
233
+ output = if result.empty? then
234
+ "[no difference--suspect ==]"
235
+ else
236
+ result.split(/\n/)
237
+ end
238
+
239
+ if $k then
240
+ warn "moving #{a.path} to #{a.path}.keep"
241
+ File.rename a.path, a.path + ".keep"
242
+ warn "moving #{b.path} to #{b.path}.keep"
243
+ File.rename b.path, b.path + ".keep"
244
+ end
245
+ end
246
+ end
247
+
248
+ output
249
+ end
250
+
243
251
  def massage(data)
244
252
  data = data.map { |l| '%3d) %s' % [count+=1, l] } if $l
245
253
  # unescape newlines, strip <> from entire string
data/lib/zentest.rb CHANGED
@@ -56,7 +56,7 @@ end
56
56
 
57
57
  class ZenTest
58
58
 
59
- VERSION = '3.10.0'
59
+ VERSION = '3.11.0'
60
60
 
61
61
  include ZenTestMapping
62
62
 
@@ -422,6 +422,20 @@ class ZenTest
422
422
  end # @klasses[klassname]
423
423
  end
424
424
 
425
+ def test_to_normal(name, klassname=nil)
426
+ super do |name|
427
+ if defined? @inherited_methods then
428
+ known_methods = (@inherited_methods[klassname] || {}).keys.sort.reverse
429
+ known_methods_re = known_methods.map {|s| Regexp.escape(s) }.join("|")
430
+
431
+ name = name.sub(/^(#{known_methods_re})(_.*)?$/) { $1 } unless
432
+ known_methods_re.empty?
433
+
434
+ name
435
+ end
436
+ end
437
+ end
438
+
425
439
  # create a given method at a given
426
440
  # indentation. Returns an array containing
427
441
  # the lines of the method.
@@ -456,8 +470,6 @@ class ZenTest
456
470
  # NotImplementedError, so that they can be filled
457
471
  # in later, and so the tests will fail to start with.
458
472
  def generate_code
459
-
460
- # @result.unshift "# run against: #{files.join(', ')}" if $DEBUG
461
473
  @result.unshift "# Code Generated by ZenTest v. #{VERSION}"
462
474
 
463
475
  if $DEBUG then
@@ -55,45 +55,63 @@ module ZenTestMapping
55
55
 
56
56
  @@method_map = @@orig_method_map.merge(@@orig_method_map.invert)
57
57
 
58
- # Generates a test method name from a normal method,
59
- # taking into account names composed of metacharacters
60
- # (used for arithmetic, etc
61
- def normal_to_test(name)
62
- name = name.to_s.dup # wtf?
58
+ @@mapped_re = @@orig_method_map.values.sort_by { |k| k.length }.map {|s|
59
+ Regexp.escape(s)
60
+ }.reverse.join("|")
61
+
62
+ def munge name
63
+ name = name.to_s.dup
64
+
63
65
  is_cls_method = name.sub!(/^self\./, '')
66
+
64
67
  name = @@method_map[name] if @@method_map.has_key? name
65
68
  name = name.sub(/=$/, '_equals')
66
69
  name = name.sub(/\?$/, '_eh')
67
70
  name = name.sub(/\!$/, '_bang')
71
+
72
+ name = yield name if block_given?
73
+
68
74
  name = "class_" + name if is_cls_method
69
- "test_#{name}"
70
- end
71
75
 
72
- # Converts a method name beginning with test to its
73
- # corresponding normal method name, taking into account
74
- # symbolic names which may have been anglicised by
75
- # #normal_to_test().
76
- def test_to_normal(name, klassname=nil)
77
- name = name.to_s
76
+ name
77
+ end
78
78
 
79
- known_methods = (@inherited_methods[klassname] || {}).keys.sort.reverse
79
+ # Generates a test method name from a normal method,
80
+ # taking into account names composed of metacharacters
81
+ # (used for arithmetic, etc
82
+ def normal_to_test name
83
+ "test_#{munge name}"
84
+ end
80
85
 
81
- mapped_re = @@orig_method_map.values.sort_by { |k| k.length }.map {|s| Regexp.escape(s)}.reverse.join("|")
82
- known_methods_re = known_methods.map {|s| Regexp.escape(s)}.join("|")
86
+ def unmunge name
87
+ name = name.to_s.dup
83
88
 
84
- name = name.sub(/^test_/, '')
85
- name = name.sub(/_equals/, '=') unless name =~ /index/
86
- name = name.sub(/_bang.*$/, '!') # FIX: deal w/ extensions separately
87
- name = name.sub(/_eh/, '?')
88
89
  is_cls_method = name.sub!(/^class_/, '')
89
- name = name.sub(/^(#{mapped_re})(.*)$/) {$1}
90
- name = name.sub(/^(#{known_methods_re})(.*)$/) {$1} unless known_methods_re.empty?
91
90
 
92
- # look up in method map
91
+ name = name.sub(/_equals(_.*)?$/, '=') unless name =~ /index/
92
+ name = name.sub(/_bang(_.*)?$/, '!')
93
+ name = name.sub(/_eh(_.*)?$/, '?')
94
+ name = name.sub(/^(#{@@mapped_re})(_.*)?$/) {$1}
95
+ name = yield name if block_given?
93
96
  name = @@method_map[name] if @@method_map.has_key? name
94
-
95
97
  name = 'self.' + name if is_cls_method
96
98
 
97
99
  name
98
100
  end
101
+
102
+ # Converts a method name beginning with test to its
103
+ # corresponding normal method name, taking into account
104
+ # symbolic names which may have been anglicised by
105
+ # #normal_to_test().
106
+ def test_to_normal(name, klassname=nil)
107
+ unmunge(name.to_s.sub(/^test_/, '')) do |n|
108
+ if defined? @inherited_methods then
109
+ known_methods = (@inherited_methods[klassname] || {}).keys.sort.reverse
110
+ known_methods_re = known_methods.map {|s| Regexp.escape(s) }.join("|")
111
+ n = n.sub(/^(#{known_methods_re})(_.*)?$/) { $1 } unless
112
+ known_methods_re.empty?
113
+ n
114
+ end
115
+ end
116
+ end
99
117
  end
@@ -182,7 +182,7 @@ class TestAutotest < Test::Unit::TestCase
182
182
  files = { "fooby.rb" => Time.at(42) }
183
183
  assert @a.find_files_to_test(files) # we find fooby,
184
184
  assert_equal empty, @a.files_to_test # but it isn't something to test
185
- assert_equal "Dunno! fooby.rb\n", @a.output.string
185
+ assert_equal "No tests matched fooby.rb\n", @a.output.string
186
186
  end
187
187
 
188
188
  def test_find_files_to_test_lib
data/test/test_zentest.rb CHANGED
@@ -12,14 +12,10 @@ $TESTING = true
12
12
  # I do this so I can still run ZenTest against the tests and itself...
13
13
  require 'zentest' unless defined? $ZENTEST
14
14
 
15
- class TrueClass # stupid YAML is breaking my tests. Enters via Test::Rails
16
- remove_method :taguri, :taguri=, :to_yaml rescue nil
17
- end
18
-
19
15
  # These are just classes set up for quick testing.
20
16
  # TODO: need to test a compound class name Mod::Cls
21
17
 
22
- class Cls1 # ZenTest SKIP
18
+ class Cls1 # ZenTest SKIP
23
19
  def meth1; end
24
20
  def self.meth2; end
25
21
  end
@@ -37,7 +33,7 @@ class SuperDuper # ZenTest SKIP
37
33
  def overridden; end
38
34
  end
39
35
 
40
- class LowlyOne < SuperDuper # ZenTest SKIP
36
+ class LowlyOne < SuperDuper # ZenTest SKIP
41
37
  def self.cls_extended; end
42
38
  def overridden; end
43
39
  def extended; end
@@ -145,6 +141,10 @@ end
145
141
  class TestTrueClass; end
146
142
 
147
143
  class TestZenTest < Test::Unit::TestCase
144
+ unless defined? Mini then
145
+ alias :refute_nil :assert_not_nil
146
+ end
147
+
148
148
 
149
149
  def setup
150
150
  @tester = ZenTest.new()
@@ -559,6 +559,9 @@ assert_equal expected, util_testcase("Something2::Blah2", "TestSomething2::TestB
559
559
  end
560
560
 
561
561
  def test_testcase9
562
+ # stupid YAML is breaking my tests. Enters via Test::Rails. order dependent.
563
+ TrueClass.send :remove_method, :taguri, :taguri=, :to_yaml if defined? YAML
564
+
562
565
  expected = "\nrequire 'test/unit' unless defined? $ZENTEST and $ZENTEST\n\nclass TestTrueClass < Test::Unit::TestCase\n def test_and\n raise NotImplementedError, 'Need to write test_and'\n end\n\n def test_carat\n raise NotImplementedError, 'Need to write test_carat'\n end\n\n def test_or\n raise NotImplementedError, 'Need to write test_or'\n end\n\n def test_to_s\n raise NotImplementedError, 'Need to write test_to_s'\n end\nend\n\n# Number of errors detected: 4"
563
566
 
564
567
  assert_equal expected, util_testcase("TestTrueClass")
@@ -16,27 +16,25 @@ class TestZentestMapping < Test::Unit::TestCase
16
16
 
17
17
  def util_simple_setup
18
18
  klasses = {
19
- "Something" =>
20
- {
21
- "method1" => true,
22
- "method1!" => true,
23
- "method1=" => true,
24
- "method1?" => true,
25
- "attrib" => true,
26
- "attrib=" => true,
27
- "equal?" => true,
19
+ "Something" => {
20
+ "method1" => true,
21
+ "method1!" => true,
22
+ "method1=" => true,
23
+ "method1?" => true,
24
+ "attrib" => true,
25
+ "attrib=" => true,
26
+ "equal?" => true,
28
27
  "self.method3" => true,
29
- "self.[]" => true,
28
+ "self.[]" => true,
30
29
  },
31
30
  }
32
31
  test_klasses = {
33
- "TestSomething" =>
34
- {
32
+ "TestSomething" => {
35
33
  "test_class_method4" => true,
36
- "test_method2" => true,
37
- "setup" => true,
38
- "teardown" => true,
39
- "test_class_index" => true,
34
+ "test_method2" => true,
35
+ "setup" => true,
36
+ "teardown" => true,
37
+ "test_class_index" => true,
40
38
  },
41
39
  }
42
40
  @tester.inherited_methods = test_klasses.merge(klasses)
@@ -101,24 +99,28 @@ end
101
99
 
102
100
  def test_normal_to_test_cls
103
101
  self.util_simple_setup
104
- assert_equal("test_class_method1", @tester.normal_to_test("self.method1"))
105
- assert_equal("test_class_method1_bang", @tester.normal_to_test("self.method1!"))
106
- assert_equal("test_class_method1_eh", @tester.normal_to_test("self.method1?"))
107
- assert_equal("test_class_method1_equals", @tester.normal_to_test("self.method1="))
102
+ assert_equal("test_class_method1",
103
+ @tester.normal_to_test("self.method1"))
104
+ assert_equal("test_class_method1_bang",
105
+ @tester.normal_to_test("self.method1!"))
106
+ assert_equal("test_class_method1_eh",
107
+ @tester.normal_to_test("self.method1?"))
108
+ assert_equal("test_class_method1_equals",
109
+ @tester.normal_to_test("self.method1="))
108
110
  end
109
111
 
110
112
  def test_normal_to_test_operators
111
113
  self.util_simple_setup
112
- assert_equal("test_and", @tester.normal_to_test("&"))
113
- assert_equal("test_bang", @tester.normal_to_test("!"))
114
- assert_equal("test_carat", @tester.normal_to_test("^"))
115
- assert_equal("test_div", @tester.normal_to_test("/"))
114
+ assert_equal("test_and", @tester.normal_to_test("&"))
115
+ assert_equal("test_bang", @tester.normal_to_test("!"))
116
+ assert_equal("test_carat", @tester.normal_to_test("^"))
117
+ assert_equal("test_div", @tester.normal_to_test("/"))
116
118
  assert_equal("test_equalstilde", @tester.normal_to_test("=~"))
117
- assert_equal("test_minus", @tester.normal_to_test("-"))
118
- assert_equal("test_or", @tester.normal_to_test("|"))
119
- assert_equal("test_percent", @tester.normal_to_test("%"))
120
- assert_equal("test_plus", @tester.normal_to_test("+"))
121
- assert_equal("test_tilde", @tester.normal_to_test("~"))
119
+ assert_equal("test_minus", @tester.normal_to_test("-"))
120
+ assert_equal("test_or", @tester.normal_to_test("|"))
121
+ assert_equal("test_percent", @tester.normal_to_test("%"))
122
+ assert_equal("test_plus", @tester.normal_to_test("+"))
123
+ assert_equal("test_tilde", @tester.normal_to_test("~"))
122
124
  end
123
125
 
124
126
  def test_normal_to_test_overlap
@@ -145,27 +147,44 @@ end
145
147
 
146
148
  def test_test_to_normal
147
149
  self.util_simple_setup
148
- assert_equal("method1!", @tester.test_to_normal("test_method1_bang", "Something"))
149
- assert_equal("method1", @tester.test_to_normal("test_method1", "Something"))
150
- assert_equal("method1=", @tester.test_to_normal("test_method1_equals", "Something"))
151
- assert_equal("method1?", @tester.test_to_normal("test_method1_eh", "Something"))
150
+ assert_equal("method1!",
151
+ @tester.test_to_normal("test_method1_bang", "Something"))
152
+ assert_equal("method1",
153
+ @tester.test_to_normal("test_method1", "Something"))
154
+ assert_equal("method1=",
155
+ @tester.test_to_normal("test_method1_equals", "Something"))
156
+ assert_equal("method1?",
157
+ @tester.test_to_normal("test_method1_eh", "Something"))
152
158
  end
153
159
 
154
160
  def test_test_to_normal_cls
155
161
  self.util_simple_setup
156
- assert_equal("self.method1", @tester.test_to_normal("test_class_method1"))
157
- assert_equal("self.method1!", @tester.test_to_normal("test_class_method1_bang"))
158
- assert_equal("self.method1?", @tester.test_to_normal("test_class_method1_eh"))
159
- assert_equal("self.method1=", @tester.test_to_normal("test_class_method1_equals"))
160
- assert_equal("self.[]", @tester.test_to_normal("test_class_index"))
162
+ assert_equal("self.method1",
163
+ @tester.test_to_normal("test_class_method1"))
164
+ assert_equal("self.method1!",
165
+ @tester.test_to_normal("test_class_method1_bang"))
166
+ assert_equal("self.method1?",
167
+ @tester.test_to_normal("test_class_method1_eh"))
168
+ assert_equal("self.method1=",
169
+ @tester.test_to_normal("test_class_method1_equals"))
170
+ assert_equal("self.[]",
171
+ @tester.test_to_normal("test_class_index"))
161
172
  end
162
173
 
163
174
  def test_test_to_normal_extended
164
175
  self.util_simple_setup
165
- assert_equal("equal?", @tester.test_to_normal("test_equal_eh_extension", "Something"))
166
- assert_equal("equal?", @tester.test_to_normal("test_equal_eh_extension_again", "Something"))
167
- assert_equal("method1", @tester.test_to_normal("test_method1_extension", "Something"))
168
- assert_equal("method1", @tester.test_to_normal("test_method1_extension_again", "Something"))
176
+ assert_equal("equal?",
177
+ @tester.test_to_normal("test_equal_eh_extension",
178
+ "Something"))
179
+ assert_equal("equal?",
180
+ @tester.test_to_normal("test_equal_eh_extension_again",
181
+ "Something"))
182
+ assert_equal("method1",
183
+ @tester.test_to_normal("test_method1_extension",
184
+ "Something"))
185
+ assert_equal("method1",
186
+ @tester.test_to_normal("test_method1_extension_again",
187
+ "Something"))
169
188
  end
170
189
 
171
190
  def test_test_to_normal_mapped
@@ -214,4 +233,9 @@ end
214
233
  assert_equal("-@", @tester.test_to_normal("test_unary_minus"))
215
234
  assert_equal("+@", @tester.test_to_normal("test_unary_plus"))
216
235
  end
236
+
237
+ def test_to_normal_subset
238
+ self.util_simple_setup
239
+ assert_equal("get_foo", @tester.test_to_normal("test_get_foo"))
240
+ end
217
241
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ZenTest
3
3
  version: !ruby/object:Gem::Version
4
- version: 3.10.0
4
+ version: 3.11.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ryan Davis
@@ -10,17 +10,18 @@ autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
12
 
13
- date: 2008-06-17 00:00:00 -07:00
13
+ date: 2008-10-22 00:00:00 -05:00
14
14
  default_executable:
15
15
  dependencies:
16
16
  - !ruby/object:Gem::Dependency
17
17
  name: hoe
18
+ type: :development
18
19
  version_requirement:
19
20
  version_requirements: !ruby/object:Gem::Requirement
20
21
  requirements:
21
22
  - - ">="
22
23
  - !ruby/object:Gem::Version
23
- version: 1.5.3
24
+ version: 1.8.0
24
25
  version:
25
26
  description: "ZenTest provides 4 different tools and 1 library: zentest, unit_diff, autotest, multiruby, and Test::Rails. ZenTest scans your target and unit-test code and writes your missing code based on simple naming rules, enabling XP at a much quicker pace. ZenTest only works with Ruby and Test::Unit. unit_diff is a command-line filter to diff expected results from actual results and allow you to quickly see exactly what is wrong. autotest is a continous testing facility meant to be used during development. As soon as you save a file, autotest will run the corresponding dependent tests. multiruby runs anything you want on multiple versions of ruby. Great for compatibility checking! Use multiruby_setup to manage your installed versions. Test::Rails helps you build industrial-strength Rails code."
26
27
  email:
@@ -80,6 +81,7 @@ files:
80
81
  - lib/autotest/rails.rb
81
82
  - lib/autotest/rcov.rb
82
83
  - lib/autotest/redgreen.rb
84
+ - lib/autotest/restart.rb
83
85
  - lib/autotest/screen.rb
84
86
  - lib/autotest/shame.rb
85
87
  - lib/autotest/snarl.rb
@@ -133,7 +135,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
133
135
  requirements: []
134
136
 
135
137
  rubyforge_project: zentest
136
- rubygems_version: 1.1.1
138
+ rubygems_version: 1.3.0
137
139
  signing_key:
138
140
  specification_version: 2
139
141
  summary: "ZenTest provides 4 different tools and 1 library: zentest, unit_diff, autotest, multiruby, and Test::Rails"