ZenTest 3.9.1 → 3.9.2

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,3 +1,20 @@
1
+ === 3.9.2 / 2008-03-20
2
+
3
+ * 4 minor enhancements:
4
+
5
+ * Added compatibility with miniunit differences.
6
+ * Added email_notify, jabber_notify, and rcov autotest plugins.
7
+ * Updated rakefile to include examples automatically in example_dot_autotest.
8
+ * multiruby now outputs each command so you can grab it easily.
9
+
10
+ * 5 bug fixes:
11
+
12
+ * Ensure tests are run after reset.
13
+ * Fixed all test/rails tests to run in any combo.
14
+ * Fixed up growl.rb a bit... still buggy (growlnotify, not growl.rb).
15
+ * Fixes for -f (fast start) and last_mtime in general.
16
+ * Fixes for 1.9 and rubinius
17
+
1
18
  === 3.9.1 / 2008-01-31
2
19
 
3
20
  * 1 bug fix:
@@ -20,16 +20,19 @@ lib/autotest/camping.rb
20
20
  lib/autotest/cctray.rb
21
21
  lib/autotest/discover.rb
22
22
  lib/autotest/emacs.rb
23
+ lib/autotest/email_notify.rb
23
24
  lib/autotest/fixtures.rb
24
25
  lib/autotest/growl.rb
25
26
  lib/autotest/heckle.rb
26
27
  lib/autotest/html_report.rb
28
+ lib/autotest/jabber_notify.rb
27
29
  lib/autotest/kdenotify.rb
28
30
  lib/autotest/menu.rb
29
31
  lib/autotest/migrate.rb
30
32
  lib/autotest/notify.rb
31
33
  lib/autotest/pretty.rb
32
34
  lib/autotest/rails.rb
35
+ lib/autotest/rcov.rb
33
36
  lib/autotest/redgreen.rb
34
37
  lib/autotest/screen.rb
35
38
  lib/autotest/shame.rb
data/Rakefile CHANGED
@@ -16,23 +16,31 @@ task :autotest do
16
16
  end
17
17
 
18
18
  task :update do
19
+ system "p4 edit example_dot_autotest.rb"
19
20
  File.open "example_dot_autotest.rb", "w" do |f|
20
21
  f.puts "# -*- ruby -*-"
21
22
  f.puts
22
23
  Dir.chdir "lib" do
23
24
  Dir["autotest/*.rb"].sort.each do |s|
25
+ next if s =~ /rails|discover/
24
26
  f.puts "# require '#{s[0..-4]}'"
25
27
  end
26
28
  end
27
29
 
28
30
  f.puts
29
- f.puts "# Autotest::AutoUpdate.sleep_time = 60"
30
- f.puts "# Autotest::AutoUpdate.update_cmd = 'svn up'"
31
- f.puts "# Autotest::Emacs.client_cmd = 'emacsclient -e'"
32
- f.puts "# Autotest::Heckle.flags << '-t test/**/*.rb'"
33
- f.puts "# Autotest::Heckle.klasses << 'MyClass'"
34
- f.puts "# Autotest::Shame.chat_app = :adium"
31
+
32
+ Dir["lib/autotest/*.rb"].sort.each do |file|
33
+ file = File.read(file)
34
+ m = file[/module.*/].split(/ /).last rescue nil
35
+ next unless m
36
+
37
+ file.grep(/def[^(]+=/).each do |setter|
38
+ setter = setter.sub(/^ *def self\./, '').sub(/\s*=\s*/, ' = ')
39
+ f.puts "# #{m}.#{setter}"
40
+ end
41
+ end
35
42
  end
43
+ system "p4 diff -du example_dot_autotest.rb"
36
44
  end
37
45
 
38
46
  task :sort do
@@ -1,4 +1,4 @@
1
- #!/usr/local/bin/ruby -w
1
+ #!/usr/bin/env ruby -w
2
2
 
3
3
  require 'fileutils'
4
4
 
@@ -96,6 +96,9 @@ versions.each do |version|
96
96
 
97
97
  puts
98
98
  puts "VERSION = #{version}"
99
+ cmd = [ruby, ARGV].flatten.map { |s| s =~ /\"/ ? "'#{s}'" : s }.join(' ')
100
+ cmd.sub!(/#{ENV['HOME']}/, '~')
101
+ puts "CMD = #{cmd}"
99
102
  puts
100
103
  system ruby, *ARGV
101
104
  puts
@@ -4,24 +4,39 @@
4
4
  # require 'autotest/camping'
5
5
  # require 'autotest/cctray'
6
6
  # require 'autotest/emacs'
7
+ # require 'autotest/email_notify'
7
8
  # require 'autotest/fixtures'
8
9
  # require 'autotest/growl'
9
10
  # require 'autotest/heckle'
10
11
  # require 'autotest/html_report'
12
+ # require 'autotest/jabber_notify'
11
13
  # require 'autotest/kdenotify'
12
14
  # require 'autotest/menu'
13
15
  # require 'autotest/migrate'
14
16
  # require 'autotest/notify'
15
17
  # require 'autotest/pretty'
18
+ # require 'autotest/rcov'
16
19
  # require 'autotest/redgreen'
17
20
  # require 'autotest/screen'
18
21
  # require 'autotest/shame'
19
22
  # require 'autotest/snarl'
20
23
  # require 'autotest/timestamp'
21
24
 
22
- # Autotest::AutoUpdate.sleep_time = 60
23
- # Autotest::AutoUpdate.update_cmd = 'svn up'
24
- # Autotest::Emacs.client_cmd = 'emacsclient -e'
25
- # Autotest::Heckle.flags << '-t test/**/*.rb'
26
- # Autotest::Heckle.klasses << 'MyClass'
27
- # Autotest::Shame.chat_app = :adium
25
+ # Autotest::AutoUpdate.sleep_time = o
26
+ # Autotest::AutoUpdate.update_cmd = o
27
+ # Autotest::CCTray.project_name = name
28
+ # Autotest::Emacs.command = o
29
+ # Autotest::EmailNotify.smtp_settings = o
30
+ # Autotest::EmailNotify.from = o
31
+ # Autotest::EmailNotify.recipients = o
32
+ # Autotest::EmailNotify.use_svn = o
33
+ # Autotest::EmailNotify.report_every_run = o
34
+ # Autotest::Growl.growl title, msg, pri = 0
35
+ # Autotest::JabberNotify.recipients = o
36
+ # Autotest::JabberNotify.account = o
37
+ # Autotest::JabberNotify.password = o
38
+ # Autotest::JabberNotify.use_svn = o
39
+ # Autotest::JabberNotify.report_every_run = o
40
+ # Autotest::RCov.pattern = o
41
+ # Autotest::Shame.chat_app = o
42
+ # Autotest::Snarl.snarl title, msg, ico = nil
@@ -222,10 +222,10 @@ class Autotest
222
222
  # Keep running the tests after a change, until all pass.
223
223
 
224
224
  def get_to_green
225
- until all_good do
225
+ begin
226
226
  run_tests
227
227
  wait_for_changes unless all_good
228
- end
228
+ end until all_good
229
229
  end
230
230
 
231
231
  ##
@@ -234,8 +234,12 @@ class Autotest
234
234
  def run_tests
235
235
  hook :run_command
236
236
 
237
- self.find_files_to_test
237
+ new_mtime = self.find_files_to_test
238
+ return unless new_mtime
239
+ self.last_mtime = new_mtime
240
+
238
241
  cmd = self.make_test_cmd self.files_to_test
242
+ return if cmd.empty?
239
243
 
240
244
  puts cmd unless $q
241
245
 
@@ -377,8 +381,11 @@ class Autotest
377
381
  self.files_to_test[filename] # creates key with default value
378
382
  end
379
383
 
380
- self.last_mtime = files.values.max
381
- not updated.empty?
384
+ if updated.empty? then
385
+ nil
386
+ else
387
+ files.values.max
388
+ end
382
389
  end
383
390
 
384
391
  ##
@@ -438,7 +445,8 @@ class Autotest
438
445
  when :reverse then
439
446
  files_to_test.sort_by { |k,v| k }.reverse
440
447
  when :random then
441
- files_to_test.sort_by { |k,v| rand }
448
+ max = files_to_test.size
449
+ files_to_test.sort_by { |k,v| rand(max) }
442
450
  when :natural then
443
451
  (self.find_order & files_to_test.keys).map { |f| [f, files_to_test[f]] }
444
452
  else
@@ -0,0 +1,66 @@
1
+ require 'net/smtp'
2
+
3
+ module Autotest::EmailNotify
4
+ @@smtp_settings = ['localhost']
5
+ @@from = nil
6
+ @@recipients = []
7
+ @@use_svn = true
8
+ @@report_every_run = false
9
+
10
+ @@last_rev = nil
11
+
12
+ def self.smtp_settings= o
13
+ @@smtp_settings = o
14
+ end
15
+
16
+ def self.from= o
17
+ @@from = o
18
+ end
19
+
20
+ def self.recipients= o
21
+ @@recipients = o
22
+ end
23
+
24
+ def self.use_svn= o
25
+ @@use_svn = o
26
+ end
27
+
28
+ def self.report_every_run= o
29
+ @@report_every_run = o
30
+ end
31
+
32
+ def self.notify title, msg
33
+ @@recipients.each do |to|
34
+ body = ["From: autotest <#{@@from}>"]
35
+ body << "To: <#{to}>"
36
+ body << "Subject: #{title}"
37
+ body << "\n"
38
+ body << msg
39
+ Net::SMTP.start(*@@smtp_settings) do |smtp|
40
+ smtp.send_message body.join("\n"), @@from, to
41
+ end
42
+ end
43
+ end
44
+
45
+ def self.svn_release
46
+ if @@use_svn
47
+ rev = `svn info`.match(/Revision: (\d+)/)[1]
48
+ return "r#{rev} "
49
+ end
50
+ end
51
+
52
+ Autotest.add_hook :ran_command do |at|
53
+ rev = self.svn_release
54
+ if @@report_every_run or rev != @@last_rev
55
+ @@last_rev = rev
56
+ output = at.results.join
57
+ failed = output.scan(/^\s+\d+\) (?:Failure|Error):\n(.*?)\((.*?)\)/)
58
+ if failed.size == 0 then
59
+ notify "#{rev}Tests Passed", output
60
+ else
61
+ f,e = failed.partition { |s| s =~ /Failure/ }
62
+ notify "#{rev}#{failed.size} Tests Failed", output
63
+ end
64
+ end
65
+ end
66
+ end
@@ -1,13 +1,16 @@
1
1
  # -*- ruby -*-
2
2
 
3
3
  module Autotest::Growl
4
- def self.growl title, msg, pri=0
5
- title += " in #{Dir.pwd}"
6
- msg += " at #{Time.now}"
7
- system "growlnotify -n autotest --image /Applications/Mail.app/Contents/Resources/Caution.tiff -p #{pri} -m #{msg.inspect} #{title}"
4
+ def self.growl title, msg, pri = 0, img = nil
5
+ title += " in #{Dir.pwd.split(/\//)[-3..-1].join("/")}"
6
+ msg += " at #{Time.now.strftime('%Y-%m-%d %H:%M:%S')}"
7
+ # TODO: parameterize default image
8
+ img ||= "/Applications/Mail.app/Contents/Resources/Caution.tiff"
9
+ cmd = "growlnotify -n autotest --image #{img} -p #{pri} -m #{msg.inspect} #{title}"
10
+ system cmd
8
11
  end
9
12
 
10
- Autotest.add_hook :run do |at|
13
+ Autotest.add_hook :initialize do |at|
11
14
  growl "autotest running", "Started"
12
15
  end
13
16
 
@@ -0,0 +1,111 @@
1
+ begin; require 'rubygems'; rescue LoadError; end
2
+ require 'xmpp4r-simple'
3
+
4
+ module Autotest::JabberNotify
5
+ @@recipients = []
6
+ @@account = nil
7
+ @@password = nil
8
+ @@use_svn = true
9
+ @@report_every_run = true
10
+
11
+ @@im = nil
12
+ @@last_rev = nil
13
+ @@green = false
14
+
15
+ def self.recipients= o
16
+ @@recipients = o
17
+ end
18
+
19
+ def self.account= o
20
+ @@account = o
21
+ end
22
+
23
+ def self.password= o
24
+ @@password = o
25
+ end
26
+
27
+ def self.use_svn= o
28
+ @@use_svn = o
29
+ end
30
+
31
+ def self.report_every_run= o
32
+ @@report_every_run = o
33
+ end
34
+
35
+ def self.im
36
+ unless @@im
37
+ puts "# creating im client"
38
+ @@im = Jabber::Simple.new(@@account,@@password)
39
+ sleep(2) # need this or else the first announcement may cause an error
40
+ end
41
+ if !@@im.connected?
42
+ puts "# reconnecting to #{@@account}"
43
+ @@im.reconnect
44
+ end
45
+ @@im
46
+ end
47
+
48
+ def self.notify(msg)
49
+ @@recipients.each do |contact|
50
+ self.im.deliver(contact, msg)
51
+ end
52
+ end
53
+
54
+ def self.status(status)
55
+ rev = self.svn_release
56
+ status = "#{rev}#{status}"
57
+ self.im.status(:chat, status)
58
+ end
59
+
60
+ def self.svn_release
61
+ if @@use_svn
62
+ rev = `svn info`.match(/Revision: (\d+)/)[1]
63
+ return "r#{rev} "
64
+ end
65
+ end
66
+
67
+ # hooks
68
+
69
+ Autotest.add_hook :run do |at|
70
+ notify "autotest started"
71
+ end
72
+
73
+ Autotest.add_hook :run_command do |at|
74
+ status "testing"
75
+ end
76
+
77
+ Autotest.add_hook :ran_command do |at|
78
+ rev = self.svn_release
79
+ if @@report_every_run or rev != @@last_rev
80
+ @@last_rev = rev
81
+ output = at.results.join
82
+ failed = output.scan(/^\s+\d+\) ((?:Failure|Error):\n.*?\.*?\))/).flatten
83
+ failed.map! {|f| f.gsub!(/\n/,' '); f.gsub(/^/,'- ') }
84
+ time = output.scan(/Finished in (.*?)\n/)
85
+ if failed.size > 0 then
86
+ notify "Tests Passed\n#{time}\n" if !@@green
87
+ @@green = true # prevent repeat success notifications
88
+ else
89
+ @@green = false
90
+ notify "#{failed.size} Tests Failed\n" + failed.join("\n")
91
+ end
92
+ end
93
+ end
94
+
95
+ Autotest.add_hook :green do |at|
96
+ status "Tests Pass"
97
+ end
98
+
99
+ Autotest.add_hook :red do |at|
100
+ status "Tests Failed"
101
+ end
102
+
103
+ Autotest.add_hook :quit do |at|
104
+ notify "autotest is exiting"
105
+ self.im.disconnect
106
+ end
107
+
108
+ Autotest.add_hook :all do |at|_hook
109
+ notify "Tests have fully passed" unless $TESTING
110
+ end
111
+ end
@@ -0,0 +1,16 @@
1
+ module Autotest::RCov
2
+ @@command, @@pattern = "rcov", "test/*.rb"
3
+
4
+ def self.command= o
5
+ @@command = o
6
+ end
7
+
8
+ def self.pattern= o
9
+ @@pattern = o
10
+ end
11
+
12
+ Autotest.add_hook :all_good do |at|
13
+ system "rake #{@@command} PATTERN=#{@@pattern}"
14
+ end
15
+ end
16
+
@@ -1,6 +1,8 @@
1
1
  ##
2
2
  # Extra assertions for Test::Unit
3
3
 
4
+ Test::Unit::Assertions = MiniTest::Unit::TestCase if defined? MiniTest # HACK
5
+
4
6
  module Test::Unit::Assertions
5
7
 
6
8
  ##
@@ -67,7 +69,7 @@ module Test::Unit::Assertions
67
69
  ##
68
70
  # Alias for assert_not_equal
69
71
 
70
- alias deny_equal assert_not_equal
72
+ alias deny_equal assert_not_equal # rescue nil
71
73
 
72
74
  ##
73
75
  # Asserts that +obj+ responds to #include? and that obj does not include
@@ -128,7 +128,7 @@ class UnitDiff
128
128
  bw = result.shift.sub(/^to equal (.*):?$/, '\1')
129
129
  butwas << bw
130
130
  else
131
- state = :butwas if result.first.sub!(/ expected but was/, '')
131
+ state = :butwas if result.first.sub!(/ expected( but was|, not)/, '')
132
132
  expect << result.shift
133
133
  end
134
134
  when :butwas then
@@ -207,7 +207,7 @@ class UnitDiff
207
207
  if result.empty? then
208
208
  output.push "[no difference--suspect ==]"
209
209
  else
210
- output.push result.map { |line| line.chomp }
210
+ output.push result.split(/\n/)
211
211
  end
212
212
 
213
213
  if $k then
@@ -56,7 +56,7 @@ end
56
56
 
57
57
  class ZenTest
58
58
 
59
- VERSION = '3.9.1'
59
+ VERSION = '3.9.2'
60
60
 
61
61
  include ZenTestMapping
62
62
 
@@ -224,11 +224,16 @@ class TestAutotest < Test::Unit::TestCase
224
224
  end
225
225
 
226
226
  def test_reorder_random
227
- srand 42
228
227
  @a.order = :random
229
- expected = ["test/test_blah.rb", "lib/blah.rb"].map { |f| [f, @files[f]] }
230
228
 
231
- assert_equal expected, @a.reorder(@files)
229
+ srand 42
230
+ expected, size = @files.dup, @files.size
231
+ expected = expected.sort_by { rand(size) }
232
+
233
+ srand 42
234
+ result = @a.reorder(@files.dup)
235
+
236
+ assert_equal expected, result
232
237
  end
233
238
 
234
239
  def test_reorder_natural
@@ -404,8 +409,8 @@ test_error2(#{@test_class}):
404
409
  end
405
410
 
406
411
  def util_find_files_to_test(f, expected)
407
- t = @a.last_mtime + 1
408
- files = { f => t }
412
+ t = @a.last_mtime
413
+ files = { f => t + 1 }
409
414
 
410
415
  assert @a.find_files_to_test(files)
411
416
  assert_equal expected, @a.files_to_test
@@ -73,25 +73,16 @@ class TestRailsAutotest < TestAutotest
73
73
  end
74
74
 
75
75
  def test_reorder_random
76
- srand 42
77
76
  @a.order = :random
78
- expected = ["test/views/admin/themes_view_test.rb",
79
- "test/functional/articles_controller_test.rb",
80
- "app/models/route.rb",
81
- "test/views/articles_view_test.rb",
82
- "test/views/route_view_test.rb",
83
- "test/controllers/articles_controller_test.rb",
84
- "test/functional/admin/themes_controller_test.rb",
85
- "test/functional/route_controller_test.rb",
86
- "test/unit/route_test.rb",
87
- "test/functional/dummy_controller_test.rb",
88
- "test/controllers/admin/themes_controller_test.rb",
89
- "test/views/layouts_view_test.rb",
90
- "test/controllers/dummy_controller_test.rb",
91
- "test/controllers/route_controller_test.rb"]
92
- expected.map! { |f| [f, @files[f]] }
93
-
94
- assert_equal expected, @a.reorder(@files)
77
+
78
+ srand 42
79
+ expected, size = @files.dup, @files.size
80
+ expected = expected.sort_by { rand(size) }
81
+
82
+ srand 42
83
+ result = @a.reorder(@files.dup)
84
+
85
+ assert_equal expected, result
95
86
  end
96
87
 
97
88
  def test_test_files_for
@@ -1,12 +1,14 @@
1
1
  require 'test/unit'
2
2
  require 'test/zentest_assertions'
3
3
 
4
- $TESTING_RTC = true
4
+ unless defined? $TESTING_RTC then
5
+ $TESTING_RTC = true
5
6
 
6
- begin
7
- require 'test/rails'
8
- rescue LoadError, NameError
9
- $TESTING_RTC = false
7
+ begin
8
+ require 'test/rails'
9
+ rescue LoadError, NameError
10
+ $TESTING_RTC = false
11
+ end
10
12
  end
11
13
 
12
14
  class TRController < ApplicationController
@@ -1,12 +1,14 @@
1
1
  require 'test/unit'
2
2
  require 'test/zentest_assertions'
3
3
 
4
- $TESTING_RTC = true
4
+ unless defined? $TESTING_RTC then
5
+ $TESTING_RTC = true
5
6
 
6
- begin
7
- require 'test/rails'
8
- rescue LoadError, NameError
9
- $TESTING_RTC = false
7
+ begin
8
+ require 'test/rails'
9
+ rescue LoadError, NameError
10
+ $TESTING_RTC = false
11
+ end
10
12
  end
11
13
 
12
14
  begin
@@ -1,7 +1,15 @@
1
1
  require 'test/unit'
2
2
  require 'test/zentest_assertions'
3
3
 
4
- $TESTING_RTC = true
4
+ unless defined? $TESTING_RTC then
5
+ $TESTING_RTC = true
6
+
7
+ begin
8
+ require 'test/rails'
9
+ rescue LoadError, NameError
10
+ $TESTING_RTC = false
11
+ end
12
+ end
5
13
 
6
14
  module Rails
7
15
  module VERSION
@@ -9,12 +17,6 @@ module Rails
9
17
  end
10
18
  end
11
19
 
12
- begin
13
- require 'test/rails'
14
- rescue LoadError, NameError
15
- $TESTING_RTC = false
16
- end
17
-
18
20
  class TestRailsViewTestCase < Test::Rails::ViewTestCase
19
21
 
20
22
  def setup
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.9.1
4
+ version: 3.9.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ryan Davis
@@ -10,7 +10,7 @@ autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
12
 
13
- date: 2008-01-31 00:00:00 -08:00
13
+ date: 2008-03-20 00:00:00 -07:00
14
14
  default_executable:
15
15
  dependencies:
16
16
  - !ruby/object:Gem::Dependency
@@ -20,7 +20,7 @@ dependencies:
20
20
  requirements:
21
21
  - - ">="
22
22
  - !ruby/object:Gem::Version
23
- version: 1.5.0
23
+ version: 1.5.1
24
24
  version:
25
25
  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! Test::Rails helps you build industrial-strength Rails code."
26
26
  email:
@@ -63,16 +63,19 @@ files:
63
63
  - lib/autotest/cctray.rb
64
64
  - lib/autotest/discover.rb
65
65
  - lib/autotest/emacs.rb
66
+ - lib/autotest/email_notify.rb
66
67
  - lib/autotest/fixtures.rb
67
68
  - lib/autotest/growl.rb
68
69
  - lib/autotest/heckle.rb
69
70
  - lib/autotest/html_report.rb
71
+ - lib/autotest/jabber_notify.rb
70
72
  - lib/autotest/kdenotify.rb
71
73
  - lib/autotest/menu.rb
72
74
  - lib/autotest/migrate.rb
73
75
  - lib/autotest/notify.rb
74
76
  - lib/autotest/pretty.rb
75
77
  - lib/autotest/rails.rb
78
+ - lib/autotest/rcov.rb
76
79
  - lib/autotest/redgreen.rb
77
80
  - lib/autotest/screen.rb
78
81
  - lib/autotest/shame.rb