Permalink
Browse files

Rake tests now create all files in a temporary directory

Rake tests now run on an independent rake application
  • Loading branch information...
1 parent 2f25507 commit 8f02e23813f31e650541fe08be116cafc7621436 @drbrain drbrain committed Jun 23, 2011
View
@@ -8,7 +8,3 @@
/coverage
/html
/pkg
-r19.diff
-temp_*
-testdata
-x
View
@@ -1,5 +0,0 @@
-if ARGV[0] != ARGV[1]
- exit 1
-else
- exit 0
-end
@@ -1,5 +0,0 @@
-if ARGV[0] != ARGV[1]
- exit 0
-else
- exit 1
-end
View
@@ -1,6 +1,6 @@
module FileCreation
- OLDFILE = "testdata/old"
- NEWFILE = "testdata/new"
+ OLDFILE = "old"
+ NEWFILE = "new"
def create_timed_files(oldfile, *newfiles)
return if (File.exist?(oldfile) &&
View
@@ -38,6 +38,11 @@ def setup
@tempdir = File.join tmpdir, "test_rake_#{$$}"
FileUtils.mkdir_p @tempdir
+
+ Dir.chdir @tempdir
+
+ Rake.application = Rake::Application.new
+ Rake::TaskManager.record_task_metadata = true
end
def teardown
@@ -69,7 +74,7 @@ def ignore_deprecations
end
def rake_system_dir
- @system_dir = File.join @tempdir, 'system'
+ @system_dir = 'system'
FileUtils.mkdir_p @system_dir
@@ -82,16 +87,12 @@ def rake_system_dir
end
ENV['RAKE_SYSTEM'] = @system_dir
-
- Dir.chdir @tempdir
end
def rakefile contents
- open File.join(@tempdir, 'Rakefile'), 'w' do |io|
+ open 'Rakefile', 'w' do |io|
io << contents
end
-
- Dir.chdir @tempdir
end
def rakefile_access
@@ -402,14 +403,10 @@ def rakefile_namespace
end
def rakefile_nosearch
- Dir.chdir @tempdir
-
FileUtils.touch 'dummy'
end
def rakefile_rakelib
- Dir.chdir @tempdir
-
FileUtils.mkdir_p 'rakelib'
Dir.chdir 'rakelib' do
@@ -432,11 +429,9 @@ def rakefile_rakelib
end
def rakefile_rbext
- open File.join(@tempdir, 'rakefile.rb'), 'w' do |io|
+ open 'rakefile.rb', 'w' do |io|
io << 'task :default do puts "OK" end'
end
-
- Dir.chdir @tempdir
end
def rakefile_statusreturn
@@ -453,10 +448,9 @@ def rakefile_statusreturn
def rakefile_unittest
rakefile '# Empty Rakefile for Unit Test'
- subdir = File.join @tempdir, 'subdir'
- FileUtils.mkdir_p subdir
+ readme = File.join 'subdir', 'README'
+ FileUtils.mkdir_p File.dirname readme
- readme = File.join subdir, 'README'
FileUtils.touch readme
end
View
@@ -1,3 +0,0 @@
-# For --require testing
-
-TESTING_REQUIRE << 1
View
@@ -1,3 +0,0 @@
-# For --require testing
-
-TESTING_REQUIRE << 2
View
@@ -1,3 +0,0 @@
-# For --require testing
-
-TESTING_REQUIRE << 3
View
@@ -1,3 +0,0 @@
-#!/usr/bin/env ruby
-
-exit((ARGV[0] || "0").to_i)
View
@@ -26,13 +26,15 @@ def test_can_override_application
old_app = Rake.application
fake_app = Object.new
Rake.application = fake_app
+
assert_equal fake_app, Rake.application
+
ensure
Rake.application = old_app
end
def test_original_dir_reports_current_dir
- assert_equal Dir.pwd, Rake.original_dir
+ assert_equal @tempdir, Rake.original_dir
end
end
@@ -5,15 +5,8 @@ class TestRakeApplication < Rake::TestCase
def setup
super
- @app = Rake::Application.new
+ @app = Rake.application
@app.options.rakelib = []
- Rake::TaskManager.record_task_metadata = true
- end
-
- def teardown
- Rake::TaskManager.record_task_metadata = false
-
- super
end
def test_constant_warning
@@ -177,8 +170,11 @@ def test_load_rakefile_prints_rakefile_directory_from_subdir
rakefile_unittest
Dir.chdir 'subdir'
+ app = Rake::Application.new
+ app.options.rakelib = []
+
_, err = capture_io do
- @app.instance_eval do
+ app.instance_eval do
raw_load_rakefile
end
end
@@ -230,6 +226,8 @@ def test_load_from_system_rakefile
assert_equal @system_dir, @app.system_dir
assert_nil @app.rakefile
+ rescue SystemExit
+ flunk 'failed to load rakefile'
end
def test_load_from_calculated_system_rakefile
@@ -319,9 +317,13 @@ def test_good_run
rakefile_default
- @app.run
+ out, err = capture_io do
+ @app.run
+ end
assert ran
+ assert_empty err
+ assert_equal "DEFAULT\n", out
end
def test_display_task_run
@@ -131,12 +131,21 @@ def test_rakelib
end
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)
+ $LOAD_PATH.unshift @tempdir
+
+ open 'reqfile.rb', 'w' do |io| io << 'TESTING_REQUIRE << 1' end
+ open 'reqfile2.rb', 'w' do |io| io << 'TESTING_REQUIRE << 2' end
+ open 'reqfile3.rake', 'w' do |io| io << 'TESTING_REQUIRE << 3' end
+
+ flags(['--require', 'reqfile'], '-rreqfile2', '-rreqfile3')
+
+ assert_includes TESTING_REQUIRE, 1
+ assert_includes TESTING_REQUIRE, 2
+ assert_includes TESTING_REQUIRE, 3
+
assert_equal 3, TESTING_REQUIRE.size
+ ensure
+ $LOAD_PATH.delete @tempdir
end
def test_missing_require
@@ -299,8 +308,6 @@ def test_environment_definition
assert '12', ENV['TESTKEY']
end
- private
-
def flags(*sets)
sets.each do |set|
ARGV.clear
View
@@ -4,6 +4,8 @@
class TestRakeClean < Rake::TestCase
include Rake
def test_clean
+ load 'rake/clean.rb', true
+
assert Task['clean'], "Should define clean"
assert Task['clobber'], "Should define clobber"
assert Task['clobber'].prerequisites.include?("clean"),
@@ -4,7 +4,7 @@
class TestRakeDefinitions < Rake::TestCase
include Rake
- EXISTINGFILE = "testdata/existing"
+ EXISTINGFILE = "existing"
def setup
super
@@ -23,10 +23,10 @@ def test_task
def test_file_task
done = false
- file "testdata/one" => "testdata/two" do done = true end
- file "testdata/two"
- file "testdata/three" => ["testdata/one", "testdata/two"]
- check_tasks("testdata/one", "testdata/two", "testdata/three")
+ file "one" => "two" do done = true end
+ file "two"
+ file "three" => ["one", "two"]
+ check_tasks("one", "two", "three")
assert done, "Should be done"
end
@@ -55,7 +55,7 @@ def test_incremental_definitions
end
def test_missing_dependencies
- task :x => ["testdata/missing"]
+ task :x => ["missing"]
assert_raises(RuntimeError) { Task[:x].invoke }
end
@@ -4,52 +4,42 @@
class TestRakeDirectoryTask < Rake::TestCase
include Rake
- def setup
- super
+ def test_directory
+ desc "DESC"
- Rake.rm_rf "testdata", :verbose=>false
- end
+ directory "a/b/c"
- def teardown
- Rake.rm_rf "testdata", :verbose=>false
+ assert_equal FileCreationTask, Task["a"].class
+ assert_equal FileCreationTask, Task["a/b"].class
+ assert_equal FileCreationTask, Task["a/b/c"].class
- super
- end
+ assert_nil Task["a"].comment
+ assert_nil Task["a/b"].comment
+ assert_equal "DESC", Task["a/b/c"].comment
- def test_directory
- desc "DESC"
- directory "testdata/a/b/c"
- assert_equal FileCreationTask, Task["testdata"].class
- assert_equal FileCreationTask, Task["testdata/a"].class
- assert_equal FileCreationTask, Task["testdata/a/b/c"].class
- assert_nil Task["testdata"].comment
- assert_equal "DESC", Task["testdata/a/b/c"].comment
- assert_nil Task["testdata/a/b"].comment
verbose(false) {
- Task['testdata/a/b'].invoke
+ Task['a/b'].invoke
}
- assert File.exist?("testdata/a/b")
- assert ! File.exist?("testdata/a/b/c")
+
+ assert File.exist?("a/b")
+ refute File.exist?("a/b/c")
end
if Rake::Win32.windows?
def test_directory_win32
desc "WIN32 DESC"
- FileUtils.mkdir_p("testdata")
- Dir.chdir("testdata") do
- directory 'c:/testdata/a/b/c'
- assert_equal FileCreationTask, Task['c:/testdata'].class
- assert_equal FileCreationTask, Task['c:/testdata/a'].class
- assert_equal FileCreationTask, Task['c:/testdata/a/b/c'].class
- assert_nil Task['c:/testdata'].comment
- assert_equal "WIN32 DESC", Task['c:/testdata/a/b/c'].comment
- assert_nil Task['c:/testdata/a/b'].comment
- verbose(false) {
- Task['c:/testdata/a/b'].invoke
- }
- assert File.exist?('c:/testdata/a/b')
- assert ! File.exist?('c:/testdata/a/b/c')
- end
+ directory 'c:/a/b/c'
+ assert_equal FileCreationTask, Task['c:'].class
+ assert_equal FileCreationTask, Task['c:/a'].class
+ assert_equal FileCreationTask, Task['c:/a/b/c'].class
+ assert_nil Task['c:/'].comment
+ assert_equal "WIN32 DESC", Task['c:/a/b/c'].comment
+ assert_nil Task['c:/a/b'].comment
+ verbose(false) {
+ Task['c:/a/b'].invoke
+ }
+ assert File.exist?('c:/a/b')
+ refute File.exist?('c:/a/b/c')
end
end
end
@@ -6,20 +6,14 @@ class TestRakeFileCreationTask < Rake::TestCase
include Rake
include Rake::DSL
- DUMMY_DIR = 'testdata/dummy_dir'
+ DUMMY_DIR = 'dummy_dir'
def setup
super
Task.clear
end
- def teardown
- FileUtils.rm_rf DUMMY_DIR
-
- super
- end
-
def test_file_needed
create_dir DUMMY_DIR
fc_task = Task[DUMMY_DIR]
Oops, something went wrong.

0 comments on commit 8f02e23

Please sign in to comment.