test-cmd.rb 0.9.2 → 0.10.0

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: 3d07ddf04e4a028f4c745b1583b0fb54a8d0a66c6545be5ae06a36fe2bed5d44
4
- data.tar.gz: fc37608b53d4648fcc580c8845af31a8d423087816fdc862662e6e9dda99d29f
3
+ metadata.gz: 809adac1c621abbe0f30ba697594c4fe2bf931169b5f5bebdc833c5153e840cd
4
+ data.tar.gz: 6882e65bd6fa276500285b2f735158506458c19509fa0278fc42410fb1ade2da
5
5
  SHA512:
6
- metadata.gz: b170b84a449b49991d94f902b4d60aa9030f257e3123335e2eb42718b8116ff27200d396738c83cfe38c03eeb762bf07f47887e0508f0a5f88cb4185b4ea7e82
7
- data.tar.gz: 07e946aa6b365bfc17e6337eb3c0c7fd773783a8e3b7cdb80dbdf88e91cdfb1550a086d727ea5b14ab350d259c2ad46038ea7683ada3146066dd34cd6d792dc9
6
+ metadata.gz: d7f8f2757c6eb96e0b27fae6d59ce8e39b2c7d34e865b25a07e02871a8a4116b08ce78513757fc561a8cd356e6b3e25c04b60ec7a54de347de2dbad251a402e6
7
+ data.tar.gz: 827b850156e8b11cc38b625c93c3760037dcee47514a0a21761c5d4d9a64f89d2a2b834f2c001f24a7a46e8282cce1a862ed6d336e90736dad722a41ed3c0d56
data/README.md CHANGED
@@ -59,12 +59,12 @@ results. Consider the following example, where the output will be
59
59
  ``` ruby
60
60
  ##
61
61
  # test.rb
62
- pid = fork do
62
+ fork do
63
63
  sleep(1)
64
64
  puts "bar"
65
65
  end
66
66
  puts "foo"
67
- Process.wait(pid)
67
+ Process.wait
68
68
 
69
69
  ##
70
70
  # cmd.rb
@@ -77,12 +77,12 @@ And with output flushed to the operating system immediately:
77
77
  ##
78
78
  # test.rb
79
79
  $stdout.sync = true
80
- pid = fork do
80
+ fork do
81
81
  sleep(1)
82
82
  puts "bar"
83
83
  end
84
84
  puts "foo"
85
- Process.wait(pid)
85
+ Process.wait
86
86
 
87
87
  ##
88
88
  # cmd.rb
data/lib/test/cmd.rb CHANGED
@@ -1,4 +1,5 @@
1
- require_relative "../test-cmd"
1
+ module Test
2
+ end unless defined?(Test)
2
3
 
3
4
  ##
4
5
  # test-cmd.rb provides an object oriented interface
@@ -84,12 +85,19 @@ class Test::Cmd
84
85
  status.exitstatus
85
86
  end
86
87
 
88
+ ##
89
+ # @return [Boolean]
90
+ # Returns true when a command exited successfully
91
+ def success?
92
+ status.success?
93
+ end
94
+
87
95
  ##
88
96
  # Yields an instance of {Test::Cmd Test::Cmd}.
89
97
  #
90
98
  # @example
91
99
  # cmd("ruby", "-e", "exit 0")
92
- # .success { print "Command exited successfully: #{_1.exit_status}", "\n" }
100
+ # .success { print "Command [#{_1.pid}] exited successfully", "\n" }
93
101
  # .failure { }
94
102
  #
95
103
  # @return [Test::Cmd]
@@ -106,7 +114,7 @@ class Test::Cmd
106
114
  # @example
107
115
  # cmd("ruby", "-e", "exit 1")
108
116
  # .success { }
109
- # .failure { print "Command exited unsuccessfully: #{_1.exit_status}", "\n" }
117
+ # .failure { print "Command [#{_1.pid}] exited unsuccessfully", "\n" }
110
118
  #
111
119
  # @return [Test::Cmd]
112
120
  def failure
@@ -131,3 +139,12 @@ class Test::Cmd
131
139
  }
132
140
  end
133
141
  end
142
+
143
+ module Kernel
144
+ ##
145
+ # @param (see Test::Cmd#initialize)
146
+ # @return (see Test::Cmd#initialize)
147
+ def cmd(cmd, *argv)
148
+ Test::Cmd.new(cmd, *argv)
149
+ end
150
+ end
data/lib/test-cmd.rb CHANGED
@@ -1,15 +1 @@
1
- module Test
2
- end unless defined?(Test)
3
-
4
- module Test
5
- require_relative "test/cmd"
6
- end
7
-
8
- module Kernel
9
- ##
10
- # @param (see Test::Cmd#initialize)
11
- # @return (see Test::Cmd#initialize)
12
- def cmd(cmd, *argv)
13
- Test::Cmd.new(cmd, *argv)
14
- end
15
- end
1
+ require_relative "test/cmd"
@@ -19,6 +19,7 @@ class CmdTest < Test::Unit::TestCase
19
19
 
20
20
  def test_ruby_success_status
21
21
  assert_equal true, cmd("ruby", "-e", "exit 0").status.success?
22
+ assert_equal true, cmd("ruby", "-e", "exit 0").success?
22
23
  end
23
24
 
24
25
  def test_ruby_success_callback
@@ -42,12 +43,12 @@ class CmdTest < Test::Unit::TestCase
42
43
  def test_stdout_with_fork
43
44
  code = <<-CODE.each_line.map { _1.chomp.strip }.join(";")
44
45
  $stdout.sync = true
45
- pid = fork do
46
+ fork do
46
47
  sleep(1)
47
48
  puts "bar"
48
49
  end
49
50
  puts "foo"
50
- Process.wait(pid)
51
+ Process.wait
51
52
  CODE
52
53
  assert_equal "foo\nbar\n", cmd("ruby", "-e", code).stdout
53
54
  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.9.2"
8
+ gem.version = "0.10.0"
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.9.2
4
+ version: 0.10.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - '0x1eef'
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2024-05-12 00:00:00.000000000 Z
11
+ date: 2024-05-15 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: test-unit