Cache: change to a Singleton object so it is only loaded from disk once
This commit is contained in:
1 parent
5ce8940d54
commit
160434b903
6 files changed
+54
-35
No files matched your search
@@ -5,14 +5,11 @@ module Rscons
|
||||
end
|
||||
|
||||
def build_from(cache)
|
||||
JSON.should_receive(:load).and_return(cache)
|
||||
Cache.new
|
||||
end
|
||||
|
||||
describe ".clear" do
|
||||
it "removes the cache file" do
|
||||
FileUtils.should_receive(:rm_f).with(Cache::CACHE_FILE)
|
||||
Cache.clear
|
||||
JSON.stub(:load) do
|
||||
cache
|
||||
end
|
||||
Cache.instance.tap do |cache|
|
||||
cache.send(:initialize!)
|
||||
end
|
||||
end
|
||||
|
||||
@@ -21,11 +18,21 @@ module Rscons
|
||||
it "prints a warning and defaults to an empty hash" do
|
||||
JSON.should_receive(:load).and_return("string")
|
||||
$stderr.should_receive(:puts).with(/Warning:.*was.corrupt/)
|
||||
Cache.new.instance_variable_get(:@cache).is_a?(Hash).should be_true
|
||||
c = Cache.instance
|
||||
c.send(:initialize!)
|
||||
c.instance_variable_get(:@cache).is_a?(Hash).should be_true
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
describe "#clear" do
|
||||
it "removes the cache file" do
|
||||
FileUtils.should_receive(:rm_f).with(Cache::CACHE_FILE)
|
||||
JSON.stub(:load) {{}}
|
||||
Cache.instance.clear
|
||||
end
|
||||
end
|
||||
|
||||
describe "#write" do
|
||||
it "should fill in 'version' and write to file" do
|
||||
cache = {}
|
||||
|
||||
@@ -140,7 +140,8 @@ module Rscons
|
||||
env.Program("a.out", "main.c")
|
||||
|
||||
cache = "cache"
|
||||
Cache.should_receive(:new).and_return(cache)
|
||||
Cache.should_receive(:instance).and_return(cache)
|
||||
cache.should_receive(:clear_checksum_cache!)
|
||||
env.should_receive(:run_builder).with(anything, "a.out", ["main.c"], cache, {}).and_return(true)
|
||||
cache.should_receive(:write)
|
||||
|
||||
@@ -153,7 +154,8 @@ module Rscons
|
||||
env.Object("main.o", "other.cc")
|
||||
|
||||
cache = "cache"
|
||||
Cache.should_receive(:new).and_return(cache)
|
||||
Cache.should_receive(:instance).and_return(cache)
|
||||
cache.should_receive(:clear_checksum_cache!)
|
||||
env.should_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")
|
||||
cache.should_receive(:write)
|
||||
@@ -167,7 +169,8 @@ module Rscons
|
||||
env.Object("main.o", "other.cc")
|
||||
|
||||
cache = "cache"
|
||||
Cache.should_receive(:new).and_return(cache)
|
||||
Cache.should_receive(:instance).and_return(cache)
|
||||
cache.should_receive(:clear_checksum_cache!)
|
||||
env.should_receive(:run_builder).with(anything, "main.o", ["other.cc"], cache, {}).and_return(false)
|
||||
cache.should_receive(:write)
|
||||
|
||||
|
||||
Reference in new issue
Block a user