test-cmd.rb 0.12.0 → 0.12.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 +4 -4
- data/.github/workflows/specs.yml +1 -1
- data/lib/test/cmd.rb +30 -22
- data/test/cmd_test.rb +0 -16
- data/test-cmd.rb.gemspec +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 67a69e56d58ed586edecb9b4792bbc54913f2044a6468ce6d098744142cf78a0
|
4
|
+
data.tar.gz: 713bd38cbe6812e61e8847e156e16732cdcfc72026f206bd9df70c03c6d8a946
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: b8f1e8928b018372d5d6247300509f249bb3f7934a04b4a7356beff15d9c223a396657e1bb5e050bb7777b36185f2cf106618330f73df6939204c430a25eb584
|
7
|
+
data.tar.gz: 1f76220a3ab003bf434ab2dd7d604f7abe0577543abd5d86afee3b0a1fb82c3f164f8e6ba62489c1cacb9193c44860cd3fb152e93c3bcf4491400584805dde41
|
data/.github/workflows/specs.yml
CHANGED
data/lib/test/cmd.rb
CHANGED
@@ -7,6 +7,18 @@ end
|
|
7
7
|
# test-cmd.rb provides an object oriented interface
|
8
8
|
# for spawning a command.
|
9
9
|
class Test::Cmd
|
10
|
+
##
|
11
|
+
# @api private
|
12
|
+
class Pipe < Struct.new(:r, :w)
|
13
|
+
def self.pair
|
14
|
+
new(*IO.pipe)
|
15
|
+
end
|
16
|
+
|
17
|
+
def close
|
18
|
+
[r, w].each(&:close)
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
10
22
|
##
|
11
23
|
# @param [String] cmd
|
12
24
|
# A command to spawn
|
@@ -18,6 +30,8 @@ class Test::Cmd
|
|
18
30
|
@argv = argv.dup
|
19
31
|
@status = nil
|
20
32
|
@spawned = false
|
33
|
+
@stdout = ""
|
34
|
+
@stderr = ""
|
21
35
|
end
|
22
36
|
|
23
37
|
##
|
@@ -35,15 +49,21 @@ class Test::Cmd
|
|
35
49
|
return self if @spawned
|
36
50
|
|
37
51
|
tap do
|
52
|
+
out, err = Pipe.pair, Pipe.pair
|
38
53
|
@spawned = true
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
54
|
+
t = Thread.new do
|
55
|
+
Process.spawn(@cmd, *@argv, {out: out.w, err: err.w})
|
56
|
+
Process.wait
|
57
|
+
@status = $?
|
58
|
+
end
|
59
|
+
loop do
|
60
|
+
break unless t.alive?
|
61
|
+
io, _ = IO.select([out.r, err.r], nil, nil, 0.01)
|
62
|
+
io&.include?(out.r) ? @stdout << out.r.read(1) : nil
|
63
|
+
io&.include?(err.r) ? @stderr << err.r.read(1) : nil
|
64
|
+
end
|
44
65
|
ensure
|
45
66
|
[out, err].each(&:close)
|
46
|
-
[stdout, stderr]
|
47
67
|
end
|
48
68
|
end
|
49
69
|
|
@@ -51,24 +71,16 @@ class Test::Cmd
|
|
51
71
|
# @return [String]
|
52
72
|
# Returns the contents of stdout
|
53
73
|
def stdout
|
54
|
-
|
55
|
-
|
56
|
-
out_io.read.tap { out_io.close }
|
57
|
-
rescue IOError
|
58
|
-
@stdout
|
59
|
-
end
|
74
|
+
spawn
|
75
|
+
@stdout
|
60
76
|
end
|
61
77
|
|
62
78
|
##
|
63
79
|
# @return [String]
|
64
80
|
# Returns the contents of stderr
|
65
81
|
def stderr
|
66
|
-
|
67
|
-
|
68
|
-
err_io.read.tap { err_io.close }
|
69
|
-
rescue IOError
|
70
|
-
@stderr
|
71
|
-
end
|
82
|
+
spawn
|
83
|
+
@stderr
|
72
84
|
end
|
73
85
|
|
74
86
|
##
|
@@ -138,10 +150,6 @@ class Test::Cmd
|
|
138
150
|
def spawned?
|
139
151
|
@spawned
|
140
152
|
end
|
141
|
-
|
142
|
-
private
|
143
|
-
|
144
|
-
attr_reader :out_io, :err_io
|
145
153
|
end
|
146
154
|
|
147
155
|
module Kernel
|
data/test/cmd_test.rb
CHANGED
@@ -85,22 +85,6 @@ class Test::Cmd
|
|
85
85
|
end
|
86
86
|
end
|
87
87
|
|
88
|
-
##
|
89
|
-
# Test::Cmd#spawn
|
90
|
-
class SpawnTest < Test
|
91
|
-
def test_io_closed_after_spawn
|
92
|
-
%i[out_io err_io].each do |io|
|
93
|
-
assert_equal true, spawned_command.send(io).closed?
|
94
|
-
end
|
95
|
-
end
|
96
|
-
|
97
|
-
private
|
98
|
-
|
99
|
-
def spawned_command
|
100
|
-
ruby("puts 42").spawn
|
101
|
-
end
|
102
|
-
end
|
103
|
-
|
104
88
|
##
|
105
89
|
# Test::Cmd#spawned?
|
106
90
|
class SpawnedTest < Test
|
data/test-cmd.rb.gemspec
CHANGED
@@ -5,7 +5,7 @@ Gem::Specification.new do |gem|
|
|
5
5
|
gem.authors = ["0x1eef"]
|
6
6
|
gem.email = ["0x1eef@protonmail.com"]
|
7
7
|
gem.homepage = "https://github.com/0x1eef/test-cmd.rb#readme"
|
8
|
-
gem.version = "0.12.
|
8
|
+
gem.version = "0.12.1"
|
9
9
|
gem.required_ruby_version = ">= 3.0"
|
10
10
|
gem.licenses = ["0BSD"]
|
11
11
|
gem.files = `git ls-files`.split($/)
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: test-cmd.rb
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.12.
|
4
|
+
version: 0.12.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- '0x1eef'
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2024-06-
|
11
|
+
date: 2024-06-13 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: test-unit
|