terrapin 0.6.0 → 1.1.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +5 -5
- data/.github/workflows/ci.yml +32 -0
- data/.github/workflows/dynamic-readme.yml +17 -0
- data/.github/workflows/dynamic-security.yml +19 -0
- data/CODEOWNERS +15 -0
- data/Gemfile +0 -4
- data/NEWS.md +26 -0
- data/README.md +33 -28
- data/SECURITY.md +20 -0
- data/lib/terrapin/command_line/multi_pipe.rb +38 -6
- data/lib/terrapin/command_line/runners.rb +0 -1
- data/lib/terrapin/command_line.rb +15 -10
- data/lib/terrapin/version.rb +1 -1
- data/spec/spec_helper.rb +5 -4
- data/spec/support/nonblocking_examples.rb +14 -3
- data/spec/support/stub_os.rb +5 -5
- data/spec/terrapin/command_line/runners/backticks_runner_spec.rb +3 -3
- data/spec/terrapin/command_line/runners/fake_runner_spec.rb +4 -4
- data/spec/terrapin/command_line/runners/popen_runner_spec.rb +3 -3
- data/spec/terrapin/command_line/runners/process_runner_spec.rb +3 -3
- data/spec/terrapin/command_line_spec.rb +39 -27
- data/spec/terrapin/errors_spec.rb +13 -16
- data/spec/terrapin/os_detector_spec.rb +4 -4
- data/spec/terrapin/runners_spec.rb +20 -35
- data/terrapin.gemspec +18 -21
- metadata +23 -63
- data/.travis.yml +0 -6
- data/lib/terrapin/command_line/runners/posix_runner.rb +0 -49
- data/spec/support/unsetting_exitstatus.rb +0 -7
- data/spec/terrapin/command_line/runners/posix_runner_spec.rb +0 -40
|
@@ -1,49 +0,0 @@
|
|
|
1
|
-
# coding: UTF-8
|
|
2
|
-
|
|
3
|
-
module Terrapin
|
|
4
|
-
class CommandLine
|
|
5
|
-
class PosixRunner
|
|
6
|
-
def self.available?
|
|
7
|
-
return @available unless @available.nil?
|
|
8
|
-
|
|
9
|
-
@available = posix_spawn_gem_available?
|
|
10
|
-
end
|
|
11
|
-
|
|
12
|
-
def self.supported?
|
|
13
|
-
available? && !OS.java?
|
|
14
|
-
end
|
|
15
|
-
|
|
16
|
-
def supported?
|
|
17
|
-
self.class.supported?
|
|
18
|
-
end
|
|
19
|
-
|
|
20
|
-
def call(command, env = {}, options = {})
|
|
21
|
-
pipe = MultiPipe.new
|
|
22
|
-
pid = spawn(env, command, options.merge(pipe.pipe_options))
|
|
23
|
-
pipe.read_and_then do
|
|
24
|
-
waitpid(pid)
|
|
25
|
-
end
|
|
26
|
-
pipe.output
|
|
27
|
-
end
|
|
28
|
-
|
|
29
|
-
private
|
|
30
|
-
|
|
31
|
-
def spawn(*args)
|
|
32
|
-
POSIX::Spawn.spawn(*args)
|
|
33
|
-
end
|
|
34
|
-
|
|
35
|
-
def waitpid(pid)
|
|
36
|
-
Process.waitpid(pid)
|
|
37
|
-
end
|
|
38
|
-
|
|
39
|
-
def self.posix_spawn_gem_available?
|
|
40
|
-
require 'posix/spawn'
|
|
41
|
-
true
|
|
42
|
-
rescue LoadError
|
|
43
|
-
false
|
|
44
|
-
end
|
|
45
|
-
|
|
46
|
-
private_class_method :posix_spawn_gem_available?
|
|
47
|
-
end
|
|
48
|
-
end
|
|
49
|
-
end
|
|
@@ -1,40 +0,0 @@
|
|
|
1
|
-
require 'spec_helper'
|
|
2
|
-
|
|
3
|
-
describe Terrapin::CommandLine::PosixRunner do
|
|
4
|
-
if Terrapin::CommandLine::PosixRunner.supported?
|
|
5
|
-
it_behaves_like 'a command that does not block'
|
|
6
|
-
|
|
7
|
-
it 'runs the command given and captures the output' do
|
|
8
|
-
output = subject.call("echo hello")
|
|
9
|
-
expect(output).to have_output "hello\n"
|
|
10
|
-
end
|
|
11
|
-
|
|
12
|
-
it 'runs the command given and captures the error output' do
|
|
13
|
-
output = subject.call("echo hello 1>&2")
|
|
14
|
-
expect(output).to have_error_output "hello\n"
|
|
15
|
-
end
|
|
16
|
-
|
|
17
|
-
it 'modifies the environment and runs the command given' do
|
|
18
|
-
output = subject.call("echo $yes", {"yes" => "no"})
|
|
19
|
-
expect(output).to have_output "no\n"
|
|
20
|
-
end
|
|
21
|
-
|
|
22
|
-
it 'sets the exitstatus when a command completes' do
|
|
23
|
-
subject.call("ruby -e 'exit 0'")
|
|
24
|
-
$?.exitstatus.should == 0
|
|
25
|
-
subject.call("ruby -e 'exit 5'")
|
|
26
|
-
$?.exitstatus.should == 5
|
|
27
|
-
end
|
|
28
|
-
|
|
29
|
-
it "runs the command it's given and allows access to stderr afterwards" do
|
|
30
|
-
cmd = Terrapin::CommandLine.new(
|
|
31
|
-
"ruby",
|
|
32
|
-
"-e '$stdout.puts %{hello}; $stderr.puts %{goodbye}'",
|
|
33
|
-
:swallow_stderr => false
|
|
34
|
-
)
|
|
35
|
-
cmd.run
|
|
36
|
-
expect(cmd.command_output).to eq "hello\n"
|
|
37
|
-
expect(cmd.command_error_output).to eq "goodbye\n"
|
|
38
|
-
end
|
|
39
|
-
end
|
|
40
|
-
end
|