update more rspec expectations
This commit is contained in:
parent
0778f043ee
commit
5783ed993a
@ -16,8 +16,8 @@ module Rscons
|
|||||||
describe "#initialize" do
|
describe "#initialize" do
|
||||||
context "when corrupt" do
|
context "when corrupt" do
|
||||||
it "prints a warning and defaults to an empty hash" do
|
it "prints a warning and defaults to an empty hash" do
|
||||||
JSON.should_receive(:load).and_return("string")
|
expect(JSON).to receive(:load).and_return("string")
|
||||||
$stderr.should_receive(:puts).with(/Warning:.*was.corrupt/)
|
expect($stderr).to receive(:puts).with(/Warning:.*was.corrupt/)
|
||||||
c = Cache.instance
|
c = Cache.instance
|
||||||
c.send(:initialize!)
|
c.send(:initialize!)
|
||||||
expect(c.instance_variable_get(:@cache).is_a?(Hash)).to be_truthy
|
expect(c.instance_variable_get(:@cache).is_a?(Hash)).to be_truthy
|
||||||
@ -27,18 +27,18 @@ module Rscons
|
|||||||
|
|
||||||
describe "#clear" do
|
describe "#clear" do
|
||||||
it "removes the cache file" do
|
it "removes the cache file" do
|
||||||
FileUtils.should_receive(:rm_f).with(Cache::CACHE_FILE)
|
expect(FileUtils).to receive(:rm_f).with(Cache::CACHE_FILE)
|
||||||
JSON.stub(:load) {{}}
|
JSON.stub(:load) {{}}
|
||||||
Cache.instance.clear
|
Cache.instance.clear
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
describe "#write" do
|
describe "#write" do
|
||||||
it "should fill in 'version' and write to file" do
|
it "fills in 'version' and write to file" do
|
||||||
cache = {}
|
cache = {}
|
||||||
fh = $stdout
|
fh = $stdout
|
||||||
fh.should_receive(:puts)
|
expect(fh).to receive(:puts)
|
||||||
File.should_receive(:open).and_yield(fh)
|
expect(File).to receive(:open).and_yield(fh)
|
||||||
build_from(cache).write
|
build_from(cache).write
|
||||||
expect(cache["version"]).to eq Rscons::VERSION
|
expect(cache["version"]).to eq Rscons::VERSION
|
||||||
end
|
end
|
||||||
@ -51,28 +51,28 @@ module Rscons
|
|||||||
end
|
end
|
||||||
|
|
||||||
it "returns false when target file does not exist" do
|
it "returns false when target file does not exist" do
|
||||||
File.should_receive(:exists?).with("target").and_return(false)
|
expect(File).to receive(:exists?).with("target").and_return(false)
|
||||||
expect(build_from({}).up_to_date?("target", "command", [], empty_env)).to be_falsey
|
expect(build_from({}).up_to_date?("target", "command", [], empty_env)).to be_falsey
|
||||||
end
|
end
|
||||||
|
|
||||||
it "returns false when target is not registered in the cache" do
|
it "returns false when target is not registered in the cache" do
|
||||||
File.should_receive(:exists?).with("target").and_return(true)
|
expect(File).to receive(:exists?).with("target").and_return(true)
|
||||||
expect(build_from({}).up_to_date?("target", "command", [], empty_env)).to be_falsey
|
expect(build_from({}).up_to_date?("target", "command", [], empty_env)).to be_falsey
|
||||||
end
|
end
|
||||||
|
|
||||||
it "returns false when the target's checksum does not match" do
|
it "returns false when the target's checksum does not match" do
|
||||||
_cache = {"targets" => {"target" => {"checksum" => "abc"}}}
|
_cache = {"targets" => {"target" => {"checksum" => "abc"}}}
|
||||||
cache = build_from(_cache)
|
cache = build_from(_cache)
|
||||||
File.should_receive(:exists?).with("target").and_return(true)
|
expect(File).to receive(:exists?).with("target").and_return(true)
|
||||||
cache.should_receive(:calculate_checksum).with("target").and_return("def")
|
expect(cache).to receive(:calculate_checksum).with("target").and_return("def")
|
||||||
expect(cache.up_to_date?("target", "command", [], empty_env)).to be_falsey
|
expect(cache.up_to_date?("target", "command", [], empty_env)).to be_falsey
|
||||||
end
|
end
|
||||||
|
|
||||||
it "returns false when the build command has changed" do
|
it "returns false when the build command has changed" do
|
||||||
_cache = {"targets" => {"target" => {"checksum" => "abc", "command" => Digest::MD5.hexdigest("old command".inspect)}}}
|
_cache = {"targets" => {"target" => {"checksum" => "abc", "command" => Digest::MD5.hexdigest("old command".inspect)}}}
|
||||||
cache = build_from(_cache)
|
cache = build_from(_cache)
|
||||||
File.should_receive(:exists?).with("target").and_return(true)
|
expect(File).to receive(:exists?).with("target").and_return(true)
|
||||||
cache.should_receive(:calculate_checksum).with("target").and_return("abc")
|
expect(cache).to receive(:calculate_checksum).with("target").and_return("abc")
|
||||||
expect(cache.up_to_date?("target", "command", [], empty_env)).to be_falsey
|
expect(cache.up_to_date?("target", "command", [], empty_env)).to be_falsey
|
||||||
end
|
end
|
||||||
|
|
||||||
@ -81,8 +81,8 @@ module Rscons
|
|||||||
"command" => Digest::MD5.hexdigest("command".inspect),
|
"command" => Digest::MD5.hexdigest("command".inspect),
|
||||||
"deps" => [{"fname" => "dep.1"}]}}}
|
"deps" => [{"fname" => "dep.1"}]}}}
|
||||||
cache = build_from(_cache)
|
cache = build_from(_cache)
|
||||||
File.should_receive(:exists?).with("target").and_return(true)
|
expect(File).to receive(:exists?).with("target").and_return(true)
|
||||||
cache.should_receive(:calculate_checksum).with("target").and_return("abc")
|
expect(cache).to receive(:calculate_checksum).with("target").and_return("abc")
|
||||||
expect(cache.up_to_date?("target", "command", ["dep.1", "dep.2"], empty_env)).to be_falsey
|
expect(cache.up_to_date?("target", "command", ["dep.1", "dep.2"], empty_env)).to be_falsey
|
||||||
end
|
end
|
||||||
|
|
||||||
@ -97,10 +97,10 @@ module Rscons
|
|||||||
"checksum" => "extra.dep.chk"}],
|
"checksum" => "extra.dep.chk"}],
|
||||||
"user_deps" => []}}}
|
"user_deps" => []}}}
|
||||||
cache = build_from(_cache)
|
cache = build_from(_cache)
|
||||||
File.should_receive(:exists?).with("target").and_return(true)
|
expect(File).to receive(:exists?).with("target").and_return(true)
|
||||||
cache.should_receive(:calculate_checksum).with("target").and_return("abc")
|
expect(cache).to receive(:calculate_checksum).with("target").and_return("abc")
|
||||||
cache.should_receive(:calculate_checksum).with("dep.1").and_return("dep.1.chk")
|
expect(cache).to receive(:calculate_checksum).with("dep.1").and_return("dep.1.chk")
|
||||||
cache.should_receive(:calculate_checksum).with("dep.2").and_return("dep.2.changed")
|
expect(cache).to receive(:calculate_checksum).with("dep.2").and_return("dep.2.changed")
|
||||||
expect(cache.up_to_date?("target", "command", ["dep.1", "dep.2"], empty_env)).to be_falsey
|
expect(cache.up_to_date?("target", "command", ["dep.1", "dep.2"], empty_env)).to be_falsey
|
||||||
end
|
end
|
||||||
|
|
||||||
@ -115,8 +115,8 @@ module Rscons
|
|||||||
"checksum" => "extra.dep.chk"}],
|
"checksum" => "extra.dep.chk"}],
|
||||||
"user_deps" => []}}}
|
"user_deps" => []}}}
|
||||||
cache = build_from(_cache)
|
cache = build_from(_cache)
|
||||||
File.should_receive(:exists?).with("target").and_return(true)
|
expect(File).to receive(:exists?).with("target").and_return(true)
|
||||||
cache.should_receive(:calculate_checksum).with("target").and_return("abc")
|
expect(cache).to receive(:calculate_checksum).with("target").and_return("abc")
|
||||||
expect(cache.up_to_date?("target", "command", ["dep.1", "dep.2"], empty_env, strict_deps: true)).to be_falsey
|
expect(cache.up_to_date?("target", "command", ["dep.1", "dep.2"], empty_env, strict_deps: true)).to be_falsey
|
||||||
end
|
end
|
||||||
|
|
||||||
@ -127,9 +127,9 @@ module Rscons
|
|||||||
"user_deps" => []}}}
|
"user_deps" => []}}}
|
||||||
cache = build_from(_cache)
|
cache = build_from(_cache)
|
||||||
env = "env"
|
env = "env"
|
||||||
env.should_receive(:get_user_deps).with("target").and_return(["file.ld"])
|
expect(env).to receive(:get_user_deps).with("target").and_return(["file.ld"])
|
||||||
File.should_receive(:exists?).with("target").and_return(true)
|
expect(File).to receive(:exists?).with("target").and_return(true)
|
||||||
cache.should_receive(:calculate_checksum).with("target").and_return("abc")
|
expect(cache).to receive(:calculate_checksum).with("target").and_return("abc")
|
||||||
expect(cache.up_to_date?("target", "command", ["dep.1"], env)).to be_falsey
|
expect(cache.up_to_date?("target", "command", ["dep.1"], env)).to be_falsey
|
||||||
end
|
end
|
||||||
|
|
||||||
@ -146,13 +146,13 @@ module Rscons
|
|||||||
"checksum" => "user.dep.chk"}]}}}
|
"checksum" => "user.dep.chk"}]}}}
|
||||||
cache = build_from(_cache)
|
cache = build_from(_cache)
|
||||||
env = "env"
|
env = "env"
|
||||||
env.should_receive(:get_user_deps).with("target").and_return(["user.dep"])
|
expect(env).to receive(:get_user_deps).with("target").and_return(["user.dep"])
|
||||||
File.should_receive(:exists?).with("target").and_return(true)
|
expect(File).to receive(:exists?).with("target").and_return(true)
|
||||||
cache.should_receive(:calculate_checksum).with("target").and_return("abc")
|
expect(cache).to receive(:calculate_checksum).with("target").and_return("abc")
|
||||||
cache.should_receive(:calculate_checksum).with("dep.1").and_return("dep.1.chk")
|
expect(cache).to receive(:calculate_checksum).with("dep.1").and_return("dep.1.chk")
|
||||||
cache.should_receive(:calculate_checksum).with("dep.2").and_return("dep.2.chk")
|
expect(cache).to receive(:calculate_checksum).with("dep.2").and_return("dep.2.chk")
|
||||||
cache.should_receive(:calculate_checksum).with("extra.dep").and_return("extra.dep.chk")
|
expect(cache).to receive(:calculate_checksum).with("extra.dep").and_return("extra.dep.chk")
|
||||||
cache.should_receive(:calculate_checksum).with("user.dep").and_return("INCORRECT")
|
expect(cache).to receive(:calculate_checksum).with("user.dep").and_return("INCORRECT")
|
||||||
expect(cache.up_to_date?("target", "command", ["dep.1", "dep.2"], env)).to be_falsey
|
expect(cache.up_to_date?("target", "command", ["dep.1", "dep.2"], env)).to be_falsey
|
||||||
end
|
end
|
||||||
|
|
||||||
@ -167,11 +167,11 @@ module Rscons
|
|||||||
"checksum" => "extra.dep.chk"}],
|
"checksum" => "extra.dep.chk"}],
|
||||||
"user_deps" => []}}}
|
"user_deps" => []}}}
|
||||||
cache = build_from(_cache)
|
cache = build_from(_cache)
|
||||||
File.should_receive(:exists?).with("target").and_return(true)
|
expect(File).to receive(:exists?).with("target").and_return(true)
|
||||||
cache.should_receive(:calculate_checksum).with("target").and_return("abc")
|
expect(cache).to receive(:calculate_checksum).with("target").and_return("abc")
|
||||||
cache.should_receive(:calculate_checksum).with("dep.1").and_return("dep.1.chk")
|
expect(cache).to receive(:calculate_checksum).with("dep.1").and_return("dep.1.chk")
|
||||||
cache.should_receive(:calculate_checksum).with("dep.2").and_return("dep.2.chk")
|
expect(cache).to receive(:calculate_checksum).with("dep.2").and_return("dep.2.chk")
|
||||||
cache.should_receive(:calculate_checksum).with("extra.dep").and_return("extra.dep.chk")
|
expect(cache).to receive(:calculate_checksum).with("extra.dep").and_return("extra.dep.chk")
|
||||||
expect(cache.up_to_date?("target", "command", ["dep.1", "dep.2"], empty_env)).to be_truthy
|
expect(cache.up_to_date?("target", "command", ["dep.1", "dep.2"], empty_env)).to be_truthy
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
@ -181,14 +181,14 @@ module Rscons
|
|||||||
_cache = {}
|
_cache = {}
|
||||||
cache = build_from(_cache)
|
cache = build_from(_cache)
|
||||||
env = "env"
|
env = "env"
|
||||||
env.should_receive(:get_user_deps).with("the target").and_return(["user.dep"])
|
expect(env).to receive(:get_user_deps).with("the target").and_return(["user.dep"])
|
||||||
cache.should_receive(:calculate_checksum).with("the target").and_return("the checksum")
|
expect(cache).to receive(:calculate_checksum).with("the target").and_return("the checksum")
|
||||||
cache.should_receive(:calculate_checksum).with("dep 1").and_return("dep 1 checksum")
|
expect(cache).to receive(:calculate_checksum).with("dep 1").and_return("dep 1 checksum")
|
||||||
cache.should_receive(:calculate_checksum).with("dep 2").and_return("dep 2 checksum")
|
expect(cache).to receive(:calculate_checksum).with("dep 2").and_return("dep 2 checksum")
|
||||||
cache.should_receive(:calculate_checksum).with("user.dep").and_return("user.dep checksum")
|
expect(cache).to receive(:calculate_checksum).with("user.dep").and_return("user.dep checksum")
|
||||||
cache.register_build("the target", "the command", ["dep 1", "dep 2"], env)
|
cache.register_build("the target", "the command", ["dep 1", "dep 2"], env)
|
||||||
cached_target = cache.instance_variable_get(:@cache)["targets"]["the target"]
|
cached_target = cache.instance_variable_get(:@cache)["targets"]["the target"]
|
||||||
cached_target.should_not be_nil
|
expect(cached_target).to_not be_nil
|
||||||
expect(cached_target["command"]).to eq Digest::MD5.hexdigest("the command".inspect)
|
expect(cached_target["command"]).to eq Digest::MD5.hexdigest("the command".inspect)
|
||||||
expect(cached_target["checksum"]).to eq "the checksum"
|
expect(cached_target["checksum"]).to eq "the checksum"
|
||||||
expect(cached_target["deps"]).to eq [
|
expect(cached_target["deps"]).to eq [
|
||||||
@ -212,15 +212,15 @@ module Rscons
|
|||||||
it "makes directories and records any created in the cache" do
|
it "makes directories and records any created in the cache" do
|
||||||
_cache = {}
|
_cache = {}
|
||||||
cache = build_from(_cache)
|
cache = build_from(_cache)
|
||||||
File.should_receive(:exists?).with("one").and_return(true)
|
expect(File).to receive(:exists?).with("one").and_return(true)
|
||||||
File.should_receive(:exists?).with("one/two").and_return(false)
|
expect(File).to receive(:exists?).with("one/two").and_return(false)
|
||||||
FileUtils.should_receive(:mkdir).with("one/two")
|
expect(FileUtils).to receive(:mkdir).with("one/two")
|
||||||
File.should_receive(:exists?).with("one/two/three").and_return(false)
|
expect(File).to receive(:exists?).with("one/two/three").and_return(false)
|
||||||
FileUtils.should_receive(:mkdir).with("one/two/three")
|
expect(FileUtils).to receive(:mkdir).with("one/two/three")
|
||||||
File.should_receive(:exists?).with("one").and_return(true)
|
expect(File).to receive(:exists?).with("one").and_return(true)
|
||||||
File.should_receive(:exists?).with("one/two").and_return(true)
|
expect(File).to receive(:exists?).with("one/two").and_return(true)
|
||||||
File.should_receive(:exists?).with("one/two/four").and_return(false)
|
expect(File).to receive(:exists?).with("one/two/four").and_return(false)
|
||||||
FileUtils.should_receive(:mkdir).with("one/two/four")
|
expect(FileUtils).to receive(:mkdir).with("one/two/four")
|
||||||
cache.mkdir_p("one/two/three")
|
cache.mkdir_p("one/two/three")
|
||||||
cache.mkdir_p("one\\two\\four")
|
cache.mkdir_p("one\\two\\four")
|
||||||
expect(cache.directories).to eq ["one/two", "one/two/three", "one/two/four"]
|
expect(cache.directories).to eq ["one/two", "one/two/three", "one/two/four"]
|
||||||
@ -229,9 +229,9 @@ module Rscons
|
|||||||
it "handles absolute paths" do
|
it "handles absolute paths" do
|
||||||
_cache = {}
|
_cache = {}
|
||||||
cache = build_from(_cache)
|
cache = build_from(_cache)
|
||||||
File.should_receive(:exists?).with("/one").and_return(true)
|
expect(File).to receive(:exists?).with("/one").and_return(true)
|
||||||
File.should_receive(:exists?).with("/one/two").and_return(false)
|
expect(File).to receive(:exists?).with("/one/two").and_return(false)
|
||||||
FileUtils.should_receive(:mkdir).with("/one/two")
|
expect(FileUtils).to receive(:mkdir).with("/one/two")
|
||||||
cache.mkdir_p("/one/two")
|
cache.mkdir_p("/one/two")
|
||||||
expect(cache.directories).to eq ["/one/two"]
|
expect(cache.directories).to eq ["/one/two"]
|
||||||
end
|
end
|
||||||
@ -248,13 +248,13 @@ module Rscons
|
|||||||
it "does not re-calculate the checksum when it is already cached" do
|
it "does not re-calculate the checksum when it is already cached" do
|
||||||
cache = build_from({})
|
cache = build_from({})
|
||||||
cache.instance_variable_set(:@lookup_checksums, {"f1" => "f1.chk"})
|
cache.instance_variable_set(:@lookup_checksums, {"f1" => "f1.chk"})
|
||||||
cache.should_not_receive(:calculate_checksum)
|
expect(cache).to_not receive(:calculate_checksum)
|
||||||
expect(cache.send(:lookup_checksum, "f1")).to eq "f1.chk"
|
expect(cache.send(:lookup_checksum, "f1")).to eq "f1.chk"
|
||||||
end
|
end
|
||||||
|
|
||||||
it "calls calculate_checksum when the checksum is not cached" do
|
it "calls calculate_checksum when the checksum is not cached" do
|
||||||
cache = build_from({})
|
cache = build_from({})
|
||||||
cache.should_receive(:calculate_checksum).with("f1").and_return("ck")
|
expect(cache).to receive(:calculate_checksum).with("f1").and_return("ck")
|
||||||
expect(cache.send(:lookup_checksum, "f1")).to eq "ck"
|
expect(cache.send(:lookup_checksum, "f1")).to eq "ck"
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
@ -262,8 +262,8 @@ module Rscons
|
|||||||
describe "#calculate_checksum" do
|
describe "#calculate_checksum" do
|
||||||
it "calculates the MD5 of the file contents" do
|
it "calculates the MD5 of the file contents" do
|
||||||
contents = "contents"
|
contents = "contents"
|
||||||
File.should_receive(:read).with("fname", mode: "rb").and_return(contents)
|
expect(File).to receive(:read).with("fname", mode: "rb").and_return(contents)
|
||||||
Digest::MD5.should_receive(:hexdigest).with(contents).and_return("the_checksum")
|
expect(Digest::MD5).to receive(:hexdigest).with(contents).and_return("the_checksum")
|
||||||
expect(build_from({}).send(:calculate_checksum, "fname")).to eq "the_checksum"
|
expect(build_from({}).send(:calculate_checksum, "fname")).to eq "the_checksum"
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -3,11 +3,11 @@ module Rscons
|
|||||||
describe "#initialize" do
|
describe "#initialize" do
|
||||||
it "adds the default builders when they are not excluded" do
|
it "adds the default builders when they are not excluded" do
|
||||||
env = Environment.new
|
env = Environment.new
|
||||||
env.builders.size.should be > 0
|
expect(env.builders.size).to be > 0
|
||||||
expect(env.builders.map {|name, builder| builder.is_a?(Builder)}.all?).to be_truthy
|
expect(env.builders.map {|name, builder| builder.is_a?(Builder)}.all?).to be_truthy
|
||||||
env.builders.find {|name, builder| name == "Object"}.should_not be_nil
|
expect(env.builders.find {|name, builder| name == "Object"}).to_not be_nil
|
||||||
env.builders.find {|name, builder| name == "Program"}.should_not be_nil
|
expect(env.builders.find {|name, builder| name == "Program"}).to_not be_nil
|
||||||
env.builders.find {|name, builder| name == "Library"}.should_not be_nil
|
expect(env.builders.find {|name, builder| name == "Library"}).to_not be_nil
|
||||||
end
|
end
|
||||||
|
|
||||||
it "excludes the default builders with exclude_builders: :all" do
|
it "excludes the default builders with exclude_builders: :all" do
|
||||||
@ -18,14 +18,14 @@ module Rscons
|
|||||||
context "when a block is given" do
|
context "when a block is given" do
|
||||||
it "yields self and invokes #process()" do
|
it "yields self and invokes #process()" do
|
||||||
env = Environment.new do |env|
|
env = Environment.new do |env|
|
||||||
env.should_receive(:process)
|
expect(env).to receive(:process)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
describe "#clone" do
|
describe "#clone" do
|
||||||
it 'should create unique copies of each construction variable' do
|
it 'creates unique copies of each construction variable' do
|
||||||
env = Environment.new
|
env = Environment.new
|
||||||
env["CPPPATH"] << "path1"
|
env["CPPPATH"] << "path1"
|
||||||
env2 = env.clone
|
env2 = env.clone
|
||||||
@ -59,7 +59,7 @@ module Rscons
|
|||||||
it "yields self and invokes #process()" do
|
it "yields self and invokes #process()" do
|
||||||
env = Environment.new
|
env = Environment.new
|
||||||
env.clone do |env2|
|
env.clone do |env2|
|
||||||
env2.should_receive(:process)
|
expect(env2).to receive(:process)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
@ -161,10 +161,10 @@ module Rscons
|
|||||||
env.Program("a.out", "main.c")
|
env.Program("a.out", "main.c")
|
||||||
|
|
||||||
cache = "cache"
|
cache = "cache"
|
||||||
Cache.should_receive(:instance).and_return(cache)
|
expect(Cache).to receive(:instance).and_return(cache)
|
||||||
cache.should_receive(:clear_checksum_cache!)
|
expect(cache).to receive(:clear_checksum_cache!)
|
||||||
env.should_receive(:run_builder).with(anything, "a.out", ["main.c"], cache, {}).and_return(true)
|
expect(env).to receive(:run_builder).with(anything, "a.out", ["main.c"], cache, {}).and_return(true)
|
||||||
cache.should_receive(:write)
|
expect(cache).to receive(:write)
|
||||||
|
|
||||||
env.process
|
env.process
|
||||||
end
|
end
|
||||||
@ -175,11 +175,11 @@ module Rscons
|
|||||||
env.Object("main.o", "other.cc")
|
env.Object("main.o", "other.cc")
|
||||||
|
|
||||||
cache = "cache"
|
cache = "cache"
|
||||||
Cache.should_receive(:instance).and_return(cache)
|
expect(Cache).to receive(:instance).and_return(cache)
|
||||||
cache.should_receive(:clear_checksum_cache!)
|
expect(cache).to receive(:clear_checksum_cache!)
|
||||||
env.should_receive(:run_builder).with(anything, "main.o", ["other.cc"], cache, {}).and_return("main.o")
|
expect(env).to receive(:run_builder).with(anything, "main.o", ["other.cc"], cache, {}).and_return("main.o")
|
||||||
env.should_receive(:run_builder).with(anything, "a.out", ["main.o"], cache, {}).and_return("a.out")
|
expect(env).to receive(:run_builder).with(anything, "a.out", ["main.o"], cache, {}).and_return("a.out")
|
||||||
cache.should_receive(:write)
|
expect(cache).to receive(:write)
|
||||||
|
|
||||||
env.process
|
env.process
|
||||||
end
|
end
|
||||||
@ -190,10 +190,10 @@ module Rscons
|
|||||||
env.Object("main.o", "other.cc")
|
env.Object("main.o", "other.cc")
|
||||||
|
|
||||||
cache = "cache"
|
cache = "cache"
|
||||||
Cache.should_receive(:instance).and_return(cache)
|
expect(Cache).to receive(:instance).and_return(cache)
|
||||||
cache.should_receive(:clear_checksum_cache!)
|
expect(cache).to receive(:clear_checksum_cache!)
|
||||||
env.should_receive(:run_builder).with(anything, "main.o", ["other.cc"], cache, {}).and_return(false)
|
expect(env).to receive(:run_builder).with(anything, "main.o", ["other.cc"], cache, {}).and_return(false)
|
||||||
cache.should_receive(:write)
|
expect(cache).to receive(:write)
|
||||||
|
|
||||||
expect { env.process }.to raise_error BuildError, /Failed.to.build.main.o/
|
expect { env.process }.to raise_error BuildError, /Failed.to.build.main.o/
|
||||||
end
|
end
|
||||||
@ -203,12 +203,12 @@ module Rscons
|
|||||||
env.Object("module.o", "module.c")
|
env.Object("module.o", "module.c")
|
||||||
|
|
||||||
cache = "cache"
|
cache = "cache"
|
||||||
Cache.should_receive(:instance).and_return(cache)
|
expect(Cache).to receive(:instance).and_return(cache)
|
||||||
cache.should_receive(:clear_checksum_cache!)
|
expect(cache).to receive(:clear_checksum_cache!)
|
||||||
env.stub(:run_builder) do |builder, target, sources, cache, vars|
|
env.stub(:run_builder) do |builder, target, sources, cache, vars|
|
||||||
raise "Ruby exception thrown by builder"
|
raise "Ruby exception thrown by builder"
|
||||||
end
|
end
|
||||||
cache.should_receive(:write)
|
expect(cache).to receive(:write)
|
||||||
|
|
||||||
expect { env.process }.to raise_error RuntimeError, /Ruby exception thrown by builder/
|
expect { env.process }.to raise_error RuntimeError, /Ruby exception thrown by builder/
|
||||||
end
|
end
|
||||||
@ -258,8 +258,8 @@ module Rscons
|
|||||||
context "with no errors" do
|
context "with no errors" do
|
||||||
it "prints the short description and executes the command" do
|
it "prints the short description and executes the command" do
|
||||||
env = Environment.new(echo: :short)
|
env = Environment.new(echo: :short)
|
||||||
env.should_receive(:puts).with("short desc")
|
expect(env).to receive(:puts).with("short desc")
|
||||||
env.should_receive(:system).with(*Rscons.command_executer, "a", "command").and_return(true)
|
expect(env).to receive(:system).with(*Rscons.command_executer, "a", "command").and_return(true)
|
||||||
env.execute("short desc", ["a", "command"])
|
env.execute("short desc", ["a", "command"])
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
@ -267,10 +267,10 @@ module Rscons
|
|||||||
context "with errors" do
|
context "with errors" do
|
||||||
it "prints the short description, executes the command, and prints the failed command line" do
|
it "prints the short description, executes the command, and prints the failed command line" do
|
||||||
env = Environment.new(echo: :short)
|
env = Environment.new(echo: :short)
|
||||||
env.should_receive(:puts).with("short desc")
|
expect(env).to receive(:puts).with("short desc")
|
||||||
env.should_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)
|
||||||
$stdout.should_receive(:write).with("Failed command was: ")
|
expect($stdout).to receive(:write).with("Failed command was: ")
|
||||||
env.should_receive(:puts).with("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
|
||||||
@ -279,8 +279,8 @@ module Rscons
|
|||||||
context "with echo: :command" do
|
context "with echo: :command" do
|
||||||
it "prints the command executed and executes the command" do
|
it "prints the command executed and executes the command" do
|
||||||
env = Environment.new(echo: :command)
|
env = Environment.new(echo: :command)
|
||||||
env.should_receive(:puts).with("a command '--arg=val with spaces'")
|
expect(env).to receive(:puts).with("a command '--arg=val with spaces'")
|
||||||
env.should_receive(:system).with({modified: :environment}, *Rscons.command_executer, "a", "command", "--arg=val with spaces", {opt: :val}).and_return(false)
|
expect(env).to receive(:system).with({modified: :environment}, *Rscons.command_executer, "a", "command", "--arg=val with spaces", {opt: :val}).and_return(false)
|
||||||
env.execute("short desc", ["a", "command", "--arg=val with spaces"], env: {modified: :environment}, options: {opt: :val})
|
env.execute("short desc", ["a", "command", "--arg=val with spaces"], env: {modified: :environment}, options: {opt: :val})
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
@ -297,7 +297,7 @@ module Rscons
|
|||||||
expect(env.instance_variable_get(:@targets)).to eq({})
|
expect(env.instance_variable_get(:@targets)).to eq({})
|
||||||
env.Object("target.o", ["src1.c", "src2.c"], var: "val")
|
env.Object("target.o", ["src1.c", "src2.c"], var: "val")
|
||||||
target = env.instance_variable_get(:@targets)["target.o"]
|
target = env.instance_variable_get(:@targets)["target.o"]
|
||||||
target.should_not be_nil
|
expect(target).to_not be_nil
|
||||||
expect(target[:builder].is_a?(Builder)).to be_truthy
|
expect(target[:builder].is_a?(Builder)).to be_truthy
|
||||||
expect(target[:sources]).to eq ["src1.c", "src2.c"]
|
expect(target[:sources]).to eq ["src1.c", "src2.c"]
|
||||||
expect(target[:vars]).to eq({var: "val"})
|
expect(target[:vars]).to eq({var: "val"})
|
||||||
@ -335,8 +335,8 @@ module Rscons
|
|||||||
cache = "cache"
|
cache = "cache"
|
||||||
env = Environment.new
|
env = Environment.new
|
||||||
env.add_builder(ABuilder.new)
|
env.add_builder(ABuilder.new)
|
||||||
env.builders["Object"].should_receive(:run).with("mod.o", ["mod.c"], cache, env, anything).and_return("mod.o")
|
expect(env.builders["Object"]).to receive(:run).with("mod.o", ["mod.c"], cache, env, anything).and_return("mod.o")
|
||||||
env.builders["ABuilder"].should_receive(:run).with("mod2.ab_out", ["mod2.ab_in"], cache, env, anything).and_return("mod2.ab_out")
|
expect(env.builders["ABuilder"]).to receive(:run).with("mod2.ab_out", ["mod2.ab_in"], cache, env, anything).and_return("mod2.ab_out")
|
||||||
expect(env.build_sources(["precompiled.o", "mod.c", "mod2.ab_in"], [".o", ".ab_out"], cache, {})).to eq ["precompiled.o", "mod.o", "mod2.ab_out"]
|
expect(env.build_sources(["precompiled.o", "mod.c", "mod2.ab_in"], [".o", ".ab_out"], cache, {})).to eq ["precompiled.o", "mod.o", "mod2.ab_out"]
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
@ -368,13 +368,13 @@ module Rscons
|
|||||||
it "determines shell flag to be /c when SHELL is specified as 'cmd'" do
|
it "determines shell flag to be /c when SHELL is specified as 'cmd'" do
|
||||||
env = Environment.new
|
env = Environment.new
|
||||||
env["SHELL"] = "cmd"
|
env["SHELL"] = "cmd"
|
||||||
IO.should_receive(:popen).with(["cmd", "/c", "my_cmd"])
|
expect(IO).to receive(:popen).with(["cmd", "/c", "my_cmd"])
|
||||||
env.shell("my_cmd")
|
env.shell("my_cmd")
|
||||||
end
|
end
|
||||||
it "determines shell flag to be -c when SHELL is specified as something else" do
|
it "determines shell flag to be -c when SHELL is specified as something else" do
|
||||||
env = Environment.new
|
env = Environment.new
|
||||||
env["SHELL"] = "my_shell"
|
env["SHELL"] = "my_shell"
|
||||||
IO.should_receive(:popen).with(["my_shell", "-c", "my_cmd"])
|
expect(IO).to receive(:popen).with(["my_shell", "-c", "my_cmd"])
|
||||||
env.shell("my_cmd")
|
env.shell("my_cmd")
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
@ -383,7 +383,7 @@ module Rscons
|
|||||||
it "executes the shell command and parses the returned flags when the input argument begins with !" do
|
it "executes the shell command and parses the returned flags when the input argument begins with !" do
|
||||||
env = Environment.new
|
env = Environment.new
|
||||||
env["CFLAGS"] = ["-g"]
|
env["CFLAGS"] = ["-g"]
|
||||||
env.should_receive(:shell).with("my_command").and_return(%[-arch my_arch -Done=two -include ii -isysroot sr -Iincdir -Llibdir -lmy_lib -mno-cygwin -mwindows -pthread -std=c99 -Wa,'asm,args 1 2' -Wl,linker,"args 1 2" -Wp,cpp,args,1,2 -arbitrary +other_arbitrary some_lib /a/b/c/lib])
|
expect(env).to receive(:shell).with("my_command").and_return(%[-arch my_arch -Done=two -include ii -isysroot sr -Iincdir -Llibdir -lmy_lib -mno-cygwin -mwindows -pthread -std=c99 -Wa,'asm,args 1 2' -Wl,linker,"args 1 2" -Wp,cpp,args,1,2 -arbitrary +other_arbitrary some_lib /a/b/c/lib])
|
||||||
rv = env.parse_flags("!my_command")
|
rv = env.parse_flags("!my_command")
|
||||||
expect(rv).to eq({
|
expect(rv).to eq({
|
||||||
"CCFLAGS" => %w[-arch my_arch -include ii -isysroot sr -mno-cygwin -pthread -arbitrary +other_arbitrary],
|
"CCFLAGS" => %w[-arch my_arch -include ii -isysroot sr -mno-cygwin -pthread -arbitrary +other_arbitrary],
|
||||||
@ -435,14 +435,14 @@ module Rscons
|
|||||||
|
|
||||||
describe ".parse_makefile_deps" do
|
describe ".parse_makefile_deps" do
|
||||||
it 'handles dependencies on one line' do
|
it 'handles dependencies on one line' do
|
||||||
File.should_receive(:read).with('makefile').and_return(<<EOS)
|
expect(File).to receive(:read).with('makefile').and_return(<<EOS)
|
||||||
module.o: source.cc
|
module.o: source.cc
|
||||||
EOS
|
EOS
|
||||||
expect(Environment.parse_makefile_deps('makefile', 'module.o')).to eq ['source.cc']
|
expect(Environment.parse_makefile_deps('makefile', 'module.o')).to eq ['source.cc']
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'handles dependencies split across many lines' do
|
it 'handles dependencies split across many lines' do
|
||||||
File.should_receive(:read).with('makefile').and_return(<<EOS)
|
expect(File).to receive(:read).with('makefile').and_return(<<EOS)
|
||||||
module.o: module.c \\
|
module.o: module.c \\
|
||||||
module.h \\
|
module.h \\
|
||||||
other.h
|
other.h
|
||||||
|
Loading…
x
Reference in New Issue
Block a user