rake 0.9.0 → 0.9.1

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.

Files changed (66) hide show
  1. data/CHANGES +9 -8
  2. data/RRR +10 -0
  3. data/Rakefile +9 -45
  4. data/bin/rake +4 -3
  5. data/doc/release_notes/rake-0.9.1.rdoc +52 -0
  6. data/lib/rake/dsl_definition.rb +19 -0
  7. data/lib/rake/version.rb +1 -1
  8. data/test/data/access/Rakefile +3 -1
  9. data/test/data/default/Rakefile +0 -2
  10. data/test/data/file_creation_task/Rakefile +0 -2
  11. data/test/data/multidesc/Rakefile +0 -2
  12. data/test/data/namespace/Rakefile +0 -2
  13. data/test/data/statusreturn/Rakefile +0 -2
  14. data/test/file_creation.rb +0 -2
  15. data/test/helper.rb +44 -0
  16. data/test/in_environment.rb +4 -1
  17. data/test/{lib/rake_test.rb → test_rake.rb} +2 -5
  18. data/test/test_rake_application.rb +364 -0
  19. data/test/test_rake_application_options.rb +382 -0
  20. data/test/{lib/clean_test.rb → test_rake_clean.rb} +2 -5
  21. data/test/{lib/definitions_test.rb → test_rake_definitions.rb} +5 -10
  22. data/test/test_rake_directory_task.rb +55 -0
  23. data/test/test_rake_dsl.rb +53 -0
  24. data/test/{lib/earlytime_test.rb → test_rake_early_time.rb} +2 -5
  25. data/test/{lib/extension_test.rb → test_rake_extension.rb} +2 -6
  26. data/test/{lib/file_creation_task_test.rb → test_rake_file_creation_task.rb} +7 -7
  27. data/test/{lib/filelist_test.rb → test_rake_file_list.rb} +18 -22
  28. data/test/test_rake_file_list_path_map.rb +8 -0
  29. data/test/{lib/file_task_test.rb → test_rake_file_task.rb} +22 -61
  30. data/test/{lib/fileutils_test.rb → test_rake_file_utils.rb} +11 -15
  31. data/test/{lib/ftp_test.rb → test_rake_ftp_file.rb} +5 -5
  32. data/test/{functional/session_based_tests.rb → test_rake_functional.rb} +35 -24
  33. data/test/test_rake_invocation_chain.rb +52 -0
  34. data/test/{lib/makefile_loader_test.rb → test_rake_makefile_loader.rb} +2 -5
  35. data/test/{lib/multitask_test.rb → test_rake_multi_task.rb} +5 -7
  36. data/test/{lib/namespace_test.rb → test_rake_name_space.rb} +4 -16
  37. data/test/{lib/package_task_test.rb → test_rake_package_task.rb} +2 -6
  38. data/test/{lib/pathmap_test.rb → test_rake_path_map.rb} +4 -58
  39. data/test/test_rake_path_map_explode.rb +31 -0
  40. data/test/test_rake_path_map_partial.rb +18 -0
  41. data/test/{lib/pseudo_status_test.rb → test_rake_pseudo_status.rb} +2 -8
  42. data/test/{lib/rdoc_task_test.rb → test_rake_rdoc_task.rb} +4 -7
  43. data/test/{lib/require_test.rb → test_rake_require.rb} +3 -9
  44. data/test/{lib/rules_test.rb → test_rake_rules.rb} +11 -13
  45. data/test/{lib/task_test.rb → test_rake_task.rb} +16 -182
  46. data/test/test_rake_task_argument_parsing.rb +116 -0
  47. data/test/{lib/task_arguments_test.rb → test_rake_task_arguments.rb} +2 -5
  48. data/test/{lib/tasklib_test.rb → test_rake_task_lib.rb} +2 -5
  49. data/test/{lib/task_manager_test.rb → test_rake_task_manager.rb} +7 -45
  50. data/test/test_rake_task_manager_argument_resolution.rb +36 -0
  51. data/test/test_rake_task_with_arguments.rb +162 -0
  52. data/test/{lib/test_task_test.rb → test_rake_test_task.rb} +52 -7
  53. data/test/{lib/top_level_functions_test.rb → test_rake_top_level_functions.rb} +8 -20
  54. data/test/{lib/win32_test.rb → test_rake_win32.rb} +4 -12
  55. data/test/{contrib/test_sys.rb → test_sys.rb} +2 -6
  56. metadata +60 -44
  57. data/lib/rake/dsl.rb +0 -2
  58. data/test/capture_stdout.rb +0 -26
  59. data/test/functional/functional_test.rb +0 -25
  60. data/test/lib/application_test.rb +0 -863
  61. data/test/lib/dsl_test.rb +0 -52
  62. data/test/lib/invocation_chain_test.rb +0 -81
  63. data/test/lib/testtask_test.rb +0 -49
  64. data/test/rake_test_setup.rb +0 -20
  65. data/test/ruby_version_test.rb +0 -3
  66. data/test/test_helper.rb +0 -19
@@ -1,23 +1,10 @@
1
- #!/usr/bin/env ruby
1
+ require File.expand_path('../helper', __FILE__)
2
2
 
3
- begin
4
- require 'rubygems'
5
- rescue LoadError
6
- # got no gems
7
- end
8
-
9
- require 'test/unit'
10
- require 'flexmock/test_unit'
11
- require 'test/capture_stdout'
12
- require 'test/rake_test_setup'
13
- require 'rake'
14
-
15
- class TestTopLevelFunctions < Test::Unit::TestCase
16
- include CaptureStdout
17
- include TestMethods
3
+ class TestRakeTopLevelFunctions < Rake::TestCase
18
4
 
19
5
  def setup
20
6
  super
7
+
21
8
  @app = Rake.application
22
9
  Rake.application = flexmock("app")
23
10
  Rake.application.should_receive(:deprecate).
@@ -26,6 +13,7 @@ class TestTopLevelFunctions < Test::Unit::TestCase
26
13
 
27
14
  def teardown
28
15
  Rake.application = @app
16
+
29
17
  super
30
18
  end
31
19
 
@@ -42,7 +30,7 @@ class TestTopLevelFunctions < Test::Unit::TestCase
42
30
  end
43
31
 
44
32
  def test_when_writing
45
- out = capture_stdout do
33
+ out, = capture_io do
46
34
  when_writing("NOTWRITING") do
47
35
  puts "WRITING"
48
36
  end
@@ -52,12 +40,12 @@ class TestTopLevelFunctions < Test::Unit::TestCase
52
40
 
53
41
  def test_when_not_writing
54
42
  Rake::FileUtilsExt.nowrite_flag = true
55
- out = capture_stderr do
43
+ _, err = capture_io do
56
44
  when_writing("NOTWRITING") do
57
45
  puts "WRITING"
58
46
  end
59
47
  end
60
- assert_equal "DRYRUN: NOTWRITING\n", out
48
+ assert_equal "DRYRUN: NOTWRITING\n", err
61
49
  ensure
62
50
  Rake::FileUtilsExt.nowrite_flag = false
63
51
  end
@@ -83,6 +71,6 @@ class TestTopLevelFunctions < Test::Unit::TestCase
83
71
  end
84
72
 
85
73
  def test_missing_other_constant
86
- assert_exception(NameError) do Object.const_missing(:Xyz) end
74
+ assert_raises(NameError) do Object.const_missing(:Xyz) end
87
75
  end
88
76
  end
@@ -1,15 +1,7 @@
1
- #!/usr/bin/env ruby
1
+ require File.expand_path('../helper', __FILE__)
2
2
 
3
- require 'test/unit'
4
- require 'test/rake_test_setup'
5
- require 'test/in_environment'
6
-
7
- require 'rake'
8
-
9
- class TestWin32 < Test::Unit::TestCase
3
+ class TestRakeWin32 < Rake::TestCase
10
4
  include InEnvironment
11
- include TestMethods
12
- include CaptureStdout
13
5
 
14
6
  Win32 = Rake::Win32
15
7
 
@@ -64,7 +56,7 @@ class TestWin32 < Test::Unit::TestCase
64
56
  'APPDATA' => nil,
65
57
  "USERPROFILE" => nil
66
58
  ) do
67
- assert_exception(Rake::Win32::Win32HomeError) do
59
+ assert_raises(Rake::Win32::Win32HomeError) do
68
60
  Win32.win32_system_dir
69
61
  end
70
62
  end
@@ -83,7 +75,7 @@ class TestWin32 < Test::Unit::TestCase
83
75
  rake.options.trace = true
84
76
  rake.instance_variable_set(:@rakefile, 'Rakefile')
85
77
 
86
- err = capture_stderr { rake.display_error_message(ex) }
78
+ _, err = capture_io { rake.display_error_message(ex) }
87
79
 
88
80
  assert_match(/rakefile/, err)
89
81
  end
@@ -1,7 +1,4 @@
1
- #!/usr/bin/env ruby
2
-
3
- require 'test/unit'
4
- require 'test/file_creation'
1
+ require File.expand_path('../helper', __FILE__)
5
2
  begin
6
3
  old_verbose = $VERBOSE
7
4
  $VERBOSE = nil
@@ -10,8 +7,7 @@ ensure
10
7
  $VERBOSE = old_verbose
11
8
  end
12
9
 
13
- class TestSys < Test::Unit::TestCase
14
- include FileCreation
10
+ class TestSys < Rake::TestCase
15
11
 
16
12
  def test_split_all
17
13
  assert_equal ['a'], Sys.split_all('a')
metadata CHANGED
@@ -2,7 +2,7 @@
2
2
  name: rake
3
3
  version: !ruby/object:Gem::Version
4
4
  prerelease:
5
- version: 0.9.0
5
+ version: 0.9.1
6
6
  platform: ruby
7
7
  authors:
8
8
  - Jim Weirich
@@ -10,30 +10,41 @@ autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
12
 
13
- date: 2011-05-20 00:00:00 Z
13
+ date: 2011-06-01 00:00:00 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
- name: session
16
+ name: minitest
17
17
  prerelease: false
18
18
  requirement: &id001 !ruby/object:Gem::Requirement
19
19
  none: false
20
20
  requirements:
21
21
  - - ~>
22
22
  - !ruby/object:Gem::Version
23
- version: "2.4"
23
+ version: "2.1"
24
24
  type: :development
25
25
  version_requirements: *id001
26
26
  - !ruby/object:Gem::Dependency
27
- name: flexmock
27
+ name: session
28
28
  prerelease: false
29
29
  requirement: &id002 !ruby/object:Gem::Requirement
30
30
  none: false
31
31
  requirements:
32
32
  - - ~>
33
33
  - !ruby/object:Gem::Version
34
- version: 0.8.11
34
+ version: "2.4"
35
35
  type: :development
36
36
  version_requirements: *id002
37
+ - !ruby/object:Gem::Dependency
38
+ name: flexmock
39
+ prerelease: false
40
+ requirement: &id003 !ruby/object:Gem::Requirement
41
+ none: false
42
+ requirements:
43
+ - - ~>
44
+ - !ruby/object:Gem::Version
45
+ version: 0.8.11
46
+ type: :development
47
+ version_requirements: *id003
37
48
  description: " Rake is a Make-like program implemented in Ruby. Tasks\n and dependencies are specified in standard Ruby syntax.\n"
38
49
  email: jim@weirichhouse.org
39
50
  executables:
@@ -68,6 +79,7 @@ extra_rdoc_files:
68
79
  - doc/release_notes/rake-0.8.6.rdoc
69
80
  - doc/release_notes/rake-0.8.7.rdoc
70
81
  - doc/release_notes/rake-0.9.0.rdoc
82
+ - doc/release_notes/rake-0.9.1.rdoc
71
83
  files:
72
84
  - .gemtest
73
85
  - install.rb
@@ -75,6 +87,7 @@ files:
75
87
  - MIT-LICENSE
76
88
  - Rakefile
77
89
  - README.rdoc
90
+ - RRR
78
91
  - TODO
79
92
  - bin/rake
80
93
  - lib/rake/alt_system.rb
@@ -89,7 +102,6 @@ files:
89
102
  - lib/rake/contrib/sshpublisher.rb
90
103
  - lib/rake/contrib/sys.rb
91
104
  - lib/rake/default_loader.rb
92
- - lib/rake/dsl.rb
93
105
  - lib/rake/dsl_definition.rb
94
106
  - lib/rake/early_time.rb
95
107
  - lib/rake/ext/core.rb
@@ -125,52 +137,55 @@ files:
125
137
  - lib/rake/version.rb
126
138
  - lib/rake/win32.rb
127
139
  - lib/rake.rb
128
- - test/capture_stdout.rb
129
140
  - test/check_expansion.rb
130
141
  - test/check_no_expansion.rb
131
- - test/contrib/test_sys.rb
132
142
  - test/data/rakelib/test1.rb
133
143
  - test/data/rbext/rakefile.rb
134
144
  - test/file_creation.rb
135
- - test/functional/functional_test.rb
136
- - test/functional/session_based_tests.rb
145
+ - test/helper.rb
137
146
  - test/in_environment.rb
138
- - test/lib/application_test.rb
139
- - test/lib/clean_test.rb
140
- - test/lib/definitions_test.rb
141
- - test/lib/dsl_test.rb
142
- - test/lib/earlytime_test.rb
143
- - test/lib/extension_test.rb
144
- - test/lib/file_creation_task_test.rb
145
- - test/lib/file_task_test.rb
146
- - test/lib/filelist_test.rb
147
- - test/lib/fileutils_test.rb
148
- - test/lib/ftp_test.rb
149
- - test/lib/invocation_chain_test.rb
150
- - test/lib/makefile_loader_test.rb
151
- - test/lib/multitask_test.rb
152
- - test/lib/namespace_test.rb
153
- - test/lib/package_task_test.rb
154
- - test/lib/pathmap_test.rb
155
- - test/lib/pseudo_status_test.rb
156
- - test/lib/rake_test.rb
157
- - test/lib/rdoc_task_test.rb
158
- - test/lib/require_test.rb
159
- - test/lib/rules_test.rb
160
- - test/lib/task_arguments_test.rb
161
- - test/lib/task_manager_test.rb
162
- - test/lib/task_test.rb
163
- - test/lib/tasklib_test.rb
164
- - test/lib/test_task_test.rb
165
- - test/lib/testtask_test.rb
166
- - test/lib/top_level_functions_test.rb
167
- - test/lib/win32_test.rb
168
- - test/rake_test_setup.rb
169
147
  - test/reqfile.rb
170
148
  - test/reqfile2.rb
171
- - test/ruby_version_test.rb
172
149
  - test/shellcommand.rb
173
- - test/test_helper.rb
150
+ - test/test_rake.rb
151
+ - test/test_rake_application.rb
152
+ - test/test_rake_application_options.rb
153
+ - test/test_rake_clean.rb
154
+ - test/test_rake_definitions.rb
155
+ - test/test_rake_directory_task.rb
156
+ - test/test_rake_dsl.rb
157
+ - test/test_rake_early_time.rb
158
+ - test/test_rake_extension.rb
159
+ - test/test_rake_file_creation_task.rb
160
+ - test/test_rake_file_list.rb
161
+ - test/test_rake_file_list_path_map.rb
162
+ - test/test_rake_file_task.rb
163
+ - test/test_rake_file_utils.rb
164
+ - test/test_rake_ftp_file.rb
165
+ - test/test_rake_functional.rb
166
+ - test/test_rake_invocation_chain.rb
167
+ - test/test_rake_makefile_loader.rb
168
+ - test/test_rake_multi_task.rb
169
+ - test/test_rake_name_space.rb
170
+ - test/test_rake_package_task.rb
171
+ - test/test_rake_path_map.rb
172
+ - test/test_rake_path_map_explode.rb
173
+ - test/test_rake_path_map_partial.rb
174
+ - test/test_rake_pseudo_status.rb
175
+ - test/test_rake_rdoc_task.rb
176
+ - test/test_rake_require.rb
177
+ - test/test_rake_rules.rb
178
+ - test/test_rake_task.rb
179
+ - test/test_rake_task_argument_parsing.rb
180
+ - test/test_rake_task_arguments.rb
181
+ - test/test_rake_task_lib.rb
182
+ - test/test_rake_task_manager.rb
183
+ - test/test_rake_task_manager_argument_resolution.rb
184
+ - test/test_rake_task_with_arguments.rb
185
+ - test/test_rake_test_task.rb
186
+ - test/test_rake_top_level_functions.rb
187
+ - test/test_rake_win32.rb
188
+ - test/test_sys.rb
174
189
  - test/data/imports/deps.mf
175
190
  - test/data/sample.mf
176
191
  - test/data/access/Rakefile
@@ -216,6 +231,7 @@ files:
216
231
  - doc/release_notes/rake-0.8.6.rdoc
217
232
  - doc/release_notes/rake-0.8.7.rdoc
218
233
  - doc/release_notes/rake-0.9.0.rdoc
234
+ - doc/release_notes/rake-0.9.1.rdoc
219
235
  homepage: http://rake.rubyforge.org
220
236
  licenses: []
221
237
 
@@ -1,2 +0,0 @@
1
- require 'rake'
2
- include Rake::DSL
@@ -1,26 +0,0 @@
1
- #!/usr/bin/env ruby
2
-
3
- require 'stringio'
4
-
5
- # Mix-in for capturing standard output.
6
- module CaptureStdout
7
- def capture_stdout
8
- s = StringIO.new
9
- oldstdout = $stdout
10
- $stdout = s
11
- yield
12
- s.string
13
- ensure
14
- $stdout = oldstdout
15
- end
16
-
17
- def capture_stderr
18
- s = StringIO.new
19
- oldstderr = $stderr
20
- $stderr = s
21
- yield
22
- s.string
23
- ensure
24
- $stderr = oldstderr
25
- end
26
- end
@@ -1,25 +0,0 @@
1
- #!/usr/bin/env ruby
2
-
3
- begin
4
- old_verbose = $VERBOSE
5
- require 'rubygems'
6
- $VERBOSE = nil
7
- gem 'session'
8
- require 'session'
9
- rescue LoadError
10
- if File::ALT_SEPARATOR
11
- puts "Unable to run functional tests on MS Windows. Skipping."
12
- else
13
- puts "Unable to run functional tests -- please run \"gem install session\""
14
- end
15
- ensure
16
- $VERBOSE = old_verbose
17
- end
18
-
19
- if defined?(Session)
20
- if File::ALT_SEPARATOR
21
- puts "Unable to run functional tests on MS Windows. Skipping."
22
- else
23
- require 'test/functional/session_based_tests.rb'
24
- end
25
- end
@@ -1,863 +0,0 @@
1
- #!/usr/bin/env ruby
2
-
3
- begin
4
- require 'rubygems'
5
- rescue LoadError
6
- # got no gems
7
- end
8
-
9
- require 'test/unit'
10
- require 'rake'
11
- require 'test/rake_test_setup'
12
- require 'test/capture_stdout'
13
- require 'test/in_environment'
14
-
15
- TESTING_REQUIRE = [ ]
16
-
17
- ######################################################################
18
- class TestApplication < Test::Unit::TestCase
19
- include CaptureStdout
20
- include InEnvironment
21
- include TestMethods
22
-
23
- def setup
24
- super
25
- @app = Rake::Application.new
26
- @app.options.rakelib = []
27
- Rake::TaskManager.record_task_metadata = true
28
- end
29
-
30
- def teardown
31
- Rake::TaskManager.record_task_metadata = false
32
- super
33
- end
34
-
35
- def test_constant_warning
36
- error_messages = capture_stderr do @app.instance_eval { const_warning("Task") } end
37
- assert_match(/warning/i, error_messages)
38
- assert_match(/deprecated/i, error_messages)
39
- assert_match(/Task/i, error_messages)
40
- end
41
-
42
- def test_display_tasks
43
- @app.options.show_tasks = :tasks
44
- @app.options.show_task_pattern = //
45
- @app.last_description = "COMMENT"
46
- @app.define_task(Rake::Task, "t")
47
- out = capture_stdout do @app.instance_eval { display_tasks_and_comments } end
48
- assert_match(/^rake t/, out)
49
- assert_match(/# COMMENT/, out)
50
- end
51
-
52
- def test_display_tasks_with_long_comments
53
- in_environment('RAKE_COLUMNS' => '80') do
54
- @app.options.show_tasks = :tasks
55
- @app.options.show_task_pattern = //
56
- @app.last_description = "1234567890" * 8
57
- @app.define_task(Rake::Task, "t")
58
- out = capture_stdout do @app.instance_eval { display_tasks_and_comments } end
59
- assert_match(/^rake t/, out)
60
- assert_match(/# 12345678901234567890123456789012345678901234567890123456789012345\.\.\./, out)
61
- end
62
- end
63
-
64
- def test_display_tasks_with_task_name_wider_than_tty_display
65
- in_environment('RAKE_COLUMNS' => '80') do
66
- @app.options.show_tasks = :tasks
67
- @app.options.show_task_pattern = //
68
- task_name = "task name" * 80
69
- @app.last_description = "something short"
70
- @app.define_task(Rake::Task, task_name )
71
- out = capture_stdout do @app.instance_eval { display_tasks_and_comments } end
72
- # Ensure the entire task name is output and we end up showing no description
73
- assert_match(/rake #{task_name} # .../, out)
74
- end
75
- end
76
-
77
- def test_display_tasks_with_very_long_task_name_to_a_non_tty_shows_name_and_comment
78
- @app.options.show_tasks = :tasks
79
- @app.options.show_task_pattern = //
80
- @app.tty_output = false
81
- description = "something short"
82
- task_name = "task name" * 80
83
- @app.last_description = "something short"
84
- @app.define_task(Rake::Task, task_name )
85
- out = capture_stdout do @app.instance_eval { display_tasks_and_comments } end
86
- # Ensure the entire task name is output and we end up showing no description
87
- assert_match(/rake #{task_name} # #{description}/, out)
88
- end
89
-
90
- def test_display_tasks_with_long_comments_to_a_non_tty_shows_entire_comment
91
- @app.options.show_tasks = :tasks
92
- @app.options.show_task_pattern = //
93
- @app.tty_output = false
94
- @app.last_description = "1234567890" * 8
95
- @app.define_task(Rake::Task, "t")
96
- out = capture_stdout do @app.instance_eval { display_tasks_and_comments } end
97
- assert_match(/^rake t/, out)
98
- assert_match(/# #{@app.last_description}/, out)
99
- end
100
-
101
- def test_display_tasks_with_long_comments_to_a_non_tty_with_columns_set_truncates_comments
102
- in_environment("RAKE_COLUMNS" => '80') do
103
- @app.options.show_tasks = :tasks
104
- @app.options.show_task_pattern = //
105
- @app.tty_output = false
106
- @app.last_description = "1234567890" * 8
107
- @app.define_task(Rake::Task, "t")
108
- out = capture_stdout do @app.instance_eval { display_tasks_and_comments } end
109
- assert_match(/^rake t/, out)
110
- assert_match(/# 12345678901234567890123456789012345678901234567890123456789012345\.\.\./, out)
111
- end
112
- end
113
-
114
- def test_describe_tasks
115
- @app.options.show_tasks = :describe
116
- @app.options.show_task_pattern = //
117
- @app.last_description = "COMMENT"
118
- @app.define_task(Rake::Task, "t")
119
- out = capture_stdout do @app.instance_eval { display_tasks_and_comments } end
120
- assert_match(/^rake t$/, out)
121
- assert_match(/^ {4}COMMENT$/, out)
122
- end
123
-
124
- def test_show_lines
125
- @app.options.show_tasks = :lines
126
- @app.options.show_task_pattern = //
127
- @app.last_description = "COMMENT"
128
- @app.define_task(Rake::Task, "t")
129
- @app['t'].locations << "HERE:1"
130
- out = capture_stdout do @app.instance_eval { display_tasks_and_comments } end
131
- assert_match(/^rake t +[^:]+:\d+ *$/, out)
132
- end
133
-
134
- def test_finding_rakefile
135
- assert_match(/Rakefile/i, @app.instance_eval { have_rakefile })
136
- end
137
-
138
- def test_not_finding_rakefile
139
- @app.instance_eval { @rakefiles = ['NEVER_FOUND'] }
140
- assert( ! @app.instance_eval do have_rakefile end )
141
- assert_nil @app.rakefile
142
- end
143
-
144
- def test_load_rakefile
145
- in_environment("PWD" => "test/data/unittest") do
146
- @app.instance_eval do
147
- handle_options
148
- options.silent = true
149
- load_rakefile
150
- end
151
- assert_equal "rakefile", @app.rakefile.downcase
152
- assert_match(%r(unittest$), Dir.pwd)
153
- end
154
- end
155
-
156
- def test_load_rakefile_doesnt_print_rakefile_directory_from_same_dir
157
- in_environment("PWD" => "test/data/unittest") do
158
- error_messages = capture_stderr do
159
- @app.instance_eval do
160
- @original_dir = File.expand_path(".") # pretend we started from the unittest dir
161
- raw_load_rakefile
162
- end
163
- end
164
- _, location = @app.find_rakefile_location
165
- assert_no_match(/\(in #{location}\)/, error_messages)
166
- end
167
- end
168
-
169
- def test_load_rakefile_from_subdir
170
- in_environment("PWD" => "test/data/unittest/subdir") do
171
- @app.instance_eval do
172
- handle_options
173
- options.silent = true
174
- load_rakefile
175
- end
176
- assert_equal "rakefile", @app.rakefile.downcase
177
- assert_match(%r(unittest$), Dir.pwd)
178
- end
179
- end
180
-
181
- def test_load_rakefile_prints_rakefile_directory_from_subdir
182
- in_environment("PWD" => "test/data/unittest/subdir") do
183
- error_messages = capture_stderr do
184
- @app.instance_eval do
185
- raw_load_rakefile
186
- end
187
- end
188
- _, location = @app.find_rakefile_location
189
- assert_match(/\(in #{location}\)/, error_messages)
190
- end
191
- end
192
-
193
- def test_load_rakefile_doesnt_print_rakefile_directory_from_subdir_if_silent
194
- in_environment("PWD" => "test/data/unittest/subdir") do
195
- error_messages = capture_stderr do
196
- @app.instance_eval do
197
- handle_options
198
- options.silent = true
199
- raw_load_rakefile
200
- end
201
- end
202
- _, location = @app.find_rakefile_location
203
- assert_no_match(/\(in #{location}\)/, error_messages)
204
- end
205
- end
206
-
207
- def test_load_rakefile_not_found
208
- in_environment("PWD" => "/", "RAKE_SYSTEM" => 'not_exist') do
209
- @app.instance_eval do
210
- handle_options
211
- options.silent = true
212
- end
213
- ex = assert_exception(RuntimeError) do
214
- @app.instance_eval do raw_load_rakefile end
215
- end
216
- assert_match(/no rakefile found/i, ex.message)
217
- end
218
- end
219
-
220
- def test_load_from_system_rakefile
221
- in_environment('RAKE_SYSTEM' => 'test/data/sys') do
222
- @app.options.rakelib = []
223
- @app.instance_eval do
224
- handle_options
225
- options.silent = true
226
- options.load_system = true
227
- options.rakelib = []
228
- load_rakefile
229
- end
230
- assert_equal "test/data/sys", @app.system_dir
231
- assert_nil @app.rakefile
232
- end
233
- end
234
-
235
- def test_load_from_calculated_system_rakefile
236
- flexmock(@app, :standard_system_dir => "__STD_SYS_DIR__")
237
- in_environment('RAKE_SYSTEM' => nil) do
238
- @app.options.rakelib = []
239
- @app.instance_eval do
240
- handle_options
241
- options.silent = true
242
- options.load_system = true
243
- options.rakelib = []
244
- load_rakefile
245
- end
246
- assert_equal "__STD_SYS_DIR__", @app.system_dir
247
- end
248
- end
249
-
250
- def test_windows
251
- assert ! (@app.windows? && @app.unix?)
252
- end
253
-
254
- def test_loading_imports
255
- mock = flexmock("loader")
256
- mock.should_receive(:load).with("x.dummy").once
257
- @app.instance_eval do
258
- add_loader("dummy", mock)
259
- add_import("x.dummy")
260
- load_imports
261
- end
262
- end
263
-
264
- def test_building_imported_files_on_demand
265
- mock = flexmock("loader")
266
- mock.should_receive(:load).with("x.dummy").once
267
- mock.should_receive(:make_dummy).with_no_args.once
268
- @app.instance_eval do
269
- intern(Rake::Task, "x.dummy").enhance do mock.make_dummy end
270
- add_loader("dummy", mock)
271
- add_import("x.dummy")
272
- load_imports
273
- end
274
- end
275
-
276
- def test_handle_options_should_strip_options_from_ARGV
277
- assert !@app.options.trace
278
-
279
- valid_option = '--trace'
280
- ARGV.clear
281
- ARGV << valid_option
282
-
283
- @app.handle_options
284
-
285
- assert !ARGV.include?(valid_option)
286
- assert @app.options.trace
287
- end
288
-
289
- def test_good_run
290
- ran = false
291
- ARGV.clear
292
- ARGV << '--rakelib=""'
293
- @app.options.silent = true
294
- @app.instance_eval do
295
- intern(Rake::Task, "default").enhance { ran = true }
296
- end
297
- in_environment("PWD" => "test/data/default") do
298
- @app.run
299
- end
300
- assert ran
301
- end
302
-
303
- def test_display_task_run
304
- ran = false
305
- ARGV.clear
306
- ARGV << '-f' << '-s' << '--tasks' << '--rakelib=""'
307
- @app.last_description = "COMMENT"
308
- @app.define_task(Rake::Task, "default")
309
- out = capture_stdout { @app.run }
310
- assert @app.options.show_tasks
311
- assert ! ran
312
- assert_match(/rake default/, out)
313
- assert_match(/# COMMENT/, out)
314
- end
315
-
316
- def test_display_prereqs
317
- ran = false
318
- ARGV.clear
319
- ARGV << '-f' << '-s' << '--prereqs' << '--rakelib=""'
320
- @app.last_description = "COMMENT"
321
- t = @app.define_task(Rake::Task, "default")
322
- t.enhance([:a, :b])
323
- @app.define_task(Rake::Task, "a")
324
- @app.define_task(Rake::Task, "b")
325
- out = capture_stdout { @app.run }
326
- assert @app.options.show_prereqs
327
- assert ! ran
328
- assert_match(/rake a$/, out)
329
- assert_match(/rake b$/, out)
330
- assert_match(/rake default\n( *(a|b)\n){2}/m, out)
331
- end
332
-
333
- def test_bad_run
334
- @app.intern(Rake::Task, "default").enhance { fail }
335
- ARGV.clear
336
- ARGV << '-f' << '-s' << '--rakelib=""'
337
- assert_exception(SystemExit) {
338
- error_messages = capture_stderr { @app.run }
339
- assert_match(/see full trace/, error_messages)
340
- }
341
- ensure
342
- ARGV.clear
343
- end
344
-
345
- def test_bad_run_with_trace
346
- @app.intern(Rake::Task, "default").enhance { fail }
347
- ARGV.clear
348
- ARGV << '-f' << '-s' << '-t'
349
- assert_exception(SystemExit) {
350
- error_messages = capture_stderr { capture_stdout { @app.run } }
351
- assert_no_match(/see full trace/, error_messages)
352
- }
353
- ensure
354
- ARGV.clear
355
- end
356
-
357
- def test_run_with_bad_options
358
- @app.intern(Rake::Task, "default").enhance { fail }
359
- ARGV.clear
360
- ARGV << '-f' << '-s' << '--xyzzy'
361
- assert_exception(SystemExit) {
362
- capture_stderr { capture_stdout { @app.run } }
363
- }
364
- ensure
365
- ARGV.clear
366
- end
367
-
368
- def test_deprecation_message
369
- in_environment do
370
- error_messages = capture_stderr do
371
- @app.deprecate("a", "b", "c")
372
- end
373
- assert_match(/'a' is deprecated/i, error_messages)
374
- assert_match(/use 'b' instead/i, error_messages)
375
- assert_match(/at c$/i, error_messages)
376
- end
377
- end
378
- end
379
-
380
-
381
- ######################################################################
382
- class TestApplicationOptions < Test::Unit::TestCase
383
- include CaptureStdout
384
- include TestMethods
385
- include InEnvironment
386
-
387
- def setup
388
- clear_argv
389
- Rake::FileUtilsExt.verbose_flag = false
390
- Rake::FileUtilsExt.nowrite_flag = false
391
- TESTING_REQUIRE.clear
392
- end
393
-
394
- def teardown
395
- clear_argv
396
- Rake::FileUtilsExt.verbose_flag = false
397
- Rake::FileUtilsExt.nowrite_flag = false
398
- end
399
-
400
- def clear_argv
401
- while ! ARGV.empty?
402
- ARGV.pop
403
- end
404
- end
405
-
406
- def test_default_options
407
- in_environment("RAKEOPT" => nil) do
408
- opts = command_line
409
- assert_nil opts.classic_namespace
410
- assert_nil opts.dryrun
411
- assert_nil opts.ignore_system
412
- assert_nil opts.load_system
413
- assert_nil opts.nosearch
414
- assert_equal ['rakelib'], opts.rakelib
415
- assert_nil opts.show_prereqs
416
- assert_nil opts.show_task_pattern
417
- assert_nil opts.show_tasks
418
- assert_nil opts.silent
419
- assert_nil opts.trace
420
- assert_equal ['rakelib'], opts.rakelib
421
- assert ! Rake::FileUtilsExt.verbose_flag
422
- assert ! Rake::FileUtilsExt.nowrite_flag
423
- end
424
- end
425
-
426
- def test_dry_run
427
- in_environment do
428
- flags('--dry-run', '-n') do |opts|
429
- assert opts.dryrun
430
- assert opts.trace
431
- assert Rake::FileUtilsExt.verbose_flag
432
- assert Rake::FileUtilsExt.nowrite_flag
433
- end
434
- end
435
- end
436
-
437
- def test_describe
438
- in_environment do
439
- flags('--describe') do |opts|
440
- assert_equal :describe, opts.show_tasks
441
- assert_equal(//.to_s, opts.show_task_pattern.to_s)
442
- end
443
- end
444
- end
445
-
446
- def test_describe_with_pattern
447
- in_environment do
448
- flags('--describe=X') do |opts|
449
- assert_equal :describe, opts.show_tasks
450
- assert_equal(/X/.to_s, opts.show_task_pattern.to_s)
451
- end
452
- end
453
- end
454
-
455
- def test_execute
456
- in_environment do
457
- $xyzzy = 0
458
- flags('--execute=$xyzzy=1', '-e $xyzzy=1') do |opts|
459
- assert_equal 1, $xyzzy
460
- assert_equal :exit, @exit
461
- $xyzzy = 0
462
- end
463
- end
464
- end
465
-
466
- def test_execute_and_continue
467
- in_environment do
468
- $xyzzy = 0
469
- flags('--execute-continue=$xyzzy=1', '-E $xyzzy=1') do |opts|
470
- assert_equal 1, $xyzzy
471
- assert_not_equal :exit, @exit
472
- $xyzzy = 0
473
- end
474
- end
475
- end
476
-
477
- def test_execute_and_print
478
- in_environment do
479
- $xyzzy = 0
480
- flags('--execute-print=$xyzzy="pugh"', '-p $xyzzy="pugh"') do |opts|
481
- assert_equal 'pugh', $xyzzy
482
- assert_equal :exit, @exit
483
- assert_match(/^pugh$/, @out)
484
- $xyzzy = 0
485
- end
486
- end
487
- end
488
-
489
- def test_help
490
- in_environment do
491
- flags('--help', '-H', '-h') do |opts|
492
- assert_match(/\Arake/, @out)
493
- assert_match(/\boptions\b/, @out)
494
- assert_match(/\btargets\b/, @out)
495
- assert_equal :exit, @exit
496
- assert_equal :exit, @exit
497
- end
498
- end
499
- end
500
-
501
- def test_libdir
502
- in_environment do
503
- flags(['--libdir', 'xx'], ['-I', 'xx'], ['-Ixx']) do |opts|
504
- $:.include?('xx')
505
- end
506
- end
507
- ensure
508
- $:.delete('xx')
509
- end
510
-
511
- def test_rakefile
512
- in_environment do
513
- flags(['--rakefile', 'RF'], ['--rakefile=RF'], ['-f', 'RF'], ['-fRF']) do |opts|
514
- assert_equal ['RF'], @app.instance_eval { @rakefiles }
515
- end
516
- end
517
- end
518
-
519
- def test_rakelib
520
- in_environment do
521
- flags(['--rakelibdir', 'A:B:C'], ['--rakelibdir=A:B:C'], ['-R', 'A:B:C'], ['-RA:B:C']) do |opts|
522
- assert_equal ['A', 'B', 'C'], opts.rakelib
523
- end
524
- end
525
- end
526
-
527
- def test_require
528
- in_environment do
529
- flags(['--require', 'test/reqfile'], '-rtest/reqfile2', '-rtest/reqfile3') do |opts|
530
- end
531
- assert TESTING_REQUIRE.include?(1)
532
- assert TESTING_REQUIRE.include?(2)
533
- assert TESTING_REQUIRE.include?(3)
534
- assert_equal 3, TESTING_REQUIRE.size
535
- end
536
- end
537
-
538
- def test_missing_require
539
- in_environment do
540
- ex = assert_exception(LoadError) do
541
- flags(['--require', 'test/missing']) do |opts|
542
- end
543
- end
544
- assert_match(/such file/, ex.message)
545
- assert_match(/test\/missing/, ex.message)
546
- end
547
- end
548
-
549
- def test_prereqs
550
- in_environment do
551
- flags('--prereqs', '-P') do |opts|
552
- assert opts.show_prereqs
553
- end
554
- end
555
- end
556
-
557
- def test_quiet
558
- in_environment do
559
- flags('--quiet', '-q') do |opts|
560
- assert ! Rake::FileUtilsExt.verbose_flag
561
- assert ! opts.silent
562
- end
563
- end
564
- end
565
-
566
- def test_no_search
567
- in_environment do
568
- flags('--nosearch', '--no-search', '-N') do |opts|
569
- assert opts.nosearch
570
- end
571
- end
572
- end
573
-
574
- def test_silent
575
- in_environment do
576
- flags('--silent', '-s') do |opts|
577
- assert ! Rake::FileUtilsExt.verbose_flag
578
- assert opts.silent
579
- end
580
- end
581
- end
582
-
583
- def test_system
584
- in_environment do
585
- flags('--system', '-g') do |opts|
586
- assert opts.load_system
587
- end
588
- end
589
- end
590
-
591
- def test_no_system
592
- in_environment do
593
- flags('--no-system', '-G') do |opts|
594
- assert opts.ignore_system
595
- end
596
- end
597
- end
598
-
599
- def test_trace
600
- in_environment do
601
- flags('--trace', '-t') do |opts|
602
- assert opts.trace
603
- assert Rake::FileUtilsExt.verbose_flag
604
- assert ! Rake::FileUtilsExt.nowrite_flag
605
- end
606
- end
607
- end
608
-
609
- def test_trace_rules
610
- in_environment do
611
- flags('--rules') do |opts|
612
- assert opts.trace_rules
613
- end
614
- end
615
- end
616
-
617
- def test_tasks
618
- in_environment do
619
- flags('--tasks', '-T') do |opts|
620
- assert_equal :tasks, opts.show_tasks
621
- assert_equal(//.to_s, opts.show_task_pattern.to_s)
622
- end
623
- flags(['--tasks', 'xyz'], ['-Txyz']) do |opts|
624
- assert_equal :tasks, opts.show_tasks
625
- assert_equal(/xyz/.to_s, opts.show_task_pattern.to_s)
626
- end
627
- end
628
- end
629
-
630
- def test_where
631
- in_environment do
632
- flags('--where', '-W') do |opts|
633
- assert_equal :lines, opts.show_tasks
634
- assert_equal(//.to_s, opts.show_task_pattern.to_s)
635
- end
636
- flags(['--where', 'xyz'], ['-Wxyz']) do |opts|
637
- assert_equal :lines, opts.show_tasks
638
- assert_equal(/xyz/.to_s, opts.show_task_pattern.to_s)
639
- end
640
- end
641
- end
642
-
643
- def test_no_deprecated_messages
644
- in_environment do
645
- flags('--no-deprecation-warnings', '-X') do |opts|
646
- assert opts.ignore_deprecate
647
- end
648
- end
649
- end
650
-
651
- def test_verbose
652
- in_environment do
653
- flags('--verbose', '-V') do |opts|
654
- assert Rake::FileUtilsExt.verbose_flag
655
- assert ! opts.silent
656
- end
657
- end
658
- end
659
-
660
- def test_version
661
- in_environment do
662
- flags('--version', '-V') do |opts|
663
- assert_match(/\bversion\b/, @out)
664
- assert_match(/\b#{RAKEVERSION}\b/, @out)
665
- assert_equal :exit, @exit
666
- end
667
- end
668
- end
669
-
670
- def test_classic_namespace
671
- in_environment do
672
- error_messages = capture_stderr do
673
- flags(['--classic-namespace'], ['-C', '-T', '-P', '-n', '-s', '-t']) do |opts|
674
- assert opts.classic_namespace
675
- assert_equal opts.show_tasks, $show_tasks
676
- assert_equal opts.show_prereqs, $show_prereqs
677
- assert_equal opts.trace, $trace
678
- assert_equal opts.dryrun, $dryrun
679
- assert_equal opts.silent, $silent
680
- end
681
- end
682
- assert_match(/deprecated/, error_messages)
683
- end
684
- end
685
-
686
- def test_bad_option
687
- in_environment do
688
- error_messages = capture_stderr do
689
- ex = assert_exception(OptionParser::InvalidOption) do
690
- flags('--bad-option')
691
- end
692
- if ex.message =~ /^While/ # Ruby 1.9 error message
693
- assert_match(/while parsing/i, ex.message)
694
- else # Ruby 1.8 error message
695
- assert_match(/(invalid|unrecognized) option/i, ex.message)
696
- assert_match(/--bad-option/, ex.message)
697
- end
698
- end
699
- assert_equal '', error_messages
700
- end
701
- end
702
-
703
- def test_task_collection
704
- command_line("a", "b")
705
- assert_equal ["a", "b"], @tasks.sort
706
- end
707
-
708
- def test_default_task_collection
709
- command_line()
710
- assert_equal ["default"], @tasks
711
- end
712
-
713
- def test_environment_definition
714
- ENV.delete('TESTKEY')
715
- command_line("a", "TESTKEY=12")
716
- assert_equal ["a"], @tasks.sort
717
- assert '12', ENV['TESTKEY']
718
- end
719
-
720
- private
721
-
722
- def flags(*sets)
723
- sets.each do |set|
724
- ARGV.clear
725
- @out = capture_stdout {
726
- @exit = catch(:system_exit) { command_line(*set) }
727
- }
728
- yield(@app.options) if block_given?
729
- end
730
- end
731
-
732
- def command_line(*options)
733
- options.each do |opt| ARGV << opt end
734
- @app = Rake::Application.new
735
- def @app.exit(*args)
736
- throw :system_exit, :exit
737
- end
738
- @app.instance_eval do
739
- handle_options
740
- collect_tasks
741
- end
742
- @tasks = @app.top_level_tasks
743
- @app.options
744
- end
745
- end
746
-
747
- class TestTaskArgumentParsing < Test::Unit::TestCase
748
- def setup
749
- @app = Rake::Application.new
750
- end
751
-
752
- def test_name_only
753
- name, args = @app.parse_task_string("name")
754
- assert_equal "name", name
755
- assert_equal [], args
756
- end
757
-
758
- def test_empty_args
759
- name, args = @app.parse_task_string("name[]")
760
- assert_equal "name", name
761
- assert_equal [], args
762
- end
763
-
764
- def test_one_argument
765
- name, args = @app.parse_task_string("name[one]")
766
- assert_equal "name", name
767
- assert_equal ["one"], args
768
- end
769
-
770
- def test_two_arguments
771
- name, args = @app.parse_task_string("name[one,two]")
772
- assert_equal "name", name
773
- assert_equal ["one", "two"], args
774
- end
775
-
776
- def test_can_handle_spaces_between_args
777
- name, args = @app.parse_task_string("name[one, two,\tthree , \tfour]")
778
- assert_equal "name", name
779
- assert_equal ["one", "two", "three", "four"], args
780
- end
781
-
782
- def test_keeps_embedded_spaces
783
- name, args = @app.parse_task_string("name[a one ana, two]")
784
- assert_equal "name", name
785
- assert_equal ["a one ana", "two"], args
786
- end
787
-
788
- end
789
-
790
- class TestTaskArgumentParsing < Test::Unit::TestCase
791
- include InEnvironment
792
-
793
- def test_terminal_width_using_env
794
- app = Rake::Application.new
795
- in_environment('RAKE_COLUMNS' => '1234') do
796
- assert_equal 1234, app.terminal_width
797
- end
798
- end
799
-
800
- def test_terminal_width_using_stty
801
- app = Rake::Application.new
802
- flexmock(app,
803
- :unix? => true,
804
- :dynamic_width_stty => 1235,
805
- :dynamic_width_tput => 0)
806
- in_environment('RAKE_COLUMNS' => nil) do
807
- assert_equal 1235, app.terminal_width
808
- end
809
- end
810
-
811
- def test_terminal_width_using_tput
812
- app = Rake::Application.new
813
- flexmock(app,
814
- :unix? => true,
815
- :dynamic_width_stty => 0,
816
- :dynamic_width_tput => 1236)
817
- in_environment('RAKE_COLUMNS' => nil) do
818
- assert_equal 1236, app.terminal_width
819
- end
820
- end
821
-
822
- def test_terminal_width_using_hardcoded_80
823
- app = Rake::Application.new
824
- flexmock(app, :unix? => false)
825
- in_environment('RAKE_COLUMNS' => nil) do
826
- assert_equal 80, app.terminal_width
827
- end
828
- end
829
-
830
- def test_terminal_width_with_failure
831
- app = Rake::Application.new
832
- flexmock(app).should_receive(:unix?).and_throw(RuntimeError)
833
- in_environment('RAKE_COLUMNS' => nil) do
834
- assert_equal 80, app.terminal_width
835
- end
836
- end
837
-
838
- def test_no_rakeopt
839
- in_environment do
840
- ARGV << '--trace'
841
- app = Rake::Application.new
842
- app.init
843
- assert !app.options.silent
844
- end
845
- end
846
-
847
- def test_rakeopt_with_blank_options
848
- in_environment("RAKEOPT" => "") do
849
- ARGV << '--trace'
850
- app = Rake::Application.new
851
- app.init
852
- assert !app.options.silent
853
- end
854
- end
855
-
856
- def test_rakeopt_with_silent_options
857
- in_environment("RAKEOPT" => "-s") do
858
- app = Rake::Application.new
859
- app.init
860
- assert app.options.silent
861
- end
862
- end
863
- end