From 551b8fa3656bf562ccd764c1bf84bcc66a696bfe Mon Sep 17 00:00:00 2001 From: Josh Holtrop Date: Thu, 16 Feb 2017 19:08:03 -0500 Subject: [PATCH] add integration test to verify cache is written if a builder fails --- lib/rscons/cache.rb | 14 ++++++++++++-- spec/build_tests_spec.rb | 33 +++++++++++++++++++++++++++++++++ 2 files changed, 45 insertions(+), 2 deletions(-) diff --git a/lib/rscons/cache.rb b/lib/rscons/cache.rb index 50c5afb..9c71339 100644 --- a/lib/rscons/cache.rb +++ b/lib/rscons/cache.rb @@ -2,7 +2,6 @@ require "digest/md5" require "fileutils" require "json" require "set" -require "singleton" require "rscons/version" module Rscons @@ -51,7 +50,6 @@ module Rscons # }, # } class Cache - include Singleton # Name of the file to store cache information in CACHE_FILE = ".rsconscache" @@ -59,6 +57,18 @@ module Rscons # Prefix for phony cache entries. PHONY_PREFIX = ":PHONY:" + class << self + # Access the singleton instance. + def instance + @instance ||= Cache.new + end + + # Reset the cache (for unit/integration test purposes) + def reset! + @instance = nil + end + end + # Create a Cache object and load in the previous contents from the cache # file. def initialize diff --git a/spec/build_tests_spec.rb b/spec/build_tests_spec.rb index 8baf883..ce2a91c 100644 --- a/spec/build_tests_spec.rb +++ b/spec/build_tests_spec.rb @@ -54,6 +54,7 @@ describe Rscons do def test_dir(build_test_directory) FileUtils.cp_r("build_tests/#{build_test_directory}", BUILD_TEST_RUN_DIR) Dir.chdir(BUILD_TEST_RUN_DIR) + @saved_stderr.reopen(".stderr") end def file_sub(fname) @@ -798,6 +799,38 @@ EOF ]) end + it "does not re-run previously successful builders if one fails" do + test_dir('simple') + File.open("two.c", "w") do |fh| + fh.puts("FOO") + end + expect do + Rscons::Environment.new do |env| + env.Program("simple", %w[simple.c two.c]) + end + end.to raise_error /Failed to build simple/ + result = lines + expect(result.size).to be > 2 + expect(result[0, 2]).to eq [ + "CC simple.o", + "CC two.o", + ] + expect(File.exists?("simple.o")).to be_truthy + expect(File.exists?("two.o")).to be_falsey + expect(File.exists?("two_sources#{Rscons::Environment.new["PROGSUFFIX"]}")).to be_falsey + + Rscons::Cache.reset! + + File.open("two.c", "w") {|fh|} + Rscons::Environment.new do |env| + env.Program("simple", %w[simple.c two.c]) + end + expect(lines).to eq [ + "CC two.o", + "LD simple", + ] + end + context "Directory builder" do it "creates the requested directory" do test_dir("simple")