test-cmd.rb 2.7.1 → 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: 79bec627803ce82d85c99a7f55f00b007cdfba9ecf54634b8c48e9fa64083b17
4
- data.tar.gz: 73ab470f82fc83f120ab84c5a4345ce6da2c417edf121e24db314ba2cd9b1dad
3
+ metadata.gz: a9c323a0dbc2f142481d09008829ca2f3e6d8dc53d4f4c3dcf1efacc3096f58b
4
+ data.tar.gz: d3ff8c6062fe90054e4953a5ea69c6aacb4048b420c6b6344b6985ebee751e29
5
5
  SHA512:
6
- metadata.gz: e9d84416530c7becb5915bca84d2bc7eb17532d0bbb53756d205ab2ba06c6f63999ad395ca206e6a943d6f24fc2ce3913b0db7061164bab018499021a3705e20
7
- data.tar.gz: 6aedc2200539e08f31eebd9d480cbb3c7a4ee0096e477d153a969096df542e79e5b3ac236ebabce6c476bba9f3fce2c3b5210c97e5378d9dd50a3e6fbc406d9c
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.1"
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
data/test/cmd_test.rb CHANGED
@@ -263,3 +263,44 @@ class Test::Command
263
263
  end
264
264
  end
265
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
305
+ end
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.1
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