jimweirich-rake 0.8.1.5

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 (94) hide show
  1. data/CHANGES +364 -0
  2. data/MIT-LICENSE +21 -0
  3. data/README +242 -0
  4. data/Rakefile +413 -0
  5. data/TODO +20 -0
  6. data/bin/rake +31 -0
  7. data/doc/example/Rakefile1 +38 -0
  8. data/doc/example/Rakefile2 +35 -0
  9. data/doc/example/a.c +6 -0
  10. data/doc/example/b.c +6 -0
  11. data/doc/example/main.c +11 -0
  12. data/doc/glossary.rdoc +51 -0
  13. data/doc/jamis.rb +591 -0
  14. data/doc/proto_rake.rdoc +127 -0
  15. data/doc/rake.1.gz +0 -0
  16. data/doc/rakefile.rdoc +411 -0
  17. data/doc/rational.rdoc +151 -0
  18. data/doc/release_notes/rake-0.4.14.rdoc +23 -0
  19. data/doc/release_notes/rake-0.4.15.rdoc +35 -0
  20. data/doc/release_notes/rake-0.5.0.rdoc +53 -0
  21. data/doc/release_notes/rake-0.5.3.rdoc +78 -0
  22. data/doc/release_notes/rake-0.5.4.rdoc +46 -0
  23. data/doc/release_notes/rake-0.6.0.rdoc +141 -0
  24. data/doc/release_notes/rake-0.7.0.rdoc +119 -0
  25. data/doc/release_notes/rake-0.7.1.rdoc +59 -0
  26. data/doc/release_notes/rake-0.7.2.rdoc +121 -0
  27. data/doc/release_notes/rake-0.7.3.rdoc +47 -0
  28. data/doc/release_notes/rake-0.8.0.rdoc +114 -0
  29. data/install.rb +88 -0
  30. data/lib/rake/classic_namespace.rb +8 -0
  31. data/lib/rake/clean.rb +33 -0
  32. data/lib/rake/contrib/compositepublisher.rb +24 -0
  33. data/lib/rake/contrib/ftptools.rb +153 -0
  34. data/lib/rake/contrib/publisher.rb +75 -0
  35. data/lib/rake/contrib/rubyforgepublisher.rb +18 -0
  36. data/lib/rake/contrib/sshpublisher.rb +47 -0
  37. data/lib/rake/contrib/sys.rb +209 -0
  38. data/lib/rake/gempackagetask.rb +103 -0
  39. data/lib/rake/loaders/makefile.rb +40 -0
  40. data/lib/rake/packagetask.rb +184 -0
  41. data/lib/rake/rake_test_loader.rb +5 -0
  42. data/lib/rake/rdoctask.rb +147 -0
  43. data/lib/rake/ruby182_test_unit_fix.rb +23 -0
  44. data/lib/rake/runtest.rb +23 -0
  45. data/lib/rake/tasklib.rb +18 -0
  46. data/lib/rake/testtask.rb +161 -0
  47. data/lib/rake.rb +2312 -0
  48. data/test/capture_stdout.rb +26 -0
  49. data/test/contrib/testsys.rb +47 -0
  50. data/test/data/chains/Rakefile +15 -0
  51. data/test/data/default/Rakefile +19 -0
  52. data/test/data/dryrun/Rakefile +22 -0
  53. data/test/data/file_creation_task/Rakefile +30 -0
  54. data/test/data/imports/Rakefile +19 -0
  55. data/test/data/imports/deps.mf +1 -0
  56. data/test/data/multidesc/Rakefile +17 -0
  57. data/test/data/namespace/Rakefile +57 -0
  58. data/test/data/rakelib/test1.rb +3 -0
  59. data/test/data/rbext/rakefile.rb +3 -0
  60. data/test/data/sample.mf +9 -0
  61. data/test/data/statusreturn/Rakefile +8 -0
  62. data/test/data/unittest/Rakefile +1 -0
  63. data/test/filecreation.rb +32 -0
  64. data/test/functional.rb +15 -0
  65. data/test/rake_test_setup.rb +5 -0
  66. data/test/reqfile.rb +3 -0
  67. data/test/reqfile2.rb +3 -0
  68. data/test/session_functional.rb +267 -0
  69. data/test/shellcommand.rb +3 -0
  70. data/test/test_application.rb +504 -0
  71. data/test/test_clean.rb +14 -0
  72. data/test/test_definitions.rb +82 -0
  73. data/test/test_earlytime.rb +35 -0
  74. data/test/test_extension.rb +63 -0
  75. data/test/test_file_creation_task.rb +62 -0
  76. data/test/test_file_task.rb +139 -0
  77. data/test/test_filelist.rb +618 -0
  78. data/test/test_fileutils.rb +239 -0
  79. data/test/test_ftp.rb +59 -0
  80. data/test/test_invocation_chain.rb +75 -0
  81. data/test/test_makefile_loader.rb +23 -0
  82. data/test/test_multitask.rb +45 -0
  83. data/test/test_namespace.rb +36 -0
  84. data/test/test_package_task.rb +116 -0
  85. data/test/test_pathmap.rb +209 -0
  86. data/test/test_rake.rb +34 -0
  87. data/test/test_require.rb +33 -0
  88. data/test/test_rules.rb +347 -0
  89. data/test/test_task_arguments.rb +76 -0
  90. data/test/test_task_manager.rb +148 -0
  91. data/test/test_tasks.rb +372 -0
  92. data/test/test_test_task.rb +75 -0
  93. data/test/test_top_level_functions.rb +84 -0
  94. metadata +173 -0
@@ -0,0 +1,209 @@
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 "ab.xyz", "ab.xyz.rb".pathmap("%X")
64
+ assert_equal "a.xyz", "a.xyz.rb".pathmap("%X")
65
+ assert_equal "abc", "abc.rb".pathmap("%X")
66
+ assert_equal "ab", "ab.rb".pathmap("%X")
67
+ assert_equal "a", "a.rb".pathmap("%X")
68
+ assert_equal ".depends", ".depends".pathmap("%X")
69
+ assert_equal "a/dir/.depends", "a/dir/.depends".pathmap("%X")
70
+ assert_equal "/.depends", "/.depends".pathmap("%X")
71
+ end
72
+
73
+ def test_p_returns_entire_pathname
74
+ assert_equal "abc.rb", "abc.rb".pathmap("%p")
75
+ assert_equal "this/is/a/dir/abc.rb", "this/is/a/dir/abc.rb".pathmap("%p")
76
+ assert_equal "/this/is/a/dir/abc.rb", "/this/is/a/dir/abc.rb".pathmap("%p")
77
+ end
78
+
79
+ def test_dash_returns_empty_string
80
+ assert_equal "", "abc.rb".pathmap("%-")
81
+ assert_equal "abc.rb", "abc.rb".pathmap("%X%-%x")
82
+ end
83
+
84
+ def test_percent_percent_returns_percent
85
+ assert_equal "a%b", "".pathmap("a%%b")
86
+ end
87
+
88
+ def test_undefined_percent_causes_error
89
+ ex = assert_raise(ArgumentError) {
90
+ "dir/abc.rb".pathmap("%z")
91
+ }
92
+ end
93
+
94
+ def test_pattern_returns_substitutions
95
+ assert_equal "bin/org/osb",
96
+ "src/org/osb/Xyz.java".pathmap("%{src,bin}d")
97
+ end
98
+
99
+ def test_pattern_can_use_backreferences
100
+ assert_equal "dir/hi/is", "dir/this/is".pathmap("%{t(hi)s,\\1}p")
101
+ end
102
+
103
+ def test_pattern_with_star_replacement_string_uses_block
104
+ assert_equal "src/ORG/osb",
105
+ "src/org/osb/Xyz.java".pathmap("%{/org,*}d") { |d| d.upcase }
106
+ assert_equal "Xyz.java",
107
+ "src/org/osb/Xyz.java".pathmap("%{.*,*}f") { |f| f.capitalize }
108
+ end
109
+
110
+ def test_pattern_with_no_replacement_nor_block_substitutes_empty_string
111
+ assert_equal "bc.rb", "abc.rb".pathmap("%{a}f")
112
+ end
113
+
114
+ def test_pattern_works_with_certain_valid_operators
115
+ assert_equal "dir/xbc.rb", "dir/abc.rb".pathmap("%{a,x}p")
116
+ assert_equal "d1r", "dir/abc.rb".pathmap("%{i,1}d")
117
+ assert_equal "xbc.rb", "dir/abc.rb".pathmap("%{a,x}f")
118
+ assert_equal ".Rb", "dir/abc.rb".pathmap("%{r,R}x")
119
+ assert_equal "xbc", "dir/abc.rb".pathmap("%{a,x}n")
120
+ end
121
+
122
+ def test_multiple_patterns
123
+ assert_equal "this/is/b/directory/abc.rb",
124
+ "this/is/a/dir/abc.rb".pathmap("%{a,b;dir,\\0ectory}p")
125
+ end
126
+
127
+ def test_partial_directory_selection_works_with_patterns
128
+ assert_equal "this/is/a/long",
129
+ "this/is/a/really/long/path/ok.rb".pathmap("%{/really/,/}5d")
130
+ end
131
+
132
+ def test_pattern_with_invalid_operator
133
+ ex = assert_raise(ArgumentError) do
134
+ "abc.xyz".pathmap("%{src,bin}z")
135
+ end
136
+ assert_match(/unknown.*pathmap.*spec.*z/i, ex.message)
137
+ end
138
+
139
+ def test_works_with_windows_separators
140
+ if File::ALT_SEPARATOR
141
+ assert_equal "abc", 'dir\abc.rb'.pathmap("%n")
142
+ assert_equal 'this\is\a\dir',
143
+ 'this\is\a\dir\abc.rb'.pathmap("%d")
144
+ end
145
+ end
146
+
147
+ def test_complex_patterns
148
+ sep = "".pathmap("%s")
149
+ assert_equal "dir/abc.rb", "dir/abc.rb".pathmap("%d/%n%x")
150
+ assert_equal "./abc.rb", "abc.rb".pathmap("%d/%n%x")
151
+ assert_equal "Your file extension is '.rb'",
152
+ "dir/abc.rb".pathmap("Your file extension is '%x'")
153
+ assert_equal "bin/org/onstepback/proj/A.class",
154
+ "src/org/onstepback/proj/A.java".pathmap("%{src,bin}d/%n.class")
155
+ assert_equal "src_work/bin/org/onstepback/proj/A.class",
156
+ "src_work/src/org/onstepback/proj/A.java".pathmap('%{\bsrc\b,bin}X.class')
157
+ assert_equal ".depends.bak", ".depends".pathmap("%X.bak")
158
+ assert_equal "d#{sep}a/b/c#{sep}file.txt", "a/b/c/d/file.txt".pathmap("%-1d%s%3d%s%f")
159
+ end
160
+ end
161
+
162
+ class TestPathMapExplode < Test::Unit::TestCase
163
+ def setup
164
+ String.class_eval { public :pathmap_explode }
165
+ end
166
+
167
+ def teardown
168
+ String.class_eval { protected :pathmap_explode }
169
+ end
170
+
171
+ def test_explode
172
+ assert_equal ['a'], 'a'.pathmap_explode
173
+ assert_equal ['a', 'b'], 'a/b'.pathmap_explode
174
+ assert_equal ['a', 'b', 'c'], 'a/b/c'.pathmap_explode
175
+ assert_equal ['/', 'a'], '/a'.pathmap_explode
176
+ assert_equal ['/', 'a', 'b'], '/a/b'.pathmap_explode
177
+ assert_equal ['/', 'a', 'b', 'c'], '/a/b/c'.pathmap_explode
178
+ if File::ALT_SEPARATOR
179
+ assert_equal ['c:.', 'a'], 'c:a'.pathmap_explode
180
+ assert_equal ['c:.', 'a', 'b'], 'c:a/b'.pathmap_explode
181
+ assert_equal ['c:.', 'a', 'b', 'c'], 'c:a/b/c'.pathmap_explode
182
+ assert_equal ['c:/', 'a'], 'c:/a'.pathmap_explode
183
+ assert_equal ['c:/', 'a', 'b'], 'c:/a/b'.pathmap_explode
184
+ assert_equal ['c:/', 'a', 'b', 'c'], 'c:/a/b/c'.pathmap_explode
185
+ end
186
+ end
187
+ end
188
+
189
+ class TestPathMapPartial < Test::Unit::TestCase
190
+ def test_pathmap_partial
191
+ @path = "1/2/file"
192
+ def @path.call(n)
193
+ pathmap_partial(n)
194
+ end
195
+ assert_equal("1", @path.call(1))
196
+ assert_equal("1/2", @path.call(2))
197
+ assert_equal("1/2", @path.call(3))
198
+ assert_equal(".", @path.call(0))
199
+ assert_equal("2", @path.call(-1))
200
+ assert_equal("1/2", @path.call(-2))
201
+ assert_equal("1/2", @path.call(-3))
202
+ end
203
+ end
204
+
205
+ class TestFileListPathMap < Test::Unit::TestCase
206
+ def test_file_list_supports_pathmap
207
+ assert_equal ['a', 'b'], FileList['dir/a.rb', 'dir/b.rb'].pathmap("%n")
208
+ end
209
+ 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
@@ -0,0 +1,33 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'test/unit'
4
+ require 'rake'
5
+
6
+ # ====================================================================
7
+ class TestRequire < Test::Unit::TestCase
8
+
9
+ def test_can_load_rake_library
10
+ app = Rake::Application.new
11
+ assert app.instance_eval {
12
+ rake_require("test2", ['test/data/rakelib'], [])
13
+ }
14
+ end
15
+
16
+ def test_wont_reload_rake_library
17
+ app = Rake::Application.new
18
+ assert ! app.instance_eval {
19
+ rake_require("test2", ['test/data/rakelib'], ['test2'])
20
+ }
21
+ end
22
+
23
+ def test_throws_error_if_library_not_found
24
+ app = Rake::Application.new
25
+ ex = assert_raise(LoadError) {
26
+ assert app.instance_eval {
27
+ rake_require("testx", ['test/data/rakelib'], [])
28
+ }
29
+ }
30
+ assert_match(/x/, ex.message)
31
+ end
32
+ end
33
+
@@ -0,0 +1,347 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'test/unit'
4
+ require 'fileutils'
5
+ require 'rake'
6
+ require 'test/filecreation'
7
+
8
+ ######################################################################
9
+ class TestRules < Test::Unit::TestCase
10
+ include Rake
11
+ include FileCreation
12
+
13
+ SRCFILE = "testdata/abc.c"
14
+ SRCFILE2 = "testdata/xyz.c"
15
+ FTNFILE = "testdata/abc.f"
16
+ OBJFILE = "testdata/abc.o"
17
+ FOOFILE = "testdata/foo"
18
+ DOTFOOFILE = "testdata/.foo"
19
+
20
+ def setup
21
+ Task.clear
22
+ @runs = []
23
+ end
24
+
25
+ def teardown
26
+ FileList['testdata/*'].each do |f| rm_r(f, :verbose=>false) end
27
+ end
28
+
29
+ def test_multiple_rules1
30
+ create_file(FTNFILE)
31
+ delete_file(SRCFILE)
32
+ delete_file(OBJFILE)
33
+ rule(/\.o$/ => ['.c']) do @runs << :C end
34
+ rule(/\.o$/ => ['.f']) do @runs << :F end
35
+ t = Task[OBJFILE]
36
+ t.invoke
37
+ Task[OBJFILE].invoke
38
+ assert_equal [:F], @runs
39
+ end
40
+
41
+ def test_multiple_rules2
42
+ create_file(FTNFILE)
43
+ delete_file(SRCFILE)
44
+ delete_file(OBJFILE)
45
+ rule(/\.o$/ => ['.f']) do @runs << :F end
46
+ rule(/\.o$/ => ['.c']) do @runs << :C end
47
+ Task[OBJFILE].invoke
48
+ assert_equal [:F], @runs
49
+ end
50
+
51
+ def test_create_with_source
52
+ create_file(SRCFILE)
53
+ rule(/\.o$/ => ['.c']) do |t|
54
+ @runs << t.name
55
+ assert_equal OBJFILE, t.name
56
+ assert_equal SRCFILE, t.source
57
+ end
58
+ Task[OBJFILE].invoke
59
+ assert_equal [OBJFILE], @runs
60
+ end
61
+
62
+ def test_single_dependent
63
+ create_file(SRCFILE)
64
+ rule(/\.o$/ => '.c') do |t|
65
+ @runs << t.name
66
+ end
67
+ Task[OBJFILE].invoke
68
+ assert_equal [OBJFILE], @runs
69
+ end
70
+
71
+ def test_rule_can_be_created_by_string
72
+ create_file(SRCFILE)
73
+ rule '.o' => ['.c'] do |t|
74
+ @runs << t.name
75
+ end
76
+ Task[OBJFILE].invoke
77
+ assert_equal [OBJFILE], @runs
78
+ end
79
+
80
+ def test_rule_prereqs_can_be_created_by_string
81
+ create_file(SRCFILE)
82
+ rule '.o' => '.c' do |t|
83
+ @runs << t.name
84
+ end
85
+ Task[OBJFILE].invoke
86
+ assert_equal [OBJFILE], @runs
87
+ end
88
+
89
+ def test_plain_strings_as_dependents_refer_to_files
90
+ create_file(SRCFILE)
91
+ rule '.o' => SRCFILE do |t|
92
+ @runs << t.name
93
+ end
94
+ Task[OBJFILE].invoke
95
+ assert_equal [OBJFILE], @runs
96
+ end
97
+
98
+ def test_file_names_beginning_with_dot_can_be_tricked_into_refering_to_file
99
+ verbose(false) do
100
+ chdir("testdata") do
101
+ create_file('.foo')
102
+ rule '.o' => "./.foo" do |t|
103
+ @runs << t.name
104
+ end
105
+ Task[OBJFILE].invoke
106
+ assert_equal [OBJFILE], @runs
107
+ end
108
+ end
109
+ end
110
+
111
+ def test_file_names_beginning_with_dot_can_be_wrapped_in_lambda
112
+ verbose(false) do
113
+ chdir("testdata") do
114
+ create_file(".foo")
115
+ rule '.o' => lambda{".foo"} do |t|
116
+ @runs << "#{t.name} - #{t.source}"
117
+ end
118
+ Task[OBJFILE].invoke
119
+ assert_equal ["#{OBJFILE} - .foo"], @runs
120
+ end
121
+ end
122
+ end
123
+
124
+ def test_file_names_containing_percent_can_be_wrapped_in_lambda
125
+ verbose(false) do
126
+ chdir("testdata") do
127
+ create_file("foo%x")
128
+ rule '.o' => lambda{"foo%x"} do |t|
129
+ @runs << "#{t.name} - #{t.source}"
130
+ end
131
+ Task[OBJFILE].invoke
132
+ assert_equal ["#{OBJFILE} - foo%x"], @runs
133
+ end
134
+ end
135
+ end
136
+
137
+ def test_non_extension_rule_name_refers_to_file
138
+ verbose(false) do
139
+ chdir("testdata") do
140
+ create_file("abc.c")
141
+ rule "abc" => '.c' do |t|
142
+ @runs << t.name
143
+ end
144
+ Task["abc"].invoke
145
+ assert_equal ["abc"], @runs
146
+ end
147
+ end
148
+ end
149
+
150
+ def test_pathmap_automatically_applies_to_name
151
+ verbose(false) do
152
+ chdir("testdata") do
153
+ create_file("zzabc.c")
154
+ rule ".o" => 'zz%{x,a}n.c' do |t|
155
+ @runs << "#{t.name} - #{t.source}"
156
+ end
157
+ Task["xbc.o"].invoke
158
+ assert_equal ["xbc.o - zzabc.c"], @runs
159
+ end
160
+ end
161
+ end
162
+
163
+ def test_plain_strings_are_just_filenames
164
+ verbose(false) do
165
+ chdir("testdata") do
166
+ create_file("plainname")
167
+ rule ".o" => 'plainname' do |t|
168
+ @runs << "#{t.name} - #{t.source}"
169
+ end
170
+ Task["xbc.o"].invoke
171
+ assert_equal ["xbc.o - plainname"], @runs
172
+ end
173
+ end
174
+ end
175
+
176
+ def test_rule_runs_when_explicit_task_has_no_actions
177
+ create_file(SRCFILE)
178
+ create_file(SRCFILE2)
179
+ delete_file(OBJFILE)
180
+ rule '.o' => '.c' do |t|
181
+ @runs << t.source
182
+ end
183
+ file OBJFILE => [SRCFILE2]
184
+ Task[OBJFILE].invoke
185
+ assert_equal [SRCFILE], @runs
186
+ end
187
+
188
+ def test_close_matches_on_name_do_not_trigger_rule
189
+ create_file("testdata/x.c")
190
+ rule '.o' => ['.c'] do |t|
191
+ @runs << t.name
192
+ end
193
+ assert_raises(RuntimeError) { Task['testdata/x.obj'].invoke }
194
+ assert_raises(RuntimeError) { Task['testdata/x.xyo'].invoke }
195
+ end
196
+
197
+ def test_rule_rebuilds_obj_when_source_is_newer
198
+ create_timed_files(OBJFILE, SRCFILE)
199
+ rule(/\.o$/ => ['.c']) do
200
+ @runs << :RULE
201
+ end
202
+ Task[OBJFILE].invoke
203
+ assert_equal [:RULE], @runs
204
+ end
205
+
206
+ def test_rule_with_two_sources_runs_if_both_sources_are_present
207
+ create_timed_files(OBJFILE, SRCFILE, SRCFILE2)
208
+ rule OBJFILE => [lambda{SRCFILE}, lambda{SRCFILE2}] do
209
+ @runs << :RULE
210
+ end
211
+ Task[OBJFILE].invoke
212
+ assert_equal [:RULE], @runs
213
+ end
214
+
215
+ def test_rule_with_two_sources_but_one_missing_does_not_run
216
+ create_timed_files(OBJFILE, SRCFILE)
217
+ delete_file(SRCFILE2)
218
+ rule OBJFILE => [lambda{SRCFILE}, lambda{SRCFILE2}] do
219
+ @runs << :RULE
220
+ end
221
+ Task[OBJFILE].invoke
222
+ assert_equal [], @runs
223
+ end
224
+
225
+ def test_rule_with_two_sources_builds_both_sources
226
+ task 'x.aa'
227
+ task 'x.bb'
228
+ rule '.a' => '.aa' do
229
+ @runs << "A"
230
+ end
231
+ rule '.b' => '.bb' do
232
+ @runs << "B"
233
+ end
234
+ rule ".c" => ['.a', '.b'] do
235
+ @runs << "C"
236
+ end
237
+ Task["x.c"].invoke
238
+ assert_equal ["A", "B", "C"], @runs.sort
239
+ end
240
+
241
+ def test_second_rule_runs_when_first_rule_doesnt
242
+ create_timed_files(OBJFILE, SRCFILE)
243
+ delete_file(SRCFILE2)
244
+ rule OBJFILE => [lambda{SRCFILE}, lambda{SRCFILE2}] do
245
+ @runs << :RULE1
246
+ end
247
+ rule OBJFILE => [lambda{SRCFILE}] do
248
+ @runs << :RULE2
249
+ end
250
+ Task[OBJFILE].invoke
251
+ assert_equal [:RULE2], @runs
252
+ end
253
+
254
+ def test_second_rule_doest_run_if_first_triggers
255
+ create_timed_files(OBJFILE, SRCFILE, SRCFILE2)
256
+ rule OBJFILE => [lambda{SRCFILE}, lambda{SRCFILE2}] do
257
+ @runs << :RULE1
258
+ end
259
+ rule OBJFILE => [lambda{SRCFILE}] do
260
+ @runs << :RULE2
261
+ end
262
+ Task[OBJFILE].invoke
263
+ assert_equal [:RULE1], @runs
264
+ end
265
+
266
+ def test_second_rule_doest_run_if_first_triggers_with_reversed_rules
267
+ create_timed_files(OBJFILE, SRCFILE, SRCFILE2)
268
+ rule OBJFILE => [lambda{SRCFILE}] do
269
+ @runs << :RULE1
270
+ end
271
+ rule OBJFILE => [lambda{SRCFILE}, lambda{SRCFILE2}] do
272
+ @runs << :RULE2
273
+ end
274
+ Task[OBJFILE].invoke
275
+ assert_equal [:RULE1], @runs
276
+ end
277
+
278
+ def test_rule_with_proc_dependent_will_trigger
279
+ ran = false
280
+ mkdir_p("testdata/src/jw")
281
+ create_file("testdata/src/jw/X.java")
282
+ rule %r(classes/.*\.class) => [
283
+ proc { |fn| fn.pathmap("%{classes,testdata/src}d/%n.java") }
284
+ ] do |task|
285
+ assert_equal task.name, 'classes/jw/X.class'
286
+ assert_equal task.source, 'testdata/src/jw/X.java'
287
+ @runs << :RULE
288
+ end
289
+ Task['classes/jw/X.class'].invoke
290
+ assert_equal [:RULE], @runs
291
+ ensure
292
+ rm_r("testdata/src", :verbose=>false) rescue nil
293
+ end
294
+
295
+ def test_proc_returning_lists_are_flattened_into_prereqs
296
+ ran = false
297
+ mkdir_p("testdata/flatten")
298
+ create_file("testdata/flatten/a.txt")
299
+ task 'testdata/flatten/b.data' do |t|
300
+ ran = true
301
+ touch t.name, :verbose => false
302
+ end
303
+ rule '.html' =>
304
+ proc { |fn|
305
+ [
306
+ fn.ext("txt"),
307
+ "testdata/flatten/b.data"
308
+ ]
309
+ } do |task|
310
+ end
311
+ Task['testdata/flatten/a.html'].invoke
312
+ assert ran, "Should have triggered flattened dependency"
313
+ ensure
314
+ rm_r("testdata/flatten", :verbose=>false) rescue nil
315
+ end
316
+
317
+ def test_recursive_rules_will_work_as_long_as_they_terminate
318
+ actions = []
319
+ create_file("testdata/abc.xml")
320
+ rule '.y' => '.xml' do actions << 'y' end
321
+ rule '.c' => '.y' do actions << 'c'end
322
+ rule '.o' => '.c' do actions << 'o'end
323
+ rule '.exe' => '.o' do actions << 'exe'end
324
+ Task["testdata/abc.exe"].invoke
325
+ assert_equal ['y', 'c', 'o', 'exe'], actions
326
+ end
327
+
328
+ def test_recursive_rules_that_dont_terminate_will_overflow
329
+ create_file("testdata/a.a")
330
+ prev = 'a'
331
+ ('b'..'z').each do |letter|
332
+ rule ".#{letter}" => ".#{prev}" do |t| puts "#{t.name}" end
333
+ prev = letter
334
+ end
335
+ ex = assert_raises(Rake::RuleRecursionOverflowError) {
336
+ Task["testdata/a.z"].invoke
337
+ }
338
+ assert_match(/a\.z => testdata\/a.y/, ex.message)
339
+ end
340
+
341
+ def test_rules_with_bad_dependents_will_fail
342
+ rule "a" => [ 1 ] do |t| puts t.name end
343
+ assert_raise(RuntimeError) do Task['a'].invoke end
344
+ end
345
+
346
+ end
347
+
@@ -0,0 +1,76 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'test/unit'
4
+ require 'rake'
5
+
6
+ ######################################################################
7
+ class TestTaskArguments < Test::Unit::TestCase
8
+ def teardown
9
+ ENV.delete('rev')
10
+ ENV.delete('VER')
11
+ end
12
+
13
+ def test_empty_arg_list_is_empty
14
+ ta = Rake::TaskArguments.new([], [])
15
+ assert_equal({}, ta.to_hash)
16
+ end
17
+
18
+ def test_multiple_values_in_args
19
+ ta = Rake::TaskArguments.new([:a, :b, :c], [:one, :two, :three])
20
+ assert_equal({:a => :one, :b => :two, :c => :three}, ta.to_hash)
21
+ end
22
+
23
+ def test_to_s
24
+ ta = Rake::TaskArguments.new([:a, :b, :c], [1, 2, 3])
25
+ assert_equal ta.to_hash.inspect, ta.to_s
26
+ assert_equal ta.to_hash.inspect, ta.inspect
27
+ end
28
+
29
+ def test_enumerable_behavior
30
+ ta = Rake::TaskArguments.new([:a, :b, :c], [1, 2 ,3])
31
+ assert_equal [10, 20, 30], ta.collect { |k,v| v * 10 }.sort
32
+ end
33
+
34
+ def test_named_args
35
+ ta = Rake::TaskArguments.new(["aa", "bb"], [1, 2])
36
+ assert_equal 1, ta.aa
37
+ assert_equal 1, ta[:aa]
38
+ assert_equal 1, ta["aa"]
39
+ assert_equal 2, ta.bb
40
+ assert_nil ta.cc
41
+ end
42
+
43
+ def test_args_knows_its_names
44
+ ta = Rake::TaskArguments.new(["aa", "bb"], [1, 2])
45
+ assert_equal ["aa", "bb"], ta.names
46
+ end
47
+
48
+ def test_extra_names_are_nil
49
+ ta = Rake::TaskArguments.new(["aa", "bb", "cc"], [1, 2])
50
+ assert_nil ta.cc
51
+ end
52
+
53
+ def test_args_can_reference_env_values
54
+ ta = Rake::TaskArguments.new(["aa"], [1])
55
+ ENV['rev'] = "1.2"
56
+ ENV['VER'] = "2.3"
57
+ assert_equal "1.2", ta.rev
58
+ assert_equal "2.3", ta.ver
59
+ end
60
+
61
+ def test_creating_new_argument_scopes
62
+ parent = Rake::TaskArguments.new(['p'], [1])
63
+ child = parent.new_scope(['c', 'p'])
64
+ assert_equal({:c => nil, :p=>1}, child.to_hash)
65
+ assert_equal 1, child.p
66
+ assert_equal 1, child["p"]
67
+ assert_equal 1, child[:p]
68
+ assert_nil child.c
69
+ end
70
+
71
+ def test_child_hides_parent_arg_names
72
+ parent = Rake::TaskArguments.new(['aa'], [1])
73
+ child = Rake::TaskArguments.new(['aa'], [2], parent)
74
+ assert_equal 2, child.aa
75
+ end
76
+ end