Skip to content

Commit

Permalink
Applied style guide to tests.
Browse files Browse the repository at this point in the history
  • Loading branch information
jimweirich committed Apr 12, 2013
1 parent 7961fcc commit 9d09be7
Show file tree
Hide file tree
Showing 25 changed files with 217 additions and 153 deletions.
56 changes: 28 additions & 28 deletions test/helper.rb
Expand Up @@ -33,26 +33,27 @@ def setup

test_dir = File.basename File.dirname File.expand_path __FILE__

@rake_root = if test_dir == 'test' then
# rake repository
File.expand_path '../../', __FILE__
else
# ruby repository
File.expand_path '../../../', __FILE__
end
@rake_root =
if test_dir == 'test'
# rake repository
File.expand_path '../../', __FILE__
else
# ruby repository
File.expand_path '../../../', __FILE__
end

@rake_exec = File.join @rake_root, 'bin', 'rake'
@rake_lib = File.join @rake_root, 'lib'

@orig_PWD = Dir.pwd
@orig_APPDATA = ENV['APPDATA']
@orig_HOME = ENV['HOME']
@orig_HOMEDRIVE = ENV['HOMEDRIVE']
@orig_HOMEPATH = ENV['HOMEPATH']
@orig_RAKE_COLUMNS = ENV['RAKE_COLUMNS']
@orig_RAKE_SYSTEM = ENV['RAKE_SYSTEM']
@orig_RAKEOPT = ENV['RAKEOPT']
@orig_USERPROFILE = ENV['USERPROFILE']
@orig_pwd = Dir.pwd
@orig_appdata = ENV['APPDATA']
@orig_home = ENV['HOME']
@orig_homedrive = ENV['HOMEDRIVE']
@orig_homepath = ENV['HOMEPATH']
@orig_rake_columns = ENV['RAKE_COLUMNS']
@orig_rake_system = ENV['RAKE_SYSTEM']
@orig_rakeopt = ENV['RAKEOPT']
@orig_userprofile = ENV['USERPROFILE']
ENV.delete 'RAKE_COLUMNS'
ENV.delete 'RAKE_SYSTEM'
ENV.delete 'RAKEOPT'
Expand All @@ -70,22 +71,22 @@ def setup
end

def teardown
Dir.chdir @orig_PWD
Dir.chdir @orig_pwd
FileUtils.rm_rf @tempdir

if @orig_APPDATA then
ENV['APPDATA'] = @orig_APPDATA
if @orig_appdata
ENV['APPDATA'] = @orig_appdata
else
ENV.delete 'APPDATA'
end

ENV['HOME'] = @orig_HOME
ENV['HOMEDRIVE'] = @orig_HOMEDRIVE
ENV['HOMEPATH'] = @orig_HOMEPATH
ENV['RAKE_COLUMNS'] = @orig_RAKE_COLUMNS
ENV['RAKE_SYSTEM'] = @orig_RAKE_SYSTEM
ENV['RAKEOPT'] = @orig_RAKEOPT
ENV['USERPROFILE'] = @orig_USERPROFILE
ENV['HOME'] = @orig_home
ENV['HOMEDRIVE'] = @orig_homedrive
ENV['HOMEPATH'] = @orig_homepath
ENV['RAKE_COLUMNS'] = @orig_rake_columns
ENV['RAKE_SYSTEM'] = @orig_rake_system
ENV['RAKEOPT'] = @orig_rakeopt
ENV['USERPROFILE'] = @orig_userprofile
end

def ignore_deprecations
Expand All @@ -111,7 +112,7 @@ def rake_system_dir
ENV['RAKE_SYSTEM'] = @system_dir
end

def rakefile contents
def rakefile(contents)
open 'Rakefile', 'w' do |io|
io << contents
end
Expand Down Expand Up @@ -288,7 +289,6 @@ def rakefile_file_creation
target = File.join TARGET_DIR, File.basename(src)
file target => [src, TARGET_DIR] do
cp src, target
# sleep 3 if src !~ /foo#{N-1}$/ # I'm commenting out this sleep, it doesn't seem to do anything.
end
task :run => target
end
Expand Down
26 changes: 14 additions & 12 deletions test/test_rake_application.rb
Expand Up @@ -23,13 +23,14 @@ def test_display_tasks_with_long_comments
@app.terminal_columns = 80
@app.options.show_tasks = :tasks
@app.options.show_task_pattern = //
@app.last_description = "1234567890" * 8
numbers = "1234567890" * 8
@app.last_description = numbers
@app.define_task(Rake::Task, "t")

out, = capture_io do @app.instance_eval { display_tasks_and_comments } end

assert_match(/^rake t/, out)
assert_match(/# 12345678901234567890123456789012345678901234567890123456789012345\.\.\./, out)
assert_match(/# #{numbers[0, 65]}\.\.\./, out)
end

def test_display_tasks_with_task_name_wider_than_tty_display
Expand All @@ -38,7 +39,7 @@ def test_display_tasks_with_task_name_wider_than_tty_display
@app.options.show_task_pattern = //
task_name = "task name" * 80
@app.last_description = "something short"
@app.define_task(Rake::Task, task_name )
@app.define_task(Rake::Task, task_name)

out, = capture_io do @app.instance_eval { display_tasks_and_comments } end

Expand All @@ -53,7 +54,7 @@ def test_display_tasks_with_very_long_task_name_to_a_non_tty_shows_name_and_comm
description = "something short"
task_name = "task name" * 80
@app.last_description = "something short"
@app.define_task(Rake::Task, task_name )
@app.define_task(Rake::Task, task_name)

out, = capture_io do @app.instance_eval { display_tasks_and_comments } end

Expand All @@ -72,18 +73,19 @@ def test_display_tasks_with_long_comments_to_a_non_tty_shows_entire_comment
assert_match(/# #{@app.last_description}/, out)
end

def test_display_tasks_with_long_comments_to_a_non_tty_with_columns_set_truncates_comments
def test_truncating_comments_to_a_non_tty
@app.terminal_columns = 80
@app.options.show_tasks = :tasks
@app.options.show_task_pattern = //
@app.tty_output = false
@app.last_description = "1234567890" * 8
numbers = "1234567890" * 8
@app.last_description = numbers
@app.define_task(Rake::Task, "t")

out, = capture_io do @app.instance_eval { display_tasks_and_comments } end

assert_match(/^rake t/, out)
assert_match(/# 12345678901234567890123456789012345678901234567890123456789012345\.\.\./, out)
assert_match(/# #{numbers[0, 65]}\.\.\./, out)
end

def test_describe_tasks
Expand Down Expand Up @@ -114,7 +116,7 @@ def test_finding_rakefile

def test_not_finding_rakefile
@app.instance_eval { @rakefiles = ['NEVER_FOUND'] }
assert( ! @app.instance_eval do have_rakefile end )
assert(! @app.instance_eval do have_rakefile end)
assert_nil @app.rakefile
end

Expand Down Expand Up @@ -245,18 +247,18 @@ def @app.standard_system_dir
end

def test_terminal_columns
old_RAKE_COLUMNS = ENV['RAKE_COLUMNS']
old_rake_columns = ENV['RAKE_COLUMNS']

ENV['RAKE_COLUMNS'] = '42'

app = Rake::Application.new

assert_equal 42, app.terminal_columns
ensure
if old_RAKE_COLUMNS then
if old_rake_columns
ENV['RAKE_COLUMNS'].delete
else
ENV['RAKE_COLUMNS'] = old_RAKE_COLUMNS
ENV['RAKE_COLUMNS'] = old_rake_columns
end
end

Expand Down Expand Up @@ -289,7 +291,7 @@ def test_building_imported_files_on_demand
# HACK no assertions
end

def test_handle_options_should_strip_options_from_ARGV
def test_handle_options_should_strip_options_from_argv
assert !@app.options.trace

valid_option = '--trace'
Expand Down
12 changes: 7 additions & 5 deletions test/test_rake_application_options.rb
@@ -1,6 +1,6 @@
require File.expand_path('../helper', __FILE__)

TESTING_REQUIRE = [ ]
TESTING_REQUIRE = []

class TestRakeApplicationOptions < Rake::TestCase

Expand All @@ -22,9 +22,7 @@ def teardown
end

def clear_argv
while ! ARGV.empty?
ARGV.pop
end
ARGV.pop until ARGV.empty?
end

def test_default_options
Expand Down Expand Up @@ -146,7 +144,11 @@ def test_rakefile

def test_rakelib
dirs = %w(A B C).join(File::PATH_SEPARATOR)
flags(['--rakelibdir', dirs], ["--rakelibdir=#{dirs}"], ['-R', dirs], ["-R#{dirs}"]) do |opts|
flags(
['--rakelibdir', dirs],
["--rakelibdir=#{dirs}"],
['-R', dirs],
["-R#{dirs}"]) do |opts|
assert_equal ['A', 'B', 'C'], opts.rakelib
end
end
Expand Down
3 changes: 2 additions & 1 deletion test/test_rake_backtrace.rb
Expand Up @@ -83,7 +83,8 @@ def assert_something_matches(pattern, lines)
return
end
end
flunk "expected #{pattern.inspect} to match something in:\n #{lines.join("\n ")}"
flunk "expected #{pattern.inspect} to match something in:\n" +
"#{lines.join("\n ")}"
end

end
5 changes: 2 additions & 3 deletions test/test_rake_definitions.rb
Expand Up @@ -34,12 +34,12 @@ def check_tasks(n1, n2, n3)
t = Task[n1]
assert Task === t, "Should be a Task"
assert_equal n1.to_s, t.name
assert_equal [n2.to_s], t.prerequisites.collect{|n| n.to_s}
assert_equal [n2.to_s], t.prerequisites.map { |n| n.to_s }
t.invoke
t2 = Task[n2]
assert_equal FileList[], t2.prerequisites
t3 = Task[n3]
assert_equal [n1.to_s, n2.to_s], t3.prerequisites.collect{|n|n.to_s}
assert_equal [n1.to_s, n2.to_s], t3.prerequisites.map { |n| n.to_s }
end

def test_incremental_definitions
Expand Down Expand Up @@ -77,4 +77,3 @@ def create_existing_file
end

end

4 changes: 2 additions & 2 deletions test/test_rake_file_creation_task.rb
Expand Up @@ -21,7 +21,7 @@ def test_file_needed
FileUtils.rm_rf fc_task.name
assert fc_task.needed?, "file should be needed"
FileUtils.mkdir fc_task.name
assert_equal nil, fc_task.prerequisites.collect{|n| Task[n].timestamp}.max
assert_equal nil, fc_task.prerequisites.map { |n| Task[n].timestamp }.max
assert ! fc_task.needed?, "file should not be needed"
end

Expand Down Expand Up @@ -51,6 +51,6 @@ def test_no_retriggers_on_file_task
def test_very_early_timestamp
t1 = Rake.application.intern(FileCreationTask, OLDFILE)
assert t1.timestamp < Time.now
assert t1.timestamp < Time.now - 1000000
assert t1.timestamp < Time.now - 1_000_000
end
end
19 changes: 9 additions & 10 deletions test/test_rake_file_list.rb
Expand Up @@ -482,12 +482,12 @@ def test_array_comparisons
a = ['b', 'a']
b = ['b', 'b']
c = ['b', 'c']
assert_equal( 1, fl <=> a )
assert_equal( 0, fl <=> b )
assert_equal( -1, fl <=> c )
assert_equal( -1, a <=> fl )
assert_equal( 0, b <=> fl )
assert_equal( 1, c <=> fl )
assert_equal(1, fl <=> a)
assert_equal(0, fl <=> b)
assert_equal(-1, fl <=> c)
assert_equal(-1, a <=> fl)
assert_equal(0, b <=> fl)
assert_equal(1, c <=> fl)
end

def test_array_equality
Expand All @@ -503,7 +503,7 @@ def test_array_equality

def test_enumeration_methods
a = FileList['a', 'b']
b = a.collect { |it| it.upcase }
b = a.map { |it| it.upcase }
assert_equal ['A', 'B'], b
assert_equal FileList, b.class

Expand All @@ -519,7 +519,7 @@ def test_enumeration_methods
assert_equal ['a', 'b'], b
assert_equal FileList, b.class

b = a.find_all { |it| it == 'b'}
b = a.select { |it| it == 'b' }
assert_equal ['b'], b
assert_equal FileList, b.class

Expand Down Expand Up @@ -609,7 +609,7 @@ def test_other_array_returning_methods
assert_equal FileList, r.class

f = FileList['a', 'b', 'c', 'd']
r = f.values_at(1,3)
r = f.values_at(1, 3)
assert_equal ['b', 'd'], r
assert_equal FileList, r.class
end
Expand All @@ -625,4 +625,3 @@ def test_file_utils_can_use_filelists
end

end

8 changes: 4 additions & 4 deletions test/test_rake_file_task.rb
Expand Up @@ -26,7 +26,7 @@ def test_file_need

open(ftask.name, "w") { |f| f.puts "HI" }

assert_equal nil, ftask.prerequisites.collect{|n| Task[n].timestamp}.max
assert_equal nil, ftask.prerequisites.map { |n| Task[n].timestamp }.max
assert ! ftask.needed?, "file should not be needed"
ensure
File.delete(ftask.name) rescue nil
Expand Down Expand Up @@ -61,10 +61,10 @@ def test_file_times_new_depend_on_regular_task_timestamps
def test_file_times_old_depends_on_new
create_timed_files(OLDFILE, NEWFILE)

t1 = Rake.application.intern(FileTask,OLDFILE).enhance([NEWFILE])
t1 = Rake.application.intern(FileTask, OLDFILE).enhance([NEWFILE])
t2 = Rake.application.intern(FileTask, NEWFILE)
assert ! t2.needed?, "Should not need to build new file"
preq_stamp = t1.prerequisites.collect{|t| Task[t].timestamp}.max
preq_stamp = t1.prerequisites.map { |t| Task[t].timestamp }.max
assert_equal t2.timestamp, preq_stamp
assert t1.timestamp < preq_stamp, "T1 should be older"
assert t1.needed?, "Should need to rebuild old file because of new"
Expand Down Expand Up @@ -112,7 +112,7 @@ def ztest_file_deletes_on_failure
Task[NEWFILE].invoke
rescue Exception
end
assert( ! File.exist?(NEWFILE), "NEWFILE should be deleted")
assert(! File.exist?(NEWFILE), "NEWFILE should be deleted")
end

def load_phony
Expand Down
8 changes: 6 additions & 2 deletions test/test_rake_file_utils.rb
Expand Up @@ -44,15 +44,19 @@ def test_ln
class BadLink
include Rake::FileUtilsExt
attr_reader :cp_args

def initialize(klass)
@failure_class = klass
end

def cp(*args)
@cp_args = args
end

def ln(*args)
fail @failure_class, "ln not supported"
end

public :safe_ln
end

Expand Down Expand Up @@ -94,7 +98,7 @@ def test_nowrite
assert_equal true, nowrite
nowrite false
assert_equal false, nowrite
nowrite(true){
nowrite(true) {
assert_equal true, nowrite
}
assert_equal false, nowrite
Expand Down Expand Up @@ -250,7 +254,7 @@ def test_split_all
assert_equal ['..', 'a', 'b'], Rake::FileUtilsExt.split_all('../a/b')
end

def command name, text
def command(name, text)
open name, 'w', 0750 do |io|
io << text
end
Expand Down

0 comments on commit 9d09be7

Please sign in to comment.