summaryrefslogtreecommitdiff
path: root/spec
diff options
context:
space:
mode:
authorHo-Sheng Hsiao <hosheng.hsiao@gmail.com>2012-03-30 13:18:47 -0400
committerHo-Sheng Hsiao <hosh@opscode.com>2012-05-10 14:43:54 -0400
commit110a028f1b1782d7ce6f6d9b871059263ca05b69 (patch)
treebafe43433c2524202e14ea8b7822f1f646f2fc4d /spec
parent125501593717ae7954ab00dfa39a09a02a74f6dc (diff)
downloadmixlib-shellout-110a028f1b1782d7ce6f6d9b871059263ca05b69.tar.gz
[CHEF-2994][WINDOWS] Fixed multiple quotes in command
CMD.exe does not parse multiple quotes well unless the whole thing is wrapped up in quotes. Workaround: https://github.com/opscode/mixlib-shellout/pull/2#issuecomment-4837859 http://ss64.com/nt/syntax-esc.html
Diffstat (limited to 'spec')
-rw-r--r--spec/mixlib/shellout/shellout_spec.rb32
1 files changed, 23 insertions, 9 deletions
diff --git a/spec/mixlib/shellout/shellout_spec.rb b/spec/mixlib/shellout/shellout_spec.rb
index da8b2b5..b532827 100644
--- a/spec/mixlib/shellout/shellout_spec.rb
+++ b/spec/mixlib/shellout/shellout_spec.rb
@@ -383,17 +383,18 @@ describe Mixlib::ShellOut do
end
context "when running different types of command" do
+ let(:script) { open_file.tap(&write_file).tap(&:close).tap(&make_executable) }
+ let(:file_name) { "#{dir}/Setup Script.cmd" }
+ let(:script_name) { "\"#{script.path}\"" }
+
+ let(:open_file) { File.open(file_name, 'w') }
+ let(:write_file) { lambda { |f| f.write(script_content) } }
+ let(:make_executable) { lambda { |f| File.chmod(0755, f.path) } }
+
context 'with spaces in the path' do
subject { chomped_stdout }
let(:cmd) { script_name }
- let(:script) { open_file.tap(&write_file).tap(&:close).tap(&make_executable) }
- let(:file_name) { "#{dir}/blah blah.cmd" }
- let(:script_name) { "\"#{script.path}\"" }
-
- let(:open_file) { File.open(file_name, 'w') }
- let(:write_file) { lambda { |f| f.write(script_content) } }
- let(:make_executable) { lambda { |f| File.chmod(0755, f.path) } }
context 'when running under Unix', :unix_only => true do
let(:script_content) { 'echo blah' }
@@ -404,14 +405,26 @@ describe Mixlib::ShellOut do
end
context 'when running under Windows', :windows_only => true do
- let(:script_content) { '@echo blah' }
+ let(:cmd) { "#{script_name} #{argument}" }
+ let(:script_content) { '@echo %1' }
+ let(:argument) { rand(10000).to_s }
it 'should execute' do
- should eql('blah')
+ should eql(argument)
+ end
+ context 'with multiple quotes in the command and args' do
+ context 'when using a batch file' do
+ let(:argument) { "\"Random #{rand(10000)}\"" }
+
+ it 'should execute' do
+ should eql(argument)
+ end
+ end
end
end
end
+
context 'with lots of long arguments' do
subject { chomped_stdout }
@@ -436,6 +449,7 @@ describe Mixlib::ShellOut do
end
end
+
context 'with backslashes' do
subject { stdout }
let(:backslashes) { %q{\\"\\\\} }