rake 0.7.1 → 0.7.2

Sign up to get free protection for your applications and to get access to all the features.

Potentially problematic release.


This version of rake might be problematic. Click here for more details.

@@ -28,4 +28,8 @@ class TestEarlyTime < Test::Unit::TestCase
28
28
  assert t1 == t1
29
29
  assert t2 == t2
30
30
  end
31
+
32
+ def test_to_s
33
+ assert_equal "<EARLY TIME>", Rake::EARLY.to_s
34
+ end
31
35
  end
@@ -53,4 +53,10 @@ class TestFileCreationTask < Test::Unit::TestCase
53
53
  assert ! t2.needed?, "Should not need to build new file"
54
54
  assert ! t1.needed?, "Should not need to rebuild old file because of new"
55
55
  end
56
+
57
+ def test_very_early_timestamp
58
+ t1 = Rake.application.intern(FileCreationTask, OLDFILE)
59
+ assert t1.timestamp < Time.now
60
+ assert t1.timestamp < Time.now - 1000000
61
+ end
56
62
  end
@@ -130,11 +130,10 @@ class TestDirectoryTask < Test::Unit::TestCase
130
130
  assert_equal "WIN32 DESC", Task['c:/testdata/a/b/c'].comment
131
131
  assert_nil Task['c:/testdata/a/b'].comment
132
132
  verbose(false) {
133
- Task['c:/testdata/a/b'].invoke
133
+ Task['c:/testdata/a/b'].invoke
134
134
  }
135
135
  assert File.exist?('c:/testdata/a/b')
136
136
  assert ! File.exist?('c:/testdata/a/b/c')
137
137
  end
138
138
  end
139
139
  end
140
-
@@ -2,9 +2,11 @@
2
2
 
3
3
  require 'test/unit'
4
4
  require 'rake'
5
+ require 'test/capture_stdout'
5
6
 
6
7
  class TestFileList < Test::Unit::TestCase
7
8
  FileList = Rake::FileList
9
+ include CaptureStdout
8
10
 
9
11
  def setup
10
12
  create_test_data
@@ -104,6 +106,22 @@ class TestFileList < Test::Unit::TestCase
104
106
  ].sort, fl.sort
105
107
  end
106
108
 
109
+ def test_square_bracket_pattern
110
+ fl = FileList.new
111
+ fl.include("testdata/abc.[ch]")
112
+ assert fl.size == 2
113
+ assert fl.include?("testdata/abc.c")
114
+ assert fl.include?("testdata/abc.h")
115
+ end
116
+
117
+ def test_curly_bracket_pattern
118
+ fl = FileList.new
119
+ fl.include("testdata/abc.{c,h}")
120
+ assert fl.size == 2
121
+ assert fl.include?("testdata/abc.c")
122
+ assert fl.include?("testdata/abc.h")
123
+ end
124
+
107
125
  def test_reject
108
126
  fl = FileList.new
109
127
  fl.include %w(testdata/x.c testdata/abc.c testdata/xyz.c testdata/existing)
@@ -118,18 +136,30 @@ class TestFileList < Test::Unit::TestCase
118
136
  fl.each { |fn| touch fn, :verbose => false }
119
137
  x = fl.exclude(%r{/x.+\.})
120
138
  assert_equal FileList, x.class
121
- assert_equal [
122
- 'testdata/x.c', 'testdata/abc.c', 'testdata/existing'
123
- ], fl
139
+ assert_equal %w(testdata/x.c testdata/abc.c testdata/existing), fl
124
140
  assert_equal fl.object_id, x.object_id
125
141
  fl.exclude('testdata/*.c')
126
142
  assert_equal ['testdata/existing'], fl
127
143
  fl.exclude('testdata/existing')
128
144
  assert_equal [], fl
129
145
  end
146
+
147
+ def test_excluding_via_block
148
+ fl = FileList['testdata/a.c', 'testdata/b.c', 'testdata/xyz.c']
149
+ fl.exclude { |fn| fn.pathmap('%n') == 'xyz' }
150
+ assert fl.exclude?("xyz.c"), "Should exclude xyz.c"
151
+ assert_equal ['testdata/a.c', 'testdata/b.c'], fl
152
+ end
130
153
 
131
154
  def test_exclude_return_on_create
132
- fl = FileList['testdata/*'].exclude(/.*\.c$/)
155
+ fl = FileList['testdata/*'].exclude(/.*\.[hcx]$/)
156
+ assert_equal ['testdata/existing'], fl
157
+ assert_equal FileList, fl.class
158
+ end
159
+
160
+ def test_exclude_with_string_return_on_create
161
+ fl = FileList['testdata/*'].exclude('testdata/abc.c')
162
+ assert_equal %w(testdata/existing testdata/x.c testdata/abc.h testdata/abc.x testdata/xyz.c).sort, fl.sort
133
163
  assert_equal FileList, fl.class
134
164
  end
135
165
 
@@ -166,12 +196,12 @@ class TestFileList < Test::Unit::TestCase
166
196
 
167
197
  def test_to_s_pending
168
198
  fl = FileList['testdata/abc.*']
169
- assert_equal %{testdata/abc.c}, fl.to_s
199
+ assert_equal %{testdata/abc.c testdata/abc.h testdata/abc.x}.sort, fl.to_s.sort
170
200
  end
171
201
 
172
202
  def test_inspect_pending
173
203
  fl = FileList['testdata/abc.*']
174
- assert_equal %{["testdata/abc.c"]}, fl.inspect
204
+ assert_equal %{["testdata/abc.c", "testdata/abc.h", "testdata/abc.x"]}, fl.inspect
175
205
  end
176
206
 
177
207
  def test_sub
@@ -242,7 +272,22 @@ class TestFileList < Test::Unit::TestCase
242
272
  f2.sort
243
273
  end
244
274
 
245
- def test_egrep
275
+ def test_gsub!
276
+ create_test_data
277
+ f = FileList["testdata/*.c"]
278
+ f.gsub!(/a/, "A")
279
+ assert_equal ["testdAtA/Abc.c", "testdAtA/x.c", "testdAtA/xyz.c"].sort,
280
+ f.sort
281
+ end
282
+
283
+ def test_egrep_with_output
284
+ files = FileList['test/test*.rb']
285
+ the_line_number = __LINE__ + 1
286
+ out = capture_stdout do files.egrep(/PUGH/) end
287
+ assert_match(/:#{the_line_number}:/, out)
288
+ end
289
+
290
+ def test_egrep_with_block
246
291
  files = FileList['test/test*.rb']
247
292
  found = false
248
293
  the_line_number = __LINE__ + 1
@@ -342,7 +387,7 @@ class TestFileList < Test::Unit::TestCase
342
387
  b = ['a', 'b']
343
388
  assert a == b
344
389
  assert b == a
345
- # assert a.eql?(b)
390
+ # assert a.eql?(b)
346
391
  # assert b.eql?(a)
347
392
  assert ! a.equal?(b)
348
393
  assert ! b.equal?(a)
@@ -473,6 +518,8 @@ class TestFileList < Test::Unit::TestCase
473
518
  touch "testdata/x.c"
474
519
  touch "testdata/xyz.c"
475
520
  touch "testdata/abc.c"
521
+ touch "testdata/abc.h"
522
+ touch "testdata/abc.x"
476
523
  touch "testdata/existing"
477
524
  end
478
525
  end
@@ -4,6 +4,7 @@ require 'rake'
4
4
  require 'test/unit'
5
5
  require 'test/filecreation'
6
6
  require 'fileutils'
7
+ require 'stringio'
7
8
 
8
9
  class TestFileUtils < Test::Unit::TestCase
9
10
  include FileCreation
@@ -14,6 +15,7 @@ class TestFileUtils < Test::Unit::TestCase
14
15
 
15
16
  def teardown
16
17
  FileUtils.rm_rf("testdata")
18
+ FileUtils::LN_SUPPORTED[0] = true
17
19
  end
18
20
 
19
21
  def test_rm_one_file
@@ -45,12 +47,49 @@ class TestFileUtils < Test::Unit::TestCase
45
47
  assert_equal "TEST_LN\n", open("testdata/b") { |f| f.read }
46
48
  end
47
49
 
50
+ class BadLink
51
+ include RakeFileUtils
52
+ attr_reader :cp_args
53
+ def initialize(klass)
54
+ @failure_class = klass
55
+ end
56
+ def cp(*args)
57
+ @cp_args = args
58
+ end
59
+ def ln(*args)
60
+ fail @failure_class, "ln not supported"
61
+ end
62
+ public :safe_ln
63
+ end
64
+
65
+ def test_safe_ln_failover_to_cp_on_standard_error
66
+ FileUtils::LN_SUPPORTED[0] = true
67
+ c = BadLink.new(StandardError)
68
+ c.safe_ln "a", "b"
69
+ assert_equal ['a', 'b'], c.cp_args
70
+ c.safe_ln "x", "y"
71
+ assert_equal ['x', 'y'], c.cp_args
72
+ end
73
+
74
+ def test_safe_ln_failover_to_cp_on_not_implemented_error
75
+ FileUtils::LN_SUPPORTED[0] = true
76
+ c = BadLink.new(NotImplementedError)
77
+ c.safe_ln "a", "b"
78
+ assert_equal ['a', 'b'], c.cp_args
79
+ end
80
+
81
+ def test_safe_ln_fails_on_script_error
82
+ FileUtils::LN_SUPPORTED[0] = true
83
+ c = BadLink.new(ScriptError)
84
+ assert_raise(ScriptError) do c.safe_ln "a", "b" end
85
+ end
86
+
48
87
  def test_verbose
49
88
  verbose true
50
89
  assert_equal true, verbose
51
90
  verbose false
52
91
  assert_equal false, verbose
53
- verbose(true){
92
+ verbose(true) {
54
93
  assert_equal true, verbose
55
94
  }
56
95
  assert_equal false, verbose
@@ -67,6 +106,18 @@ class TestFileUtils < Test::Unit::TestCase
67
106
  assert_equal false, nowrite
68
107
  end
69
108
 
109
+ def test_file_utils_methods_are_available_at_top_level
110
+ create_file("testdata/a")
111
+ rm_rf "testdata/a"
112
+ assert ! File.exist?("testdata/a")
113
+ end
114
+
115
+ def test_fileutils_methods_dont_leak
116
+ obj = Object.new
117
+ assert_raise(NoMethodError) { obj.copy } # from FileUtils
118
+ assert_raise(NoMethodError) { obj.ruby } # from RubyFileUtils
119
+ end
120
+
70
121
  def test_sh
71
122
  verbose(false) { sh %{test/shellcommand.rb} }
72
123
  assert true, "should not fail"
@@ -93,19 +144,47 @@ class TestFileUtils < Test::Unit::TestCase
93
144
  count = 0
94
145
  verbose(false) {
95
146
  sh(%{test/shellcommand.rb}) do |ok, res|
96
- assert(ok)
97
- assert_equal 0, res.exitstatus
98
- count += 1
147
+ assert(ok)
148
+ assert_equal 0, res.exitstatus
149
+ count += 1
99
150
  end
100
151
  sh(%{test/shellcommand.rb 1}) do |ok, res|
101
- assert(!ok)
102
- assert_equal 1, res.exitstatus
103
- count += 1
152
+ assert(!ok)
153
+ assert_equal 1, res.exitstatus
154
+ count += 1
104
155
  end
105
156
  }
106
157
  assert_equal 2, count, "Block count should be 2"
107
158
  end
108
159
 
160
+ def test_sh_noop
161
+ verbose(false) { sh %{test/shellcommand.rb 1}, :noop=>true }
162
+ assert true, "should not fail"
163
+ end
164
+
165
+ def test_sh_bad_option
166
+ ex = assert_raise(ArgumentError) {
167
+ verbose(false) { sh %{test/shellcommand.rb}, :bad_option=>true }
168
+ }
169
+ assert_match(/bad_option/, ex.message)
170
+ end
171
+
172
+ def test_sh_verbose
173
+ out = redirect_stderr {
174
+ verbose(true) {
175
+ sh %{test/shellcommand.rb}, :noop=>true
176
+ }
177
+ }
178
+ assert_match(/^test\/shellcommand\.rb$/, out)
179
+ end
180
+
181
+ def test_sh_default_verbosity_is_false
182
+ out = redirect_stderr {
183
+ sh %{test/shellcommand.rb}, :noop=>true
184
+ }
185
+ assert_equal '', out
186
+ end
187
+
109
188
  def test_ruby
110
189
  verbose(false) do
111
190
  ENV['RAKE_TEST_RUBY'] = "123"
@@ -114,7 +193,7 @@ class TestFileUtils < Test::Unit::TestCase
114
193
  ruby %{-e "exit $RAKE_TEST_RUBY"} do |ok, status|
115
194
  assert(!ok)
116
195
  assert_equal 123, status.exitstatus
117
- block_run = true
196
+ block_run = true
118
197
  end
119
198
  assert block_run, "The block must be run"
120
199
 
@@ -123,10 +202,29 @@ class TestFileUtils < Test::Unit::TestCase
123
202
  ruby '-e', 'exit "$RAKE_TEST_RUBY".length' do |ok, status|
124
203
  assert(!ok)
125
204
  assert_equal 15, status.exitstatus
126
- block_run = true
205
+ block_run = true
127
206
  end
128
207
  assert block_run, "The block must be run"
129
208
  end
130
209
  end
131
210
 
211
+ def test_split_all
212
+ assert_equal ['a'], RakeFileUtils.split_all('a')
213
+ assert_equal ['..'], RakeFileUtils.split_all('..')
214
+ assert_equal ['/'], RakeFileUtils.split_all('/')
215
+ assert_equal ['a', 'b'], RakeFileUtils.split_all('a/b')
216
+ assert_equal ['/', 'a', 'b'], RakeFileUtils.split_all('/a/b')
217
+ assert_equal ['..', 'a', 'b'], RakeFileUtils.split_all('../a/b')
218
+ end
219
+
220
+ private
221
+
222
+ def redirect_stderr
223
+ old_err = $stderr
224
+ $stderr = StringIO.new
225
+ yield
226
+ $stderr.string
227
+ ensure
228
+ $stderr = old_err
229
+ end
132
230
  end
@@ -6,19 +6,27 @@ require 'flexmock'
6
6
  require 'rake'
7
7
 
8
8
  class TestNameSpace < Test::Unit::TestCase
9
+ include FlexMock::TestCase
10
+
9
11
  def test_namespace_creation
10
- FlexMock.use("TaskManager") do |mgr|
11
- ns = Rake::NameSpace.new(mgr, [])
12
- assert_not_nil ns
13
- end
12
+ mgr = flexmock("TaskManager")
13
+ ns = Rake::NameSpace.new(mgr, [])
14
+ assert_not_nil ns
14
15
  end
15
16
 
16
17
  def test_namespace_lookup
17
- FlexMock.use("TaskManager") do |mgr|
18
- mgr.should_receive(:lookup).with(:t, ["a"]).
19
- and_return(nil).once
20
- ns = Rake::NameSpace.new(mgr, ["a"])
21
- ns[:t]
22
- end
18
+ mgr = flexmock("TaskManager")
19
+ mgr.should_receive(:lookup).with(:t, ["a"]).
20
+ and_return(:dummy).once
21
+ ns = Rake::NameSpace.new(mgr, ["a"])
22
+ assert_equal :dummy, ns[:t]
23
+ end
24
+
25
+ def test_namespace_reports_tasks_it_owns
26
+ mgr = flexmock("TaskManager")
27
+ mgr.should_receive(:tasks).with().
28
+ and_return([:x, :y, :z]).once
29
+ ns = Rake::NameSpace.new(mgr, ["a"])
30
+ assert_equal [:x, :y, :z], ns.tasks
23
31
  end
24
32
  end
@@ -10,13 +10,13 @@ class TestPackageTask < Test::Unit::TestCase
10
10
  pkg = Rake::PackageTask.new("pkgr", "1.2.3") { |p|
11
11
  p.package_files << "install.rb"
12
12
  p.package_files.include(
13
- '[A-Z]*',
14
- 'bin/**/*',
15
- 'lib/**/*.rb',
16
- 'test/**/*.rb',
17
- 'doc/**/*',
18
- 'build/rubyapp.rb',
19
- '*.blurb')
13
+ '[A-Z]*',
14
+ 'bin/**/*',
15
+ 'lib/**/*.rb',
16
+ 'test/**/*.rb',
17
+ 'doc/**/*',
18
+ 'build/rubyapp.rb',
19
+ '*.blurb')
20
20
  p.package_files.exclude(/\bCVS\b/)
21
21
  p.package_files.exclude(/~$/)
22
22
  p.package_dir = 'pkg'
@@ -74,12 +74,12 @@ else
74
74
  class TestGemPackageTask < Test::Unit::TestCase
75
75
  def test_gem_package
76
76
  gem = Gem::Specification.new do |g|
77
- g.name = "pkgr"
78
- g.version = "1.2.3"
79
- g.files = FileList["x"].resolve
77
+ g.name = "pkgr"
78
+ g.version = "1.2.3"
79
+ g.files = FileList["x"].resolve
80
80
  end
81
81
  pkg = Rake::GemPackageTask.new(gem) do |p|
82
- p.package_files << "y"
82
+ p.package_files << "y"
83
83
  end
84
84
  assert_equal ["x", "y"], pkg.package_files
85
85
  assert_equal "pkgr-1.2.3.gem", pkg.gem_file
@@ -87,13 +87,13 @@ else
87
87
 
88
88
  def test_gem_package_with_specific_platform
89
89
  gem = Gem::Specification.new do |g|
90
- g.name = "pkgr"
91
- g.version = "1.2.3"
92
- g.files = FileList["x"].resolve
93
- g.platform = Gem::Platform::WIN32
90
+ g.name = "pkgr"
91
+ g.version = "1.2.3"
92
+ g.files = FileList["x"].resolve
93
+ g.platform = Gem::Platform::WIN32
94
94
  end
95
95
  pkg = Rake::GemPackageTask.new(gem) do |p|
96
- p.package_files << "y"
96
+ p.package_files << "y"
97
97
  end
98
98
  assert_equal ["x", "y"], pkg.package_files
99
99
  assert_equal "pkgr-1.2.3-mswin32.gem", pkg.gem_file
@@ -101,13 +101,13 @@ else
101
101
 
102
102
  def test_gem_package_with_current_platform
103
103
  gem = Gem::Specification.new do |g|
104
- g.name = "pkgr"
105
- g.version = "1.2.3"
106
- g.files = FileList["x"].resolve
107
- g.platform = Gem::Platform::CURRENT
104
+ g.name = "pkgr"
105
+ g.version = "1.2.3"
106
+ g.files = FileList["x"].resolve
107
+ g.platform = Gem::Platform::CURRENT
108
108
  end
109
109
  pkg = Rake::GemPackageTask.new(gem) do |p|
110
- p.package_files << "y"
110
+ p.package_files << "y"
111
111
  end
112
112
  assert_equal ["x", "y"], pkg.package_files
113
113
  assert_match(/^pkgr-1\.2\.3-(\S+)\.gem$/, pkg.gem_file)
@@ -115,13 +115,13 @@ else
115
115
 
116
116
  def test_gem_package_with_ruby_platform
117
117
  gem = Gem::Specification.new do |g|
118
- g.name = "pkgr"
119
- g.version = "1.2.3"
120
- g.files = FileList["x"].resolve
121
- g.platform = Gem::Platform::RUBY
118
+ g.name = "pkgr"
119
+ g.version = "1.2.3"
120
+ g.files = FileList["x"].resolve
121
+ g.platform = Gem::Platform::RUBY
122
122
  end
123
123
  pkg = Rake::GemPackageTask.new(gem) do |p|
124
- p.package_files << "y"
124
+ p.package_files << "y"
125
125
  end
126
126
  assert_equal ["x", "y"], pkg.package_files
127
127
  assert_equal "pkgr-1.2.3.gem", pkg.gem_file