From d28722a4bb2ba20fc5136aaae864eeae585b2440 Mon Sep 17 00:00:00 2001 From: Josh Holtrop Date: Tue, 20 Jan 2015 21:13:27 -0500 Subject: [PATCH] fix Rscons.set_suffix to append the given suffix if the filename has none --- README.md | 4 ++++ lib/rscons.rb | 2 +- spec/rscons_spec.rb | 10 ++++++++++ 3 files changed, 15 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 2186d18..f465ccd 100644 --- a/README.md +++ b/README.md @@ -383,6 +383,10 @@ http://rubydoc.info/github/holtrop/rscons/frames. ## Release Notes +### v1.9.0 + +- fix Rscons.set_suffix to append the given suffix if the filename has none + ### v1.8.1 - fix Environment#dump when construction variables are symbols diff --git a/lib/rscons.rb b/lib/rscons.rb index bc0fa3c..557e574 100644 --- a/lib/rscons.rb +++ b/lib/rscons.rb @@ -67,7 +67,7 @@ module Rscons # # @return [String] New path. def self.set_suffix(path, suffix) - path.sub(/\.[^.]*$/, suffix) + path.sub(/\.[^.]*$/, "") + suffix end # Return the system shell and arguments for executing a shell command. diff --git a/spec/rscons_spec.rb b/spec/rscons_spec.rb index 5800fe4..8f4d697 100644 --- a/spec/rscons_spec.rb +++ b/spec/rscons_spec.rb @@ -24,6 +24,16 @@ describe Rscons do end end + describe ".set_suffix" do + it "changes the suffix to the new one" do + expect(Rscons.set_suffix("foo.c", ".h")).to eq("foo.h") + end + + it "appends a suffix if the given file name does not have one" do + expect(Rscons.set_suffix("bazz", ".d")).to eq("bazz.d") + end + end + describe ".get_system_shell" do before(:each) do Rscons.class_variable_set(:@@shell, nil)