core: more heuristics for determining Cygwin
This commit is contained in:
parent
43c4de3907
commit
d5fa7416ff
|
@ -10,10 +10,17 @@ module Vagrant
|
|||
class Platform
|
||||
class << self
|
||||
def cygwin?
|
||||
# Installer detects Cygwin
|
||||
return true if ENV["VAGRANT_DETECTED_OS"] &&
|
||||
ENV["VAGRANT_DETECTED_OS"].downcase.include?("cygwin")
|
||||
|
||||
platform.include?("cygwin")
|
||||
# Ruby running in Cygwin
|
||||
return true if platform.include?("cygwin")
|
||||
|
||||
# Heuristic. If the path contains Cygwin, we just assume we're
|
||||
# in Cygwin. It is generally a safe bet.
|
||||
path = ENV["PATH"] || ""
|
||||
return path.include?("cygwin")
|
||||
end
|
||||
|
||||
[:darwin, :bsd, :freebsd, :linux, :solaris].each do |type|
|
||||
|
|
|
@ -107,6 +107,7 @@ shared_context "unit" do
|
|||
# can replace them back in later.
|
||||
old_env = {}
|
||||
environment.each do |key, value|
|
||||
key = key.to_s
|
||||
old_env[key] = ENV[key]
|
||||
ENV[key] = value
|
||||
end
|
||||
|
|
|
@ -3,8 +3,43 @@ require File.expand_path("../../../base", __FILE__)
|
|||
require "vagrant/util/platform"
|
||||
|
||||
describe Vagrant::Util::Platform do
|
||||
include_context "unit"
|
||||
|
||||
subject { described_class }
|
||||
|
||||
describe "#cygwin?" do
|
||||
before do
|
||||
allow(subject).to receive(:platform).and_return("test")
|
||||
end
|
||||
|
||||
around do |example|
|
||||
with_temp_env(VAGRANT_DETECTED_OS: "nope", PATH: "") do
|
||||
example.run
|
||||
end
|
||||
end
|
||||
|
||||
it "returns true if VAGRANT_DETECTED_OS includes cygwin" do
|
||||
with_temp_env(VAGRANT_DETECTED_OS: "cygwin") do
|
||||
expect(subject).to be_cygwin
|
||||
end
|
||||
end
|
||||
|
||||
it "returns true if platform has cygwin" do
|
||||
allow(subject).to receive(:platform).and_return("cygwin")
|
||||
expect(subject).to be_cygwin
|
||||
end
|
||||
|
||||
it "returns true if the PATH contains cygwin" do
|
||||
with_temp_env(PATH: "C:/cygwin") do
|
||||
expect(subject).to be_cygwin
|
||||
end
|
||||
end
|
||||
|
||||
it "returns false if nothing is available" do
|
||||
expect(subject).to_not be_cygwin
|
||||
end
|
||||
end
|
||||
|
||||
describe "#fs_real_path" do
|
||||
it "fixes drive letters on Windows", :windows do
|
||||
expect(described_class.fs_real_path("c:/foo").to_s).to eql("C:/foo")
|
||||
|
|
Loading…
Reference in New Issue