From 5ff555cf6a55549d0b0797c5620a6d90c6fc9908 Mon Sep 17 00:00:00 2001 From: Josh Holtrop Date: Thu, 2 Jan 2014 11:49:08 -0500 Subject: [PATCH] add Environment#expand_varref() --- lib/rscons/environment.rb | 5 +++++ spec/rscons/environment_spec.rb | 14 ++++++++++++++ 2 files changed, 19 insertions(+) diff --git a/lib/rscons/environment.rb b/lib/rscons/environment.rb index 871e1ea..16dfdb6 100644 --- a/lib/rscons/environment.rb +++ b/lib/rscons/environment.rb @@ -185,6 +185,11 @@ module Rscons @varset.merge(extra_vars).expand_varref(command_template) end + # Expand a construction variable reference (String or Array) + def expand_varref(varref) + @varset.expand_varref(varref) + end + # Execute a builder command # @param short_desc [String] Message to print if the Environment's echo # mode is set to :short diff --git a/spec/rscons/environment_spec.rb b/spec/rscons/environment_spec.rb index 03ad1d3..47d7c23 100644 --- a/spec/rscons/environment_spec.rb +++ b/spec/rscons/environment_spec.rb @@ -199,6 +199,20 @@ module Rscons end end + describe "#expand_varref" do + it "returns the fully expanded variable reference" do + env = Environment.new + env["path"] = ["dir1", "dir2"] + env["flags"] = ["-x", "-y", "${specialflag}"] + env["specialflag"] = "-z" + env.expand_varref(["-p${path}", "${flags}"]).should == ["-pdir1", "-pdir2", "-x", "-y", "-z"] + env.expand_varref("foo").should == "foo" + expect {env.expand_varref("${foo}")}.to raise_error /expand.a.variable.reference/ + env.expand_varref("${specialflag}").should == "-z" + env.expand_varref("${path}").should == ["dir1", "dir2"] + end + end + describe "#execute" do context "with echo: :short" do context "with no errors" do