Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Added email_notify, jabber_notify, and rcov autotest plugins.

   Updated rakefile to include examples automatically in example_dot_autotest.

[git-p4: depot-paths = "//src/ZenTest/dev/": change = 3827]
  • Loading branch information...
commit 1509930f5788fe3c2e385c84f3dfe0a1d4e74f89 1 parent 5a59414
@zenspider zenspider authored
View
3  Manifest.txt
@@ -20,16 +20,19 @@ lib/autotest/camping.rb
lib/autotest/cctray.rb
lib/autotest/discover.rb
lib/autotest/emacs.rb
+lib/autotest/email_notify.rb
lib/autotest/fixtures.rb
lib/autotest/growl.rb
lib/autotest/heckle.rb
lib/autotest/html_report.rb
+lib/autotest/jabber_notify.rb
lib/autotest/kdenotify.rb
lib/autotest/menu.rb
lib/autotest/migrate.rb
lib/autotest/notify.rb
lib/autotest/pretty.rb
lib/autotest/rails.rb
+lib/autotest/rcov.rb
lib/autotest/redgreen.rb
lib/autotest/screen.rb
lib/autotest/shame.rb
View
20 Rakefile
@@ -16,23 +16,31 @@ task :autotest do
end
task :update do
+ system "p4 edit example_dot_autotest.rb"
File.open "example_dot_autotest.rb", "w" do |f|
f.puts "# -*- ruby -*-"
f.puts
Dir.chdir "lib" do
Dir["autotest/*.rb"].sort.each do |s|
+ next if s =~ /rails|discover/
f.puts "# require '#{s[0..-4]}'"
end
end
f.puts
- f.puts "# Autotest::AutoUpdate.sleep_time = 60"
- f.puts "# Autotest::AutoUpdate.update_cmd = 'svn up'"
- f.puts "# Autotest::Emacs.client_cmd = 'emacsclient -e'"
- f.puts "# Autotest::Heckle.flags << '-t test/**/*.rb'"
- f.puts "# Autotest::Heckle.klasses << 'MyClass'"
- f.puts "# Autotest::Shame.chat_app = :adium"
+
+ Dir["lib/autotest/*.rb"].sort.each do |file|
+ file = File.read(file)
+ m = file[/module.*/].split(/ /).last rescue nil
+ next unless m
+
+ file.grep(/def[^(]+=/).each do |setter|
+ setter = setter.sub(/^ *def self\./, '').sub(/\s*=\s*/, ' = ')
+ f.puts "# #{m}.#{setter}"
+ end
+ end
end
+ system "p4 diff -du example_dot_autotest.rb"
end
task :sort do
View
27 example_dot_autotest.rb
@@ -4,24 +4,39 @@
# require 'autotest/camping'
# require 'autotest/cctray'
# require 'autotest/emacs'
+# require 'autotest/email_notify'
# require 'autotest/fixtures'
# require 'autotest/growl'
# require 'autotest/heckle'
# require 'autotest/html_report'
+# require 'autotest/jabber_notify'
# require 'autotest/kdenotify'
# require 'autotest/menu'
# require 'autotest/migrate'
# require 'autotest/notify'
# require 'autotest/pretty'
+# require 'autotest/rcov'
# require 'autotest/redgreen'
# require 'autotest/screen'
# require 'autotest/shame'
# require 'autotest/snarl'
# require 'autotest/timestamp'
-# Autotest::AutoUpdate.sleep_time = 60
-# Autotest::AutoUpdate.update_cmd = 'svn up'
-# Autotest::Emacs.client_cmd = 'emacsclient -e'
-# Autotest::Heckle.flags << '-t test/**/*.rb'
-# Autotest::Heckle.klasses << 'MyClass'
-# Autotest::Shame.chat_app = :adium
+# Autotest::AutoUpdate.sleep_time = o
+# Autotest::AutoUpdate.update_cmd = o
+# Autotest::CCTray.project_name = name
+# Autotest::Emacs.command = o
+# Autotest::EmailNotify.smtp_settings = o
+# Autotest::EmailNotify.from = o
+# Autotest::EmailNotify.recipients = o
+# Autotest::EmailNotify.use_svn = o
+# Autotest::EmailNotify.report_every_run = o
+# Autotest::Growl.growl title, msg, pri = 0
+# Autotest::JabberNotify.recipients = o
+# Autotest::JabberNotify.account = o
+# Autotest::JabberNotify.password = o
+# Autotest::JabberNotify.use_svn = o
+# Autotest::JabberNotify.report_every_run = o
+# Autotest::RCov.pattern = o
+# Autotest::Shame.chat_app = o
+# Autotest::Snarl.snarl title, msg, ico = nil
View
66 lib/autotest/email_notify.rb
@@ -0,0 +1,66 @@
+require 'net/smtp'
+
+module Autotest::EmailNotify
+ @@smtp_settings = ['localhost']
+ @@from = nil
+ @@recipients = []
+ @@use_svn = true
+ @@report_every_run = false
+
+ @@last_rev = nil
+
+ def self.smtp_settings= o
+ @@smtp_settings = o
+ end
+
+ def self.from= o
+ @@from = o
+ end
+
+ def self.recipients= o
+ @@recipients = o
+ end
+
+ def self.use_svn= o
+ @@use_svn = o
+ end
+
+ def self.report_every_run= o
+ @@report_every_run = o
+ end
+
+ def self.notify title, msg
+ @@recipients.each do |to|
+ body = ["From: autotest <#{@@from}>"]
+ body << "To: <#{to}>"
+ body << "Subject: #{title}"
+ body << "\n"
+ body << msg
+ Net::SMTP.start(*@@smtp_settings) do |smtp|
+ smtp.send_message body.join("\n"), @@from, to
+ end
+ end
+ end
+
+ def self.svn_release
+ if @@use_svn
+ rev = `svn info`.match(/Revision: (\d+)/)[1]
+ return "r#{rev} "
+ end
+ end
+
+ Autotest.add_hook :ran_command do |at|
+ rev = self.svn_release
+ if @@report_every_run or rev != @@last_rev
+ @@last_rev = rev
+ output = at.results.join
+ failed = output.scan(/^\s+\d+\) (?:Failure|Error):\n(.*?)\((.*?)\)/)
+ if failed.size == 0 then
+ notify "#{rev}Tests Passed", output
+ else
+ f,e = failed.partition { |s| s =~ /Failure/ }
+ notify "#{rev}#{failed.size} Tests Failed", output
+ end
+ end
+ end
+end
View
111 lib/autotest/jabber_notify.rb
@@ -0,0 +1,111 @@
+begin; require 'rubygems'; rescue LoadError; end
+require 'xmpp4r-simple'
+
+module Autotest::JabberNotify
+ @@recipients = []
+ @@account = nil
+ @@password = nil
+ @@use_svn = true
+ @@report_every_run = true
+
+ @@im = nil
+ @@last_rev = nil
+ @@green = false
+
+ def self.recipients= o
+ @@recipients = o
+ end
+
+ def self.account= o
+ @@account = o
+ end
+
+ def self.password= o
+ @@password = o
+ end
+
+ def self.use_svn= o
+ @@use_svn = o
+ end
+
+ def self.report_every_run= o
+ @@report_every_run = o
+ end
+
+ def self.im
+ unless @@im
+ puts "# creating im client"
+ @@im = Jabber::Simple.new(@@account,@@password)
+ sleep(2) # need this or else the first announcement may cause an error
+ end
+ if !@@im.connected?
+ puts "# reconnecting to #{@@account}"
+ @@im.reconnect
+ end
+ @@im
+ end
+
+ def self.notify(msg)
+ @@recipients.each do |contact|
+ self.im.deliver(contact, msg)
+ end
+ end
+
+ def self.status(status)
+ rev = self.svn_release
+ status = "#{rev}#{status}"
+ self.im.status(:chat, status)
+ end
+
+ def self.svn_release
+ if @@use_svn
+ rev = `svn info`.match(/Revision: (\d+)/)[1]
+ return "r#{rev} "
+ end
+ end
+
+ # hooks
+
+ Autotest.add_hook :run do |at|
+ notify "autotest started"
+ end
+
+ Autotest.add_hook :run_command do |at|
+ status "testing"
+ end
+
+ Autotest.add_hook :ran_command do |at|
+ rev = self.svn_release
+ if @@report_every_run or rev != @@last_rev
+ @@last_rev = rev
+ output = at.results.join
+ failed = output.scan(/^\s+\d+\) ((?:Failure|Error):\n.*?\.*?\))/).flatten
+ failed.map! {|f| f.gsub!(/\n/,' '); f.gsub(/^/,'- ') }
+ time = output.scan(/Finished in (.*?)\n/)
+ if failed.size > 0 then
+ notify "Tests Passed\n#{time}\n" if !@@green
+ @@green = true # prevent repeat success notifications
+ else
+ @@green = false
+ notify "#{failed.size} Tests Failed\n" + failed.join("\n")
+ end
+ end
+ end
+
+ Autotest.add_hook :green do |at|
+ status "Tests Pass"
+ end
+
+ Autotest.add_hook :red do |at|
+ status "Tests Failed"
+ end
+
+ Autotest.add_hook :quit do |at|
+ notify "autotest is exiting"
+ self.im.disconnect
+ end
+
+ Autotest.add_hook :all do |at|_hook
+ notify "Tests have fully passed" unless $TESTING
+ end
+end
View
12 lib/autotest/rcov.rb
@@ -0,0 +1,12 @@
+module Autotest::RCov
+ @@pattern = "test/*.rb"
+
+ def self.pattern= o
+ @@pattern = o
+ end
+
+ Autotest.add_hook :all_good do |at|
+ system "rake rcov_info PATTERN=test/test_ruby_lexer.rb"
+ end
+end
+
Please sign in to comment.
Something went wrong with that request. Please try again.