From 787b3249a79deb141ba68f8ac11ee882bc46f91d Mon Sep 17 00:00:00 2001 From: Josh Holtrop Date: Sun, 14 Apr 2019 20:45:31 -0400 Subject: [PATCH] raise error if user constructs an Environment before configuration is complete --- ...figure.rb => error_env_construction_before_configure.rb} | 1 - lib/rscons/environment.rb | 6 +++--- spec/build_tests_spec.rb | 6 +++--- spec/rscons/environment_spec.rb | 4 ++++ 4 files changed, 10 insertions(+), 7 deletions(-) rename build_tests/configure/{error_env_process_before_configure.rb => error_env_construction_before_configure.rb} (82%) diff --git a/build_tests/configure/error_env_process_before_configure.rb b/build_tests/configure/error_env_construction_before_configure.rb similarity index 82% rename from build_tests/configure/error_env_process_before_configure.rb rename to build_tests/configure/error_env_construction_before_configure.rb index 536aae1..83e7703 100644 --- a/build_tests/configure/error_env_process_before_configure.rb +++ b/build_tests/configure/error_env_construction_before_configure.rb @@ -1,4 +1,3 @@ Environment.new do |env| env.Object("simple.o", "simple.cc") - env.process end diff --git a/lib/rscons/environment.rb b/lib/rscons/environment.rb index 4f7fa71..a2b4d2a 100644 --- a/lib/rscons/environment.rb +++ b/lib/rscons/environment.rb @@ -63,6 +63,9 @@ module Rscons # If a block is given, the Environment object is yielded to the block and # when the block returns, the {#process} method is automatically called. def initialize(options = {}) + unless Cache.instance["configuration_data"]["configured"] + raise "Project must be configured before creating an Environment" + end super(options) @id = self.class.get_id self.class.register(self) @@ -258,9 +261,6 @@ module Rscons # # @return [void] def process - unless Cache.instance["configuration_data"]["configured"] - raise "Project must be configured before processing an Environment" - end @process_failures = [] @process_blocking_wait = false @process_commands_waiting_to_run = [] diff --git a/spec/build_tests_spec.rb b/spec/build_tests_spec.rb index fb00e74..2b01f2b 100644 --- a/spec/build_tests_spec.rb +++ b/spec/build_tests_spec.rb @@ -2012,10 +2012,10 @@ EOF expect(result.status).to_not eq 0 end - it "exits with an error if configuration has not been performed before attempting to process an environment" do + it "exits with an error if configuration has not been performed before attempting to create an environment" do test_dir "configure" - result = run_rscons(rsconscript: "error_env_process_before_configure.rb") - expect(result.stderr).to match /Project must be configured before processing an Environment/ + result = run_rscons(rsconscript: "error_env_construction_before_configure.rb") + expect(result.stderr).to match /Project must be configured before creating an Environment/ expect(result.status).to_not eq 0 end diff --git a/spec/rscons/environment_spec.rb b/spec/rscons/environment_spec.rb index 07eaf4e..e6feb14 100644 --- a/spec/rscons/environment_spec.rb +++ b/spec/rscons/environment_spec.rb @@ -1,5 +1,9 @@ module Rscons describe Environment do + before(:each) do + Cache.instance["configuration_data"] = {"configured" => true} + end + describe "#initialize" do it "adds the default builders when they are not excluded" do env = Environment.new