obfusk-util 0.4.4 → 0.5.0

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: ace37fd05ca1a55b9ed7197c9ef69ad8b25b5ebd
4
- data.tar.gz: d1f1fd09ce7432c58810fa072358a2b114d138d6
3
+ metadata.gz: 5bf7375bb3b37224db96e59696194cd81e6a1abc
4
+ data.tar.gz: d9c148f1ba2b5fefd2e93012ee18a1126a0db3a8
5
5
  SHA512:
6
- metadata.gz: 48e4a35b37818666e5037dc416b912e2952cdc854eae275b7821a9f14274d921b99db71e47fe7212d47367be6f8e07e8565c57ea100ed4d88eb0217534016a9c
7
- data.tar.gz: e0dfe81bb323b6222b408333184edfe287d56aada548352b23bfe6cd2032fd971625aadbb45970d809f56c7b7fe5237c0ef6f04f36b1505f2090d20646fb4b19
6
+ metadata.gz: 8ee94a5abc89f7cfb162210ea6336cf9dbdc227ef52fb65075a1a126fd5b9bdbda777085a02766d01d551aa09ea8ee26066c1969534098d533c37c59fad4c928
7
+ data.tar.gz: dfc6216044f4b197ef8c527df107c2743b87f5145c450d46ccc08c0419ab6c2b5f6c71bce3b557058128f937e732855ee223eb9fa344dd2bdaf4d9c84c5d4b8f
data/README.md CHANGED
@@ -5,7 +5,7 @@
5
5
  Date : 2014-02-20
6
6
 
7
7
  Copyright : Copyright (C) 2014 Felix C. Stegerman
8
- Version : v0.4.4
8
+ Version : v0.5.0
9
9
 
10
10
  []: }}}1
11
11
 
@@ -197,25 +197,28 @@ end
197
197
  ```ruby
198
198
  require 'obfusk/util/sh'
199
199
 
200
- Obfusk::Util::sh('echo "$0" ">>$1<<" ">>$FOO<<"',
200
+ Obfusk::Util::sh 'echo "$0" ">>$1<<" ">>$FOO<<"', '"one"', 'FOO' => 'foo'
201
+ # stdout: bash >>"one"<< >>foo<<
202
+
203
+ Obfusk::Util::sh? 'false'
204
+ # => false
205
+
206
+ Obfusk::Util::sh! 'echo FOO; false'
207
+ # stdout: FOO
208
+ # => RunError
209
+
210
+ Obfusk::Util::shc('echo "$0" ">>$1<<" ">>$FOO<<"',
201
211
  '"one"', 'FOO' => 'foo').stdout
202
212
  # => %Q{bash >>"one"<< >>foo<<}
203
213
 
204
- Obfusk::Util::sh('echo step1; false; echo step3',
214
+ Obfusk::Util::shc('echo step1; false; echo step3',
205
215
  print: true, exit: true, merge: true).stdout
206
216
  # => "+ echo step1\nstep1\n+ false\n"
207
217
 
208
- Obfusk::Util::sh? 'false'
218
+ Obfusk::Util::shc? 'false'
209
219
  # => false
210
220
 
211
- Obfusk::Util::sh! 'false'
212
- # => RunError
213
-
214
- Obfusk::Util::sys 'echo "$0" ">>$1<<" ">>$FOO<<"', '"one"', 'FOO' => 'foo'
215
- # stdout: bash >>"one"<< >>foo<<
216
-
217
- Obfusk::Util::sys! 'echo FOO; false'
218
- # stdout: FOO
221
+ Obfusk::Util::shc! 'false'
219
222
  # => RunError
220
223
 
221
224
  ```
@@ -14,8 +14,8 @@ require 'obfusk/util/run'
14
14
  # my namespace
15
15
  module Obfusk; module Util
16
16
 
17
- # shell command result
18
- class Sh < Struct.new(:cmd, :status, :stdout, :stderr) # {{{1
17
+ # common methods for Sh, Shc
18
+ module ShBase # {{{1
19
19
 
20
20
  # was the exitstatus zero?
21
21
  def ok?
@@ -32,14 +32,24 @@ module Obfusk; module Util
32
32
 
33
33
  end # }}}1
34
34
 
35
+ # shell result
36
+ class Sh < Struct.new(:cmd, :status)
37
+ include ShBase
38
+ end
39
+
40
+ # shell capture result
41
+ class Shc < Struct.new(:cmd, :status, :stdout, :stderr)
42
+ include ShBase
43
+ end
44
+
35
45
  # --
36
46
 
37
- # run a command using bash (w/ arguments) and capture its output;
38
- # see also `sys`; uses `capture{2e,3}`
47
+ # run a command using bash (w/ arguments); see also {shc}; uses
48
+ # {spawn_w}
39
49
  #
40
50
  # ```
41
- # sh('echo "$0" ">>$1<<" ">>$FOO<<"', '"one"', 'FOO' => 'foo').stdout
42
- # # => %Q{bash >>"one"<< >>foo<<}
51
+ # sh 'echo "$0" ">>$1<<" ">>$FOO<<"', '"one"', 'FOO' => 'foo'
52
+ # # stdout: bash >>"one"<< >>foo<<
43
53
  # ```
44
54
  #
45
55
  # @param [Hash] args.last
@@ -51,15 +61,11 @@ module Obfusk; module Util
51
61
  # * any other `String` key is added to the `env`
52
62
  # * any other `Symbol` key is passed as an option to `capture3`
53
63
  # @return [Sh]
54
- def self.sh(cmd, *args) # {{{1
55
- c = _sh cmd, args
56
- if c[:merge]
57
- stderr = nil; stdout, status = capture2e(*c[:cmd], c[:opts])
58
- else
59
- stdout, stderr, status = capture3(*c[:cmd], c[:opts])
60
- end
61
- Sh.new c[:cmd], status, stdout, stderr
62
- end # }}}1
64
+ def self.sh(cmd, *args)
65
+ c = _sh cmd, args; o = c[:opts]
66
+ o_ = c[:merge] ? o.merge(:err => o[:out] ? [:child, :out] : :out) : o
67
+ Sh.new c[:cmd], spawn_w(*c[:cmd], o_)
68
+ end
63
69
 
64
70
  # `sh(...).ok?`
65
71
  def self.sh?(cmd, *args)
@@ -73,30 +79,33 @@ module Obfusk; module Util
73
79
 
74
80
  # --
75
81
 
76
- # run a command using bash (w/ arguments); takes the same arguments
77
- # as `sh`; uses `spawn_w`
82
+ # run a command using bash (w/ arguments) and capture its stdout and
83
+ # stderr; accepts the same arguments as {sh}; uses `capture{2e,3}`
78
84
  #
79
85
  # ```
80
- # sys 'echo "$0" ">>$1<<" ">>$FOO<<"', '"one"', 'FOO' => 'foo'
81
- # # stdout: bash >>"one"<< >>foo<<
86
+ # shc('echo "$0" ">>$1<<" ">>$FOO<<"', '"one"', 'FOO' => 'foo').stdout
87
+ # # => %Q{bash >>"one"<< >>foo<<}
82
88
  # ```
83
89
  #
84
- # @return [Process::Status]
85
- def self.sys(cmd, *args)
86
- c = _sh cmd, args; o = c[:opts]
87
- o_ = c[:merge] ? o.merge(:err => o[:out] ? [:child, :out] : :out) : o
88
- spawn_w(*c[:cmd], o_)
89
- end
90
+ # @return [Shc]
91
+ def self.shc(cmd, *args) # {{{1
92
+ c = _sh cmd, args
93
+ if c[:merge]
94
+ stderr = nil; stdout, status = capture2e(*c[:cmd], c[:opts])
95
+ else
96
+ stdout, stderr, status = capture3(*c[:cmd], c[:opts])
97
+ end
98
+ Shc.new c[:cmd], status, stdout, stderr
99
+ end # }}}1
90
100
 
91
- # `sys(...).exitstatus == 0`
92
- def self.sys?(cmd, *args)
93
- sys(cmd, *args).exitstatus == 0
101
+ # `shc(...).ok?`
102
+ def self.shc?(cmd, *args)
103
+ shc(cmd, *args).ok?
94
104
  end
95
105
 
96
- # `sys(...)`
97
- # @raise RunError when exitstatus non-zero
98
- def self.sys!(cmd, *args)
99
- sys(cmd, *args).tap { |s| chk_exitstatus cmd, s.exitstatus }
106
+ # `shc(...).ok!`
107
+ def self.shc!(cmd, *args)
108
+ shc(cmd, *args).ok!
100
109
  end
101
110
 
102
111
  # --
@@ -118,19 +127,19 @@ module Obfusk; module Util
118
127
 
119
128
  # --
120
129
 
121
- # ohai + sys; requires `obfusk/util/message`
122
- def self.osys(*args)
123
- ::Obfusk::Util.ohai _spawn_rm_opts(args)*' '; sys(*args)
130
+ # ohai + shc; requires `obfusk/util/message`
131
+ def self.oshc(*args)
132
+ ::Obfusk::Util.ohai _spawn_rm_opts(args)*' '; shc(*args)
124
133
  end
125
134
 
126
- # ohai + sys?; requires `obfusk/util/message`
127
- def self.osys?(*args)
128
- ::Obfusk::Util.ohai _spawn_rm_opts(args)*' '; sys?(*args)
135
+ # ohai + shc?; requires `obfusk/util/message`
136
+ def self.oshc?(*args)
137
+ ::Obfusk::Util.ohai _spawn_rm_opts(args)*' '; shc?(*args)
129
138
  end
130
139
 
131
- # ohai + sys!; requires `obfusk/util/message`
132
- def self.osys!(*args)
133
- ::Obfusk::Util.ohai _spawn_rm_opts(args)*' '; sys!(*args)
140
+ # ohai + shc!; requires `obfusk/util/message`
141
+ def self.oshc!(*args)
142
+ ::Obfusk::Util.ohai _spawn_rm_opts(args)*' '; shc!(*args)
134
143
  end
135
144
 
136
145
  # --
@@ -1,5 +1,5 @@
1
1
  # my namespace
2
2
  module Obfusk; module Util
3
- VERSION = '0.4.4'
3
+ VERSION = '0.5.0'
4
4
  DATE = '2014-02-20'
5
5
  end; end
@@ -17,87 +17,100 @@ describe 'obfusk/util/sh' do
17
17
 
18
18
  context 'sh (1)' do # {{{1
19
19
  it 'echoes w/ args and env' do
20
- r = ou.sh 'echo "$0" ">>$1<<" ">>$FOO<<"', '"one"',
21
- 'FOO' => 'foo'
22
- expect(r.ok?).to eq(true)
23
- expect(r.stdout).to eq(%Q{bash >>"one"<< >>foo<<\n})
24
- expect(r.stderr).to eq('')
20
+ r, w = IO.pipe
21
+ res = ou.sh 'echo "$0" ">>$1<<" ">>$FOO<<"', '"one"',
22
+ 'FOO' => 'foo', out: w
23
+ w.close; x = r.read; r.close
24
+ expect(res.ok?).to eq(true)
25
+ expect(x).to eq(%Q{bash >>"one"<< >>foo<<\n})
25
26
  end
26
27
  it 'works w/ print, exit, and merge' do
27
- r = ou.sh 'echo step1; false; echo step3', print: true, exit: true,
28
- merge: true
29
- expect(r.ok?).to eq(false)
30
- expect(r.stdout).to eq("+ echo step1\nstep1\n+ false\n")
31
- expect(r.stderr).to eq(nil)
28
+ r, w = IO.pipe
29
+ res = ou.sh 'echo step1; false; echo step3', print: true, exit: true,
30
+ merge: true, out: w
31
+ w.close; x = r.read; r.close
32
+ expect(res.ok?).to eq(false)
33
+ expect(x).to eq("+ echo step1\nstep1\n+ false\n")
32
34
  end
33
35
  it 'outputs pwd w/ arg' do
34
- r = ou.sh 'cd "$1"; pwd', '/'
35
- expect(r.ok?).to eq(true)
36
- expect(r.stdout).to eq("/\n")
37
- expect(r.stderr).to eq('')
36
+ r, w = IO.pipe
37
+ res = ou.sh 'cd "$1"; pwd', '/', out: w
38
+ w.close; x = r.read; r.close
39
+ expect(res.ok?).to eq(true)
40
+ expect(x).to eq("/\n")
38
41
  end
39
42
  it 'outputs pwd w/ :chdir' do
40
- r = ou.sh 'pwd', chdir: '/'
41
- expect(r.ok?).to eq(true)
42
- expect(r.stdout).to eq("/\n")
43
- expect(r.stderr).to eq('')
43
+ r, w = IO.pipe
44
+ res = ou.sh 'pwd', chdir: '/', out: w
45
+ w.close; x = r.read; r.close
46
+ expect(res.ok?).to eq(true)
47
+ expect(x).to eq("/\n")
44
48
  end
45
49
  end # }}}1
46
50
 
47
51
  context 'sh (2)' do # {{{1
48
52
  it 'prints to stderr w/ print/-x' do
49
- r = ou.sh 'echo FOO; echo BAR', print: true
50
- expect(r.ok?).to eq(true)
51
- expect(r.stdout).to eq("FOO\nBAR\n")
52
- expect(r.stderr).to eq("+ echo FOO\n+ echo BAR\n")
53
+ ro, wo = IO.pipe; re, we = IO.pipe
54
+ res = ou.sh 'echo FOO; echo BAR', print: true, out: wo, err: we
55
+ wo.close; o = ro.read; ro.close
56
+ we.close; e = re.read; re.close
57
+ expect(res.ok?).to eq(true)
58
+ expect(o).to eq("FOO\nBAR\n")
59
+ expect(e).to eq("+ echo FOO\n+ echo BAR\n")
53
60
  end
54
61
  it 'ignores false w/o exit/-e' do
55
- r = ou.sh 'echo FOO; false; echo BAR'
56
- expect(r.ok?).to eq(true)
57
- expect(r.stdout).to eq("FOO\nBAR\n")
58
- expect(r.stderr).to eq('')
62
+ r, w = IO.pipe
63
+ res = ou.sh 'echo FOO; false; echo BAR', out: w
64
+ w.close; x = r.read; r.close
65
+ expect(res.ok?).to eq(true)
66
+ expect(x).to eq("FOO\nBAR\n")
59
67
  end
60
68
  it 'stops at false w/ exit/-e' do
61
- r = ou.sh 'echo FOO; false; echo BAR', exit: true
62
- expect(r.ok?).to eq(false)
63
- expect(r.stdout).to eq("FOO\n")
64
- expect(r.stderr).to eq('')
69
+ r, w = IO.pipe
70
+ res = ou.sh 'echo FOO; false; echo BAR', exit: true, out: w
71
+ w.close; x = r.read; r.close
72
+ expect(res.ok?).to eq(false)
73
+ expect(x).to eq("FOO\n")
65
74
  end
66
75
  it 'merges stdout and stderr w/ merge' do
67
- r = ou.sh 'echo FOO; echo BAR >&2; echo BAZ', merge: true
68
- expect(r.ok?).to eq(true)
69
- expect(r.stdout).to eq("FOO\nBAR\nBAZ\n")
70
- expect(r.stderr).to eq(nil)
76
+ r, w = IO.pipe
77
+ res = ou.sh 'echo FOO; echo BAR >&2; echo BAZ', merge: true, out: w
78
+ w.close; x = r.read; r.close
79
+ expect(res.ok?).to eq(true)
80
+ expect(x).to eq("FOO\nBAR\nBAZ\n")
71
81
  end
72
82
  it 'merges env w/ string keys' do
73
- r = ou.sh 'echo $FOO; echo $BAR',
74
- env: { 'FOO' => 'no', 'BAR' => 'bar' }, 'FOO' => 'yes'
75
- expect(r.ok?).to eq(true)
76
- expect(r.stdout).to eq("yes\nbar\n")
77
- expect(r.stderr).to eq('')
83
+ r, w = IO.pipe
84
+ res = ou.sh 'echo $FOO; echo $BAR',
85
+ env: { 'FOO' => 'no', 'BAR' => 'bar' }, 'FOO' => 'yes', out: w
86
+ w.close; x = r.read; r.close
87
+ expect(res.ok?).to eq(true)
88
+ expect(x).to eq("yes\nbar\n")
78
89
  end
79
90
  end # }}}1
80
91
 
81
92
  context 'sh (3)' do # {{{1
82
93
  it 'false => ok? returns false and ok! raises' do
83
- r = ou.sh 'false'
84
- expect(r.ok?).to eq(false)
85
- expect(r.status.exitstatus).to eq(1)
86
- expect { r.ok! } .to \
94
+ r, w = IO.pipe
95
+ res = ou.sh 'false', out: w
96
+ w.close; x = r.read; r.close
97
+ expect(res.ok?).to eq(false)
98
+ expect(res.status.exitstatus).to eq(1)
99
+ expect { res.ok! } .to \
87
100
  raise_error(ou::RunError, /command returned non-zero/)
88
- expect(r.stdout).to eq('')
89
- expect(r.stderr).to eq('')
101
+ expect(x).to eq('')
90
102
  end
91
103
  it 'fails w/ message on stderr w/ NONEXISTENT' do
92
- r = ou.sh 'NONEXISTENT'
93
- expect(r.ok?).to eq(false)
94
- expect(r.status.exitstatus).to eq(127)
95
- expect(r.stdout).to eq('')
96
- expect(r.stderr).to eq("bash: NONEXISTENT: command not found\n")
104
+ r, w = IO.pipe
105
+ res = ou.sh 'NONEXISTENT', err: w
106
+ w.close; x = r.read; r.close
107
+ expect(res.ok?).to eq(false)
108
+ expect(res.status.exitstatus).to eq(127)
109
+ expect(x).to eq("bash: NONEXISTENT: command not found\n")
97
110
  end
98
111
  it 'fails w/ RunError w/ shell NONEXISTENT' do
99
112
  expect { ou.sh 'irrelevant', shell: 'NONEXISTENT' } .to \
100
- raise_error(ou::RunError, /failed to capture3 command/)
113
+ raise_error(ou::RunError, /failed to spawn command/)
101
114
  end
102
115
  end # }}}1
103
116
 
@@ -120,109 +133,107 @@ describe 'obfusk/util/sh' do
120
133
  end
121
134
  end # }}}1
122
135
 
123
- context 'sys (1)' do # {{{1
136
+ context 'shc (1)' do # {{{1
124
137
  it 'echoes w/ args and env' do
125
- r, w = IO.pipe
126
- res = ou.sys 'echo "$0" ">>$1<<" ">>$FOO<<"', '"one"',
127
- 'FOO' => 'foo', out: w
128
- w.close; x = r.read; r.close
129
- expect(res.exitstatus).to eq(0)
130
- expect(x).to eq(%Q{bash >>"one"<< >>foo<<\n})
138
+ r = ou.shc 'echo "$0" ">>$1<<" ">>$FOO<<"', '"one"',
139
+ 'FOO' => 'foo'
140
+ expect(r.ok?).to eq(true)
141
+ expect(r.stdout).to eq(%Q{bash >>"one"<< >>foo<<\n})
142
+ expect(r.stderr).to eq('')
131
143
  end
132
144
  it 'works w/ print, exit, and merge' do
133
- r, w = IO.pipe
134
- res = ou.sys 'echo step1; false; echo step3', print: true, exit: true,
135
- merge: true, out: w
136
- w.close; x = r.read; r.close
137
- expect(res.exitstatus).to_not eq(0)
138
- expect(x).to eq("+ echo step1\nstep1\n+ false\n")
145
+ r = ou.shc 'echo step1; false; echo step3', print: true, exit: true,
146
+ merge: true
147
+ expect(r.ok?).to eq(false)
148
+ expect(r.stdout).to eq("+ echo step1\nstep1\n+ false\n")
149
+ expect(r.stderr).to eq(nil)
139
150
  end
140
151
  it 'outputs pwd w/ arg' do
141
- r, w = IO.pipe
142
- res = ou.sys 'cd "$1"; pwd', '/', out: w
143
- w.close; x = r.read; r.close
144
- expect(res.exitstatus).to eq(0)
145
- expect(x).to eq("/\n")
152
+ r = ou.shc 'cd "$1"; pwd', '/'
153
+ expect(r.ok?).to eq(true)
154
+ expect(r.stdout).to eq("/\n")
155
+ expect(r.stderr).to eq('')
146
156
  end
147
157
  it 'outputs pwd w/ :chdir' do
148
- r, w = IO.pipe
149
- res = ou.sys 'pwd', chdir: '/', out: w
150
- w.close; x = r.read; r.close
151
- expect(res.exitstatus).to eq(0)
152
- expect(x).to eq("/\n")
158
+ r = ou.shc 'pwd', chdir: '/'
159
+ expect(r.ok?).to eq(true)
160
+ expect(r.stdout).to eq("/\n")
161
+ expect(r.stderr).to eq('')
153
162
  end
154
163
  end # }}}1
155
164
 
156
- context 'sys (2)' do # {{{1
165
+ context 'shc (2)' do # {{{1
157
166
  it 'prints to stderr w/ print/-x' do
158
- ro, wo = IO.pipe; re, we = IO.pipe
159
- res = ou.sys 'echo FOO; echo BAR', print: true, out: wo, err: we
160
- wo.close; o = ro.read; ro.close
161
- we.close; e = re.read; re.close
162
- expect(res.exitstatus).to eq(0)
163
- expect(o).to eq("FOO\nBAR\n")
164
- expect(e).to eq("+ echo FOO\n+ echo BAR\n")
167
+ r = ou.shc 'echo FOO; echo BAR', print: true
168
+ expect(r.ok?).to eq(true)
169
+ expect(r.stdout).to eq("FOO\nBAR\n")
170
+ expect(r.stderr).to eq("+ echo FOO\n+ echo BAR\n")
165
171
  end
166
172
  it 'ignores false w/o exit/-e' do
167
- r, w = IO.pipe
168
- res = ou.sys 'echo FOO; false; echo BAR', out: w
169
- w.close; x = r.read; r.close
170
- expect(res.exitstatus).to eq(0)
171
- expect(x).to eq("FOO\nBAR\n")
173
+ r = ou.shc 'echo FOO; false; echo BAR'
174
+ expect(r.ok?).to eq(true)
175
+ expect(r.stdout).to eq("FOO\nBAR\n")
176
+ expect(r.stderr).to eq('')
172
177
  end
173
178
  it 'stops at false w/ exit/-e' do
174
- r, w = IO.pipe
175
- res = ou.sys 'echo FOO; false; echo BAR', exit: true, out: w
176
- w.close; x = r.read; r.close
177
- expect(res.exitstatus).to_not eq(0)
178
- expect(x).to eq("FOO\n")
179
+ r = ou.shc 'echo FOO; false; echo BAR', exit: true
180
+ expect(r.ok?).to eq(false)
181
+ expect(r.stdout).to eq("FOO\n")
182
+ expect(r.stderr).to eq('')
179
183
  end
180
184
  it 'merges stdout and stderr w/ merge' do
181
- r, w = IO.pipe
182
- res = ou.sys 'echo FOO; echo BAR >&2; echo BAZ', merge: true, out: w
183
- w.close; x = r.read; r.close
184
- expect(res.exitstatus).to eq(0)
185
- expect(x).to eq("FOO\nBAR\nBAZ\n")
185
+ r = ou.shc 'echo FOO; echo BAR >&2; echo BAZ', merge: true
186
+ expect(r.ok?).to eq(true)
187
+ expect(r.stdout).to eq("FOO\nBAR\nBAZ\n")
188
+ expect(r.stderr).to eq(nil)
186
189
  end
187
190
  it 'merges env w/ string keys' do
188
- r, w = IO.pipe
189
- res = ou.sys 'echo $FOO; echo $BAR',
190
- env: { 'FOO' => 'no', 'BAR' => 'bar' }, 'FOO' => 'yes', out: w
191
- w.close; x = r.read; r.close
192
- expect(res.exitstatus).to eq(0)
193
- expect(x).to eq("yes\nbar\n")
191
+ r = ou.shc 'echo $FOO; echo $BAR',
192
+ env: { 'FOO' => 'no', 'BAR' => 'bar' }, 'FOO' => 'yes'
193
+ expect(r.ok?).to eq(true)
194
+ expect(r.stdout).to eq("yes\nbar\n")
195
+ expect(r.stderr).to eq('')
194
196
  end
195
197
  end # }}}1
196
198
 
197
- context 'sys (3)' do # {{{1
199
+ context 'shc (3)' do # {{{1
200
+ it 'false => ok? returns false and ok! raises' do
201
+ r = ou.shc 'false'
202
+ expect(r.ok?).to eq(false)
203
+ expect(r.status.exitstatus).to eq(1)
204
+ expect { r.ok! } .to \
205
+ raise_error(ou::RunError, /command returned non-zero/)
206
+ expect(r.stdout).to eq('')
207
+ expect(r.stderr).to eq('')
208
+ end
198
209
  it 'fails w/ message on stderr w/ NONEXISTENT' do
199
- r, w = IO.pipe
200
- res = ou.sys 'NONEXISTENT', err: w
201
- w.close; x = r.read; r.close
202
- expect(res.exitstatus).to eq(127)
203
- expect(x).to eq("bash: NONEXISTENT: command not found\n")
210
+ r = ou.shc 'NONEXISTENT'
211
+ expect(r.ok?).to eq(false)
212
+ expect(r.status.exitstatus).to eq(127)
213
+ expect(r.stdout).to eq('')
214
+ expect(r.stderr).to eq("bash: NONEXISTENT: command not found\n")
204
215
  end
205
216
  it 'fails w/ RunError w/ shell NONEXISTENT' do
206
- expect { ou.sys 'irrelevant', shell: 'NONEXISTENT' } .to \
207
- raise_error(ou::RunError, /failed to spawn command/)
217
+ expect { ou.shc 'irrelevant', shell: 'NONEXISTENT' } .to \
218
+ raise_error(ou::RunError, /failed to capture3 command/)
208
219
  end
209
220
  end # }}}1
210
221
 
211
- context 'sys?' do # {{{1
222
+ context 'shc?' do # {{{1
212
223
  it 'true => true' do
213
- expect(ou.sys? 'true').to eq(true)
224
+ expect(ou.shc? 'true').to eq(true)
214
225
  end
215
226
  it 'false => false' do
216
- expect(ou.sys? 'false').to eq(false)
227
+ expect(ou.shc? 'false').to eq(false)
217
228
  end
218
229
  end # }}}1
219
230
 
220
- context 'sys!' do # {{{1
221
- it 'true => Process::Status' do
222
- expect( ou.sys! 'true' ).to be_an_instance_of(Process::Status)
231
+ context 'shc!' do # {{{1
232
+ it 'true => Shc' do
233
+ expect( ou.shc! 'true' ).to be_an_instance_of(ou::Shc)
223
234
  end
224
235
  it 'false => RunError' do
225
- expect { ou.sys! 'false' } .to \
236
+ expect { ou.shc! 'false' } .to \
226
237
  raise_error(ou::RunError, /command returned non-zero/)
227
238
  end
228
239
  end # }}}1
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: obfusk-util
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.4
4
+ version: 0.5.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Felix C. Stegerman