convert Object builder specs to integration tests

This commit is contained in:
Josh Holtrop 2017-05-22 16:38:57 -04:00
parent 2be738be4f
commit 7e707e7e3b
5 changed files with 39 additions and 52 deletions

View File

@ -0,0 +1,6 @@
Rscons::Environment.new do |env|
File.open("foo.xyz", "wb") do |fh|
fh.puts("hi")
end
env.Object("foo.o", "foo.xyz")
end

View File

@ -0,0 +1,4 @@
Rscons::Environment.new(echo: :command) do |env|
env.Object("simple.o", "simple.c",
"CCCMD" => %w[${CC} -c -o ${_TARGET} -Dfoobar ${_SOURCES}])
end

View File

@ -0,0 +1,4 @@
Rscons::Environment.new(echo: :command) do |env|
env["DEPFILESUFFIX"] = ".deppy"
env.Object("simple.o", "simple.c")
end

View File

@ -935,4 +935,29 @@ EOF
end
end
context "Object builder" do
it "allows overriding CCCMD construction variable" do
test_dir("simple")
result = run_test(rsconsfile: "override_cccmd.rb")
expect(result.stderr).to eq ""
expect(lines(result.stdout)).to eq [
"gcc -c -o simple.o -Dfoobar simple.c",
]
end
it "allows overriding DEPFILESUFFIX construction variable" do
test_dir("simple")
result = run_test(rsconsfile: "override_depfilesuffix.rb")
expect(result.stderr).to eq ""
expect(lines(result.stdout)).to eq [
"gcc -c -o simple.o -MMD -MF simple.deppy simple.c",
]
end
it "raises an error when given a source file with an unknown suffix" do
test_dir("simple")
result = run_test(rsconsfile: "error_unknown_suffix.rb")
expect(result.stderr).to match /unknown input file type: "foo.xyz"/
end
end
end

View File

@ -1,52 +0,0 @@
module Rscons
module Builders
describe Object do
let(:env) {Environment.new}
let(:cache) {double(Cache)}
subject {Object.new}
it "supports overriding CCCMD construction variable" do
expect(cache).to receive(:up_to_date?).and_return(false)
expect(cache).to receive(:mkdir_p)
expect(FileUtils).to receive(:rm_f)
expect(env).to receive(:execute).with("CC mod.o", ["llc", "mod.c"]).and_return(true)
expect(File).to receive(:exists?).and_return(false)
expect(cache).to receive(:register_build)
subject.run(
target: "mod.o",
sources: ["mod.c"],
cache: cache,
env: env,
vars: {"CCCMD" => ["llc", "${_SOURCES}"]})
end
it "supports overriding DEPFILESUFFIX construction variable" do
expect(cache).to receive(:up_to_date?).and_return(false)
expect(cache).to receive(:mkdir_p)
expect(FileUtils).to receive(:rm_f)
expect(env).to receive(:execute).with(anything, %w[gcc -c -o f.o -MMD -MF f.d in.c]).and_return(true)
expect(File).to receive(:exists?).with("f.d").and_return(false)
expect(cache).to receive(:register_build)
subject.run(
target: "f.o",
sources: ["in.c"],
cache: cache,
env: env,
vars: {"DEPFILESUFFIX" => ".d"})
end
it "raises an error when given a source file with an unknown suffix" do
expect do
subject.run(
target: "mod.o",
sources: ["mod.xyz"],
cache: :cache,
env: env,
vars: {})
end.to raise_error /unknown input file type: "mod.xyz"/
end
end
end
end