Skip to content

Commit

Permalink
Run the "false" command when given a non-existent path
Browse files Browse the repository at this point in the history
This change provides a command result that is equivalent
to a failed command
  • Loading branch information
0x1eef committed Jun 14, 2024
1 parent 78a6acf commit 4b27e5c
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 0 deletions.
3 changes: 3 additions & 0 deletions lib/test/cmd.rb
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,9 @@ def spawn
Process.spawn(@cmd, *@argv, {out: out.w, err: err.w})
Process.wait
@status = $?
rescue Errno::ENOENT
@cmd, @argv = "false", []
retry
end
loop do
io, _ = IO.select([out.r, err.r], nil, nil, 0.01)
Expand Down
4 changes: 4 additions & 0 deletions test/cmd_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,10 @@ def test_ruby_exit_status_predicates
assert_equal true, ruby("exit 0").status.success?
assert_equal true, ruby("exit 0").success?
end

def test_nonexistent_command
assert_equal false, cmd("/a/path/that/is/not/found").success?
end
end

##
Expand Down

0 comments on commit 4b27e5c

Please sign in to comment.