move Rscons.absolute_path?() to Util
This commit is contained in:
parent
cd2696dd0b
commit
dff80587ac
@ -66,19 +66,6 @@ module Rscons
|
||||
application.vars(*args)
|
||||
end
|
||||
|
||||
# Return whether the given path is an absolute filesystem path.
|
||||
#
|
||||
# @param path [String] the path to examine.
|
||||
#
|
||||
# @return [Boolean] Whether the given path is an absolute filesystem path.
|
||||
def absolute_path?(path)
|
||||
if RUBY_PLATFORM =~ /mingw/
|
||||
path =~ %r{^(?:\w:)?[\\/]}
|
||||
else
|
||||
path.start_with?("/")
|
||||
end
|
||||
end
|
||||
|
||||
# Return whether the given target is a phony target.
|
||||
#
|
||||
# @param target [Symbol, String] Target name.
|
||||
|
@ -2,6 +2,19 @@ module Rscons
|
||||
module Util
|
||||
class << self
|
||||
|
||||
# Return whether the given path is an absolute filesystem path.
|
||||
#
|
||||
# @param path [String] the path to examine.
|
||||
#
|
||||
# @return [Boolean] Whether the given path is an absolute filesystem path.
|
||||
def absolute_path?(path)
|
||||
if RUBY_PLATFORM =~ /mingw/
|
||||
path =~ %r{^(?:\w:)?[\\/]}
|
||||
else
|
||||
path.start_with?("/")
|
||||
end
|
||||
end
|
||||
|
||||
# Make a relative path corresponding to a possibly absolute one.
|
||||
#
|
||||
# @param path [String]
|
||||
@ -10,7 +23,7 @@ module Rscons
|
||||
# @return [String]
|
||||
# Relative path.
|
||||
def make_relative_path(path)
|
||||
if Rscons.absolute_path?(path)
|
||||
if absolute_path?(path)
|
||||
if path =~ %r{^(\w):(.*)$}
|
||||
"_#{$1}#{$2}"
|
||||
else
|
||||
|
@ -1,6 +1,34 @@
|
||||
module Rscons
|
||||
describe Util do
|
||||
|
||||
describe ".absolute_path?" do
|
||||
context "on Windows" do
|
||||
it "returns whether a path is absolute" do
|
||||
stub_const("RUBY_PLATFORM", "mingw")
|
||||
expect(Util.absolute_path?("/foo")).to be_truthy
|
||||
expect(Util.absolute_path?("\\Windows")).to be_truthy
|
||||
expect(Util.absolute_path?("C:\\Windows")).to be_truthy
|
||||
expect(Util.absolute_path?("f:\\stuff")).to be_truthy
|
||||
expect(Util.absolute_path?("g:/projects")).to be_truthy
|
||||
expect(Util.absolute_path?("x:foo")).to be_falsey
|
||||
expect(Util.absolute_path?("file.txt")).to be_falsey
|
||||
end
|
||||
end
|
||||
|
||||
context "on non-Windows" do
|
||||
it "returns whether a path is absolute" do
|
||||
stub_const("RUBY_PLATFORM", "linux")
|
||||
expect(Util.absolute_path?("/foo")).to be_truthy
|
||||
expect(Util.absolute_path?("\\Windows")).to be_falsey
|
||||
expect(Util.absolute_path?("C:\\Windows")).to be_falsey
|
||||
expect(Util.absolute_path?("f:\\stuff")).to be_falsey
|
||||
expect(Util.absolute_path?("g:/projects")).to be_falsey
|
||||
expect(Util.absolute_path?("x:foo")).to be_falsey
|
||||
expect(Util.absolute_path?("file.txt")).to be_falsey
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
describe ".make_relative_path" do
|
||||
context "when passed a relative path" do
|
||||
it "returns the path itself" do
|
||||
@ -10,7 +38,7 @@ module Rscons
|
||||
|
||||
context "when passed an absolute path" do
|
||||
before(:each) do
|
||||
expect(Rscons).to receive(:absolute_path?).and_return(true)
|
||||
expect(Util).to receive(:absolute_path?).and_return(true)
|
||||
end
|
||||
|
||||
context "on Windows" do
|
||||
@ -19,7 +47,7 @@ module Rscons
|
||||
end
|
||||
end
|
||||
|
||||
context "on POSIX" do
|
||||
context "on non-Windows" do
|
||||
it "returns a relative path corresponding to an absolute one" do
|
||||
expect(Util.make_relative_path("/foo/bar")).to eq "_/foo/bar"
|
||||
end
|
||||
|
@ -1,31 +1,4 @@
|
||||
describe Rscons do
|
||||
describe ".absolute_path?" do
|
||||
context "on Windows" do
|
||||
it "returns whether a path is absolute" do
|
||||
stub_const("RUBY_PLATFORM", "mingw")
|
||||
expect(Rscons.absolute_path?("/foo")).to be_truthy
|
||||
expect(Rscons.absolute_path?("\\Windows")).to be_truthy
|
||||
expect(Rscons.absolute_path?("C:\\Windows")).to be_truthy
|
||||
expect(Rscons.absolute_path?("f:\\stuff")).to be_truthy
|
||||
expect(Rscons.absolute_path?("g:/projects")).to be_truthy
|
||||
expect(Rscons.absolute_path?("x:foo")).to be_falsey
|
||||
expect(Rscons.absolute_path?("file.txt")).to be_falsey
|
||||
end
|
||||
end
|
||||
|
||||
context "not on Windows" do
|
||||
it "returns whether a path is absolute" do
|
||||
stub_const("RUBY_PLATFORM", "linux")
|
||||
expect(Rscons.absolute_path?("/foo")).to be_truthy
|
||||
expect(Rscons.absolute_path?("\\Windows")).to be_falsey
|
||||
expect(Rscons.absolute_path?("C:\\Windows")).to be_falsey
|
||||
expect(Rscons.absolute_path?("f:\\stuff")).to be_falsey
|
||||
expect(Rscons.absolute_path?("g:/projects")).to be_falsey
|
||||
expect(Rscons.absolute_path?("x:foo")).to be_falsey
|
||||
expect(Rscons.absolute_path?("file.txt")).to be_falsey
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
describe ".set_suffix" do
|
||||
it "changes the suffix to the new one" do
|
||||
@ -125,4 +98,5 @@ describe Rscons do
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
end
|
||||
|
Loading…
x
Reference in New Issue
Block a user