raise error if user constructs an Environment before configuration is complete

This commit is contained in:
Josh Holtrop 2019-04-14 20:45:31 -04:00
parent 3115e55739
commit 787b3249a7
4 changed files with 10 additions and 7 deletions

View File

@ -1,4 +1,3 @@
Environment.new do |env|
env.Object("simple.o", "simple.cc")
env.process
end

View File

@ -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 = []

View File

@ -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

View File

@ -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