migrate some Cache tests to integration tests
This commit is contained in:
1 parent
bfbbc19728
commit
06cb4b7a55
9 files changed
+213
-190
No files matched your search
@@ -13,194 +13,6 @@ module Rscons
|
||||
end
|
||||
end
|
||||
|
||||
describe "#initialize" do
|
||||
context "when corrupt" do
|
||||
it "prints a warning and defaults to an empty hash" do
|
||||
expect(JSON).to receive(:load).and_return("string")
|
||||
expect($stderr).to receive(:puts).with(/Warning:.*was.corrupt/)
|
||||
c = Cache.instance
|
||||
c.send(:initialize!)
|
||||
expect(c.instance_variable_get(:@cache).is_a?(Hash)).to be_truthy
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
describe "#clear" do
|
||||
it "removes the cache file" do
|
||||
expect(FileUtils).to receive(:rm_f).with(Cache::CACHE_FILE)
|
||||
allow(JSON).to receive(:load) {{}}
|
||||
Cache.instance.clear
|
||||
end
|
||||
end
|
||||
|
||||
describe "#write" do
|
||||
it "fills in 'version' and write to file" do
|
||||
cache = {}
|
||||
fh = $stdout
|
||||
expect(fh).to receive(:puts)
|
||||
expect(File).to receive(:open).and_yield(fh)
|
||||
build_from(cache).write
|
||||
expect(cache["version"]).to eq Rscons::VERSION
|
||||
end
|
||||
end
|
||||
|
||||
describe "#up_to_date?" do
|
||||
empty_env = "env"
|
||||
before do
|
||||
allow(empty_env).to receive(:get_user_deps) { nil }
|
||||
end
|
||||
|
||||
it "returns false when target file does not exist" do
|
||||
expect(File).to receive(:exists?).with("target").and_return(false)
|
||||
expect(build_from({}).up_to_date?("target", "command", [], empty_env)).to be_falsey
|
||||
end
|
||||
|
||||
it "returns false when target is not registered in the cache" do
|
||||
expect(File).to receive(:exists?).with("target").and_return(true)
|
||||
expect(build_from({}).up_to_date?("target", "command", [], empty_env)).to be_falsey
|
||||
end
|
||||
|
||||
it "returns false when the target's checksum does not match" do
|
||||
_cache = {"targets" => {"target" => {"checksum" => "abc"}}}
|
||||
cache = build_from(_cache)
|
||||
expect(File).to receive(:exists?).with("target").and_return(true)
|
||||
expect(cache).to receive(:calculate_checksum).with("target").and_return("def")
|
||||
expect(cache.up_to_date?("target", "command", [], empty_env)).to be_falsey
|
||||
end
|
||||
|
||||
it "returns false when the build command has changed" do
|
||||
_cache = {"targets" => {"target" => {"checksum" => "abc", "command" => Digest::MD5.hexdigest("old command".inspect)}}}
|
||||
cache = build_from(_cache)
|
||||
expect(File).to receive(:exists?).with("target").and_return(true)
|
||||
expect(cache).to receive(:calculate_checksum).with("target").and_return("abc")
|
||||
expect(cache.up_to_date?("target", "command", [], empty_env)).to be_falsey
|
||||
end
|
||||
|
||||
it "returns false when there is a new dependency" do
|
||||
_cache = {"targets" => {"target" => {"checksum" => "abc",
|
||||
"command" => Digest::MD5.hexdigest("command".inspect),
|
||||
"deps" => [{"fname" => "dep.1"}]}}}
|
||||
cache = build_from(_cache)
|
||||
expect(File).to receive(:exists?).with("target").and_return(true)
|
||||
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
|
||||
end
|
||||
|
||||
it "returns false when a dependency's checksum has changed" do
|
||||
_cache = {"targets" => {"target" => {"checksum" => "abc",
|
||||
"command" => Digest::MD5.hexdigest("command".inspect),
|
||||
"deps" => [{"fname" => "dep.1",
|
||||
"checksum" => "dep.1.chk"},
|
||||
{"fname" => "dep.2",
|
||||
"checksum" => "dep.2.chk"},
|
||||
{"fname" => "extra.dep",
|
||||
"checksum" => "extra.dep.chk"}],
|
||||
"user_deps" => []}}}
|
||||
cache = build_from(_cache)
|
||||
expect(File).to receive(:exists?).with("target").and_return(true)
|
||||
expect(cache).to receive(:calculate_checksum).with("target").and_return("abc")
|
||||
expect(cache).to receive(:calculate_checksum).with("dep.1").and_return("dep.1.chk")
|
||||
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
|
||||
end
|
||||
|
||||
it "returns false with strict_deps=true when cache has an extra dependency" do
|
||||
_cache = {"targets" => {"target" => {"checksum" => "abc",
|
||||
"command" => Digest::MD5.hexdigest("command".inspect),
|
||||
"deps" => [{"fname" => "dep.1",
|
||||
"checksum" => "dep.1.chk"},
|
||||
{"fname" => "dep.2",
|
||||
"checksum" => "dep.2.chk"},
|
||||
{"fname" => "extra.dep",
|
||||
"checksum" => "extra.dep.chk"}],
|
||||
"user_deps" => []}}}
|
||||
cache = build_from(_cache)
|
||||
expect(File).to receive(:exists?).with("target").and_return(true)
|
||||
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
|
||||
end
|
||||
|
||||
it "returns false when there is a new user dependency" do
|
||||
_cache = {"targets" => {"target" => {"checksum" => "abc",
|
||||
"command" => Digest::MD5.hexdigest("command".inspect),
|
||||
"deps" => [{"fname" => "dep.1"}],
|
||||
"user_deps" => []}}}
|
||||
cache = build_from(_cache)
|
||||
env = "env"
|
||||
expect(env).to receive(:get_user_deps).with("target").and_return(["file.ld"])
|
||||
expect(File).to receive(:exists?).with("target").and_return(true)
|
||||
expect(cache).to receive(:calculate_checksum).with("target").and_return("abc")
|
||||
expect(cache.up_to_date?("target", "command", ["dep.1"], env)).to be_falsey
|
||||
end
|
||||
|
||||
it "returns false when a user dependency checksum has changed" do
|
||||
_cache = {"targets" => {"target" => {"checksum" => "abc",
|
||||
"command" => Digest::MD5.hexdigest("command".inspect),
|
||||
"deps" => [{"fname" => "dep.1",
|
||||
"checksum" => "dep.1.chk"},
|
||||
{"fname" => "dep.2",
|
||||
"checksum" => "dep.2.chk"},
|
||||
{"fname" => "extra.dep",
|
||||
"checksum" => "extra.dep.chk"}],
|
||||
"user_deps" => [{"fname" => "user.dep",
|
||||
"checksum" => "user.dep.chk"}]}}}
|
||||
cache = build_from(_cache)
|
||||
env = "env"
|
||||
expect(env).to receive(:get_user_deps).with("target").and_return(["user.dep"])
|
||||
expect(File).to receive(:exists?).with("target").and_return(true)
|
||||
expect(cache).to receive(:calculate_checksum).with("target").and_return("abc")
|
||||
expect(cache).to receive(:calculate_checksum).with("dep.1").and_return("dep.1.chk")
|
||||
expect(cache).to receive(:calculate_checksum).with("dep.2").and_return("dep.2.chk")
|
||||
expect(cache).to receive(:calculate_checksum).with("extra.dep").and_return("extra.dep.chk")
|
||||
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
|
||||
end
|
||||
|
||||
it "returns true when no condition for false is met" do
|
||||
_cache = {"targets" => {"target" => {"checksum" => "abc",
|
||||
"command" => Digest::MD5.hexdigest("command".inspect),
|
||||
"deps" => [{"fname" => "dep.1",
|
||||
"checksum" => "dep.1.chk"},
|
||||
{"fname" => "dep.2",
|
||||
"checksum" => "dep.2.chk"},
|
||||
{"fname" => "extra.dep",
|
||||
"checksum" => "extra.dep.chk"}],
|
||||
"user_deps" => []}}}
|
||||
cache = build_from(_cache)
|
||||
expect(File).to receive(:exists?).with("target").and_return(true)
|
||||
expect(cache).to receive(:calculate_checksum).with("target").and_return("abc")
|
||||
expect(cache).to receive(:calculate_checksum).with("dep.1").and_return("dep.1.chk")
|
||||
expect(cache).to receive(:calculate_checksum).with("dep.2").and_return("dep.2.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
|
||||
end
|
||||
end
|
||||
|
||||
describe "#register_build" do
|
||||
it "stores the given information in the cache" do
|
||||
_cache = {}
|
||||
cache = build_from(_cache)
|
||||
env = "env"
|
||||
expect(env).to receive(:get_user_deps).with("the target").and_return(["user.dep"])
|
||||
expect(cache).to receive(:calculate_checksum).with("the target").and_return("the checksum")
|
||||
expect(cache).to receive(:calculate_checksum).with("dep 1").and_return("dep 1 checksum")
|
||||
expect(cache).to receive(:calculate_checksum).with("dep 2").and_return("dep 2 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)
|
||||
cached_target = cache.instance_variable_get(:@cache)["targets"]["the target"]
|
||||
expect(cached_target).to_not be_nil
|
||||
expect(cached_target["command"]).to eq Digest::MD5.hexdigest("the command".inspect)
|
||||
expect(cached_target["checksum"]).to eq "the checksum"
|
||||
expect(cached_target["deps"]).to eq [
|
||||
{"fname" => "dep 1", "checksum" => "dep 1 checksum"},
|
||||
{"fname" => "dep 2", "checksum" => "dep 2 checksum"},
|
||||
]
|
||||
expect(cached_target["user_deps"]).to eq [
|
||||
{"fname" => "user.dep", "checksum" => "user.dep checksum"},
|
||||
]
|
||||
end
|
||||
end
|
||||
|
||||
describe "#targets" do
|
||||
it "returns a list of targets that are cached" do
|
||||
cache = {"targets" => {"t1" => {}, "t2" => {}, "t3" => {}}}
|
||||
|
||||
Reference in new issue
Block a user