test-cmd.rb 0.12.2 → 0.12.4

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: eacb759ed6f2b3afecfc6fc35c717f2c1afe1f2db47d8ea45d6adad77732688e
4
- data.tar.gz: f51cca55a116f9fbeedae35e1bb3c2a3d73460571070f5c743c86808d3125881
3
+ metadata.gz: 9543aef60b39eebdd49dcd4a1a33b9f08841cdc7ad0176402266d0236bdb483c
4
+ data.tar.gz: 44f38f751770d9cee2d734a768b07d10a67227d3841aec53648a9ecff89ca26a
5
5
  SHA512:
6
- metadata.gz: c0a06d34973043ebb37aef9d1c73e80c63b3884a0138eb3d21dccdbb6f264087199e3702e82752187326e8b3d7c2b6e56db5daea16afe26bea0d1ccecada4727
7
- data.tar.gz: 5cbd7e228217facb5d517087b80e80b82a76fa61720a065c77874d2e8dc81e382a42f23e4696acc2680f145b6b43fdea36f99e2d35daa432771dcc3415c1b633
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.2"
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.2
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-14 00:00:00.000000000 Z
11
+ date: 2024-06-16 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: test-unit