test-cmd.rb 2.7.0 → 2.7.2

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
  SHA256:
3
- metadata.gz: c42ecb86960f6c733054ea3cd7ed041c23accec019f7addb7a2a595020b507bf
4
- data.tar.gz: 05fd256aa2c70bb23e8e9ef3e3f8e91eb9bcff9fa2680f48a059960333e74b06
3
+ metadata.gz: a9c323a0dbc2f142481d09008829ca2f3e6d8dc53d4f4c3dcf1efacc3096f58b
4
+ data.tar.gz: d3ff8c6062fe90054e4953a5ea69c6aacb4048b420c6b6344b6985ebee751e29
5
5
  SHA512:
6
- metadata.gz: e2c4e2b3858f7b090359a46756a54408d28c729603f0f47ccda5a68c35e2c11dd807dade25cf79d88af938861a112b582d9ecea0198d4b2023ab6fba504ba63d
7
- data.tar.gz: 7efb00552507bbbb2b1d66e599ccdd165e7acb3628f5a5e97daa2ec0bdafca5e63ebce274d937a737224836db806a171d4f8bbd07b2195bc092aa529ddacc2d8
6
+ metadata.gz: 13e73947059bbb45f6c9c6af29619e7d22751af6dda7574aa5c2b87485786d0c8e2f2e88f2739c9c4087c88e55536c6f18e617ce033fd2a0616494e72fea185b
7
+ data.tar.gz: 6556f3ff5a3bc05f71ecbb4242ed3cccdfd7aa5f3dc528ca09daf6c850e797595cf1de6c3c426b7a4e1061145588c84215ba034a09228fe09f5a9a51ea059d1b
@@ -4,5 +4,5 @@ end unless defined?(Test)
4
4
  class Test::Command
5
5
  ##
6
6
  # @string [String]
7
- VERSION = "2.7.0"
7
+ VERSION = "2.7.2"
8
8
  end
data/lib/test/command.rb CHANGED
@@ -102,8 +102,10 @@ class Test::Command
102
102
  @producer = Thread.new do
103
103
  @stdout = read_limited(@out.r, @limit[:stdout])
104
104
  @stderr = read_limited(@err.r, @limit[:stderr])
105
- Process.wait
106
- @status = $?
105
+ @status = Process.waitpid2(@pid).last
106
+ rescue Errno::ECHILD
107
+ errpid = Process.spawn("false")
108
+ @status = Process.waitpid2(errpid).last
107
109
  ensure
108
110
  @out.r.close
109
111
  @err.r.close
@@ -117,6 +119,7 @@ class Test::Command
117
119
  # writer thread does not block forever.
118
120
  @in_r.close unless @in_r.equal?(IO::NULL)
119
121
  @status = Process.waitpid2(Process.spawn("false")).last
122
+ self
120
123
  end
121
124
 
122
125
  ##
data/test/cmd_test.rb CHANGED
@@ -239,5 +239,68 @@ class Test::Command
239
239
  assert_equal true, ::Test::Command.new("/a/path/that/is/not/found").command_not_found?
240
240
  assert_equal true, ::Test::Command.new("/a/path/that/is/not/found").not_found?
241
241
  end
242
+
243
+ def test_spawn_returns_self_when_not_found
244
+ command = ::Test::Command.new("/a/path/that/is/not/found")
245
+ assert_equal command, command.spawn
246
+ end
247
+
248
+ def test_spawn_sets_not_found_on_self
249
+ command = ::Test::Command.new("/a/path/that/is/not/found")
250
+ command.spawn
251
+ assert_equal true, command.not_found?
252
+ end
253
+
254
+ def test_stdout_when_not_found
255
+ command = ::Test::Command.new("/a/path/that/is/not/found")
256
+ assert_equal "", command.stdout
257
+ end
258
+
259
+ def test_stderr_when_not_found
260
+ command = ::Test::Command.new("/a/path/that/is/not/found")
261
+ assert_equal "No such file or directory - /a/path/that/is/not/found",
262
+ command.stderr
263
+ end
264
+ end
265
+ end
266
+
267
+ class Test::Command
268
+ ##
269
+ # A command's status belongs to the command, and is not taken from
270
+ # another child that happens to be ready to be reaped.
271
+ #
272
+ # A bare `Process.wait` reaps whichever child is ready, so a child
273
+ # that has exited and been reaped by nobody - another test's, another
274
+ # thread's - could answer for a command that never spawned it.
275
+ class StatusTest < Test
276
+ def test_failure_is_not_answered_by_a_successful_decoy
277
+ decoy = Process.spawn("true")
278
+ sleep 0.1
279
+ assert_equal false, ::Test::Command.new("false").success?
280
+ ensure
281
+ reap(decoy)
282
+ end
283
+
284
+ def test_success_is_not_answered_by_a_failing_decoy
285
+ decoy = Process.spawn("false")
286
+ sleep 0.1
287
+ assert_equal true, ::Test::Command.new("true").success?
288
+ ensure
289
+ reap(decoy)
290
+ end
291
+
292
+ private
293
+
294
+ ##
295
+ # Reaps a decoy the command left alone, and says nothing when the
296
+ # command took it: the test that got there first is the point of
297
+ # these.
298
+ # @param [Integer, nil] pid
299
+ # @return [void]
300
+ def reap(pid)
301
+ Process.waitpid(pid) if pid
302
+ rescue Errno::ECHILD
303
+ nil
304
+ end
242
305
  end
243
306
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: test-cmd.rb
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.7.0
4
+ version: 2.7.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Robert Gleeson
@@ -124,7 +124,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
124
124
  - !ruby/object:Gem::Version
125
125
  version: '0'
126
126
  requirements: []
127
- rubygems_version: 4.0.20
127
+ rubygems_version: 4.0.16
128
128
  specification_version: 4
129
129
  summary: test-cmd.rb is a Go-inspired, object-oriented interface for running commands
130
130
  on UNIX-like systems, in the spirit of Go's `os/exec`. A command can be built by