Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

improved coverage

  • Loading branch information...
commit 8519372964e4627c8c9d83ed23d5ca6db1403b54 1 parent ecc4344
@jimweirich authored
Showing with 105 additions and 75 deletions.
  1. +2 −1  .gitignore
  2. +2 −1  Rakefile
  3. +5 −15 lib/rake.rb
  4. +96 −58 test/test_application.rb
View
3  .gitignore
@@ -1,6 +1,7 @@
TAGS
-temp_*
pkg
+coverage
+temp_*
x
*.patch
.#*
View
3  Rakefile
@@ -96,7 +96,8 @@ begin
Rcov::RcovTask.new do |t|
t.libs << "test"
t.rcov_opts = [
- '-xRakefile', '-xrakefile', '-xpublish.rf', '--text-report',
+ '-x/Library', '-xRakefile', '-xrakefile', '-xpublish.rf',
+ '--text-report',
]
t.test_files = FileList[
'test/test*.rb', 'test/functional.rb'
View
20 lib/rake.rb
@@ -1707,10 +1707,6 @@ def resolve_args(args)
end
end
- def all_names(*args)
- args.all? { |arg| arg.is_a?(String) || arg.is_a?(Symbol) }
- end
-
# Resolve task arguments for a task or rule when there are no
# dependencies declared.
#
@@ -2184,22 +2180,13 @@ def handle_options
exit
}
],
- ['--execute-continue', '-E',
+ ['--execute-continue', '-E CODE',
"Execute some Ruby code, then continue with normal task processing.",
lambda { |value| eval(value) }
],
['--libdir', '-I LIBDIR', "Include LIBDIR in the search path for required modules.",
lambda { |value| $:.push(value) }
],
- ['--system', '-G', "Run tasks using system wide (global) rakefiles (usually '~/.rake/*.rake'). Project Rakefiles are ignored.",
- lambda { |value| options.load_system = true }
- ],
- ['--no-system', '-g', "Run tasks using standard project Rakefile search paths, ignoring system wide rakefiles.",
- lambda { |value| options.ignore_system = true }
- ],
- ['--nosearch', '-N', "Do not search parent directories for the Rakefile.",
- lambda { |value| options.nosearch = true }
- ],
['--prereqs', '-P', "Display the tasks and dependencies, then exit.",
lambda { |value| options.show_prereqs = true }
],
@@ -2233,6 +2220,9 @@ def handle_options
['--rules', "Trace the rules resolution.",
lambda { |value| options.trace_rules = true }
],
+ ['--no-search', '--nosearch', '-N', "Do not search parent directories for the Rakefile.",
+ lambda { |value| options.nosearch = true }
+ ],
['--silent', '-s', "Like --quiet, but also suppresses the 'in directory' announcement.",
lambda { |value|
verbose(false)
@@ -2243,7 +2233,7 @@ def handle_options
"Using system wide (global) rakefiles (usually '~/.rake/*.rake').",
lambda { |value| options.load_system = true }
],
- ['--no-system', '-G',
+ ['--no-system', '--nosystem', '-G',
"Use standard project Rakefile search paths, ignore system wide rakefiles.",
lambda { |value| options.ignore_system = true }
],
View
154 test/test_application.rb
@@ -297,54 +297,73 @@ def clear_argv
def test_default_options
opts = command_line
- assert_nil opts.show_task_pattern
+ assert_nil opts.classic_namespace
assert_nil opts.dryrun
- assert_nil opts.trace
+ assert_nil opts.full_description
+ assert_nil opts.ignore_system
+ assert_nil opts.load_system
assert_nil opts.nosearch
- assert_nil opts.silent
+ assert_equal ['rakelib'], opts.rakelib
assert_nil opts.show_prereqs
+ assert_nil opts.show_task_pattern
assert_nil opts.show_tasks
- assert_nil opts.classic_namespace
+ assert_nil opts.silent
+ assert_nil opts.trace
assert_equal ['rakelib'], opts.rakelib
assert ! RakeFileUtils.verbose_flag
assert ! RakeFileUtils.nowrite_flag
end
- def test_bad_options
- assert_raise OptionParser::InvalidOption do
- capture_stderr do
- flags('--bad', '-t') do |opts|
- end
- end
- end
- end
-
- def test_trace_option
- flags('--trace', '-t') do |opts|
+ def test_dry_run
+ flags('--dry-run', '-n') do |opts|
+ assert opts.dryrun
assert opts.trace
assert RakeFileUtils.verbose_flag
- assert ! RakeFileUtils.nowrite_flag
+ assert RakeFileUtils.nowrite_flag
end
end
- def test_system_option
- flags('--system', '-G') do |opts|
- assert opts.load_system
+ def test_describe
+ flags('--describe') do |opts|
+ assert opts.full_description
+ assert opts.show_tasks
+ assert_equal(//.to_s, opts.show_task_pattern.to_s)
end
end
- def test_no_system_option
- flags('--no-system', '-g') do |opts|
- assert opts.ignore_system
+ def test_describe_with_pattern
+ flags('--describe=X') do |opts|
+ assert opts.full_description
+ assert opts.show_tasks
+ assert_equal(/X/.to_s, opts.show_task_pattern.to_s)
end
end
- def test_dry_run
- flags('--dry-run', '-n') do |opts|
- assert opts.dryrun
- assert opts.trace
- assert RakeFileUtils.verbose_flag
- assert RakeFileUtils.nowrite_flag
+ def test_execute
+ $xyzzy = 0
+ flags('--execute=$xyzzy=1', '-e $xyzzy=1') do |opts|
+ assert_equal 1, $xyzzy
+ assert_equal :exit, @exit
+ $xyzzy = 0
+ end
+ end
+
+ def test_execute_and_continue
+ $xyzzy = 0
+ flags('--execute-continue=$xyzzy=1', '-E $xyzzy=1') do |opts|
+ assert_equal 1, $xyzzy
+ assert_not_equal :exit, @exit
+ $xyzzy = 0
+ end
+ end
+
+ def test_execute_and_print
+ $xyzzy = 0
+ flags('--execute-print=$xyzzy="pugh"', '-p $xyzzy="pugh"') do |opts|
+ assert_equal 'pugh', $xyzzy
+ assert_equal :exit, @exit
+ assert_match(/^pugh$/, @out)
+ $xyzzy = 0
end
end
@@ -358,14 +377,6 @@ def test_help
end
end
- def test_describe
- flags('--describe') do |opts|
- assert opts.full_description
- assert opts.show_tasks
- assert_equal(//.to_s, opts.show_task_pattern.to_s)
- end
- end
-
def test_libdir
flags(['--libdir', 'xx'], ['-I', 'xx'], ['-Ixx']) do |opts|
$:.include?('xx')
@@ -374,13 +385,37 @@ def test_libdir
$:.delete('xx')
end
- def test_nosearch
- flags('--nosearch', '-N') do |opts|
- assert opts.nosearch
+ def test_rakefile
+ flags(['--rakefile', 'RF'], ['--rakefile=RF'], ['-f', 'RF'], ['-fRF']) do |opts|
+ assert_equal ['RF'], @app.instance_eval { @rakefiles }
+ end
+ end
+
+ def test_rakelib
+ flags(['--rakelibdir', 'A:B:C'], ['--rakelibdir=A:B:C'], ['-R', 'A:B:C'], ['-RA:B:C']) do |opts|
+ assert_equal ['A', 'B', 'C'], opts.rakelib
end
end
- def test_show_prereqs
+ def test_require
+ flags(['--require', 'test/reqfile'], '-rtest/reqfile2', '-rtest/reqfile3') do |opts|
+ end
+ assert TESTING_REQUIRE.include?(1)
+ assert TESTING_REQUIRE.include?(2)
+ assert TESTING_REQUIRE.include?(3)
+ assert_equal 3, TESTING_REQUIRE.size
+ end
+
+ def test_missing_require
+ ex = assert_raises(LoadError) do
+ flags(['--require', 'test/missing']) do |opts|
+ end
+ end
+ assert_match(/no such file/, ex.message)
+ assert_match(/test\/missing/, ex.message)
+ end
+
+ def test_prereqs
flags('--prereqs', '-P') do |opts|
assert opts.show_prereqs
end
@@ -393,6 +428,12 @@ def test_quiet
end
end
+ def test_no_search
+ flags('--nosearch', '--no-search', '-N') do |opts|
+ assert opts.nosearch
+ end
+ end
+
def test_silent
flags('--silent', '-s') do |opts|
assert ! RakeFileUtils.verbose_flag
@@ -400,34 +441,30 @@ def test_silent
end
end
- def test_rakefile
- flags(['--rakefile', 'RF'], ['--rakefile=RF'], ['-f', 'RF'], ['-fRF']) do |opts|
- assert_equal ['RF'], @app.instance_eval { @rakefiles }
+ def test_system
+ flags('--system', '-g') do |opts|
+ assert opts.load_system
end
end
- def test_rakelib
- flags(['--rakelibdir', 'A:B:C'], ['--rakelibdir=A:B:C'], ['-R', 'A:B:C'], ['-RA:B:C']) do |opts|
- assert_equal ['A', 'B', 'C'], opts.rakelib
+ def test_no_system
+ flags('--no-system', '-G') do |opts|
+ assert opts.ignore_system
end
end
- def test_require
- flags(['--require', 'test/reqfile'], '-rtest/reqfile2', '-rtest/reqfile3') do |opts|
+ def test_trace
+ flags('--trace', '-t') do |opts|
+ assert opts.trace
+ assert RakeFileUtils.verbose_flag
+ assert ! RakeFileUtils.nowrite_flag
end
- assert TESTING_REQUIRE.include?(1)
- assert TESTING_REQUIRE.include?(2)
- assert TESTING_REQUIRE.include?(3)
- assert_equal 3, TESTING_REQUIRE.size
end
- def test_missing_require
- ex = assert_raises(LoadError) do
- flags(['--require', 'test/missing']) do |opts|
- end
+ def test_trace_rules
+ flags('--rules') do |opts|
+ assert opts.trace_rules
end
- assert_match(/no such file/, ex.message)
- assert_match(/test\/missing/, ex.message)
end
def test_tasks
@@ -502,6 +539,7 @@ def test_environment_definition
def flags(*sets)
sets.each do |set|
+ ARGV.clear
@out = capture_stdout {
@exit = catch(:system_exit) { opts = command_line(*set) }
}
Please sign in to comment.
Something went wrong with that request. Please try again.