Skip to content

Commit

Permalink
Added autotest/restart.rb - restarts autotest if .autotest updated.
Browse files Browse the repository at this point in the history
   Hooks now take *args as well as instance of autotest.
   Added :updated hook, gets list of updated files before running tests.

[git-p4: depot-paths = "//src/ZenTest/dev/": change = 4126]
  • Loading branch information
zenspider committed Aug 5, 2008
1 parent b93eb17 commit c28dc57
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 5 deletions.
1 change: 1 addition & 0 deletions Manifest.txt
Expand Up @@ -36,6 +36,7 @@ lib/autotest/pretty.rb
lib/autotest/rails.rb
lib/autotest/rcov.rb
lib/autotest/redgreen.rb
lib/autotest/restart.rb
lib/autotest/screen.rb
lib/autotest/shame.rb
lib/autotest/snarl.rb
Expand Down
5 changes: 4 additions & 1 deletion example_dot_autotest.rb
Expand Up @@ -14,9 +14,11 @@
# require 'autotest/menu'
# require 'autotest/migrate'
# require 'autotest/notify'
# require 'autotest/once'
# require 'autotest/pretty'
# require 'autotest/rcov'
# require 'autotest/redgreen'
# require 'autotest/restart'
# require 'autotest/screen'
# require 'autotest/shame'
# require 'autotest/snarl'
Expand All @@ -31,12 +33,13 @@
# Autotest::EmailNotify.recipients = o
# Autotest::EmailNotify.use_svn = o
# Autotest::EmailNotify.report_every_run = o
# Autotest::Growl.growl title, msg, pri = 0
# Autotest::Growl.growl title, msg, pri = 0, img = nil
# 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.command = o
# Autotest::RCov.pattern = o
# Autotest::Shame.chat_app = o
# Autotest::Snarl.snarl title, msg, ico = nil
13 changes: 9 additions & 4 deletions lib/autotest.rb
Expand Up @@ -29,10 +29,13 @@
# Autotest.add_hook hook_name { |autotest| ... }
#
# The available hooks are: initialize, run, run_command, ran_command,
# red, green, all_good, reset, interrupt, and quit.
# red, green, updated, all_good, reset, interrupt, and quit.
#
# See example_dot_autotest.rb for more details.
#
# If a hook returns a true value, it signals to autotest that the hook
# was handled and should not continue executing hooks.
#
# Naming:
#
# Autotest uses a simple naming scheme to figure out how to map
Expand Down Expand Up @@ -377,7 +380,9 @@ def find_files
def find_files_to_test(files=find_files)
updated = files.select { |filename, mtime| self.last_mtime < mtime }

p updated if $v unless updated.empty? or self.last_mtime.to_i == 0
p updated if $v unless updated.empty? || self.last_mtime.to_i == 0

hook :updated, updated unless updated.empty? || self.last_mtime.to_i == 0

updated.map { |f,m| test_files_for(f) }.flatten.uniq.each do |filename|
self.files_to_test[filename] # creates key with default value
Expand Down Expand Up @@ -625,7 +630,7 @@ def exceptions
# until one returns true. Returns false if no hook handled the
# event.

def hook(name)
def hook(name, *args)
deprecated = {
# none currently
}
Expand All @@ -635,7 +640,7 @@ def hook(name)
end

HOOKS[name].any? do |plugin|
plugin[self]
plugin[self, *args]
end
end

Expand Down
11 changes: 11 additions & 0 deletions lib/autotest/restart.rb
@@ -0,0 +1,11 @@
module Autotest::Restart
Autotest.add_hook :updated do |at, *args|
if args.flatten.include? ".autotest" then
warn "Detected change to .autotest, restarting"
cmd = "autotest"
cmd << " -v" if $v

exec cmd
end
end
end

0 comments on commit c28dc57

Please sign in to comment.