Skip to content

Commit

Permalink
Merge 09bdfc1 into d067deb
Browse files Browse the repository at this point in the history
  • Loading branch information
jreidinger committed Jan 2, 2020
2 parents d067deb + 09bdfc1 commit 25279df
Show file tree
Hide file tree
Showing 5 changed files with 34 additions and 5 deletions.
1 change: 1 addition & 0 deletions .travis.yml
@@ -1,6 +1,7 @@
language: ruby
sudo: false
rvm:
- 2.7.1
- 2.6.4
- 2.5.6
- 2.4.7
Expand Down
6 changes: 6 additions & 0 deletions CHANGELOG
@@ -1,3 +1,9 @@
0.5.2 (2019-10-16)
------------------

* Fix logging error when command finish with allowed exitstatus (bsc#1153749)
* Added support for ruby 2.7

0.5.1 (2019-10-16)
------------------

Expand Down
2 changes: 1 addition & 1 deletion VERSION
@@ -1 +1 @@
0.5.1
0.5.2
21 changes: 18 additions & 3 deletions lib/cheetah.rb
Expand Up @@ -402,6 +402,10 @@ def run(*args)
select_loop(streams, pipes, recorder)
_pid, status = Process.wait2(pid)

# when more exit status are allowed, then redefine success as command
# not failed (bsc#1153749)
adapt_status(status, options)

begin
check_errors(commands, status, streams, streamed, options)
ensure
Expand All @@ -413,6 +417,14 @@ def run(*args)

private

def adapt_status(status, options)
return unless allowed_exitstatus?(options)

status.define_singleton_method(:success?) do
options[:allowed_exitstatus].include?(exitstatus)
end
end

# Parts of Cheetah.run

def with_env(env, &block)
Expand Down Expand Up @@ -645,7 +657,6 @@ def select_loop(streams, pipes, recorder)

def check_errors(commands, status, streams, streamed, options)
return if status.success?
return if options[:allowed_exitstatus].include?(status.exitstatus)

stderr_part = if streamed[:stderr]
" (error output streamed away)"
Expand Down Expand Up @@ -678,8 +689,7 @@ def build_result(streams, status, options)
[streams[:stdout].string, streams[:stderr].string]
end

# do not capture only for empty array or nil converted to empty array
if !options[:allowed_exitstatus].is_a?(Array) || !options[:allowed_exitstatus].empty?
if allowed_exitstatus?(options)
if res.nil?
res = status.exitstatus
else
Expand All @@ -691,6 +701,11 @@ def build_result(streams, status, options)
res
end

def allowed_exitstatus?(options)
# more exit status allowed for non array or non empty array
!options[:allowed_exitstatus].is_a?(Array) || !options[:allowed_exitstatus].empty?
end

def format_commands(commands)
'"' + commands.map { |c| Shellwords.join(c) }.join(" | ") + '"'
end
Expand Down
9 changes: 8 additions & 1 deletion spec/cheetah_spec.rb
@@ -1,6 +1,6 @@
# frozen_string_literal: true

require "spec_helper"
require_relative "./spec_helper"
require "fileutils"

describe Cheetah::DefaultRecorder do
Expand Down Expand Up @@ -758,6 +758,13 @@ def create_command(source, name: "command")
it "appends exitstatus to end if other capturing is requested" do
expect(Cheetah.run("/bin/false", stdout: :capture, allowed_exitstatus: 1)).to eq(["", 1])
end

it "does not log allowed exit status as error" do
logger = double(info: nil)
expect(logger).to_not receive(:error)
expect(logger).to_not receive(:warn)
expect(Cheetah.run("/bin/false", stdout: :capture, logger: logger, allowed_exitstatus: 1)).to eq(["", 1])
end
end

describe "changing environment variables" do
Expand Down

0 comments on commit 25279df

Please sign in to comment.