test-cmd.rb 0.12.2 → 0.12.4
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/test/cmd.rb +15 -0
- data/test/cmd_test.rb +18 -0
- 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: 9543aef60b39eebdd49dcd4a1a33b9f08841cdc7ad0176402266d0236bdb483c
|
4
|
+
data.tar.gz: 44f38f751770d9cee2d734a768b07d10a67227d3841aec53648a9ecff89ca26a
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: be9bba3851638c04d87a114f92fc2ee28b8683e3df14b13b9a37f7a9749ea0075589def7acf65c8b554e62f6e8575b9ccde4aa9f61b024f65a6455f360686559
|
7
|
+
data.tar.gz: 04db2f4f1b84bb1ce41acfa570778bcec93d64593d58825356c1b9e48ff08b181f8c13c516bbfe70fa8065ecf18b83488df1a8ac1354632e3513765be24a47c6
|
data/lib/test/cmd.rb
CHANGED
@@ -32,6 +32,7 @@ class Test::Cmd
|
|
32
32
|
@spawned = false
|
33
33
|
@stdout = ""
|
34
34
|
@stderr = ""
|
35
|
+
@enoent = false
|
35
36
|
end
|
36
37
|
|
37
38
|
##
|
@@ -55,6 +56,10 @@ class Test::Cmd
|
|
55
56
|
Process.spawn(@cmd, *@argv, {out: out.w, err: err.w})
|
56
57
|
Process.wait
|
57
58
|
@status = $?
|
59
|
+
rescue Errno::ENOENT => ex
|
60
|
+
@cmd, @argv, @stderr = "false", [], ex.message
|
61
|
+
@enoent = true
|
62
|
+
retry
|
58
63
|
end
|
59
64
|
loop do
|
60
65
|
io, _ = IO.select([out.r, err.r], nil, nil, 0.01)
|
@@ -104,6 +109,7 @@ class Test::Cmd
|
|
104
109
|
def exit_status
|
105
110
|
status.exitstatus
|
106
111
|
end
|
112
|
+
alias_method :exitstatus, :exit_status
|
107
113
|
|
108
114
|
##
|
109
115
|
# @return [Boolean]
|
@@ -150,6 +156,15 @@ class Test::Cmd
|
|
150
156
|
def spawned?
|
151
157
|
@spawned
|
152
158
|
end
|
159
|
+
|
160
|
+
##
|
161
|
+
# @return [Boolean]
|
162
|
+
# Returns true when a command can't be found
|
163
|
+
def command_not_found?
|
164
|
+
spawn
|
165
|
+
@enoent
|
166
|
+
end
|
167
|
+
alias_method :not_found?, :command_not_found?
|
153
168
|
end
|
154
169
|
|
155
170
|
module Kernel
|
data/test/cmd_test.rb
CHANGED
@@ -36,6 +36,10 @@ class Test::Cmd
|
|
36
36
|
assert_equal true, ruby("exit 0").status.success?
|
37
37
|
assert_equal true, ruby("exit 0").success?
|
38
38
|
end
|
39
|
+
|
40
|
+
def test_nonexistent_command
|
41
|
+
assert_equal false, cmd("/a/path/that/is/not/found").success?
|
42
|
+
end
|
39
43
|
end
|
40
44
|
|
41
45
|
##
|
@@ -61,6 +65,11 @@ class Test::Cmd
|
|
61
65
|
CODE
|
62
66
|
assert_equal "foo\nbar\n", ruby(code).stdout
|
63
67
|
end
|
68
|
+
|
69
|
+
def test_nonexistent_command
|
70
|
+
assert_equal "No such file or directory - /a/path/that/is/not/found",
|
71
|
+
cmd("/a/path/that/is/not/found").stderr
|
72
|
+
end
|
64
73
|
end
|
65
74
|
|
66
75
|
##
|
@@ -96,4 +105,13 @@ class Test::Cmd
|
|
96
105
|
assert_equal true, ruby("puts 42").tap(&:spawn).spawned?
|
97
106
|
end
|
98
107
|
end
|
108
|
+
|
109
|
+
##
|
110
|
+
# Test::Cmd#command_not_found?
|
111
|
+
class CommandNotFoundTest < Test
|
112
|
+
def test_command_not_found
|
113
|
+
assert_equal true, cmd("/a/path/that/is/not/found").command_not_found?
|
114
|
+
assert_equal true, cmd("/a/path/that/is/not/found").not_found?
|
115
|
+
end
|
116
|
+
end
|
99
117
|
end
|
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.4"
|
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.4
|
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-16 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: test-unit
|