rake 0.8.7 → 0.9.2

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 (140) hide show
  1. data/.gemtest +0 -0
  2. data/CHANGES +78 -9
  3. data/{README → README.rdoc} +14 -10
  4. data/RRR +9 -0
  5. data/Rakefile +100 -125
  6. data/TODO +1 -1
  7. data/bin/rake +4 -3
  8. data/doc/command_line_usage.rdoc +18 -6
  9. data/doc/glossary.rdoc +2 -2
  10. data/doc/jamis.rb +2 -2
  11. data/doc/proto_rake.rdoc +22 -22
  12. data/doc/rake.1.gz +0 -0
  13. data/doc/rakefile.rdoc +56 -33
  14. data/doc/rational.rdoc +6 -6
  15. data/doc/release_notes/rake-0.4.15.rdoc +1 -1
  16. data/doc/release_notes/rake-0.5.0.rdoc +1 -1
  17. data/doc/release_notes/rake-0.7.0.rdoc +1 -1
  18. data/doc/release_notes/rake-0.7.2.rdoc +3 -3
  19. data/doc/release_notes/rake-0.7.3.rdoc +2 -2
  20. data/doc/release_notes/rake-0.8.0.rdoc +1 -1
  21. data/doc/release_notes/rake-0.8.2.rdoc +3 -3
  22. data/doc/release_notes/rake-0.8.3.rdoc +2 -2
  23. data/doc/release_notes/rake-0.8.4.rdoc +1 -1
  24. data/doc/release_notes/rake-0.8.5.rdoc +1 -1
  25. data/doc/release_notes/rake-0.8.6.rdoc +1 -1
  26. data/doc/release_notes/rake-0.8.7.rdoc +1 -1
  27. data/doc/release_notes/rake-0.9.0.rdoc +112 -0
  28. data/doc/release_notes/rake-0.9.1.rdoc +52 -0
  29. data/doc/release_notes/rake-0.9.2.rdoc +49 -0
  30. data/install.rb +14 -12
  31. data/lib/rake/alt_system.rb +7 -6
  32. data/lib/rake/application.rb +589 -0
  33. data/lib/rake/classic_namespace.rb +1 -0
  34. data/lib/rake/clean.rb +2 -4
  35. data/lib/rake/cloneable.rb +25 -0
  36. data/lib/rake/contrib/compositepublisher.rb +2 -5
  37. data/lib/rake/contrib/ftptools.rb +5 -8
  38. data/lib/rake/contrib/publisher.rb +2 -8
  39. data/lib/rake/contrib/rubyforgepublisher.rb +2 -4
  40. data/lib/rake/contrib/sshpublisher.rb +4 -6
  41. data/lib/rake/contrib/sys.rb +7 -25
  42. data/lib/rake/default_loader.rb +10 -0
  43. data/lib/rake/dsl_definition.rb +167 -0
  44. data/lib/rake/early_time.rb +18 -0
  45. data/lib/rake/ext/core.rb +27 -0
  46. data/lib/rake/ext/module.rb +39 -0
  47. data/lib/rake/ext/string.rb +167 -0
  48. data/lib/rake/ext/time.rb +14 -0
  49. data/lib/rake/file_creation_task.rb +24 -0
  50. data/lib/rake/file_list.rb +403 -0
  51. data/lib/rake/file_task.rb +47 -0
  52. data/lib/rake/file_utils.rb +112 -0
  53. data/lib/rake/file_utils_ext.rb +142 -0
  54. data/lib/rake/gempackagetask.rb +6 -90
  55. data/lib/rake/invocation_chain.rb +51 -0
  56. data/lib/rake/invocation_exception_mixin.rb +16 -0
  57. data/lib/rake/loaders/makefile.rb +13 -15
  58. data/lib/rake/multi_task.rb +16 -0
  59. data/lib/rake/name_space.rb +25 -0
  60. data/lib/rake/packagetask.rb +13 -12
  61. data/lib/rake/pathmap.rb +1 -0
  62. data/lib/rake/pseudo_status.rb +24 -0
  63. data/lib/rake/rake_module.rb +29 -0
  64. data/lib/rake/rake_test_loader.rb +10 -2
  65. data/lib/rake/rdoctask.rb +211 -190
  66. data/lib/rake/ruby182_test_unit_fix.rb +9 -7
  67. data/lib/rake/rule_recursion_overflow_error.rb +20 -0
  68. data/lib/rake/runtest.rb +4 -6
  69. data/lib/rake/task.rb +327 -0
  70. data/lib/rake/task_argument_error.rb +7 -0
  71. data/lib/rake/task_arguments.rb +74 -0
  72. data/lib/rake/task_manager.rb +307 -0
  73. data/lib/rake/tasklib.rb +1 -2
  74. data/lib/rake/testtask.rb +57 -27
  75. data/lib/rake/version.rb +10 -0
  76. data/lib/rake/win32.rb +4 -4
  77. data/lib/rake.rb +29 -2470
  78. data/test/data/access/Rakefile +35 -0
  79. data/test/data/comments/Rakefile +18 -0
  80. data/test/data/default/Rakefile +1 -3
  81. data/test/data/deprecated_import/Rakefile +1 -0
  82. data/test/data/dryrun/Rakefile +1 -1
  83. data/test/data/extra/Rakefile +1 -0
  84. data/test/data/file_creation_task/Rakefile +1 -3
  85. data/test/data/multidesc/Rakefile +0 -2
  86. data/test/data/namespace/Rakefile +9 -2
  87. data/test/data/rakelib/test1.rb +1 -0
  88. data/test/data/statusreturn/Rakefile +0 -2
  89. data/test/data/verbose/Rakefile +34 -0
  90. data/test/{filecreation.rb → file_creation.rb} +11 -9
  91. data/test/helper.rb +44 -0
  92. data/test/in_environment.rb +11 -6
  93. data/test/test_rake.rb +3 -6
  94. data/test/test_rake_application.rb +364 -0
  95. data/test/test_rake_application_options.rb +382 -0
  96. data/test/{test_clean.rb → test_rake_clean.rb} +2 -4
  97. data/test/{test_definitions.rb → test_rake_definitions.rb} +7 -12
  98. data/test/test_rake_directory_task.rb +55 -0
  99. data/test/test_rake_dsl.rb +73 -0
  100. data/test/{test_earlytime.rb → test_rake_early_time.rb} +3 -7
  101. data/test/{test_extension.rb → test_rake_extension.rb} +4 -8
  102. data/test/{test_file_creation_task.rb → test_rake_file_creation_task.rb} +7 -7
  103. data/test/{test_filelist.rb → test_rake_file_list.rb} +45 -35
  104. data/test/test_rake_file_list_path_map.rb +8 -0
  105. data/test/{test_file_task.rb → test_rake_file_task.rb} +23 -62
  106. data/test/{test_fileutils.rb → test_rake_file_utils.rb} +34 -33
  107. data/test/{test_ftp.rb → test_rake_ftp_file.rb} +5 -5
  108. data/test/{session_functional.rb → test_rake_functional.rb} +173 -44
  109. data/test/test_rake_invocation_chain.rb +52 -0
  110. data/test/{test_makefile_loader.rb → test_rake_makefile_loader.rb} +2 -5
  111. data/test/{test_multitask.rb → test_rake_multi_task.rb} +18 -12
  112. data/test/{test_namespace.rb → test_rake_name_space.rb} +4 -16
  113. data/test/test_rake_package_task.rb +78 -0
  114. data/test/{test_pathmap.rb → test_rake_path_map.rb} +5 -58
  115. data/test/test_rake_path_map_explode.rb +31 -0
  116. data/test/test_rake_path_map_partial.rb +18 -0
  117. data/test/{test_pseudo_status.rb → test_rake_pseudo_status.rb} +2 -8
  118. data/test/{test_rdoc_task.rb → test_rake_rdoc_task.rb} +22 -29
  119. data/test/{test_require.rb → test_rake_require.rb} +11 -11
  120. data/test/{test_rules.rb → test_rake_rules.rb} +12 -15
  121. data/test/{test_tasks.rb → test_rake_task.rb} +75 -178
  122. data/test/test_rake_task_argument_parsing.rb +116 -0
  123. data/test/{test_task_arguments.rb → test_rake_task_arguments.rb} +7 -10
  124. data/test/{test_tasklib.rb → test_rake_task_lib.rb} +2 -5
  125. data/test/{test_task_manager.rb → test_rake_task_manager.rb} +12 -40
  126. data/test/test_rake_task_manager_argument_resolution.rb +36 -0
  127. data/test/test_rake_task_with_arguments.rb +162 -0
  128. data/test/test_rake_test_task.rb +122 -0
  129. data/test/{test_top_level_functions.rb → test_rake_top_level_functions.rb} +12 -22
  130. data/test/{test_win32.rb → test_rake_win32.rb} +21 -10
  131. data/test/test_sys.rb +20 -0
  132. metadata +129 -51
  133. data/test/capture_stdout.rb +0 -26
  134. data/test/contrib/test_sys.rb +0 -47
  135. data/test/functional.rb +0 -15
  136. data/test/rake_test_setup.rb +0 -24
  137. data/test/test_application.rb +0 -675
  138. data/test/test_invocation_chain.rb +0 -81
  139. data/test/test_package_task.rb +0 -118
  140. data/test/test_test_task.rb +0 -77
@@ -0,0 +1,35 @@
1
+ TOP_LEVEL_CONSTANT = 0
2
+
3
+ def a_top_level_function
4
+ end
5
+
6
+ task :default => [:work, :obj, :const]
7
+
8
+ task :work do
9
+ begin
10
+ a_top_level_function
11
+ puts "GOOD:M Top level methods can be called in tasks"
12
+ rescue NameError => ex
13
+ puts "BAD:M Top level methods can not be called in tasks"
14
+ end
15
+ end
16
+
17
+ # TODO: remove `disabled_' when DeprecatedObjectDSL removed
18
+ task :obj
19
+ task :disabled_obj do
20
+ begin
21
+ Object.new.instance_eval { task :xyzzy }
22
+ puts "BAD:D Rake DSL are polluting objects"
23
+ rescue StandardError => ex
24
+ puts "GOOD:D Rake DSL are not polluting objects"
25
+ end
26
+ end
27
+
28
+ task :const do
29
+ begin
30
+ TOP_LEVEL_CONSTANT
31
+ puts "GOOD:C Top level constants are available in tasks"
32
+ rescue StandardError => ex
33
+ puts "BAD:C Top level constants are NOT available in tasks"
34
+ end
35
+ end
@@ -0,0 +1,18 @@
1
+ # comment for t1
2
+ task :t1 do
3
+ end
4
+
5
+ # no comment or task because there's a blank line
6
+
7
+ task :t2 do
8
+ end
9
+
10
+ desc "override comment for t3"
11
+ # this is not the description
12
+ multitask :t3 do
13
+ end
14
+
15
+ # this is not the description
16
+ desc "override comment for t4"
17
+ file :t4 do
18
+ end
@@ -1,5 +1,3 @@
1
- #!/usr/bin/env ruby
2
-
3
1
  if ENV['TESTTOPSCOPE']
4
2
  puts "TOPSCOPE"
5
3
  end
@@ -16,4 +14,4 @@ task :task_scope do
16
14
  if ENV['TESTTASKSCOPE']
17
15
  puts "TASKSCOPE"
18
16
  end
19
- end
17
+ end
@@ -0,0 +1 @@
1
+ import "a"
@@ -1,4 +1,4 @@
1
- #
1
+ #
2
2
 
3
3
  task :default => ["temp_main"]
4
4
 
@@ -0,0 +1 @@
1
+ task :default
@@ -1,11 +1,9 @@
1
- #!/usr/bin/env ruby
2
-
3
1
  N = 2
4
2
 
5
3
  task :default => :run
6
4
 
7
5
  BUILD_DIR = 'build'
8
- task :clean do
6
+ task :clean do
9
7
  rm_rf 'build'
10
8
  rm_rf 'src'
11
9
  end
@@ -1,5 +1,3 @@
1
- #!/usr/bin/env ruby
2
-
3
1
  task :b
4
2
 
5
3
  desc "A"
@@ -1,5 +1,3 @@
1
- #!/usr/bin/env ruby
2
-
3
1
  desc "copy"
4
2
  task :copy do
5
3
  puts "COPY"
@@ -55,3 +53,12 @@ namespace "file2" do
55
53
  end
56
54
  end
57
55
 
56
+ namespace "scopedep" do
57
+ task :prepare do
58
+ touch "scopedep.rb"
59
+ puts "PREPARE"
60
+ end
61
+ file "scopedep.rb" => [:prepare] do
62
+ puts "SCOPEDEP"
63
+ end
64
+ end
@@ -1,3 +1,4 @@
1
+
1
2
  task :default do
2
3
  puts "TEST1"
3
4
  end
@@ -1,5 +1,3 @@
1
- #!/usr/bin/env ruby
2
-
3
1
  task :exit5 do
4
2
  exit(5)
5
3
  end
@@ -0,0 +1,34 @@
1
+
2
+ task :standalone_verbose_true do
3
+ verbose true
4
+ sh "ruby -e '0'"
5
+ end
6
+
7
+ task :standalone_verbose_false do
8
+ verbose false
9
+ sh "ruby -e '0'"
10
+ end
11
+
12
+ task :inline_verbose_default do
13
+ sh "ruby -e '0'"
14
+ end
15
+
16
+ task :inline_verbose_false do
17
+ sh "ruby -e '0'", :verbose => false
18
+ end
19
+
20
+ task :inline_verbose_true do
21
+ sh "ruby -e '0'", :verbose => true
22
+ end
23
+
24
+ task :block_verbose_true do
25
+ verbose(true) do
26
+ sh "ruby -e '0'"
27
+ end
28
+ end
29
+
30
+ task :block_verbose_false do
31
+ verbose(false) do
32
+ sh "ruby -e '0'"
33
+ end
34
+ end
@@ -1,17 +1,18 @@
1
- #!/usr/bin/env ruby
2
-
3
1
  module FileCreation
4
2
  OLDFILE = "testdata/old"
5
3
  NEWFILE = "testdata/new"
6
4
 
7
5
  def create_timed_files(oldfile, *newfiles)
8
- return if File.exist?(oldfile) && newfiles.all? { |newfile| File.exist?(newfile) }
9
- old_time = create_file(oldfile)
6
+ return if (File.exist?(oldfile) &&
7
+ newfiles.all? { |newfile|
8
+ File.exist?(newfile) && File.stat(newfile).mtime > File.stat(oldfile).mtime
9
+ })
10
+ now = Time.now
11
+
12
+ create_file(oldfile, now - 60)
13
+
10
14
  newfiles.each do |newfile|
11
- while create_file(newfile) <= old_time
12
- sleep(0.1)
13
- File.delete(newfile) rescue nil
14
- end
15
+ create_file(newfile, now)
15
16
  end
16
17
  end
17
18
 
@@ -20,9 +21,10 @@ module FileCreation
20
21
  File.stat(dirname).mtime
21
22
  end
22
23
 
23
- def create_file(name)
24
+ def create_file(name, file_time=nil)
24
25
  create_dir(File.dirname(name))
25
26
  FileUtils.touch(name) unless File.exist?(name)
27
+ File.utime(file_time, file_time, name) unless file_time.nil?
26
28
  File.stat(name).mtime
27
29
  end
28
30
 
data/test/helper.rb ADDED
@@ -0,0 +1,44 @@
1
+ require 'rubygems'
2
+ require 'minitest/unit'
3
+ require 'flexmock/test_unit_integration'
4
+ require 'minitest/autorun'
5
+ require 'rake'
6
+ require File.expand_path('../file_creation', __FILE__)
7
+ require File.expand_path('../in_environment', __FILE__)
8
+
9
+ class Rake::TestCase < MiniTest::Unit::TestCase
10
+ include FlexMock::ArgumentTypes
11
+ include FlexMock::MockContainer
12
+
13
+ include InEnvironment
14
+ include FileCreation
15
+
16
+ include Rake::DSL
17
+
18
+ class TaskManager
19
+ include Rake::TaskManager
20
+ end
21
+
22
+ def setup
23
+ @orig_PWD = Dir.pwd
24
+ end
25
+
26
+ def teardown
27
+ flexmock_teardown
28
+
29
+ Dir.chdir @orig_PWD
30
+ end
31
+
32
+ def ignore_deprecations
33
+ Rake.application.options.ignore_deprecate = true
34
+ yield
35
+ ensure
36
+ Rake.application.options.ignore_deprecate = false
37
+ end
38
+
39
+ end
40
+
41
+ # workarounds for 1.8
42
+ $" << 'test/helper.rb'
43
+ Test::Unit.run = true if Test::Unit.respond_to? :run=
44
+
@@ -1,20 +1,24 @@
1
1
  module InEnvironment
2
2
  private
3
-
3
+
4
4
  # Create an environment for a test. At the completion of the yielded
5
5
  # block, the environment is restored to its original conditions.
6
- def in_environment(settings)
7
- original_settings = set_env(settings)
8
- yield
6
+ def in_environment(settings=nil)
7
+ settings ||= {}
8
+ full_settings = {"RAKEOPT" => nil}.merge(settings)
9
+ original_settings = set_env(full_settings)
10
+ yield
9
11
  ensure
10
- set_env(original_settings)
12
+ set_env(original_settings) rescue nil
11
13
  end
12
14
 
13
15
  # Set the environment according to the settings hash.
14
- def set_env(settings) # :nodoc:
16
+ def set_env(settings) # :nodoc:
15
17
  result = {}
18
+
16
19
  settings.each do |k, v|
17
20
  result[k] = ENV[k]
21
+
18
22
  if k == 'PWD'
19
23
  result[k] = Dir.pwd
20
24
  Dir.chdir(v)
@@ -24,6 +28,7 @@ module InEnvironment
24
28
  ENV[k] = v
25
29
  end
26
30
  end
31
+
27
32
  result
28
33
  end
29
34
 
data/test/test_rake.rb CHANGED
@@ -1,9 +1,6 @@
1
- #!/usr/bin/env ruby
1
+ require File.expand_path('../helper', __FILE__)
2
2
 
3
- require 'test/unit'
4
- require 'rake'
5
-
6
- class TestRake < Test::Unit::TestCase
3
+ class TestRake < Rake::TestCase
7
4
  def test_each_dir_parent
8
5
  assert_equal ['a'], alldirs('a')
9
6
  assert_equal ['a/b', 'a'], alldirs('a/b')
@@ -37,5 +34,5 @@ class TestRake < Test::Unit::TestCase
37
34
  def test_original_dir_reports_current_dir
38
35
  assert_equal Dir.pwd, Rake.original_dir
39
36
  end
40
-
37
+
41
38
  end
@@ -0,0 +1,364 @@
1
+ require File.expand_path('../helper', __FILE__)
2
+
3
+ class TestRakeApplication < Rake::TestCase
4
+ include InEnvironment
5
+
6
+ def setup
7
+ super
8
+
9
+ @app = Rake::Application.new
10
+ @app.options.rakelib = []
11
+ Rake::TaskManager.record_task_metadata = true
12
+ end
13
+
14
+ def teardown
15
+ Rake::TaskManager.record_task_metadata = false
16
+
17
+ super
18
+ end
19
+
20
+ def test_constant_warning
21
+ _, err = capture_io do @app.instance_eval { const_warning("Task") } end
22
+ assert_match(/warning/i, err)
23
+ assert_match(/deprecated/i, err)
24
+ assert_match(/Task/i, err)
25
+ end
26
+
27
+ def test_display_tasks
28
+ @app.options.show_tasks = :tasks
29
+ @app.options.show_task_pattern = //
30
+ @app.last_description = "COMMENT"
31
+ @app.define_task(Rake::Task, "t")
32
+ out, = capture_io do @app.instance_eval { display_tasks_and_comments } end
33
+ assert_match(/^rake t/, out)
34
+ assert_match(/# COMMENT/, out)
35
+ end
36
+
37
+ def test_display_tasks_with_long_comments
38
+ in_environment('RAKE_COLUMNS' => '80') do
39
+ @app.options.show_tasks = :tasks
40
+ @app.options.show_task_pattern = //
41
+ @app.last_description = "1234567890" * 8
42
+ @app.define_task(Rake::Task, "t")
43
+ out, = capture_io do @app.instance_eval { display_tasks_and_comments } end
44
+ assert_match(/^rake t/, out)
45
+ assert_match(/# 12345678901234567890123456789012345678901234567890123456789012345\.\.\./, out)
46
+ end
47
+ end
48
+
49
+ def test_display_tasks_with_task_name_wider_than_tty_display
50
+ in_environment('RAKE_COLUMNS' => '80') do
51
+ @app.options.show_tasks = :tasks
52
+ @app.options.show_task_pattern = //
53
+ task_name = "task name" * 80
54
+ @app.last_description = "something short"
55
+ @app.define_task(Rake::Task, task_name )
56
+ out, = capture_io do @app.instance_eval { display_tasks_and_comments } end
57
+ # Ensure the entire task name is output and we end up showing no description
58
+ assert_match(/rake #{task_name} # .../, out)
59
+ end
60
+ end
61
+
62
+ def test_display_tasks_with_very_long_task_name_to_a_non_tty_shows_name_and_comment
63
+ @app.options.show_tasks = :tasks
64
+ @app.options.show_task_pattern = //
65
+ @app.tty_output = false
66
+ description = "something short"
67
+ task_name = "task name" * 80
68
+ @app.last_description = "something short"
69
+ @app.define_task(Rake::Task, task_name )
70
+ out, = capture_io do @app.instance_eval { display_tasks_and_comments } end
71
+ # Ensure the entire task name is output and we end up showing no description
72
+ assert_match(/rake #{task_name} # #{description}/, out)
73
+ end
74
+
75
+ def test_display_tasks_with_long_comments_to_a_non_tty_shows_entire_comment
76
+ @app.options.show_tasks = :tasks
77
+ @app.options.show_task_pattern = //
78
+ @app.tty_output = false
79
+ @app.last_description = "1234567890" * 8
80
+ @app.define_task(Rake::Task, "t")
81
+ out, = capture_io do @app.instance_eval { display_tasks_and_comments } end
82
+ assert_match(/^rake t/, out)
83
+ assert_match(/# #{@app.last_description}/, out)
84
+ end
85
+
86
+ def test_display_tasks_with_long_comments_to_a_non_tty_with_columns_set_truncates_comments
87
+ in_environment("RAKE_COLUMNS" => '80') do
88
+ @app.options.show_tasks = :tasks
89
+ @app.options.show_task_pattern = //
90
+ @app.tty_output = false
91
+ @app.last_description = "1234567890" * 8
92
+ @app.define_task(Rake::Task, "t")
93
+ out, = capture_io do @app.instance_eval { display_tasks_and_comments } end
94
+ assert_match(/^rake t/, out)
95
+ assert_match(/# 12345678901234567890123456789012345678901234567890123456789012345\.\.\./, out)
96
+ end
97
+ end
98
+
99
+ def test_describe_tasks
100
+ @app.options.show_tasks = :describe
101
+ @app.options.show_task_pattern = //
102
+ @app.last_description = "COMMENT"
103
+ @app.define_task(Rake::Task, "t")
104
+ out, = capture_io do @app.instance_eval { display_tasks_and_comments } end
105
+ assert_match(/^rake t$/, out)
106
+ assert_match(/^ {4}COMMENT$/, out)
107
+ end
108
+
109
+ def test_show_lines
110
+ @app.options.show_tasks = :lines
111
+ @app.options.show_task_pattern = //
112
+ @app.last_description = "COMMENT"
113
+ @app.define_task(Rake::Task, "t")
114
+ @app['t'].locations << "HERE:1"
115
+ out, = capture_io do @app.instance_eval { display_tasks_and_comments } end
116
+ assert_match(/^rake t +[^:]+:\d+ *$/, out)
117
+ end
118
+
119
+ def test_finding_rakefile
120
+ assert_match(/Rakefile/i, @app.instance_eval { have_rakefile })
121
+ end
122
+
123
+ def test_not_finding_rakefile
124
+ @app.instance_eval { @rakefiles = ['NEVER_FOUND'] }
125
+ assert( ! @app.instance_eval do have_rakefile end )
126
+ assert_nil @app.rakefile
127
+ end
128
+
129
+ def test_load_rakefile
130
+ in_environment("PWD" => "test/data/unittest") do
131
+ @app.instance_eval do
132
+ handle_options
133
+ options.silent = true
134
+ load_rakefile
135
+ end
136
+ assert_equal "rakefile", @app.rakefile.downcase
137
+ assert_match(%r(unittest$), Dir.pwd)
138
+ end
139
+ end
140
+
141
+ def test_load_rakefile_doesnt_print_rakefile_directory_from_same_dir
142
+ in_environment("PWD" => "test/data/unittest") do
143
+ _, err = capture_io do
144
+ @app.instance_eval do
145
+ @original_dir = File.expand_path(".") # pretend we started from the unittest dir
146
+ raw_load_rakefile
147
+ end
148
+ end
149
+ _, location = @app.find_rakefile_location
150
+ refute_match(/\(in #{location}\)/, err)
151
+ end
152
+ end
153
+
154
+ def test_load_rakefile_from_subdir
155
+ in_environment("PWD" => "test/data/unittest/subdir") do
156
+ @app.instance_eval do
157
+ handle_options
158
+ options.silent = true
159
+ load_rakefile
160
+ end
161
+ assert_equal "rakefile", @app.rakefile.downcase
162
+ assert_match(%r(unittest$), Dir.pwd)
163
+ end
164
+ end
165
+
166
+ def test_load_rakefile_prints_rakefile_directory_from_subdir
167
+ in_environment("PWD" => "test/data/unittest/subdir") do
168
+ _, err = capture_io do
169
+ @app.instance_eval do
170
+ raw_load_rakefile
171
+ end
172
+ end
173
+ _, location = @app.find_rakefile_location
174
+ assert_match(/\(in #{location}\)/, err)
175
+ end
176
+ end
177
+
178
+ def test_load_rakefile_doesnt_print_rakefile_directory_from_subdir_if_silent
179
+ in_environment("PWD" => "test/data/unittest/subdir") do
180
+ _, err = capture_io do
181
+ @app.instance_eval do
182
+ handle_options
183
+ options.silent = true
184
+ raw_load_rakefile
185
+ end
186
+ end
187
+ _, location = @app.find_rakefile_location
188
+ refute_match(/\(in #{location}\)/, err)
189
+ end
190
+ end
191
+
192
+ def test_load_rakefile_not_found
193
+ in_environment("PWD" => "/", "RAKE_SYSTEM" => 'not_exist') do
194
+ @app.instance_eval do
195
+ handle_options
196
+ options.silent = true
197
+ end
198
+ ex = assert_raises(RuntimeError) do
199
+ @app.instance_eval do raw_load_rakefile end
200
+ end
201
+ assert_match(/no rakefile found/i, ex.message)
202
+ end
203
+ end
204
+
205
+ def test_load_from_system_rakefile
206
+ in_environment('RAKE_SYSTEM' => 'test/data/sys') do
207
+ @app.options.rakelib = []
208
+ @app.instance_eval do
209
+ handle_options
210
+ options.silent = true
211
+ options.load_system = true
212
+ options.rakelib = []
213
+ load_rakefile
214
+ end
215
+ assert_equal "test/data/sys", @app.system_dir
216
+ assert_nil @app.rakefile
217
+ end
218
+ end
219
+
220
+ def test_load_from_calculated_system_rakefile
221
+ flexmock(@app, :standard_system_dir => "__STD_SYS_DIR__")
222
+ in_environment('RAKE_SYSTEM' => nil) do
223
+ @app.options.rakelib = []
224
+ @app.instance_eval do
225
+ handle_options
226
+ options.silent = true
227
+ options.load_system = true
228
+ options.rakelib = []
229
+ load_rakefile
230
+ end
231
+ assert_equal "__STD_SYS_DIR__", @app.system_dir
232
+ end
233
+ end
234
+
235
+ def test_windows
236
+ assert ! (@app.windows? && @app.unix?)
237
+ end
238
+
239
+ def test_loading_imports
240
+ mock = flexmock("loader")
241
+ mock.should_receive(:load).with("x.dummy").once
242
+ @app.instance_eval do
243
+ add_loader("dummy", mock)
244
+ add_import("x.dummy")
245
+ load_imports
246
+ end
247
+ end
248
+
249
+ def test_building_imported_files_on_demand
250
+ mock = flexmock("loader")
251
+ mock.should_receive(:load).with("x.dummy").once
252
+ mock.should_receive(:make_dummy).with_no_args.once
253
+ @app.instance_eval do
254
+ intern(Rake::Task, "x.dummy").enhance do mock.make_dummy end
255
+ add_loader("dummy", mock)
256
+ add_import("x.dummy")
257
+ load_imports
258
+ end
259
+ end
260
+
261
+ def test_handle_options_should_strip_options_from_ARGV
262
+ assert !@app.options.trace
263
+
264
+ valid_option = '--trace'
265
+ ARGV.clear
266
+ ARGV << valid_option
267
+
268
+ @app.handle_options
269
+
270
+ assert !ARGV.include?(valid_option)
271
+ assert @app.options.trace
272
+ end
273
+
274
+ def test_good_run
275
+ ran = false
276
+ ARGV.clear
277
+ ARGV << '--rakelib=""'
278
+ @app.options.silent = true
279
+ @app.instance_eval do
280
+ intern(Rake::Task, "default").enhance { ran = true }
281
+ end
282
+ in_environment("PWD" => "test/data/default") do
283
+ @app.run
284
+ end
285
+ assert ran
286
+ end
287
+
288
+ def test_display_task_run
289
+ ran = false
290
+ ARGV.clear
291
+ ARGV << '-f' << '-s' << '--tasks' << '--rakelib=""'
292
+ @app.last_description = "COMMENT"
293
+ @app.define_task(Rake::Task, "default")
294
+ out, = capture_io { @app.run }
295
+ assert @app.options.show_tasks
296
+ assert ! ran
297
+ assert_match(/rake default/, out)
298
+ assert_match(/# COMMENT/, out)
299
+ end
300
+
301
+ def test_display_prereqs
302
+ ran = false
303
+ ARGV.clear
304
+ ARGV << '-f' << '-s' << '--prereqs' << '--rakelib=""'
305
+ @app.last_description = "COMMENT"
306
+ t = @app.define_task(Rake::Task, "default")
307
+ t.enhance([:a, :b])
308
+ @app.define_task(Rake::Task, "a")
309
+ @app.define_task(Rake::Task, "b")
310
+ out, = capture_io { @app.run }
311
+ assert @app.options.show_prereqs
312
+ assert ! ran
313
+ assert_match(/rake a$/, out)
314
+ assert_match(/rake b$/, out)
315
+ assert_match(/rake default\n( *(a|b)\n){2}/m, out)
316
+ end
317
+
318
+ def test_bad_run
319
+ @app.intern(Rake::Task, "default").enhance { fail }
320
+ ARGV.clear
321
+ ARGV << '-f' << '-s' << '--rakelib=""'
322
+ assert_raises(SystemExit) {
323
+ _, err = capture_io { @app.run }
324
+ assert_match(/see full trace/, err)
325
+ }
326
+ ensure
327
+ ARGV.clear
328
+ end
329
+
330
+ def test_bad_run_with_trace
331
+ @app.intern(Rake::Task, "default").enhance { fail }
332
+ ARGV.clear
333
+ ARGV << '-f' << '-s' << '-t'
334
+ assert_raises(SystemExit) {
335
+ _, err = capture_io { @app.run }
336
+ refute_match(/see full trace/, err)
337
+ }
338
+ ensure
339
+ ARGV.clear
340
+ end
341
+
342
+ def test_run_with_bad_options
343
+ @app.intern(Rake::Task, "default").enhance { fail }
344
+ ARGV.clear
345
+ ARGV << '-f' << '-s' << '--xyzzy'
346
+ assert_raises(SystemExit) {
347
+ capture_io { @app.run }
348
+ }
349
+ ensure
350
+ ARGV.clear
351
+ end
352
+
353
+ def test_deprecation_message
354
+ in_environment do
355
+ _, err = capture_io do
356
+ @app.deprecate("a", "b", "c")
357
+ end
358
+ assert_match(/'a' is deprecated/i, err)
359
+ assert_match(/use 'b' instead/i, err)
360
+ assert_match(/at c$/i, err)
361
+ end
362
+ end
363
+ end
364
+