jbarnette-lather 1.2.1 → 1.3.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.
- data/README.markdown +26 -29
- data/Rakefile +12 -4
- data/lib/lather/version.rb +1 -1
- data/lib/rake/lathertask.rb +68 -9
- metadata +2 -3
- data/lib/rake/lathertesttask.rb +0 -118
data/README.markdown
CHANGED
@@ -37,33 +37,34 @@ If you want to mess with the polling interval:
|
|
37
37
|
|
38
38
|
require "rake/lathertask"
|
39
39
|
|
40
|
-
Rake::LatherTask.new "lib/**/*.rb" do |
|
41
|
-
|
42
|
-
|
40
|
+
Rake::LatherTask.new "lib/**/*.rb" do |l|
|
41
|
+
l.target = :something
|
42
|
+
l.globs << "ext/**/*.{c,h}"
|
43
43
|
end
|
44
44
|
|
45
45
|
This creates a `lather` task, which will call the `target` task any
|
46
|
-
time the `globs` change. The block is optional
|
46
|
+
time the `globs` change. The block is optional: `target` defaults to
|
47
|
+
`:test`.
|
47
48
|
|
48
|
-
|
49
|
-
|
49
|
+
If `target` is set to an **instance** of `Rake::TestTask`, some
|
50
|
+
special behavior is enabled: Lather will add the test task's file list
|
51
|
+
to `globs`, and will set the `TEST` environment variable to the list
|
52
|
+
of tests that need to be run.
|
50
53
|
|
51
|
-
require "rake/
|
52
|
-
|
53
|
-
Rake::LatherTestTask.new do |test|
|
54
|
-
|
55
|
-
# These are the defaults, you don't need to specify 'em.
|
54
|
+
require "rake/testtask"
|
55
|
+
require "rake/lathertask"
|
56
56
|
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
test.options = { :force => true }
|
61
|
-
test.tests = %w(test/**/*_test.rb)
|
62
|
-
test.verbose = false
|
57
|
+
test = Rake::TestTask.new do |t|
|
58
|
+
t.libs << "test"
|
59
|
+
t.test_files = "test/**/*_test.rb"
|
63
60
|
end
|
64
61
|
|
65
|
-
|
66
|
-
|
62
|
+
Rake::LatherTask.new "lib/**/*.rb", :target => test
|
63
|
+
|
64
|
+
The heuristic is really simple: If `lib/foo.rb` changes, any test
|
65
|
+
whose path contains `foo` will be run. There's no tracking of failures
|
66
|
+
or single test runs. If you want more than this, you should be using
|
67
|
+
Autotest.
|
67
68
|
|
68
69
|
## Installing
|
69
70
|
|
@@ -71,28 +72,24 @@ optional. See Lather's `Rakefile` for a working example.
|
|
71
72
|
|
72
73
|
## Hacking
|
73
74
|
|
74
|
-
|
75
|
-
something changes. If you're looking for something to work on, chew on
|
76
|
-
these:
|
75
|
+
If you're looking for something to work on, chew on these:
|
77
76
|
|
78
|
-
* A way to get at the list of changed files in a `-r` command
|
79
|
-
the Rake tasks.
|
77
|
+
* A way to get at the list of changed files in a `-r` command.
|
80
78
|
|
81
79
|
* Some default exclude (like backup/editor files, `.svn`, `.git`)
|
82
80
|
patterns, and an easy way to add new ones.
|
83
81
|
|
84
|
-
* A `--sleep <secs>` switch for the command-line tool
|
85
|
-
task.
|
82
|
+
* A `--sleep <secs>` switch for the command-line tool.
|
86
83
|
|
87
84
|
## Thanks
|
88
85
|
|
89
86
|
Lather owes a huge debt to Ryan Davis' ZenTest library, specifically
|
90
|
-
`autotest`. Use it.
|
91
|
-
|
87
|
+
`autotest`. Use it. See also Mike Clark and Geoffrey Grosenbach's
|
88
|
+
`rstakeout`.
|
92
89
|
|
93
90
|
## License
|
94
91
|
|
95
|
-
Copyright 2009 John Barnette
|
92
|
+
Copyright 2009 John Barnette, Seattle.rb.
|
96
93
|
|
97
94
|
Permission is hereby granted, free of charge, to any person obtaining
|
98
95
|
a copy of this software and associated documentation files (the
|
data/Rakefile
CHANGED
@@ -2,7 +2,12 @@ require "rubygems/specification"
|
|
2
2
|
require "rake/testtask"
|
3
3
|
|
4
4
|
require "./lib/lather"
|
5
|
-
require "./lib/rake/
|
5
|
+
require "./lib/rake/lathertask"
|
6
|
+
|
7
|
+
desc "Straighten up"
|
8
|
+
task :clean do
|
9
|
+
rm_rf "*.gem"
|
10
|
+
end
|
6
11
|
|
7
12
|
namespace :gem do
|
8
13
|
LATHER = Gem::Specification.new do |s|
|
@@ -33,13 +38,16 @@ namespace :gem do
|
|
33
38
|
end
|
34
39
|
|
35
40
|
desc "Build and install the gem"
|
36
|
-
task :install => gemfile do
|
41
|
+
task :install => [gemfile, :clean] do
|
37
42
|
sh "sudo gem install #{LATHER.name}-#{LATHER.version}.gem"
|
38
43
|
end
|
39
44
|
end
|
40
45
|
|
41
|
-
Rake::
|
42
|
-
|
46
|
+
test = Rake::TestTask.new do |t|
|
47
|
+
t.libs << "test"
|
48
|
+
t.ruby_opts << "-rhelper"
|
49
|
+
t.test_files = "test/**/*_test.rb"
|
43
50
|
end
|
44
51
|
|
45
52
|
task :default => :test
|
53
|
+
Rake::LatherTask.new "lib/**/*.rb", :target => test
|
data/lib/lather/version.rb
CHANGED
data/lib/rake/lathertask.rb
CHANGED
@@ -13,32 +13,91 @@ module Rake
|
|
13
13
|
|
14
14
|
attr_accessor :globs
|
15
15
|
|
16
|
-
#
|
16
|
+
# A hash of options, most of which are passed on to
|
17
|
+
# <tt>Lather::Watcher</tt>.
|
18
|
+
|
19
|
+
attr_accessor :options
|
20
|
+
|
21
|
+
# The task to run when things change. Default is
|
22
|
+
# <tt>:test</tt>. If this is an instance of
|
23
|
+
# <tt>Rake::TestTask</tt>, the task's <tt>pattern</tt> will be
|
24
|
+
# added to <tt>globs</tt>, and the <tt>TEST</tt> environment
|
25
|
+
# variable will be set to a glob of changed tests before each
|
26
|
+
# invocation.
|
17
27
|
|
18
28
|
attr_accessor :target
|
19
29
|
|
20
30
|
def initialize *globs, &block
|
21
|
-
@
|
22
|
-
@globs
|
31
|
+
@options = Hash === globs.last ? globs.pop : {}
|
32
|
+
@globs = globs
|
33
|
+
@target = @options.delete(:target) || :test
|
34
|
+
|
35
|
+
@changed = case @target
|
36
|
+
when Rake::TestTask then handle_rake_test_task
|
37
|
+
else lambda {}
|
38
|
+
end
|
23
39
|
|
24
40
|
yield self if block_given?
|
25
41
|
|
26
|
-
|
27
|
-
Rake::Task.define_task :lather do
|
28
|
-
watcher = Lather::Watcher.new @globs do
|
29
|
-
target = Rake::Task[@target]
|
42
|
+
@target = Rake::Task[@target]
|
30
43
|
|
44
|
+
desc "Rinse and repeat"
|
45
|
+
task :lather do
|
46
|
+
watcher = Lather::Watcher.new @globs, @options do |changed|
|
31
47
|
begin
|
32
|
-
|
48
|
+
@changed[changed]
|
49
|
+
@target.invoke
|
33
50
|
rescue StandardError => e
|
34
51
|
raise e unless e.to_s =~ /^Command failed/
|
35
52
|
ensure
|
36
|
-
target
|
53
|
+
reenable @target
|
37
54
|
end
|
38
55
|
end
|
39
56
|
|
40
57
|
watcher.go!
|
41
58
|
end
|
42
59
|
end
|
60
|
+
|
61
|
+
# Get and set the block called each time a file matching one of
|
62
|
+
# the <tt>globs</tt> changes. Default is <tt>lambda {}</tt>.
|
63
|
+
|
64
|
+
def changed &block
|
65
|
+
return @changed unless block_given?
|
66
|
+
@changed = block
|
67
|
+
end
|
68
|
+
|
69
|
+
private
|
70
|
+
|
71
|
+
def reenable target
|
72
|
+
target.reenable
|
73
|
+
target.prerequisites.each { |p| reenable Rake::Task[p] }
|
74
|
+
end
|
75
|
+
|
76
|
+
# Special setup when <tt>target</tt> is a <tt>Rake::TestTask</tt>.
|
77
|
+
|
78
|
+
def handle_rake_test_task
|
79
|
+
test_task = @target
|
80
|
+
all_tests = test_task.file_list
|
81
|
+
|
82
|
+
@target = test_task.name
|
83
|
+
@globs << test_task.file_list
|
84
|
+
@options[:force] = true
|
85
|
+
|
86
|
+
@changed = lambda do |changed|
|
87
|
+
tests = all_tests & changed
|
88
|
+
|
89
|
+
basenames = (changed - tests).collect do |f|
|
90
|
+
File.basename(f).split(".").first
|
91
|
+
end
|
92
|
+
|
93
|
+
tests.concat all_tests.
|
94
|
+
select { |t| basenames.any? { |b| t =~ /#{b}/ } }
|
95
|
+
|
96
|
+
tests = all_tests.dup if tests.empty?
|
97
|
+
|
98
|
+
# Nice API, Rake::TestTask.
|
99
|
+
ENV["TEST"] = "{#{tests.uniq.join(',')}}"
|
100
|
+
end
|
101
|
+
end
|
43
102
|
end
|
44
103
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: jbarnette-lather
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.3.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- John Barnette
|
@@ -9,7 +9,7 @@ autorequire:
|
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
11
|
|
12
|
-
date: 2009-02-
|
12
|
+
date: 2009-02-08 00:00:00 -08:00
|
13
13
|
default_executable: lather
|
14
14
|
dependencies: []
|
15
15
|
|
@@ -32,7 +32,6 @@ files:
|
|
32
32
|
- lib/lather.rb
|
33
33
|
- lib/rake
|
34
34
|
- lib/rake/lathertask.rb
|
35
|
-
- lib/rake/lathertesttask.rb
|
36
35
|
- test/helper.rb
|
37
36
|
- test/lather
|
38
37
|
- test/lather/cli_test.rb
|
data/lib/rake/lathertesttask.rb
DELETED
@@ -1,118 +0,0 @@
|
|
1
|
-
require "rake"
|
2
|
-
require "rake/tasklib"
|
3
|
-
require "lather/watcher"
|
4
|
-
|
5
|
-
module Rake
|
6
|
-
|
7
|
-
# A simplified version of <tt>Rake::TestTask</tt> with support for
|
8
|
-
# Lather. It creates <tt>test</tt> and <tt>test:lather</tt>
|
9
|
-
# tasks. It's more opinionated and less configurable than
|
10
|
-
# <tt>Rake::TestTask</tt>: Test file load order is random.
|
11
|
-
#
|
12
|
-
# When lathering, a very stupid heuristic is used to decide which
|
13
|
-
# test files to run: Any test file whose path contains the basename
|
14
|
-
# (without extension) of the file that changed. If no test files
|
15
|
-
# match, everything gets run. No tracking of failures, no specific
|
16
|
-
# tests. If you want more than this, you should be using Autotest.
|
17
|
-
|
18
|
-
class LatherTestTask < TaskLib
|
19
|
-
|
20
|
-
# An optional array of stuff to tack on to the end of the Ruby
|
21
|
-
# command-line. Default is <tt>[]</tt>.
|
22
|
-
|
23
|
-
attr_accessor :extras
|
24
|
-
|
25
|
-
# An array of glob patterns to match implementation files. Default
|
26
|
-
# is <tt>%w(lib/**/*.rb)</tt>.
|
27
|
-
|
28
|
-
attr_accessor :files
|
29
|
-
|
30
|
-
# An array of command-line flags to pass on to Ruby. Default is
|
31
|
-
# <tt>%w(-w)</tt>.
|
32
|
-
|
33
|
-
attr_accessor :flags
|
34
|
-
|
35
|
-
# An array of directories to add to the load path. Default is
|
36
|
-
# <tt>%w(lib test)</tt>.
|
37
|
-
|
38
|
-
attr_accessor :libs
|
39
|
-
|
40
|
-
# A hash of options to pass on to <tt>Lather::Watcher.new</tt>.
|
41
|
-
# Default is <tt>{ :force => true }</tt>.
|
42
|
-
|
43
|
-
attr_accessor :options
|
44
|
-
|
45
|
-
# An array of glob patterns to match test files. Default is
|
46
|
-
# <tt>%w(test/**/*_test.rb)</tt>.
|
47
|
-
|
48
|
-
attr_accessor :tests
|
49
|
-
|
50
|
-
# Be chatty? Default is <tt>false</tt>.
|
51
|
-
|
52
|
-
attr_accessor :verbose
|
53
|
-
|
54
|
-
def initialize
|
55
|
-
@extras = []
|
56
|
-
@files = %w(lib/**/*.rb)
|
57
|
-
@flags = %w(-w)
|
58
|
-
@libs = %w(lib test)
|
59
|
-
@options = { :force => true }
|
60
|
-
@tests = %w(test/**/*_test.rb)
|
61
|
-
@verbose = false
|
62
|
-
|
63
|
-
yield self if block_given?
|
64
|
-
|
65
|
-
desc "Run the tests"
|
66
|
-
task :test, [:tests] do |task, args|
|
67
|
-
|
68
|
-
tests = if args.tests.nil? || args.tests.empty?
|
69
|
-
FileList[@tests]
|
70
|
-
else
|
71
|
-
args.tests
|
72
|
-
end
|
73
|
-
|
74
|
-
cmd = @flags.dup
|
75
|
-
cmd << "-I#{@libs.join(':')}"
|
76
|
-
cmd << "-e 'ARGV.each { |f| load f }'"
|
77
|
-
|
78
|
-
cmd.concat tests.collect { |f| "'#{f}'" }.sort_by { rand }
|
79
|
-
cmd.concat @extras
|
80
|
-
|
81
|
-
RakeFileUtils.verbose(@verbose) { ruby cmd.join(" ") }
|
82
|
-
end
|
83
|
-
|
84
|
-
namespace :test do
|
85
|
-
desc "Test, rinse, repeat"
|
86
|
-
task :lather do
|
87
|
-
watcher = Lather::Watcher.new @files, @tests, @options do |changed|
|
88
|
-
all_tests = FileList[@tests]
|
89
|
-
tests = all_tests & changed
|
90
|
-
|
91
|
-
basenames = (changed - tests).collect do |f|
|
92
|
-
File.basename(f).split(".").first
|
93
|
-
end
|
94
|
-
|
95
|
-
tests.concat all_tests.
|
96
|
-
select { |t| basenames.any? { |b| t =~ /#{b}/ } }
|
97
|
-
|
98
|
-
task = Rake::Task[:test]
|
99
|
-
|
100
|
-
begin
|
101
|
-
task.invoke tests.uniq
|
102
|
-
rescue StandardError => e
|
103
|
-
raise e unless e.to_s =~ /^Command failed/
|
104
|
-
ensure
|
105
|
-
|
106
|
-
# FIXME: walk the whole tree
|
107
|
-
|
108
|
-
task.reenable
|
109
|
-
task.prerequisites.each { |p| Rake::Task[p].reenable }
|
110
|
-
end
|
111
|
-
end
|
112
|
-
|
113
|
-
watcher.go!
|
114
|
-
end
|
115
|
-
end
|
116
|
-
end
|
117
|
-
end
|
118
|
-
end
|