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
|
@@ -6,37 +6,49 @@ describe Terrapin::CommandLine do
|
|
|
6
6
|
on_unix! # Assume we're on unix unless otherwise specified.
|
|
7
7
|
end
|
|
8
8
|
|
|
9
|
+
describe ".new" do
|
|
10
|
+
it "treats nil params as blank" do
|
|
11
|
+
cmd = Terrapin::CommandLine.new("echo", nil)
|
|
12
|
+
expect(cmd.run).to eq("\n")
|
|
13
|
+
end
|
|
14
|
+
|
|
15
|
+
it "raises when given nil options" do
|
|
16
|
+
expect { Terrapin::CommandLine.new("echo", "", nil) }
|
|
17
|
+
.to raise_error(ArgumentError)
|
|
18
|
+
end
|
|
19
|
+
end
|
|
20
|
+
|
|
9
21
|
it "takes a command and parameters and produces a Bash command line" do
|
|
10
22
|
cmd = Terrapin::CommandLine.new("convert", "a.jpg b.png", :swallow_stderr => false)
|
|
11
|
-
cmd.command.
|
|
23
|
+
expect(cmd.command).to eq("convert a.jpg b.png")
|
|
12
24
|
end
|
|
13
25
|
|
|
14
26
|
it "specifies the $PATH where the command can be found on unix" do
|
|
15
27
|
Terrapin::CommandLine.path = ["/path/to/command/dir", "/"]
|
|
16
28
|
cmd = Terrapin::CommandLine.new("ls")
|
|
17
|
-
cmd.command.
|
|
29
|
+
expect(cmd.command).to eq("PATH=/path/to/command/dir:/:$PATH; ls")
|
|
18
30
|
end
|
|
19
31
|
|
|
20
32
|
it "specifies the %PATH% where the command can be found on windows" do
|
|
21
33
|
on_windows!
|
|
22
34
|
Terrapin::CommandLine.path = ['C:\system32', 'D:\\']
|
|
23
35
|
cmd = Terrapin::CommandLine.new("dir")
|
|
24
|
-
cmd.command.
|
|
36
|
+
expect(cmd.command).to eq('SET PATH=C:\system32;D:\;%PATH% & dir')
|
|
25
37
|
end
|
|
26
38
|
|
|
27
39
|
it "specifies more than one path where the command can be found" do
|
|
28
40
|
Terrapin::CommandLine.path = ["/path/to/command/dir", "/some/other/path"]
|
|
29
41
|
cmd = Terrapin::CommandLine.new("ruby", "-e 'puts ENV[%{PATH}]'")
|
|
30
42
|
output = cmd.run
|
|
31
|
-
output.
|
|
32
|
-
output.
|
|
43
|
+
expect(output).to match(%r{/path/to/command/dir})
|
|
44
|
+
expect(output).to match(%r{/some/other/path})
|
|
33
45
|
end
|
|
34
46
|
|
|
35
47
|
it "temporarily changes specified environment variables" do
|
|
36
48
|
Terrapin::CommandLine.environment['TEST'] = 'Hello, world!'
|
|
37
49
|
cmd = Terrapin::CommandLine.new("ruby", "-e 'puts ENV[%{TEST}]'")
|
|
38
50
|
output = cmd.run
|
|
39
|
-
output.
|
|
51
|
+
expect(output).to match(%r{Hello, world!})
|
|
40
52
|
end
|
|
41
53
|
|
|
42
54
|
it 'changes environment variables for the command line' do
|
|
@@ -45,13 +57,13 @@ describe Terrapin::CommandLine do
|
|
|
45
57
|
"-e 'puts ENV[%{TEST}]'",
|
|
46
58
|
:environment => {'TEST' => 'Hej hej'})
|
|
47
59
|
output = cmd.run
|
|
48
|
-
output.
|
|
60
|
+
expect(output).to match(%r{Hej hej})
|
|
49
61
|
end
|
|
50
62
|
|
|
51
63
|
it 'passes the existing environment variables through to the runner' do
|
|
52
64
|
command = Terrapin::CommandLine.new('echo', '$HOME')
|
|
53
65
|
output = command.run
|
|
54
|
-
output.chomp.
|
|
66
|
+
expect(output.chomp).not_to eq('')
|
|
55
67
|
end
|
|
56
68
|
|
|
57
69
|
it "can interpolate quoted variables into the command line's parameters" do
|
|
@@ -60,7 +72,7 @@ describe Terrapin::CommandLine do
|
|
|
60
72
|
:swallow_stderr => false)
|
|
61
73
|
|
|
62
74
|
command_string = cmd.command(:one => "a.jpg", :two => "b.png")
|
|
63
|
-
command_string.
|
|
75
|
+
expect(command_string).to eq("convert 'a.jpg' 'b.png'")
|
|
64
76
|
end
|
|
65
77
|
|
|
66
78
|
it 'does not over-interpolate in a command line' do
|
|
@@ -69,17 +81,17 @@ describe Terrapin::CommandLine do
|
|
|
69
81
|
:swallow_stderr => false)
|
|
70
82
|
|
|
71
83
|
command_string = cmd.command(:hell => "a.jpg", :two => "b.png", :hello => "c.tiff")
|
|
72
|
-
command_string.
|
|
84
|
+
expect(command_string).to eq("convert 'a.jpg' 'b.png' 'c.tiff'")
|
|
73
85
|
end
|
|
74
86
|
|
|
75
87
|
it "interpolates when running a command" do
|
|
76
88
|
command = Terrapin::CommandLine.new("echo", ":hello_world")
|
|
77
|
-
command.run(:hello_world => "Hello, world").
|
|
89
|
+
expect(command.run(:hello_world => "Hello, world")).to match(/Hello, world/)
|
|
78
90
|
end
|
|
79
91
|
|
|
80
92
|
it "interpolates any Array arguments when running a command" do
|
|
81
93
|
command = Terrapin::CommandLine.new("echo", "Hello :worlds and :dwarfs")
|
|
82
|
-
command.command(:worlds => %w[mercury venus earth], :dwarfs => "pluto").
|
|
94
|
+
expect(command.command(:worlds => %w[mercury venus earth], :dwarfs => "pluto")).to eq("echo Hello 'mercury' 'venus' 'earth' and 'pluto'")
|
|
83
95
|
end
|
|
84
96
|
|
|
85
97
|
it "quotes command line options differently if we're on windows" do
|
|
@@ -88,7 +100,7 @@ describe Terrapin::CommandLine do
|
|
|
88
100
|
":one :{two}",
|
|
89
101
|
:swallow_stderr => false)
|
|
90
102
|
command_string = cmd.command(:one => "a.jpg", :two => "b.png")
|
|
91
|
-
command_string.
|
|
103
|
+
expect(command_string).to eq('convert "a.jpg" "b.png"')
|
|
92
104
|
end
|
|
93
105
|
|
|
94
106
|
it "can quote and interpolate dangerous variables" do
|
|
@@ -96,12 +108,12 @@ describe Terrapin::CommandLine do
|
|
|
96
108
|
":one :two",
|
|
97
109
|
:swallow_stderr => false)
|
|
98
110
|
command_string = cmd.command(:one => "`rm -rf`.jpg", :two => "ha'ha.png'")
|
|
99
|
-
command_string.
|
|
111
|
+
expect(command_string).to eq("convert '`rm -rf`.jpg' 'ha'\\''ha.png'\\'''")
|
|
100
112
|
end
|
|
101
113
|
|
|
102
114
|
it 'cannot recursively introduce a place where user-supplied commands can run' do
|
|
103
115
|
cmd = Terrapin::CommandLine.new('convert', ':foo :bar')
|
|
104
|
-
cmd.command(:foo => ':bar', :bar => '`rm -rf`').
|
|
116
|
+
expect(cmd.command(:foo => ':bar', :bar => '`rm -rf`')).to eq('convert \':bar\' \'`rm -rf`\'')
|
|
105
117
|
end
|
|
106
118
|
|
|
107
119
|
it "can quote and interpolate dangerous variables even on windows" do
|
|
@@ -110,7 +122,7 @@ describe Terrapin::CommandLine do
|
|
|
110
122
|
":one :two",
|
|
111
123
|
:swallow_stderr => false)
|
|
112
124
|
command_string = cmd.command(:one => "`rm -rf`.jpg", :two => "ha'ha.png")
|
|
113
|
-
command_string.
|
|
125
|
+
expect(command_string).to eq(%{convert "`rm -rf`.jpg" "ha'ha.png"})
|
|
114
126
|
end
|
|
115
127
|
|
|
116
128
|
it "quotes blank values into the command line's parameters" do
|
|
@@ -118,18 +130,18 @@ describe Terrapin::CommandLine do
|
|
|
118
130
|
"-X POST -d :data :url",
|
|
119
131
|
:swallow_stderr => false)
|
|
120
132
|
command_string = cmd.command(:data => "", :url => "http://localhost:9000")
|
|
121
|
-
command_string.
|
|
133
|
+
expect(command_string).to eq("curl -X POST -d '' 'http://localhost:9000'")
|
|
122
134
|
end
|
|
123
135
|
|
|
124
136
|
it "allows colons in parameters" do
|
|
125
137
|
cmd = Terrapin::CommandLine.new("convert", "'a.jpg' xc:black 'b.jpg'", :swallow_stderr => false)
|
|
126
|
-
cmd.command.
|
|
138
|
+
expect(cmd.command).to eq("convert 'a.jpg' xc:black 'b.jpg'")
|
|
127
139
|
end
|
|
128
140
|
|
|
129
141
|
it 'handles symbols in user supplied values' do
|
|
130
142
|
cmd = Terrapin::CommandLine.new("echo", ":foo")
|
|
131
143
|
command_string = cmd.command(:foo => :bar)
|
|
132
|
-
command_string.
|
|
144
|
+
expect(command_string).to eq("echo 'bar'")
|
|
133
145
|
end
|
|
134
146
|
|
|
135
147
|
it "can redirect stderr to the bit bucket if requested" do
|
|
@@ -137,7 +149,7 @@ describe Terrapin::CommandLine do
|
|
|
137
149
|
"a.jpg b.png",
|
|
138
150
|
:swallow_stderr => true)
|
|
139
151
|
|
|
140
|
-
cmd.command.
|
|
152
|
+
expect(cmd.command).to eq("convert a.jpg b.png 2>/dev/null")
|
|
141
153
|
end
|
|
142
154
|
|
|
143
155
|
it "can redirect stderr to the bit bucket on windows" do
|
|
@@ -146,7 +158,7 @@ describe Terrapin::CommandLine do
|
|
|
146
158
|
"a.jpg b.png",
|
|
147
159
|
:swallow_stderr => true)
|
|
148
160
|
|
|
149
|
-
cmd.command.
|
|
161
|
+
expect(cmd.command).to eq("convert a.jpg b.png 2>NUL")
|
|
150
162
|
end
|
|
151
163
|
|
|
152
164
|
it "runs the command it's given and returns the output" do
|
|
@@ -163,33 +175,33 @@ describe Terrapin::CommandLine do
|
|
|
163
175
|
it "colorizes the output to a tty" do
|
|
164
176
|
logger = FakeLogger.new(:tty => true)
|
|
165
177
|
Terrapin::CommandLine.new("echo", "'Logging!' :foo", :logger => logger).run(:foo => "bar")
|
|
166
|
-
logger.entries.
|
|
178
|
+
expect(logger.entries).to include("\e[32mCommand\e[0m :: echo 'Logging!' 'bar'")
|
|
167
179
|
end
|
|
168
180
|
|
|
169
181
|
it 'can still take something that does not respond to tty as a logger' do
|
|
170
182
|
output_buffer = StringIO.new
|
|
171
183
|
logger = best_logger.new(output_buffer)
|
|
172
|
-
logger.
|
|
184
|
+
expect(logger).not_to respond_to(:tty?)
|
|
173
185
|
Terrapin::CommandLine.new("echo", "'Logging!' :foo", :logger => logger).run(:foo => "bar")
|
|
174
186
|
output_buffer.rewind
|
|
175
|
-
output_buffer.read.
|
|
187
|
+
expect(output_buffer.read).to eq("Command :: echo 'Logging!' 'bar'\n")
|
|
176
188
|
end
|
|
177
189
|
|
|
178
190
|
it "logs the command to a supplied logger" do
|
|
179
191
|
logger = FakeLogger.new
|
|
180
192
|
Terrapin::CommandLine.new("echo", "'Logging!' :foo", :logger => logger).run(:foo => "bar")
|
|
181
|
-
logger.entries.
|
|
193
|
+
expect(logger.entries).to include("Command :: echo 'Logging!' 'bar'")
|
|
182
194
|
end
|
|
183
195
|
|
|
184
196
|
it "logs the command to a default logger" do
|
|
185
197
|
Terrapin::CommandLine.logger = FakeLogger.new
|
|
186
198
|
Terrapin::CommandLine.new("echo", "'Logging!'").run
|
|
187
|
-
Terrapin::CommandLine.logger.entries.
|
|
199
|
+
expect(Terrapin::CommandLine.logger.entries).to include("Command :: echo 'Logging!'")
|
|
188
200
|
end
|
|
189
201
|
|
|
190
202
|
it "is fine if no logger is supplied" do
|
|
191
203
|
Terrapin::CommandLine.logger = nil
|
|
192
204
|
cmd = Terrapin::CommandLine.new("echo", "'Logging!'", :logger => nil)
|
|
193
|
-
|
|
205
|
+
expect { cmd.run }.not_to raise_error
|
|
194
206
|
end
|
|
195
207
|
end
|
|
@@ -3,38 +3,36 @@ require 'spec_helper'
|
|
|
3
3
|
describe "When an error happens" do
|
|
4
4
|
it "raises a CommandLineError if the result code command isn't expected" do
|
|
5
5
|
cmd = Terrapin::CommandLine.new("echo", "hello")
|
|
6
|
-
cmd.
|
|
6
|
+
expect(cmd).to receive(:execute)
|
|
7
7
|
with_exitstatus_returning(1) do
|
|
8
|
-
|
|
8
|
+
expect { cmd.run }.to raise_error(Terrapin::CommandLineError)
|
|
9
9
|
end
|
|
10
10
|
end
|
|
11
11
|
|
|
12
12
|
it "does not raise if the result code is expected, even if nonzero" do
|
|
13
13
|
cmd = Terrapin::CommandLine.new("echo", "hello", expected_outcodes: [0, 1])
|
|
14
|
-
cmd.
|
|
14
|
+
expect(cmd).to receive(:execute)
|
|
15
15
|
with_exitstatus_returning(1) do
|
|
16
|
-
|
|
16
|
+
expect { cmd.run }.not_to raise_error
|
|
17
17
|
end
|
|
18
18
|
end
|
|
19
19
|
|
|
20
20
|
it "adds command output to exception message if the result code is nonzero" do
|
|
21
21
|
cmd = Terrapin::CommandLine.new("echo", "hello")
|
|
22
22
|
error_output = "Error 315"
|
|
23
|
-
cmd.
|
|
24
|
-
stubs(:execute).
|
|
25
|
-
returns(Terrapin::CommandLine::Output.new("", error_output))
|
|
23
|
+
expect(cmd).to receive(:execute).and_return(Terrapin::CommandLine::Output.new("", error_output))
|
|
26
24
|
with_exitstatus_returning(1) do
|
|
27
25
|
begin
|
|
28
26
|
cmd.run
|
|
29
27
|
rescue Terrapin::ExitStatusError => e
|
|
30
|
-
e.message.
|
|
28
|
+
expect(e.message).to match(/STDERR:\s+#{error_output}/)
|
|
31
29
|
end
|
|
32
30
|
end
|
|
33
31
|
end
|
|
34
32
|
|
|
35
33
|
it 'passes the error message to the exception when command is not found' do
|
|
36
34
|
cmd = Terrapin::CommandLine.new('test', '')
|
|
37
|
-
cmd.
|
|
35
|
+
expect(cmd).to receive(:execute).and_raise(Errno::ENOENT.new("not found"))
|
|
38
36
|
begin
|
|
39
37
|
cmd.run
|
|
40
38
|
rescue Terrapin::CommandNotFoundError => e
|
|
@@ -44,19 +42,18 @@ describe "When an error happens" do
|
|
|
44
42
|
|
|
45
43
|
it "should keep result code in #exitstatus" do
|
|
46
44
|
cmd = Terrapin::CommandLine.new("convert")
|
|
47
|
-
cmd.
|
|
45
|
+
expect(cmd).to receive(:execute).with("convert").and_return(:correct_value)
|
|
48
46
|
with_exitstatus_returning(1) do
|
|
49
47
|
cmd.run rescue nil
|
|
50
48
|
end
|
|
51
|
-
cmd.exit_status.
|
|
49
|
+
expect(cmd.exit_status).to eq(1)
|
|
52
50
|
end
|
|
53
51
|
|
|
54
52
|
it "does not blow up if running the command errored before execution" do
|
|
55
|
-
|
|
56
|
-
command
|
|
57
|
-
command.stubs(:command).raises("An Error")
|
|
53
|
+
cmd = Terrapin::CommandLine.new("echo", ":hello_world")
|
|
54
|
+
expect(cmd).to receive(:command).and_raise("An Error")
|
|
58
55
|
|
|
59
|
-
|
|
60
|
-
|
|
56
|
+
expect{ cmd.run }.to raise_error("An Error")
|
|
57
|
+
expect(cmd.exit_status).to eq 0
|
|
61
58
|
end
|
|
62
59
|
end
|
|
@@ -3,21 +3,21 @@ require 'spec_helper'
|
|
|
3
3
|
describe Terrapin::OSDetector do
|
|
4
4
|
it "detects that the system is unix" do
|
|
5
5
|
on_unix!
|
|
6
|
-
Terrapin::OS.
|
|
6
|
+
expect(Terrapin::OS).to be_unix
|
|
7
7
|
end
|
|
8
8
|
|
|
9
9
|
it "detects that the system is windows" do
|
|
10
10
|
on_windows!
|
|
11
|
-
Terrapin::OS.
|
|
11
|
+
expect(Terrapin::OS).to be_windows
|
|
12
12
|
end
|
|
13
13
|
|
|
14
14
|
it "detects that the system is windows (mingw)" do
|
|
15
15
|
on_mingw!
|
|
16
|
-
Terrapin::OS.
|
|
16
|
+
expect(Terrapin::OS).to be_windows
|
|
17
17
|
end
|
|
18
18
|
|
|
19
19
|
it "detects that the current Ruby is on Java" do
|
|
20
20
|
on_java!
|
|
21
|
-
Terrapin::OS.
|
|
21
|
+
expect(Terrapin::OS).to be_java
|
|
22
22
|
end
|
|
23
23
|
end
|
|
@@ -2,49 +2,37 @@ require 'spec_helper'
|
|
|
2
2
|
|
|
3
3
|
describe "When picking a Runner" do
|
|
4
4
|
it "uses the BackticksRunner by default" do
|
|
5
|
-
Terrapin::CommandLine::ProcessRunner.
|
|
6
|
-
Terrapin::CommandLine::PosixRunner.stubs(:supported?).returns(false)
|
|
5
|
+
expect(Terrapin::CommandLine::ProcessRunner).to receive(:supported?).and_return(false)
|
|
7
6
|
|
|
8
7
|
cmd = Terrapin::CommandLine.new("echo", "hello")
|
|
9
8
|
|
|
10
|
-
cmd.runner.class.
|
|
9
|
+
expect(cmd.runner.class).to eq(Terrapin::CommandLine::BackticksRunner)
|
|
11
10
|
end
|
|
12
11
|
|
|
13
12
|
it "uses the ProcessRunner on 1.9 and it's available" do
|
|
14
|
-
Terrapin::CommandLine::ProcessRunner.
|
|
15
|
-
Terrapin::CommandLine::PosixRunner.stubs(:supported?).returns(false)
|
|
13
|
+
expect(Terrapin::CommandLine::ProcessRunner).to receive(:supported?).and_return(true)
|
|
16
14
|
|
|
17
15
|
cmd = Terrapin::CommandLine.new("echo", "hello")
|
|
18
|
-
cmd.runner.class.
|
|
16
|
+
expect(cmd.runner.class).to eq(Terrapin::CommandLine::ProcessRunner)
|
|
19
17
|
end
|
|
20
18
|
|
|
21
|
-
it "uses the
|
|
22
|
-
Terrapin::CommandLine::PosixRunner.stubs(:supported?).returns(true)
|
|
23
|
-
|
|
24
|
-
cmd = Terrapin::CommandLine.new("echo", "hello")
|
|
25
|
-
cmd.runner.class.should == Terrapin::CommandLine::PosixRunner
|
|
26
|
-
end
|
|
27
|
-
|
|
28
|
-
it "uses the BackticksRunner if the PosixRunner is available, but we told it to use Backticks all the time" do
|
|
29
|
-
Terrapin::CommandLine::PosixRunner.stubs(:supported?).returns(true)
|
|
19
|
+
it "uses the BackticksRunner if we told it to use Backticks all the time" do
|
|
30
20
|
Terrapin::CommandLine.runner = Terrapin::CommandLine::BackticksRunner.new
|
|
31
21
|
|
|
32
22
|
cmd = Terrapin::CommandLine.new("echo", "hello")
|
|
33
|
-
cmd.runner.class.
|
|
23
|
+
expect(cmd.runner.class).to eq(Terrapin::CommandLine::BackticksRunner)
|
|
34
24
|
end
|
|
35
25
|
|
|
36
|
-
it "uses the BackticksRunner if
|
|
37
|
-
Terrapin::CommandLine::PosixRunner.stubs(:supported?).returns(true)
|
|
38
|
-
|
|
26
|
+
it "uses the BackticksRunner, if we told it to use Backticks" do
|
|
39
27
|
cmd = Terrapin::CommandLine.new("echo", "hello", :runner => Terrapin::CommandLine::BackticksRunner.new)
|
|
40
|
-
cmd.runner.class.
|
|
28
|
+
expect(cmd.runner.class).to eq(Terrapin::CommandLine::BackticksRunner)
|
|
41
29
|
end
|
|
42
30
|
|
|
43
31
|
it "can go into 'Fake' mode" do
|
|
44
32
|
Terrapin::CommandLine.fake!
|
|
45
33
|
|
|
46
34
|
cmd = Terrapin::CommandLine.new("echo", "hello")
|
|
47
|
-
cmd.runner.class.
|
|
35
|
+
expect(cmd.runner.class).to eq Terrapin::CommandLine::FakeRunner
|
|
48
36
|
end
|
|
49
37
|
|
|
50
38
|
it "can turn off Fake mode" do
|
|
@@ -52,43 +40,40 @@ describe "When picking a Runner" do
|
|
|
52
40
|
Terrapin::CommandLine.unfake!
|
|
53
41
|
|
|
54
42
|
cmd = Terrapin::CommandLine.new("echo", "hello")
|
|
55
|
-
cmd.runner.class.
|
|
43
|
+
expect(cmd.runner.class).not_to eq Terrapin::CommandLine::FakeRunner
|
|
56
44
|
end
|
|
57
45
|
|
|
58
46
|
it "can use a FakeRunner even if not in Fake mode" do
|
|
59
47
|
Terrapin::CommandLine.unfake!
|
|
60
48
|
|
|
61
49
|
cmd = Terrapin::CommandLine.new("echo", "hello", :runner => Terrapin::CommandLine::FakeRunner.new)
|
|
62
|
-
cmd.runner.class.
|
|
50
|
+
expect(cmd.runner.class).to eq Terrapin::CommandLine::FakeRunner
|
|
63
51
|
end
|
|
64
52
|
end
|
|
65
53
|
|
|
66
54
|
describe 'When running an executable in the supplemental path' do
|
|
67
|
-
before do
|
|
68
|
-
path = Pathname.new(File.dirname(__FILE__)) + '..' + 'support'
|
|
69
|
-
File.open(path + 'ls', 'w'){|f| f.puts "#!/bin/sh\necho overridden-ls\n" }
|
|
70
|
-
FileUtils.chmod(0755, path + 'ls')
|
|
71
|
-
Terrapin::CommandLine.path = path
|
|
72
|
-
end
|
|
73
|
-
|
|
74
|
-
after do
|
|
75
|
-
FileUtils.rm_f("#{Terrapin::CommandLine.path}/ls")
|
|
76
|
-
end
|
|
77
|
-
|
|
78
55
|
[
|
|
79
56
|
Terrapin::CommandLine::BackticksRunner,
|
|
80
57
|
Terrapin::CommandLine::PopenRunner,
|
|
81
|
-
Terrapin::CommandLine::PosixRunner,
|
|
82
58
|
Terrapin::CommandLine::ProcessRunner
|
|
83
59
|
].each do |runner_class|
|
|
84
60
|
if runner_class.supported?
|
|
85
61
|
describe runner_class do
|
|
86
62
|
describe '#run' do
|
|
87
63
|
it 'finds the correct executable' do
|
|
64
|
+
path = Pathname.new(File.dirname(__FILE__)) + '..' + 'support'
|
|
65
|
+
File.open(path + 'ls', 'w'){|f| f.puts "#!/bin/sh\necho overridden-ls\n" }
|
|
66
|
+
FileUtils.chmod(0755, path + 'ls')
|
|
67
|
+
Terrapin::CommandLine.path = path
|
|
88
68
|
Terrapin::CommandLine.runner = runner_class.new
|
|
89
69
|
command = Terrapin::CommandLine.new('ls')
|
|
70
|
+
|
|
90
71
|
result = command.run
|
|
72
|
+
|
|
91
73
|
expect(result.strip).to eq('overridden-ls')
|
|
74
|
+
|
|
75
|
+
ensure
|
|
76
|
+
FileUtils.rm("#{Terrapin::CommandLine.path}/ls")
|
|
92
77
|
end
|
|
93
78
|
end
|
|
94
79
|
end
|
data/terrapin.gemspec
CHANGED
|
@@ -1,28 +1,25 @@
|
|
|
1
1
|
$LOAD_PATH.push File.expand_path("../lib", __FILE__)
|
|
2
|
-
require
|
|
2
|
+
require "terrapin/version"
|
|
3
3
|
|
|
4
4
|
Gem::Specification.new do |s|
|
|
5
|
-
s.name
|
|
6
|
-
s.version
|
|
7
|
-
s.platform
|
|
8
|
-
s.author
|
|
9
|
-
s.email
|
|
10
|
-
s.homepage
|
|
11
|
-
s.summary
|
|
12
|
-
s.description
|
|
13
|
-
s.license
|
|
5
|
+
s.name = "terrapin"
|
|
6
|
+
s.version = Terrapin::VERSION.dup
|
|
7
|
+
s.platform = Gem::Platform::RUBY
|
|
8
|
+
s.author = "Jon Yurek"
|
|
9
|
+
s.email = "jyurek@thoughtbot.com"
|
|
10
|
+
s.homepage = "https://github.com/thoughtbot/terrapin"
|
|
11
|
+
s.summary = "Run shell commands safely, even with user-supplied values"
|
|
12
|
+
s.description = "Run shell commands safely, even with user-supplied values"
|
|
13
|
+
s.license = "MIT"
|
|
14
14
|
|
|
15
|
-
s.files
|
|
16
|
-
s.
|
|
17
|
-
s.executables = `git ls-files -- bin/*`.split("\n").map{|f| File.basename(f)}
|
|
15
|
+
s.files = `git ls-files`.split("\n")
|
|
16
|
+
s.executables = `git ls-files -- bin/*`.split("\n").map { |f| File.basename(f) }
|
|
18
17
|
s.require_paths = ["lib"]
|
|
19
18
|
|
|
20
|
-
s.add_dependency(
|
|
21
|
-
s.add_development_dependency(
|
|
22
|
-
s.add_development_dependency(
|
|
23
|
-
s.add_development_dependency(
|
|
24
|
-
s.add_development_dependency(
|
|
25
|
-
s.add_development_dependency(
|
|
26
|
-
s.add_development_dependency('pry')
|
|
19
|
+
s.add_dependency("climate_control")
|
|
20
|
+
s.add_development_dependency("rspec")
|
|
21
|
+
s.add_development_dependency("rake")
|
|
22
|
+
s.add_development_dependency("activesupport", ">= 3.0.0", "< 5.0")
|
|
23
|
+
s.add_development_dependency("pry")
|
|
24
|
+
s.add_development_dependency("logger")
|
|
27
25
|
end
|
|
28
|
-
|
metadata
CHANGED
|
@@ -1,14 +1,13 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: terrapin
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version:
|
|
4
|
+
version: 1.1.1
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Jon Yurek
|
|
8
|
-
autorequire:
|
|
9
8
|
bindir: bin
|
|
10
9
|
cert_chain: []
|
|
11
|
-
date:
|
|
10
|
+
date: 1980-01-02 00:00:00.000000000 Z
|
|
12
11
|
dependencies:
|
|
13
12
|
- !ruby/object:Gem::Dependency
|
|
14
13
|
name: climate_control
|
|
@@ -16,20 +15,14 @@ dependencies:
|
|
|
16
15
|
requirements:
|
|
17
16
|
- - ">="
|
|
18
17
|
- !ruby/object:Gem::Version
|
|
19
|
-
version: 0
|
|
20
|
-
- - "<"
|
|
21
|
-
- !ruby/object:Gem::Version
|
|
22
|
-
version: '1.0'
|
|
18
|
+
version: '0'
|
|
23
19
|
type: :runtime
|
|
24
20
|
prerelease: false
|
|
25
21
|
version_requirements: !ruby/object:Gem::Requirement
|
|
26
22
|
requirements:
|
|
27
23
|
- - ">="
|
|
28
24
|
- !ruby/object:Gem::Version
|
|
29
|
-
version: 0
|
|
30
|
-
- - "<"
|
|
31
|
-
- !ruby/object:Gem::Version
|
|
32
|
-
version: '1.0'
|
|
25
|
+
version: '0'
|
|
33
26
|
- !ruby/object:Gem::Dependency
|
|
34
27
|
name: rspec
|
|
35
28
|
requirement: !ruby/object:Gem::Requirement
|
|
@@ -45,7 +38,7 @@ dependencies:
|
|
|
45
38
|
- !ruby/object:Gem::Version
|
|
46
39
|
version: '0'
|
|
47
40
|
- !ruby/object:Gem::Dependency
|
|
48
|
-
name:
|
|
41
|
+
name: rake
|
|
49
42
|
requirement: !ruby/object:Gem::Requirement
|
|
50
43
|
requirements:
|
|
51
44
|
- - ">="
|
|
@@ -59,21 +52,27 @@ dependencies:
|
|
|
59
52
|
- !ruby/object:Gem::Version
|
|
60
53
|
version: '0'
|
|
61
54
|
- !ruby/object:Gem::Dependency
|
|
62
|
-
name:
|
|
55
|
+
name: activesupport
|
|
63
56
|
requirement: !ruby/object:Gem::Requirement
|
|
64
57
|
requirements:
|
|
65
58
|
- - ">="
|
|
66
59
|
- !ruby/object:Gem::Version
|
|
67
|
-
version:
|
|
60
|
+
version: 3.0.0
|
|
61
|
+
- - "<"
|
|
62
|
+
- !ruby/object:Gem::Version
|
|
63
|
+
version: '5.0'
|
|
68
64
|
type: :development
|
|
69
65
|
prerelease: false
|
|
70
66
|
version_requirements: !ruby/object:Gem::Requirement
|
|
71
67
|
requirements:
|
|
72
68
|
- - ">="
|
|
73
69
|
- !ruby/object:Gem::Version
|
|
74
|
-
version:
|
|
70
|
+
version: 3.0.0
|
|
71
|
+
- - "<"
|
|
72
|
+
- !ruby/object:Gem::Version
|
|
73
|
+
version: '5.0'
|
|
75
74
|
- !ruby/object:Gem::Dependency
|
|
76
|
-
name:
|
|
75
|
+
name: pry
|
|
77
76
|
requirement: !ruby/object:Gem::Requirement
|
|
78
77
|
requirements:
|
|
79
78
|
- - ">="
|
|
@@ -87,27 +86,7 @@ dependencies:
|
|
|
87
86
|
- !ruby/object:Gem::Version
|
|
88
87
|
version: '0'
|
|
89
88
|
- !ruby/object:Gem::Dependency
|
|
90
|
-
name:
|
|
91
|
-
requirement: !ruby/object:Gem::Requirement
|
|
92
|
-
requirements:
|
|
93
|
-
- - ">="
|
|
94
|
-
- !ruby/object:Gem::Version
|
|
95
|
-
version: 3.0.0
|
|
96
|
-
- - "<"
|
|
97
|
-
- !ruby/object:Gem::Version
|
|
98
|
-
version: '5.0'
|
|
99
|
-
type: :development
|
|
100
|
-
prerelease: false
|
|
101
|
-
version_requirements: !ruby/object:Gem::Requirement
|
|
102
|
-
requirements:
|
|
103
|
-
- - ">="
|
|
104
|
-
- !ruby/object:Gem::Version
|
|
105
|
-
version: 3.0.0
|
|
106
|
-
- - "<"
|
|
107
|
-
- !ruby/object:Gem::Version
|
|
108
|
-
version: '5.0'
|
|
109
|
-
- !ruby/object:Gem::Dependency
|
|
110
|
-
name: pry
|
|
89
|
+
name: logger
|
|
111
90
|
requirement: !ruby/object:Gem::Requirement
|
|
112
91
|
requirements:
|
|
113
92
|
- - ">="
|
|
@@ -126,14 +105,18 @@ executables: []
|
|
|
126
105
|
extensions: []
|
|
127
106
|
extra_rdoc_files: []
|
|
128
107
|
files:
|
|
108
|
+
- ".github/workflows/ci.yml"
|
|
109
|
+
- ".github/workflows/dynamic-readme.yml"
|
|
110
|
+
- ".github/workflows/dynamic-security.yml"
|
|
129
111
|
- ".gitignore"
|
|
130
|
-
-
|
|
112
|
+
- CODEOWNERS
|
|
131
113
|
- GOALS
|
|
132
114
|
- Gemfile
|
|
133
115
|
- LICENSE
|
|
134
116
|
- NEWS.md
|
|
135
117
|
- README.md
|
|
136
118
|
- Rakefile
|
|
119
|
+
- SECURITY.md
|
|
137
120
|
- lib/terrapin.rb
|
|
138
121
|
- lib/terrapin/command_line.rb
|
|
139
122
|
- lib/terrapin/command_line/multi_pipe.rb
|
|
@@ -142,7 +125,6 @@ files:
|
|
|
142
125
|
- lib/terrapin/command_line/runners/backticks_runner.rb
|
|
143
126
|
- lib/terrapin/command_line/runners/fake_runner.rb
|
|
144
127
|
- lib/terrapin/command_line/runners/popen_runner.rb
|
|
145
|
-
- lib/terrapin/command_line/runners/posix_runner.rb
|
|
146
128
|
- lib/terrapin/command_line/runners/process_runner.rb
|
|
147
129
|
- lib/terrapin/exceptions.rb
|
|
148
130
|
- lib/terrapin/os_detector.rb
|
|
@@ -152,13 +134,11 @@ files:
|
|
|
152
134
|
- spec/support/have_output.rb
|
|
153
135
|
- spec/support/nonblocking_examples.rb
|
|
154
136
|
- spec/support/stub_os.rb
|
|
155
|
-
- spec/support/unsetting_exitstatus.rb
|
|
156
137
|
- spec/support/with_exitstatus.rb
|
|
157
138
|
- spec/terrapin/command_line/output_spec.rb
|
|
158
139
|
- spec/terrapin/command_line/runners/backticks_runner_spec.rb
|
|
159
140
|
- spec/terrapin/command_line/runners/fake_runner_spec.rb
|
|
160
141
|
- spec/terrapin/command_line/runners/popen_runner_spec.rb
|
|
161
|
-
- spec/terrapin/command_line/runners/posix_runner_spec.rb
|
|
162
142
|
- spec/terrapin/command_line/runners/process_runner_spec.rb
|
|
163
143
|
- spec/terrapin/command_line_spec.rb
|
|
164
144
|
- spec/terrapin/errors_spec.rb
|
|
@@ -169,7 +149,6 @@ homepage: https://github.com/thoughtbot/terrapin
|
|
|
169
149
|
licenses:
|
|
170
150
|
- MIT
|
|
171
151
|
metadata: {}
|
|
172
|
-
post_install_message:
|
|
173
152
|
rdoc_options: []
|
|
174
153
|
require_paths:
|
|
175
154
|
- lib
|
|
@@ -184,26 +163,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
|
184
163
|
- !ruby/object:Gem::Version
|
|
185
164
|
version: '0'
|
|
186
165
|
requirements: []
|
|
187
|
-
|
|
188
|
-
rubygems_version: 2.6.14
|
|
189
|
-
signing_key:
|
|
166
|
+
rubygems_version: 3.6.7
|
|
190
167
|
specification_version: 4
|
|
191
168
|
summary: Run shell commands safely, even with user-supplied values
|
|
192
|
-
test_files:
|
|
193
|
-
- spec/spec_helper.rb
|
|
194
|
-
- spec/support/fake_logger.rb
|
|
195
|
-
- spec/support/have_output.rb
|
|
196
|
-
- spec/support/nonblocking_examples.rb
|
|
197
|
-
- spec/support/stub_os.rb
|
|
198
|
-
- spec/support/unsetting_exitstatus.rb
|
|
199
|
-
- spec/support/with_exitstatus.rb
|
|
200
|
-
- spec/terrapin/command_line/output_spec.rb
|
|
201
|
-
- spec/terrapin/command_line/runners/backticks_runner_spec.rb
|
|
202
|
-
- spec/terrapin/command_line/runners/fake_runner_spec.rb
|
|
203
|
-
- spec/terrapin/command_line/runners/popen_runner_spec.rb
|
|
204
|
-
- spec/terrapin/command_line/runners/posix_runner_spec.rb
|
|
205
|
-
- spec/terrapin/command_line/runners/process_runner_spec.rb
|
|
206
|
-
- spec/terrapin/command_line_spec.rb
|
|
207
|
-
- spec/terrapin/errors_spec.rb
|
|
208
|
-
- spec/terrapin/os_detector_spec.rb
|
|
209
|
-
- spec/terrapin/runners_spec.rb
|
|
169
|
+
test_files: []
|