1+ #
2+ # Author:: Hongli Lai (hongli@phusion.nl)
3+ # Copyright:: Copyright (c) 2009 Phusion
4+ # License:: Apache License, Version 2.0
5+ #
6+ # Licensed under the Apache License, Version 2.0 (the "License");
7+ # you may not use this file except in compliance with the License.
8+ # You may obtain a copy of the License at
9+ #
10+ # http://www.apache.org/licenses/LICENSE-2.0
11+ #
12+ # Unless required by applicable law or agreed to in writing, software
13+ # distributed under the License is distributed on an "AS IS" BASIS,
14+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15+ # See the License for the specific language governing permissions and
16+ # limitations under the License.
17+ #
18+
19+ require File . expand_path ( File . join ( File . dirname ( __FILE__ ) , ".." , ".." , "spec_helper" ) )
20+
21+ describe Chef ::Mixin ::Command , "popen4" do
22+
23+ include Chef ::Mixin ::Command
24+
25+ it "should be possible to read the child process's stdout and stderr" do
26+ popen4 ( "sh -c 'echo hello && echo world >&2'" ) do |pid , stdin , stdout , stderr |
27+ stdout . read . should == "hello\n "
28+ stderr . read . should == "world\n "
29+ end
30+ end
31+
32+ end
33+
34+ describe Chef ::Mixin ::Command , "run_command" do
35+
36+ include Chef ::Mixin ::Command
37+
38+ it "logs the command's stderr and stdout output if the command failed" do
39+ begin
40+ run_command ( :command => "sh -c 'echo hello; echo world >&2; false'" )
41+ violated "Exception expected, but nothing raised."
42+ rescue => e
43+ e . message . should =~ /STDOUT: hello/
44+ e . message . should =~ /STDERR: world/
45+ end
46+ end
47+
48+ end
0 commit comments