70 lines
3.0 KiB
Ruby
70 lines
3.0 KiB
Ruby
describe Rscons do
|
|
describe ".clean" do
|
|
it "removes all build targets and created directories" do
|
|
cache = "cache"
|
|
Rscons::Cache.should_receive(:instance).and_return(cache)
|
|
cache.should_receive(:targets).and_return(["build/a.out", "build/main.o"])
|
|
FileUtils.should_receive(:rm_f).with("build/a.out")
|
|
FileUtils.should_receive(:rm_f).with("build/main.o")
|
|
cache.should_receive(:directories).and_return(["build/one", "build/one/two", "build", "other"])
|
|
File.should_receive(:directory?).with("build/one/two").and_return(true)
|
|
Dir.should_receive(:entries).with("build/one/two").and_return([".", ".."])
|
|
Dir.should_receive(:rmdir).with("build/one/two")
|
|
File.should_receive(:directory?).with("build/one").and_return(true)
|
|
Dir.should_receive(:entries).with("build/one").and_return([".", ".."])
|
|
Dir.should_receive(:rmdir).with("build/one")
|
|
File.should_receive(:directory?).with("build").and_return(true)
|
|
Dir.should_receive(:entries).with("build").and_return([".", ".."])
|
|
Dir.should_receive(:rmdir).with("build")
|
|
File.should_receive(:directory?).with("other").and_return(true)
|
|
Dir.should_receive(:entries).with("other").and_return([".", "..", "other.file"])
|
|
cache.should_receive(:clear)
|
|
|
|
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
|