test/test_environment_variables.rb in rake-compiler-dock-1.1.0 vs test/test_environment_variables.rb in rake-compiler-dock-1.2.0
- old
+ new
@@ -4,51 +4,76 @@
begin
require 'test/unit/notify'
rescue LoadError
end
-class TestEnvironmentVariables < Test::Unit::TestCase
- @@rcd_env = nil
+class TestEnvironmentVariables
+ module Common
+ IMAGE_NAME = "larskanis/rake-compiler-dock-mri-x86-mingw32:#{RakeCompilerDock::IMAGE_VERSION}"
- def setup
- @@rcd_env ||= begin
- args = "bash -c 'set'"
- idir = File.join(File.dirname(__FILE__), '../lib')
- cmd = "#{RbConfig::CONFIG['RUBY_INSTALL_NAME']} -I#{idir.inspect} bin/rake-compiler-dock #{args}"
- output = `#{cmd}`
+ def rcd_env
+ self.class.instance_variable_get("@rcd_env") || begin
+ command = "env"
+ output = %x(#{invocation(command)})
- output.split("\n").inject({}) do |hash, line|
- if line =~ /\A(\w+)=(.*)\z/
- hash[$1] = $2.chomp
+ env = output.split("\n").each_with_object({}) do |line, hash|
+ hash[Regexp.last_match(1)] = Regexp.last_match(2).chomp if line =~ /\A(\w+)=(.*)\z/
end
- hash
+
+ self.class.instance_variable_set("@rcd_env", env)
end
end
- end
- def rcd_env
- @@rcd_env
- end
+ def test_RUBY_CC_VERSION
+ df = File.read(File.expand_path("../../Dockerfile.mri.erb", __FILE__))
+ df =~ /^ENV RUBY_CC_VERSION\s+(.*)\s+$/
+ assert_equal $1, rcd_env['RUBY_CC_VERSION']
+ end
- def test_IMAGE
- assert_equal "larskanis/rake-compiler-dock-mri-x86-mingw32:#{RakeCompilerDock::IMAGE_VERSION}", rcd_env['RCD_IMAGE']
- end
+ def test_RAKE_EXTENSION_TASK_NO_NATIVE
+ assert_equal "true", rcd_env['RAKE_EXTENSION_TASK_NO_NATIVE']
+ end
- def test_RUBY_CC_VERSION
- df = File.read(File.expand_path("../../Dockerfile.mri.erb", __FILE__))
- df =~ /^ENV RUBY_CC_VERSION\s+(.*)\s+$/
- assert_equal $1, rcd_env['RUBY_CC_VERSION']
- end
+ def test_symlink_rake_compiler
+ cmd = invocation("if test -h $HOME/.rake-compiler ; then echo yes ; else echo no ; fi")
+ assert_equal("yes", %x(#{cmd}).strip)
+ end
- def test_HOST_RUBY_PLATFORM
- assert_equal RUBY_PLATFORM, rcd_env['RCD_HOST_RUBY_PLATFORM']
+ def test_gem_directory
+ cmd = invocation("if test -d $HOME/.gem ; then echo yes ; else echo no ; fi")
+ assert_equal("yes", %x(#{cmd}).strip)
+ end
end
- def test_HOST_RUBY_VERSION
- assert_equal RUBY_VERSION, rcd_env['RCD_HOST_RUBY_VERSION']
- end
+ class UsingWrapper < Test::Unit::TestCase
+ include Common
- def test_PWD
- assert_equal Dir.pwd, rcd_env['PWD']
+ def invocation(command)
+ idir = File.join(File.dirname(__FILE__), '../lib')
+ "#{RbConfig::CONFIG['RUBY_INSTALL_NAME']} -I#{idir.inspect} bin/rake-compiler-dock bash -c '#{command}'"
+ end
+
+ def test_HOST_RUBY_PLATFORM
+ assert_equal RUBY_PLATFORM, rcd_env['RCD_HOST_RUBY_PLATFORM']
+ end
+
+ def test_HOST_RUBY_VERSION
+ assert_equal RUBY_VERSION, rcd_env['RCD_HOST_RUBY_VERSION']
+ end
+
+ def test_IMAGE
+ assert_equal IMAGE_NAME, rcd_env['RCD_IMAGE']
+ end
+
+ def test_PWD
+ assert_equal Dir.pwd, rcd_env['PWD']
+ end
end
+ class AsIfContinuousIntegration < Test::Unit::TestCase
+ include Common
+
+ def invocation(command)
+ "docker run -it #{IMAGE_NAME} bash -c '#{command}'"
+ end
+ end
end