update some non-integration-test specs

This commit is contained in:
Josh Holtrop 2017-05-22 16:25:49 -04:00
parent 06cb4b7a55
commit 7b3bffd329
4 changed files with 45 additions and 68 deletions

View File

@ -6,12 +6,22 @@ module Rscons
it "supports overriding AR construction variable" do it "supports overriding AR construction variable" do
expect(subject).to receive(:standard_build).with("AR prog.a", "prog.a", ["sp-ar", "rcs", "prog.a", "prog.o"], ["prog.o"], env, :cache) expect(subject).to receive(:standard_build).with("AR prog.a", "prog.a", ["sp-ar", "rcs", "prog.a", "prog.o"], ["prog.o"], env, :cache)
subject.run("prog.a", ["prog.o"], :cache, env, "AR" => "sp-ar") subject.run(
target: "prog.a",
sources: ["prog.o"],
cache: :cache,
env: env,
vars: {"AR" => "sp-ar"})
end end
it "supports overriding ARCMD construction variable" do it "supports overriding ARCMD construction variable" do
expect(subject).to receive(:standard_build).with("AR prog.a", "prog.a", ["special", "AR!", "prog.o"], ["prog.o"], env, :cache) expect(subject).to receive(:standard_build).with("AR prog.a", "prog.a", ["special", "AR!", "prog.o"], ["prog.o"], env, :cache)
subject.run("prog.a", ["prog.o"], :cache, env, "ARCMD" => ["special", "AR!", "${_SOURCES}"]) subject.run(
target: "prog.a",
sources: ["prog.o"],
cache: :cache,
env: env,
vars: {"ARCMD" => ["special", "AR!", "${_SOURCES}"]})
end end
end end
end end

View File

@ -13,7 +13,12 @@ module Rscons
expect(File).to receive(:exists?).and_return(false) expect(File).to receive(:exists?).and_return(false)
expect(cache).to receive(:register_build) expect(cache).to receive(:register_build)
subject.run("mod.o", ["mod.c"], cache, env, "CCCMD" => ["llc", "${_SOURCES}"]) subject.run(
target: "mod.o",
sources: ["mod.c"],
cache: cache,
env: env,
vars: {"CCCMD" => ["llc", "${_SOURCES}"]})
end end
it "supports overriding DEPFILESUFFIX construction variable" do it "supports overriding DEPFILESUFFIX construction variable" do
@ -24,11 +29,23 @@ module Rscons
expect(File).to receive(:exists?).with("f.d").and_return(false) expect(File).to receive(:exists?).with("f.d").and_return(false)
expect(cache).to receive(:register_build) expect(cache).to receive(:register_build)
subject.run("f.o", ["in.c"], cache, env, "DEPFILESUFFIX" => ".d") subject.run(
target: "f.o",
sources: ["in.c"],
cache: cache,
env: env,
vars: {"DEPFILESUFFIX" => ".d"})
end end
it "raises an error when given a source file with an unknown suffix" do it "raises an error when given a source file with an unknown suffix" do
expect { subject.run("mod.o", ["mod.xyz"], :cache, env, {}) }.to raise_error /unknown input file type: "mod.xyz"/ 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
end end

View File

@ -6,12 +6,22 @@ module Rscons
it "supports overriding CC construction variable" do it "supports overriding CC construction variable" do
expect(subject).to receive(:standard_build).with("LD prog", "prog", ["sp-c++", "-o", "prog", "prog.o"], ["prog.o"], env, :cache) expect(subject).to receive(:standard_build).with("LD prog", "prog", ["sp-c++", "-o", "prog", "prog.o"], ["prog.o"], env, :cache)
subject.run("prog", ["prog.o"], :cache, env, "CC" => "sp-c++") subject.run(
target: "prog",
sources: ["prog.o"],
cache: :cache,
env: env,
vars: {"CC" => "sp-c++"})
end end
it "supports overriding LDCMD construction variable" do it "supports overriding LDCMD construction variable" do
expect(subject).to receive(:standard_build).with("LD prog.exe", "prog.exe", ["special", "LD!", "prog.o"], ["prog.o"], env, :cache) expect(subject).to receive(:standard_build).with("LD prog.exe", "prog.exe", ["special", "LD!", "prog.o"], ["prog.o"], env, :cache)
subject.run("prog.exe", ["prog.o"], :cache, env, "LDCMD" => ["special", "LD!", "${_SOURCES}"]) subject.run(
target: "prog.exe",
sources: ["prog.o"],
cache: :cache,
env: env,
vars: {"LDCMD" => ["special", "LD!", "${_SOURCES}"]})
end end
end end
end end

View File

@ -162,65 +162,6 @@ module Rscons
end end
end end
describe "#process" do
it "runs builders for all of the targets specified" do
env = Environment.new
env.Program("a.out", "main.c")
cache = "cache"
expect(Cache).to receive(:instance).and_return(cache)
allow(cache).to receive(:clear_checksum_cache!)
expect(env).to receive(:run_builder).with(anything, "a.out", ["main.c"], cache, {}, allow_delayed_execution: true, setup_info: nil).and_return(true)
expect(cache).to receive(:write)
env.process
end
it "builds dependent targets first" do
env = Environment.new
env.Program("a.out", "main.o")
env.Object("main.o", "other.cc")
cache = "cache"
expect(Cache).to receive(:instance).and_return(cache)
allow(cache).to receive(:clear_checksum_cache!)
expect(env).to receive(:run_builder).with(anything, "main.o", ["other.cc"], cache, {}, allow_delayed_execution: true, setup_info: nil).and_return("main.o")
expect(env).to receive(:run_builder).with(anything, "a.out", ["main.o"], cache, {}, allow_delayed_execution: true, setup_info: nil).and_return("a.out")
expect(cache).to receive(:write)
env.process
end
it "raises a BuildError when building fails" do
env = Environment.new
env.Program("a.out", "main.o")
env.Object("main.o", "other.cc")
cache = "cache"
expect(Cache).to receive(:instance).and_return(cache)
allow(cache).to receive(:clear_checksum_cache!)
expect(env).to receive(:run_builder).with(anything, "main.o", ["other.cc"], cache, {}, allow_delayed_execution: true, setup_info: nil).and_return(false)
expect(cache).to receive(:write)
expect { env.process }.to raise_error BuildError, /Failed.to.build.main.o/
end
it "writes the cache when the Builder raises an exception" do
env = Environment.new
env.Object("module.o", "module.c")
cache = "cache"
expect(Cache).to receive(:instance).and_return(cache)
expect(cache).to receive(:clear_checksum_cache!)
allow(env).to receive(:run_builder) do |builder, target, sources, cache, vars|
raise "Ruby exception thrown by builder"
end
expect(cache).to receive(:write)
expect { env.process }.to raise_error RuntimeError, /Ruby exception thrown by builder/
end
end
describe "#build_command" do describe "#build_command" do
it "returns a command based on the variables in the Environment" do it "returns a command based on the variables in the Environment" do
env = Environment.new env = Environment.new
@ -264,8 +205,7 @@ module Rscons
env = Environment.new(echo: :short) env = Environment.new(echo: :short)
expect(env).to receive(:puts).with("short desc") expect(env).to receive(:puts).with("short desc")
expect(env).to receive(:system).with(*Rscons.command_executer, "a", "command").and_return(false) expect(env).to receive(:system).with(*Rscons.command_executer, "a", "command").and_return(false)
expect($stdout).to receive(:write).with("Failed command was: ") expect($stdout).to receive(:puts).with("Failed command was: a command")
expect(env).to receive(:puts).with("a command")
env.execute("short desc", ["a", "command"]) env.execute("short desc", ["a", "command"])
end end
end end