Skip to content

Commit

Permalink
improved coverage
Browse files Browse the repository at this point in the history
  • Loading branch information
jimweirich committed Sep 1, 2008
1 parent ecc4344 commit 8519372
Show file tree
Hide file tree
Showing 4 changed files with 105 additions and 75 deletions.
3 changes: 2 additions & 1 deletion .gitignore
@@ -1,6 +1,7 @@
TAGS
temp_*
pkg
coverage
temp_*
x
*.patch
.#*
3 changes: 2 additions & 1 deletion Rakefile
Expand Up @@ -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'
Expand Down
20 changes: 5 additions & 15 deletions lib/rake.rb
Expand Up @@ -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.
#
Expand Down Expand Up @@ -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 }
],
Expand Down Expand Up @@ -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)
Expand All @@ -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 }
],
Expand Down
154 changes: 96 additions & 58 deletions test/test_application.rb
Expand Up @@ -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

Expand All @@ -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')
Expand All @@ -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
Expand All @@ -393,41 +428,43 @@ 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
assert opts.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
Expand Down Expand Up @@ -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) }
}
Expand Down

0 comments on commit 8519372

Please sign in to comment.