test-cmd.rb 0.5.1 → 0.6.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 +4 -4
- data/README.md +11 -21
- data/Rakefile.rb +9 -0
- data/lib/test-cmd.rb +16 -9
- data/test-cmd.rb.gemspec +2 -1
- metadata +17 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 031f9708015f5e2e10d4b9afe09db3841c2a7c8ffa9ee83717d12ff4e078cd02
|
4
|
+
data.tar.gz: e1afc91430c82bfb3e146ea3b3a8a58c9fdb047b4c25c2be7b62d2b1470fd694
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 599e9bd0599c675f58b742e556b60c0d475b3a8fbe50012eddcc633eb1f09492791e88f0fbc7161a63172b96df1268a80304cd1b6dbb738ddd06d48ce9ad30ed
|
7
|
+
data.tar.gz: acc8485e9f6fde4c25e80dd354933f5750804fe0f066054b2e4cea3c4093a2020df28d86ab7f055766466658d3a69d6a53d89699bb6f0d3652b3cdd8f46eec3d
|
data/README.md
CHANGED
@@ -1,11 +1,7 @@
|
|
1
1
|
## About
|
2
2
|
|
3
3
|
test-cmd.rb is a library for accessing the output streams
|
4
|
-
(both stdout and stderr) of a spawned process.
|
5
|
-
first realized in a test environment, where it provided a path
|
6
|
-
for verifying that when code examples are run they produce the
|
7
|
-
expected output. The library can be generally useful outside a
|
8
|
-
test environment, too.
|
4
|
+
(both stdout and stderr) of a spawned process.
|
9
5
|
|
10
6
|
## Examples
|
11
7
|
|
@@ -53,7 +49,7 @@ require "test/cmd"
|
|
53
49
|
str = cmd("du")
|
54
50
|
.arg("-s").arg("-h")
|
55
51
|
.spawn.stdout
|
56
|
-
puts str
|
52
|
+
puts str
|
57
53
|
```
|
58
54
|
|
59
55
|
### IO#sync
|
@@ -96,30 +92,24 @@ Process.wait(pid)
|
|
96
92
|
p cmd("ruby test.rb").stdout # => "foo\nbar\n"
|
97
93
|
```
|
98
94
|
|
99
|
-
##
|
95
|
+
## Documentation
|
100
96
|
|
101
|
-
|
102
|
-
|
97
|
+
A complete API reference is available at
|
98
|
+
[0x1eef.github.io/x/test-cmd.rb](https://0x1eef.github.io/x/test-cmd.rb).
|
103
99
|
|
104
100
|
## Install
|
105
101
|
|
106
|
-
test-cmd.rb is distributed as a RubyGem through its git repositories. <br>
|
107
|
-
[GitHub](https://github.com/0x1eef/test-cmd.rb),
|
108
|
-
and
|
109
|
-
[GitLab](https://gitlab.com/0x1eef/test-cmd.rb)
|
110
|
-
are available as sources.
|
111
|
-
|
112
|
-
``` ruby
|
113
|
-
# Gemfile
|
114
|
-
gem "test-cmd.rb", github: "0x1eef/test-cmd.rb", tag: "v0.5.1"
|
115
|
-
```
|
116
|
-
|
117
102
|
**Rubygems.org**
|
118
103
|
|
119
|
-
test-cmd.rb can
|
104
|
+
test-cmd.rb can be installed via rubygems.org.
|
120
105
|
|
121
106
|
gem install test-cmd.rb
|
122
107
|
|
108
|
+
## Sources
|
109
|
+
|
110
|
+
* [GitHub](https://github.com/0x1eef/test-cmd.rb#readme)
|
111
|
+
* [GitLab](https://gitlab.com/0x1eef/test-cmd.rb#about)
|
112
|
+
|
123
113
|
## License
|
124
114
|
|
125
115
|
[BSD Zero Clause](https://choosealicense.com/licenses/0bsd/).
|
data/Rakefile.rb
ADDED
data/lib/test-cmd.rb
CHANGED
@@ -3,11 +3,7 @@ end unless defined?(Test)
|
|
3
3
|
|
4
4
|
##
|
5
5
|
# test-cmd.rb is a library for accessing the output streams
|
6
|
-
# (both stdout and stderr) of a spawned process.
|
7
|
-
# first realized in a test environment, where it provided a path
|
8
|
-
# for verifying that when code examples are run they produce the
|
9
|
-
# expected output. The library can be generally useful outside a
|
10
|
-
# test environment, too.
|
6
|
+
# (both stdout and stderr) of a spawned process.
|
11
7
|
class Test::Cmd
|
12
8
|
require "tempfile"
|
13
9
|
|
@@ -20,8 +16,8 @@ class Test::Cmd
|
|
20
16
|
def initialize(cmd, args = [])
|
21
17
|
@cmd = cmd
|
22
18
|
@args = args.dup
|
23
|
-
@out = Tempfile.new("cmd-stdout")
|
24
|
-
@err = Tempfile.new("cmd-stderr")
|
19
|
+
@out = unlink!(Tempfile.new("cmd-stdout"))
|
20
|
+
@err = unlink!(Tempfile.new("cmd-stderr"))
|
25
21
|
@status = nil
|
26
22
|
@spawned = false
|
27
23
|
end
|
@@ -105,9 +101,20 @@ class Test::Cmd
|
|
105
101
|
io = @status.success? ? @stdout : @stderr
|
106
102
|
io.each_line.each { yield(_1.chomp) }
|
107
103
|
end
|
104
|
+
|
105
|
+
private
|
106
|
+
|
107
|
+
##
|
108
|
+
# @api private
|
109
|
+
def unlink!(file)
|
110
|
+
file.tap do
|
111
|
+
File.chmod(0, file.path)
|
112
|
+
file.unlink
|
113
|
+
end
|
114
|
+
end
|
108
115
|
end
|
109
116
|
|
110
|
-
module Test::
|
117
|
+
module Test::Cmd::Mixin
|
111
118
|
##
|
112
119
|
# @param [String] cmd
|
113
120
|
# A command to execute
|
@@ -121,5 +128,5 @@ module Test::CmdMixin
|
|
121
128
|
end
|
122
129
|
|
123
130
|
module Kernel
|
124
|
-
include Test::
|
131
|
+
include Test::Cmd::Mixin
|
125
132
|
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.
|
8
|
+
gem.version = "0.6.0"
|
9
9
|
gem.required_ruby_version = ">= 3.0"
|
10
10
|
gem.licenses = ["0BSD"]
|
11
11
|
gem.files = `git ls-files`.split($/)
|
@@ -18,4 +18,5 @@ Gem::Specification.new do |gem|
|
|
18
18
|
gem.add_development_dependency "yard", "~> 0.9"
|
19
19
|
gem.add_development_dependency "redcarpet", "~> 3.5"
|
20
20
|
gem.add_development_dependency "standard", "~> 1.24"
|
21
|
+
gem.add_development_dependency "rake", "~> 13.1"
|
21
22
|
end
|
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.
|
4
|
+
version: 0.6.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-
|
11
|
+
date: 2024-03-17 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: test-unit
|
@@ -66,6 +66,20 @@ dependencies:
|
|
66
66
|
- - "~>"
|
67
67
|
- !ruby/object:Gem::Version
|
68
68
|
version: '1.24'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: rake
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - "~>"
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '13.1'
|
76
|
+
type: :development
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - "~>"
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '13.1'
|
69
83
|
description: test-cmd.rb provides access to the output streams (both stdout and stderr)
|
70
84
|
of a spawned process.
|
71
85
|
email:
|
@@ -82,6 +96,7 @@ files:
|
|
82
96
|
- Gemfile
|
83
97
|
- LICENSE
|
84
98
|
- README.md
|
99
|
+
- Rakefile.rb
|
85
100
|
- lib/test-cmd.rb
|
86
101
|
- lib/test/cmd.rb
|
87
102
|
- test-cmd.rb.gemspec
|