/
helper.rb
129 lines (101 loc) · 2.74 KB
/
helper.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
# frozen_string_literal: true
$:.unshift File.expand_path("../../lib", __FILE__)
begin
if ENV["COVERALLS"]
gem "coveralls"
require "coveralls"
Coveralls.wear!
end
rescue Gem::LoadError
end
gem "minitest", "~> 5"
require "minitest/autorun"
require "rake"
require "tmpdir"
require_relative "support/file_creation"
require_relative "support/ruby_runner"
require_relative "support/rakefile_definitions"
class Rake::TestCase < Minitest::Test
include FileCreation
include Rake::DSL
class TaskManager
include Rake::TaskManager
end
RUBY = File.realpath(ENV["BUNDLE_RUBY"] || Gem.ruby)
def setup
ARGV.clear
@verbose = ENV["VERBOSE"]
@rake_root = File.expand_path "../../", __FILE__
@rake_exec = File.join @rake_root, "exe", "rake"
@rake_lib = File.join @rake_root, "lib"
@ruby_options = ["-I#{@rake_lib}", "-I."]
@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"
tmpdir = Dir.chdir Dir.tmpdir do Dir.pwd end
@tempdir = File.join tmpdir, "test_rake_#{$$}"
FileUtils.mkdir_p @tempdir
Dir.chdir @tempdir
Rake.application = Rake::Application.new
Rake::TaskManager.record_task_metadata = true
RakeFileUtils.verbose_flag = false
end
def teardown
Dir.chdir @orig_pwd
FileUtils.rm_rf @tempdir
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
end
def ignore_deprecations
Rake.application.options.ignore_deprecate = true
yield
ensure
Rake.application.options.ignore_deprecate = false
end
def rake_system_dir
@system_dir = "system"
FileUtils.mkdir_p @system_dir
open File.join(@system_dir, "sys1.rake"), "w" do |io|
io << <<-SYS
task "sys1" do
puts "SYS1"
end
SYS
end
ENV["RAKE_SYSTEM"] = @system_dir
end
def rakefile(contents)
open "Rakefile", "w" do |io|
io << contents
end
end
def jruby?
defined?(JRUBY_VERSION)
end
def jruby17?
jruby? && (JRUBY_VERSION < "9.0.0.0")
end
def jruby9?
jruby? && (JRUBY_VERSION >= "9.0.0.0")
end
include RakefileDefinitions
end