rake 0.4.8 → 0.7.3

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.
Files changed (77) hide show
  1. data/CHANGES +183 -0
  2. data/README +47 -14
  3. data/Rakefile +212 -44
  4. data/bin/rake +2 -3
  5. data/doc/jamis.rb +591 -0
  6. data/doc/rake.1.gz +0 -0
  7. data/doc/rakefile.rdoc +180 -3
  8. data/doc/release_notes/rake-0.4.14.rdoc +23 -0
  9. data/doc/release_notes/rake-0.4.15.rdoc +35 -0
  10. data/doc/release_notes/rake-0.5.0.rdoc +53 -0
  11. data/doc/release_notes/rake-0.5.3.rdoc +78 -0
  12. data/doc/release_notes/rake-0.5.4.rdoc +46 -0
  13. data/doc/release_notes/rake-0.6.0.rdoc +141 -0
  14. data/doc/release_notes/rake-0.7.0.rdoc +119 -0
  15. data/doc/release_notes/rake-0.7.1.rdoc +59 -0
  16. data/doc/release_notes/rake-0.7.2.rdoc +121 -0
  17. data/doc/release_notes/rake-0.7.3.rdoc +47 -0
  18. data/lib/rake/classic_namespace.rb +8 -0
  19. data/lib/rake/clean.rb +3 -1
  20. data/lib/rake/contrib/ftptools.rb +21 -21
  21. data/lib/rake/contrib/rubyforgepublisher.rb +3 -3
  22. data/lib/rake/contrib/sshpublisher.rb +1 -1
  23. data/lib/rake/contrib/sys.rb +20 -21
  24. data/lib/rake/gempackagetask.rb +12 -9
  25. data/lib/rake/loaders/makefile.rb +40 -0
  26. data/lib/rake/packagetask.rb +65 -33
  27. data/lib/rake/rake_test_loader.rb +5 -0
  28. data/lib/rake/rdoctask.rb +34 -15
  29. data/lib/rake/ruby182_test_unit_fix.rb +23 -0
  30. data/lib/rake/runtest.rb +4 -4
  31. data/lib/rake/tasklib.rb +3 -9
  32. data/lib/rake/testtask.rb +67 -24
  33. data/lib/rake.rb +1600 -552
  34. data/test/capture_stdout.rb +26 -0
  35. data/test/data/chains/Rakefile +15 -0
  36. data/test/data/default/Rakefile +19 -0
  37. data/test/data/dryrun/Rakefile +22 -0
  38. data/test/data/file_creation_task/Rakefile +30 -0
  39. data/test/data/imports/Rakefile +19 -0
  40. data/test/data/imports/deps.mf +1 -0
  41. data/test/data/multidesc/Rakefile +14 -0
  42. data/test/data/namespace/Rakefile +57 -0
  43. data/test/data/rakelib/test1.rb +3 -0
  44. data/test/data/sample.mf +9 -0
  45. data/test/data/unittest/Rakefile +1 -0
  46. data/test/filecreation.rb +18 -10
  47. data/test/functional.rb +3 -72
  48. data/test/reqfile.rb +3 -0
  49. data/test/reqfile2.rb +3 -0
  50. data/test/session_functional.rb +218 -0
  51. data/test/shellcommand.rb +3 -0
  52. data/test/test_application.rb +425 -0
  53. data/test/{testclean.rb → test_clean.rb} +1 -0
  54. data/test/test_definitions.rb +82 -0
  55. data/test/test_earlytime.rb +35 -0
  56. data/test/test_file_creation_task.rb +62 -0
  57. data/test/test_file_task.rb +139 -0
  58. data/test/test_filelist.rb +574 -0
  59. data/test/test_fileutils.rb +230 -0
  60. data/test/test_makefile_loader.rb +23 -0
  61. data/test/test_multitask.rb +45 -0
  62. data/test/test_namespace.rb +32 -0
  63. data/test/test_package_task.rb +130 -0
  64. data/test/test_pathmap.rb +188 -0
  65. data/test/test_rake.rb +34 -0
  66. data/test/test_require.rb +33 -0
  67. data/test/test_rules.rb +305 -0
  68. data/test/test_task_manager.rb +148 -0
  69. data/test/test_tasks.rb +146 -0
  70. data/test/{testtesttask.rb → test_test_task.rb} +5 -0
  71. data/test/test_top_level_functions.rb +79 -0
  72. metadata +134 -68
  73. data/test/testfilelist.rb +0 -255
  74. data/test/testfileutils.rb +0 -55
  75. data/test/testpackagetask.rb +0 -81
  76. data/test/testtasks.rb +0 -371
  77. /data/test/{testftp.rb → test_ftp.rb} +0 -0
@@ -0,0 +1,230 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'rake'
4
+ require 'test/unit'
5
+ require 'test/filecreation'
6
+ require 'fileutils'
7
+ require 'stringio'
8
+
9
+ class TestFileUtils < Test::Unit::TestCase
10
+ include FileCreation
11
+
12
+ def setup
13
+ File.chmod(0750,"test/shellcommand.rb")
14
+ end
15
+
16
+ def teardown
17
+ FileUtils.rm_rf("testdata")
18
+ FileUtils::LN_SUPPORTED[0] = true
19
+ end
20
+
21
+ def test_rm_one_file
22
+ create_file("testdata/a")
23
+ FileUtils.rm_rf "testdata/a"
24
+ assert ! File.exist?("testdata/a")
25
+ end
26
+
27
+ def test_rm_two_files
28
+ create_file("testdata/a")
29
+ create_file("testdata/b")
30
+ FileUtils.rm_rf ["testdata/a", "testdata/b"]
31
+ assert ! File.exist?("testdata/a")
32
+ assert ! File.exist?("testdata/b")
33
+ end
34
+
35
+ def test_rm_filelist
36
+ list = Rake::FileList.new << "testdata/a" << "testdata/b"
37
+ list.each { |fn| create_file(fn) }
38
+ FileUtils.rm_r list
39
+ assert ! File.exist?("testdata/a")
40
+ assert ! File.exist?("testdata/b")
41
+ end
42
+
43
+ def test_ln
44
+ create_dir("testdata")
45
+ open("testdata/a", "w") { |f| f.puts "TEST_LN" }
46
+ RakeFileUtils.safe_ln("testdata/a", "testdata/b", :verbose => false)
47
+ assert_equal "TEST_LN\n", open("testdata/b") { |f| f.read }
48
+ end
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
+
87
+ def test_verbose
88
+ verbose true
89
+ assert_equal true, verbose
90
+ verbose false
91
+ assert_equal false, verbose
92
+ verbose(true) {
93
+ assert_equal true, verbose
94
+ }
95
+ assert_equal false, verbose
96
+ end
97
+
98
+ def test_nowrite
99
+ nowrite true
100
+ assert_equal true, nowrite
101
+ nowrite false
102
+ assert_equal false, nowrite
103
+ nowrite(true){
104
+ assert_equal true, nowrite
105
+ }
106
+ assert_equal false, nowrite
107
+ end
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
+
121
+ def test_sh
122
+ verbose(false) { sh %{test/shellcommand.rb} }
123
+ assert true, "should not fail"
124
+ end
125
+
126
+ def test_sh_multiple_arguments
127
+ ENV['RAKE_TEST_SH'] = 'someval'
128
+ # This one gets expanded by the shell
129
+ verbose(false) { sh %{test $RAKE_TEST_SH = someval} }
130
+ assert true, "should not fail"
131
+ assert_raises(RuntimeError) {
132
+ # This one does not get expanded
133
+ verbose(false) { sh 'test','$RAKE_TEST_SH', '=', 'someval' }
134
+ }
135
+ end
136
+
137
+ def test_sh_failure
138
+ assert_raises(RuntimeError) {
139
+ verbose(false) { sh %{test/shellcommand.rb 1} }
140
+ }
141
+ end
142
+
143
+ def test_sh_special_handling
144
+ count = 0
145
+ verbose(false) {
146
+ sh(%{test/shellcommand.rb}) do |ok, res|
147
+ assert(ok)
148
+ assert_equal 0, res.exitstatus
149
+ count += 1
150
+ end
151
+ sh(%{test/shellcommand.rb 1}) do |ok, res|
152
+ assert(!ok)
153
+ assert_equal 1, res.exitstatus
154
+ count += 1
155
+ end
156
+ }
157
+ assert_equal 2, count, "Block count should be 2"
158
+ end
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
+
188
+ def test_ruby
189
+ verbose(false) do
190
+ ENV['RAKE_TEST_RUBY'] = "123"
191
+ block_run = false
192
+ # This one gets expanded by the shell
193
+ ruby %{-e "exit $RAKE_TEST_RUBY"} do |ok, status|
194
+ assert(!ok)
195
+ assert_equal 123, status.exitstatus
196
+ block_run = true
197
+ end
198
+ assert block_run, "The block must be run"
199
+
200
+ # This one does not get expanded
201
+ block_run = false
202
+ ruby '-e', 'exit "$RAKE_TEST_RUBY".length' do |ok, status|
203
+ assert(!ok)
204
+ assert_equal 15, status.exitstatus
205
+ block_run = true
206
+ end
207
+ assert block_run, "The block must be run"
208
+ end
209
+ end
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
230
+ end
@@ -0,0 +1,23 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'test/unit'
4
+ require 'rake'
5
+ require 'rake/loaders/makefile'
6
+
7
+ class TestMakefileLoader < Test::Unit::TestCase
8
+ include Rake
9
+
10
+ def test_create
11
+ Task.clear
12
+ loader = Rake::MakefileLoader.new
13
+ loader.load("test/data/sample.mf")
14
+ %w(a b c d).each do |t|
15
+ assert Task.task_defined?(t), "#{t} should be a defined task"
16
+ end
17
+ assert_equal %w(a1 a2 a3 a4 a5 a6 a7).sort, Task['a'].prerequisites.sort
18
+ assert_equal %w(b1 b2 b3 b4 b5 b6 b7).sort, Task['b'].prerequisites.sort
19
+ assert_equal %w(c1).sort, Task['c'].prerequisites.sort
20
+ assert_equal %w(d1 d2).sort, Task['d'].prerequisites.sort
21
+ assert_equal 4, Task.tasks.size
22
+ end
23
+ end
@@ -0,0 +1,45 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'test/unit'
4
+ require 'rake'
5
+
6
+ ######################################################################
7
+ class TestMultiTask < Test::Unit::TestCase
8
+ include Rake
9
+
10
+ def setup
11
+ Task.clear
12
+ @runs = Array.new
13
+ end
14
+
15
+ def test_running_multitasks
16
+ task :a do 3.times do |i| @runs << "A#{i}"; sleep 0.01; end end
17
+ task :b do 3.times do |i| @runs << "B#{i}"; sleep 0.01; end end
18
+ multitask :both => [:a, :b]
19
+ Task[:both].invoke
20
+ assert_equal 6, @runs.size
21
+ assert @runs.index("A0") < @runs.index("A1")
22
+ assert @runs.index("A1") < @runs.index("A2")
23
+ assert @runs.index("B0") < @runs.index("B1")
24
+ assert @runs.index("B1") < @runs.index("B2")
25
+ end
26
+
27
+ def test_all_multitasks_wait_on_slow_prerequisites
28
+ task :slow do 3.times do |i| @runs << "S#{i}"; sleep 0.05 end end
29
+ task :a => [:slow] do 3.times do |i| @runs << "A#{i}"; sleep 0.01 end end
30
+ task :b => [:slow] do 3.times do |i| @runs << "B#{i}"; sleep 0.01 end end
31
+ multitask :both => [:a, :b]
32
+ Task[:both].invoke
33
+ assert_equal 9, @runs.size
34
+ assert @runs.index("S0") < @runs.index("S1")
35
+ assert @runs.index("S1") < @runs.index("S2")
36
+ assert @runs.index("S2") < @runs.index("A0")
37
+ assert @runs.index("S2") < @runs.index("B0")
38
+ assert @runs.index("A0") < @runs.index("A1")
39
+ assert @runs.index("A1") < @runs.index("A2")
40
+ assert @runs.index("B0") < @runs.index("B1")
41
+ assert @runs.index("B1") < @runs.index("B2")
42
+ end
43
+ end
44
+
45
+
@@ -0,0 +1,32 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'rubygems'
4
+ require 'test/unit'
5
+ require 'flexmock'
6
+ require 'rake'
7
+
8
+ class TestNameSpace < Test::Unit::TestCase
9
+ include FlexMock::TestCase
10
+
11
+ def test_namespace_creation
12
+ mgr = flexmock("TaskManager")
13
+ ns = Rake::NameSpace.new(mgr, [])
14
+ assert_not_nil ns
15
+ end
16
+
17
+ def test_namespace_lookup
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
31
+ end
32
+ end
@@ -0,0 +1,130 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'test/unit'
4
+ require 'rake/packagetask'
5
+
6
+ class TestPackageTask < Test::Unit::TestCase
7
+ include Rake
8
+
9
+ def test_create
10
+ pkg = Rake::PackageTask.new("pkgr", "1.2.3") { |p|
11
+ p.package_files << "install.rb"
12
+ p.package_files.include(
13
+ '[A-Z]*',
14
+ 'bin/**/*',
15
+ 'lib/**/*.rb',
16
+ 'test/**/*.rb',
17
+ 'doc/**/*',
18
+ 'build/rubyapp.rb',
19
+ '*.blurb')
20
+ p.package_files.exclude(/\bCVS\b/)
21
+ p.package_files.exclude(/~$/)
22
+ p.package_dir = 'pkg'
23
+ p.need_tar = true
24
+ p.need_tar_gz = true
25
+ p.need_tar_bz2 = true
26
+ p.need_zip = true
27
+ }
28
+ assert_equal "pkg", pkg.package_dir
29
+ assert pkg.package_files.include?("bin/rake")
30
+ assert "pkgr", pkg.name
31
+ assert "1.2.3", pkg.version
32
+ assert Task[:package]
33
+ assert Task['pkg/pkgr-1.2.3.tgz']
34
+ assert Task['pkg/pkgr-1.2.3.tar.gz']
35
+ assert Task['pkg/pkgr-1.2.3.tar.bz2']
36
+ assert Task['pkg/pkgr-1.2.3.zip']
37
+ assert Task["pkg/pkgr-1.2.3"]
38
+ assert Task[:clobber_package]
39
+ assert Task[:repackage]
40
+ end
41
+
42
+ def test_missing_version
43
+ assert_raises(RuntimeError) {
44
+ pkg = Rake::PackageTask.new("pkgr") { |p| }
45
+ }
46
+ end
47
+
48
+ def test_no_version
49
+ pkg = Rake::PackageTask.new("pkgr", :noversion) { |p| }
50
+ assert "pkgr", pkg.send(:package_name)
51
+ end
52
+
53
+ def test_clone
54
+ pkg = Rake::PackageTask.new("x", :noversion)
55
+ p2 = pkg.clone
56
+ pkg.package_files << "y"
57
+ p2.package_files << "x"
58
+ assert_equal ["y"], pkg.package_files
59
+ assert_equal ["x"], p2.package_files
60
+ end
61
+ end
62
+
63
+
64
+ begin
65
+ require 'rubygems'
66
+ require 'rake/gempackagetask'
67
+ rescue Exception
68
+ puts "WARNING: RubyGems not installed"
69
+ end
70
+
71
+ if ! defined?(Gem)
72
+ puts "WARNING: Unable to test GemPackaging ... requires RubyGems"
73
+ else
74
+ class TestGemPackageTask < Test::Unit::TestCase
75
+ def test_gem_package
76
+ gem = Gem::Specification.new do |g|
77
+ g.name = "pkgr"
78
+ g.version = "1.2.3"
79
+ g.files = FileList["x"].resolve
80
+ end
81
+ pkg = Rake::GemPackageTask.new(gem) do |p|
82
+ p.package_files << "y"
83
+ end
84
+ assert_equal ["x", "y"], pkg.package_files
85
+ assert_equal "pkgr-1.2.3.gem", pkg.gem_file
86
+ end
87
+
88
+ def test_gem_package_with_specific_platform
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
94
+ end
95
+ pkg = Rake::GemPackageTask.new(gem) do |p|
96
+ p.package_files << "y"
97
+ end
98
+ assert_equal ["x", "y"], pkg.package_files
99
+ assert_equal "pkgr-1.2.3-mswin32.gem", pkg.gem_file
100
+ end
101
+
102
+ def test_gem_package_with_current_platform
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
108
+ end
109
+ pkg = Rake::GemPackageTask.new(gem) do |p|
110
+ p.package_files << "y"
111
+ end
112
+ assert_equal ["x", "y"], pkg.package_files
113
+ assert_match(/^pkgr-1\.2\.3-(\S+)\.gem$/, pkg.gem_file)
114
+ end
115
+
116
+ def test_gem_package_with_ruby_platform
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
122
+ end
123
+ pkg = Rake::GemPackageTask.new(gem) do |p|
124
+ p.package_files << "y"
125
+ end
126
+ assert_equal ["x", "y"], pkg.package_files
127
+ assert_equal "pkgr-1.2.3.gem", pkg.gem_file
128
+ end
129
+ end
130
+ end
@@ -0,0 +1,188 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'test/unit'
4
+ require 'rake'
5
+
6
+ # ====================================================================
7
+ class TestPathMap < Test::Unit::TestCase
8
+
9
+ def test_returns_self_with_no_args
10
+ assert_equal "abc.rb", "abc.rb".pathmap
11
+ end
12
+
13
+ def test_s_returns_file_separator
14
+ sep = File::ALT_SEPARATOR || File::SEPARATOR
15
+ assert_equal sep, "abc.rb".pathmap("%s")
16
+ assert_equal sep, "".pathmap("%s")
17
+ assert_equal "a#{sep}b", "a/b".pathmap("%d%s%f")
18
+ end
19
+
20
+ def test_f_returns_basename
21
+ assert_equal "abc.rb", "abc.rb".pathmap("%f")
22
+ assert_equal "abc.rb", "this/is/a/dir/abc.rb".pathmap("%f")
23
+ assert_equal "abc.rb", "/this/is/a/dir/abc.rb".pathmap("%f")
24
+ end
25
+
26
+ def test_n_returns_basename_without_extension
27
+ assert_equal "abc", "abc.rb".pathmap("%n")
28
+ assert_equal "abc", "abc".pathmap("%n")
29
+ assert_equal "abc", "this/is/a/dir/abc.rb".pathmap("%n")
30
+ assert_equal "abc", "/this/is/a/dir/abc.rb".pathmap("%n")
31
+ assert_equal "abc", "/this/is/a/dir/abc".pathmap("%n")
32
+ end
33
+
34
+ def test_d_returns_dirname
35
+ assert_equal ".", "abc.rb".pathmap("%d")
36
+ assert_equal "/", "/abc".pathmap("%d")
37
+ assert_equal "this/is/a/dir", "this/is/a/dir/abc.rb".pathmap("%d")
38
+ assert_equal "/this/is/a/dir", "/this/is/a/dir/abc.rb".pathmap("%d")
39
+ end
40
+
41
+ def test_9d_returns_partial_dirname
42
+ assert_equal "this/is", "this/is/a/dir/abc.rb".pathmap("%2d")
43
+ assert_equal "this", "this/is/a/dir/abc.rb".pathmap("%1d")
44
+ assert_equal ".", "this/is/a/dir/abc.rb".pathmap("%0d")
45
+ assert_equal "dir", "this/is/a/dir/abc.rb".pathmap("%-1d")
46
+ assert_equal "a/dir", "this/is/a/dir/abc.rb".pathmap("%-2d")
47
+ assert_equal "this/is/a/dir", "this/is/a/dir/abc.rb".pathmap("%100d")
48
+ assert_equal "this/is/a/dir", "this/is/a/dir/abc.rb".pathmap("%-100d")
49
+ end
50
+
51
+ def test_x_returns_extension
52
+ assert_equal "", "abc".pathmap("%x")
53
+ assert_equal ".rb", "abc.rb".pathmap("%x")
54
+ assert_equal ".rb", "abc.xyz.rb".pathmap("%x")
55
+ assert_equal "", ".depends".pathmap("%x")
56
+ assert_equal "", "dir/.depends".pathmap("%x")
57
+ end
58
+
59
+ def test_X_returns_everything_but_extension
60
+ assert_equal "abc", "abc".pathmap("%X")
61
+ assert_equal "abc", "abc.rb".pathmap("%X")
62
+ assert_equal "abc.xyz", "abc.xyz.rb".pathmap("%X")
63
+ assert_equal ".depends", ".depends".pathmap("%X")
64
+ assert_equal "a/dir/.depends", "a/dir/.depends".pathmap("%X")
65
+ assert_equal "/.depends", "/.depends".pathmap("%X")
66
+ end
67
+
68
+ def test_p_returns_entire_pathname
69
+ assert_equal "abc.rb", "abc.rb".pathmap("%p")
70
+ assert_equal "this/is/a/dir/abc.rb", "this/is/a/dir/abc.rb".pathmap("%p")
71
+ assert_equal "/this/is/a/dir/abc.rb", "/this/is/a/dir/abc.rb".pathmap("%p")
72
+ end
73
+
74
+ def test_dash_returns_empty_string
75
+ assert_equal "", "abc.rb".pathmap("%-")
76
+ assert_equal "abc.rb", "abc.rb".pathmap("%X%-%x")
77
+ end
78
+
79
+ def test_percent_percent_returns_percent
80
+ assert_equal "a%b", "".pathmap("a%%b")
81
+ end
82
+
83
+ def test_undefined_percent_causes_error
84
+ ex = assert_raise(ArgumentError) {
85
+ "dir/abc.rb".pathmap("%z")
86
+ }
87
+ end
88
+
89
+ def test_pattern_returns_substitutions
90
+ assert_equal "bin/org/osb",
91
+ "src/org/osb/Xyz.java".pathmap("%{src,bin}d")
92
+ end
93
+
94
+ def test_pattern_can_use_backreferences
95
+ assert_equal "dir/hi/is", "dir/this/is".pathmap("%{t(hi)s,\\1}p")
96
+ end
97
+
98
+ def test_pattern_with_star_replacement_string_uses_block
99
+ assert_equal "src/ORG/osb",
100
+ "src/org/osb/Xyz.java".pathmap("%{/org,*}d") { |d| d.upcase }
101
+ assert_equal "Xyz.java",
102
+ "src/org/osb/Xyz.java".pathmap("%{.*,*}f") { |f| f.capitalize }
103
+ end
104
+
105
+ def test_pattern_with_no_replacement_nor_block_substitutes_empty_string
106
+ assert_equal "bc.rb", "abc.rb".pathmap("%{a}f")
107
+ end
108
+
109
+ def test_pattern_works_with_certain_valid_operators
110
+ assert_equal "dir/xbc.rb", "dir/abc.rb".pathmap("%{a,x}p")
111
+ assert_equal "d1r", "dir/abc.rb".pathmap("%{i,1}d")
112
+ assert_equal "xbc.rb", "dir/abc.rb".pathmap("%{a,x}f")
113
+ assert_equal ".Rb", "dir/abc.rb".pathmap("%{r,R}x")
114
+ assert_equal "xbc", "dir/abc.rb".pathmap("%{a,x}n")
115
+ end
116
+
117
+ def test_multiple_patterns
118
+ assert_equal "this/is/b/directory/abc.rb",
119
+ "this/is/a/dir/abc.rb".pathmap("%{a,b;dir,\\0ectory}p")
120
+ end
121
+
122
+ def test_partial_directory_selection_works_with_patterns
123
+ assert_equal "this/is/a/long",
124
+ "this/is/a/really/long/path/ok.rb".pathmap("%{/really/,/}5d")
125
+ end
126
+
127
+ def test_pattern_with_invalid_operator
128
+ ex = assert_raise(ArgumentError) do
129
+ "abc.xyz".pathmap("%{src,bin}z")
130
+ end
131
+ assert_match(/unknown.*pathmap.*spec.*z/i, ex.message)
132
+ end
133
+
134
+ def test_works_with_windows_separators
135
+ if File::ALT_SEPARATOR
136
+ assert_equal "abc", 'dir\abc.rb'.pathmap("%n")
137
+ assert_equal 'this\is\a\dir',
138
+ 'this\is\a\dir\abc.rb'.pathmap("%d")
139
+ end
140
+ end
141
+
142
+ def test_complex_patterns
143
+ sep = "".pathmap("%s")
144
+ assert_equal "dir/abc.rb", "dir/abc.rb".pathmap("%d/%n%x")
145
+ assert_equal "./abc.rb", "abc.rb".pathmap("%d/%n%x")
146
+ assert_equal "Your file extension is '.rb'",
147
+ "dir/abc.rb".pathmap("Your file extension is '%x'")
148
+ assert_equal "bin/org/onstepback/proj/A.class",
149
+ "src/org/onstepback/proj/A.java".pathmap("%{src,bin}d/%n.class")
150
+ assert_equal "src_work/bin/org/onstepback/proj/A.class",
151
+ "src_work/src/org/onstepback/proj/A.java".pathmap('%{\bsrc\b,bin}X.class')
152
+ assert_equal ".depends.bak", ".depends".pathmap("%X.bak")
153
+ assert_equal "d#{sep}a/b/c#{sep}file.txt", "a/b/c/d/file.txt".pathmap("%-1d%s%3d%s%f")
154
+ end
155
+ end
156
+
157
+ class TestPathMapExplode < Test::Unit::TestCase
158
+ def setup
159
+ String.class_eval { public :pathmap_explode }
160
+ end
161
+
162
+ def teardown
163
+ String.class_eval { protected :pathmap_explode }
164
+ end
165
+
166
+ def test_explode
167
+ assert_equal ['a'], 'a'.pathmap_explode
168
+ assert_equal ['a', 'b'], 'a/b'.pathmap_explode
169
+ assert_equal ['a', 'b', 'c'], 'a/b/c'.pathmap_explode
170
+ assert_equal ['/', 'a'], '/a'.pathmap_explode
171
+ assert_equal ['/', 'a', 'b'], '/a/b'.pathmap_explode
172
+ assert_equal ['/', 'a', 'b', 'c'], '/a/b/c'.pathmap_explode
173
+ if File::ALT_SEPARATOR
174
+ assert_equal ['c:.', 'a'], 'c:a'.pathmap_explode
175
+ assert_equal ['c:.', 'a', 'b'], 'c:a/b'.pathmap_explode
176
+ assert_equal ['c:.', 'a', 'b', 'c'], 'c:a/b/c'.pathmap_explode
177
+ assert_equal ['c:/', 'a'], 'c:/a'.pathmap_explode
178
+ assert_equal ['c:/', 'a', 'b'], 'c:/a/b'.pathmap_explode
179
+ assert_equal ['c:/', 'a', 'b', 'c'], 'c:/a/b/c'.pathmap_explode
180
+ end
181
+ end
182
+ end
183
+
184
+ class TestFileListPathMap < Test::Unit::TestCase
185
+ def test_file_list_supports_pathmap
186
+ assert_equal ['a', 'b'], FileList['dir/a.rb', 'dir/b.rb'].pathmap("%n")
187
+ end
188
+ end
data/test/test_rake.rb ADDED
@@ -0,0 +1,34 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'test/unit'
4
+ require 'rake'
5
+
6
+ class TestRake < Test::Unit::TestCase
7
+ def test_each_dir_parent
8
+ assert_equal ['a'], alldirs('a')
9
+ assert_equal ['a/b', 'a'], alldirs('a/b')
10
+ assert_equal ['/a/b', '/a', '/'], alldirs('/a/b')
11
+ assert_equal ['c:/a/b', 'c:/a', 'c:'], alldirs('c:/a/b')
12
+ assert_equal ['c:a/b', 'c:a'], alldirs('c:a/b')
13
+ end
14
+
15
+ def alldirs(fn)
16
+ result = []
17
+ Rake.each_dir_parent(fn) { |d| result << d }
18
+ result
19
+ end
20
+
21
+ def test_can_override_application
22
+ old_app = Rake.application
23
+ fake_app = Object.new
24
+ Rake.application = fake_app
25
+ assert_equal fake_app, Rake.application
26
+ ensure
27
+ Rake.application = old_app
28
+ end
29
+
30
+ def test_original_dir_reports_current_dir
31
+ assert_equal Dir.pwd, Rake.original_dir
32
+ end
33
+
34
+ end