add Environment#shell - close #11

This commit is contained in:
josh committed 2014-06-11 14:59:31 -04:00
1 parent a1a4cc18cd
commit ae9021a505
4 files changed
+120

No files matched your search

+19
View File
@@ -360,6 +360,25 @@ module Rscons
end
end
describe "#shell" do
it "executes the given shell command and returns the results" do
env = Environment.new
expect(env.shell("echo hello").strip).to eq("hello")
end
it "determines shell flag to be /c when SHELL is specified as 'cmd'" do
env = Environment.new
env["SHELL"] = "cmd"
IO.should_receive(:popen).with(["cmd", "/c", "my_cmd"])
env.shell("my_cmd")
end
it "determines shell flag to be -c when SHELL is specified as something else" do
env = Environment.new
env["SHELL"] = "my_shell"
IO.should_receive(:popen).with(["my_shell", "-c", "my_cmd"])
env.shell("my_cmd")
end
end
describe ".parse_makefile_deps" do
it 'handles dependencies on one line' do
File.should_receive(:read).with('makefile').and_return(<<EOS)
+43
View File
@@ -23,4 +23,47 @@ describe Rscons do
Rscons.clean
end
end
describe ".get_system_shell" do
before(:each) do
Rscons.class_variable_set(:@@shell, nil)
end
after(:each) do
Rscons.class_variable_set(:@@shell, nil)
end
it "uses the SHELL environment variable if it tests successfully" do
my_ENV = {"SHELL" => "my_shell"}
ENV.stub(:[]) {|*args| my_ENV[*args]}
io = StringIO.new("success\n")
IO.should_receive(:popen).with(["my_shell", "-c", "echo success"]).and_yield(io)
expect(Rscons.get_system_shell).to eq(["my_shell", "-c"])
end
it "uses sh -c on a mingw platform if it tests successfully" do
my_ENV = {"SHELL" => nil}
ENV.stub(:[]) {|*args| my_ENV[*args]}
io = StringIO.new("success\n")
IO.should_receive(:popen).with(["sh", "-c", "echo success"]).and_yield(io)
Object.should_receive(:const_get).with("RUBY_PLATFORM").and_return("x86-mingw")
expect(Rscons.get_system_shell).to eq(["sh", "-c"])
end
it "uses cmd /c on a mingw platform if sh -c does not test successfully" do
my_ENV = {"SHELL" => nil}
ENV.stub(:[]) {|*args| my_ENV[*args]}
io = StringIO.new("success\n")
IO.should_receive(:popen).with(["sh", "-c", "echo success"]).and_raise "ENOENT"
Object.should_receive(:const_get).with("RUBY_PLATFORM").and_return("x86-mingw")
expect(Rscons.get_system_shell).to eq(["cmd", "/c"])
end
it "uses sh -c on a non-mingw platform if SHELL is not specified" do
my_ENV = {"SHELL" => nil}
ENV.stub(:[]) {|*args| my_ENV[*args]}
Object.should_receive(:const_get).with("RUBY_PLATFORM").and_return("x86-linux")
expect(Rscons.get_system_shell).to eq(["sh", "-c"])
end
end
end