tty-command 0.8.1 → 0.8.2

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.
Files changed (48) hide show
  1. checksums.yaml +5 -5
  2. data/CHANGELOG.md +9 -0
  3. data/examples/bash.rb +2 -2
  4. data/examples/basic.rb +2 -2
  5. data/examples/env.rb +3 -3
  6. data/examples/logger.rb +2 -2
  7. data/examples/output.rb +2 -2
  8. data/examples/pty.rb +3 -1
  9. data/examples/redirect_stderr.rb +2 -2
  10. data/examples/redirect_stdin.rb +2 -2
  11. data/examples/redirect_stdout.rb +2 -2
  12. data/examples/stdin_input.rb +2 -2
  13. data/examples/threaded.rb +3 -1
  14. data/examples/timeout.rb +7 -3
  15. data/examples/timeout_input.rb +2 -2
  16. data/examples/wait.rb +2 -2
  17. data/lib/tty/command/process_runner.rb +3 -0
  18. data/lib/tty/command/version.rb +1 -1
  19. data/spec/spec_helper.rb +78 -0
  20. data/spec/unit/binmode_spec.rb +27 -0
  21. data/spec/unit/cmd_spec.rb +152 -0
  22. data/spec/unit/dry_run_spec.rb +42 -0
  23. data/spec/unit/exit_error_spec.rb +25 -0
  24. data/spec/unit/input_spec.rb +11 -0
  25. data/spec/unit/output_spec.rb +25 -0
  26. data/spec/unit/printer_spec.rb +50 -0
  27. data/spec/unit/printers/custom_spec.rb +48 -0
  28. data/spec/unit/printers/null_spec.rb +36 -0
  29. data/spec/unit/printers/pretty_spec.rb +172 -0
  30. data/spec/unit/printers/progress_spec.rb +45 -0
  31. data/spec/unit/printers/quiet_spec.rb +71 -0
  32. data/spec/unit/pty_spec.rb +60 -0
  33. data/spec/unit/redirect_spec.rb +104 -0
  34. data/spec/unit/result_spec.rb +64 -0
  35. data/spec/unit/ruby_spec.rb +20 -0
  36. data/spec/unit/run_spec.rb +161 -0
  37. data/spec/unit/test_spec.rb +11 -0
  38. data/spec/unit/timeout_spec.rb +36 -0
  39. data/spec/unit/truncator_spec.rb +73 -0
  40. data/tty-command.gemspec +1 -1
  41. metadata +24 -10
  42. data/.gitignore +0 -9
  43. data/.rspec +0 -4
  44. data/.travis.yml +0 -29
  45. data/CODE_OF_CONDUCT.md +0 -49
  46. data/Gemfile +0 -14
  47. data/appveyor.yml +0 -26
  48. data/benchmarks/memory.rb +0 -11
@@ -0,0 +1,11 @@
1
+ # encoding: utf-8
2
+
3
+ RSpec.describe TTY::Command, '#test' do
4
+ it "implements classic bash command" do
5
+ cmd = TTY::Command.new
6
+ result = double(:success? => true)
7
+ allow(cmd).to receive(:run!).with(:test, '-e /etc/passwd').and_return(result)
8
+ expect(cmd.test("-e /etc/passwd")).to eq(true)
9
+ expect(cmd).to have_received(:run!)
10
+ end
11
+ end
@@ -0,0 +1,36 @@
1
+ # encoding: utf-8
2
+
3
+ RSpec.describe TTY::Command, '#run' do
4
+ it "times out infinite process without input or output" do
5
+ infinite = fixtures_path('infinite_no_output')
6
+ output = StringIO.new
7
+ cmd = TTY::Command.new(output: output)
8
+
9
+ expect {
10
+ cmd.run("ruby #{infinite}", timeout: 0.1)
11
+ }.to raise_error(TTY::Command::TimeoutExceeded)
12
+ end
13
+
14
+ it "times out an infite process with constant output" do
15
+ infinite = fixtures_path('infinite_output')
16
+ output = StringIO.new
17
+ cmd = TTY::Command.new(output: output, timeout: 0.1)
18
+
19
+ expect {
20
+ cmd.run("ruby #{infinite}")
21
+ }.to raise_error(TTY::Command::TimeoutExceeded)
22
+ end
23
+
24
+ it "times out an infinite process with constant input data" do
25
+ cli = fixtures_path('infinite_input')
26
+ output = StringIO.new
27
+ cmd = TTY::Command.new(output: output)
28
+
29
+ range = 1..Float::INFINITY
30
+ infinite_input = range.lazy.map { |x| "hello" }.first(100).join("\n")
31
+
32
+ expect {
33
+ cmd.run("ruby #{cli}", input: infinite_input, timeout: 0.1)
34
+ }.to raise_error(TTY::Command::TimeoutExceeded)
35
+ end
36
+ end
@@ -0,0 +1,73 @@
1
+ # encoding: utf-8
2
+
3
+ RSpec.describe TTY::Command::Truncator do
4
+ it "writes nil content" do
5
+ truncator = described_class.new(max_size: 2)
6
+
7
+ truncator.write(nil)
8
+
9
+ expect(truncator.read).to eq('')
10
+ end
11
+
12
+ it "writes content within maximum size" do
13
+ truncator = described_class.new(max_size: 2)
14
+
15
+ truncator.write("a")
16
+
17
+ expect(truncator.read).to eq("a")
18
+ end
19
+
20
+ it "writes both prefix and suffix" do
21
+ truncator = described_class.new(max_size: 2)
22
+
23
+ truncator.write("abc")
24
+ truncator.write("d")
25
+
26
+ expect(truncator.read).to eq("abcd")
27
+ end
28
+
29
+ it "writes more bytes letter" do
30
+ truncator = described_class.new(max_size: 1000)
31
+ multibytes_string = "’test’"
32
+
33
+ truncator.write(multibytes_string)
34
+
35
+ expect(truncator.read).to eq(multibytes_string)
36
+ end
37
+
38
+ it "overflows prefix and suffix " do
39
+ truncator = described_class.new(max_size: 2)
40
+
41
+ truncator.write("abc")
42
+ truncator.write("d")
43
+ truncator.write("e")
44
+
45
+ expect(truncator.read).to eq("ab\n... omitting 1 bytes ...\nde")
46
+ end
47
+
48
+ it "omits bytes " do
49
+ truncator = described_class.new(max_size: 2)
50
+
51
+ truncator.write("abc___________________yz")
52
+
53
+ expect(truncator.read).to eq("ab\n... omitting 20 bytes ...\nyz")
54
+ end
55
+
56
+ it "reflows suffix with less content" do
57
+ truncator = described_class.new(max_size: 2)
58
+
59
+ truncator.write("abc____________________y")
60
+ truncator.write("z")
61
+
62
+ expect(truncator.read).to eq("ab\n... omitting 21 bytes ...\nyz")
63
+ end
64
+
65
+ it "reflows suffix with more content" do
66
+ truncator = described_class.new(max_size: 2)
67
+
68
+ truncator.write("abc____________________y")
69
+ truncator.write("zwx")
70
+
71
+ expect(truncator.read).to eq("ab\n... omitting 23 bytes ...\nwx")
72
+ end
73
+ end
@@ -14,7 +14,7 @@ Gem::Specification.new do |spec|
14
14
  spec.homepage = "https://piotrmurach.github.io/tty"
15
15
  spec.license = "MIT"
16
16
 
17
- spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
17
+ spec.files = Dir['README.md', 'LICENSE.txt', 'CHANGELOG.md', 'Rakefile', "{lib,spec}/**/*.rb", "{bin,examples,tasks}/*", 'tty-command.gemspec']
18
18
  spec.bindir = "exe"
19
19
  spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
20
20
  spec.require_paths = ["lib"]
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: tty-command
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.8.1
4
+ version: 0.8.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Piotr Murach
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2018-05-20 00:00:00.000000000 Z
11
+ date: 2018-08-07 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: pastel
@@ -81,17 +81,10 @@ executables: []
81
81
  extensions: []
82
82
  extra_rdoc_files: []
83
83
  files:
84
- - ".gitignore"
85
- - ".rspec"
86
- - ".travis.yml"
87
84
  - CHANGELOG.md
88
- - CODE_OF_CONDUCT.md
89
- - Gemfile
90
85
  - LICENSE.txt
91
86
  - README.md
92
87
  - Rakefile
93
- - appveyor.yml
94
- - benchmarks/memory.rb
95
88
  - bin/console
96
89
  - bin/setup
97
90
  - examples/bash.rb
@@ -124,6 +117,27 @@ files:
124
117
  - lib/tty/command/result.rb
125
118
  - lib/tty/command/truncator.rb
126
119
  - lib/tty/command/version.rb
120
+ - spec/spec_helper.rb
121
+ - spec/unit/binmode_spec.rb
122
+ - spec/unit/cmd_spec.rb
123
+ - spec/unit/dry_run_spec.rb
124
+ - spec/unit/exit_error_spec.rb
125
+ - spec/unit/input_spec.rb
126
+ - spec/unit/output_spec.rb
127
+ - spec/unit/printer_spec.rb
128
+ - spec/unit/printers/custom_spec.rb
129
+ - spec/unit/printers/null_spec.rb
130
+ - spec/unit/printers/pretty_spec.rb
131
+ - spec/unit/printers/progress_spec.rb
132
+ - spec/unit/printers/quiet_spec.rb
133
+ - spec/unit/pty_spec.rb
134
+ - spec/unit/redirect_spec.rb
135
+ - spec/unit/result_spec.rb
136
+ - spec/unit/ruby_spec.rb
137
+ - spec/unit/run_spec.rb
138
+ - spec/unit/test_spec.rb
139
+ - spec/unit/timeout_spec.rb
140
+ - spec/unit/truncator_spec.rb
127
141
  - tasks/console.rake
128
142
  - tasks/coverage.rake
129
143
  - tasks/spec.rake
@@ -148,7 +162,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
148
162
  version: '0'
149
163
  requirements: []
150
164
  rubyforge_project:
151
- rubygems_version: 2.5.1
165
+ rubygems_version: 2.7.3
152
166
  signing_key:
153
167
  specification_version: 4
154
168
  summary: Execute shell commands with pretty output logging and capture their stdout,
data/.gitignore DELETED
@@ -1,9 +0,0 @@
1
- /.bundle/
2
- /.yardoc
3
- /Gemfile.lock
4
- /_yardoc/
5
- /coverage/
6
- /doc/
7
- /pkg/
8
- /spec/reports/
9
- /tmp/
data/.rspec DELETED
@@ -1,4 +0,0 @@
1
- --require spec_helper
2
- --color
3
- --format doc
4
- --warnings
@@ -1,29 +0,0 @@
1
- ---
2
- language: ruby
3
- sudo: false
4
- cache: bundler
5
- before_install: "gem update bundler"
6
- script: "bundle exec rake ci"
7
- rvm:
8
- - 2.0.0
9
- - 2.1.10
10
- - 2.2.8
11
- - 2.3.6
12
- - 2.4.3
13
- - 2.5.0
14
- - ruby-head
15
- - jruby-9.1.1.0
16
- - jruby-head
17
- env:
18
- global:
19
- - JRUBY_OPTS=''
20
- matrix:
21
- allow_failures:
22
- - rvm: ruby-head
23
- - rvm: jruby-head
24
- - rvm: jruby-9.1.1.0
25
- fast_finish: true
26
- branches:
27
- only: master
28
- notifications:
29
- email: false
@@ -1,49 +0,0 @@
1
- # Contributor Code of Conduct
2
-
3
- As contributors and maintainers of this project, and in the interest of
4
- fostering an open and welcoming community, we pledge to respect all people who
5
- contribute through reporting issues, posting feature requests, updating
6
- documentation, submitting pull requests or patches, and other activities.
7
-
8
- We are committed to making participation in this project a harassment-free
9
- experience for everyone, regardless of level of experience, gender, gender
10
- identity and expression, sexual orientation, disability, personal appearance,
11
- body size, race, ethnicity, age, religion, or nationality.
12
-
13
- Examples of unacceptable behavior by participants include:
14
-
15
- * The use of sexualized language or imagery
16
- * Personal attacks
17
- * Trolling or insulting/derogatory comments
18
- * Public or private harassment
19
- * Publishing other's private information, such as physical or electronic
20
- addresses, without explicit permission
21
- * Other unethical or unprofessional conduct
22
-
23
- Project maintainers have the right and responsibility to remove, edit, or
24
- reject comments, commits, code, wiki edits, issues, and other contributions
25
- that are not aligned to this Code of Conduct, or to ban temporarily or
26
- permanently any contributor for other behaviors that they deem inappropriate,
27
- threatening, offensive, or harmful.
28
-
29
- By adopting this Code of Conduct, project maintainers commit themselves to
30
- fairly and consistently applying these principles to every aspect of managing
31
- this project. Project maintainers who do not follow or enforce the Code of
32
- Conduct may be permanently removed from the project team.
33
-
34
- This code of conduct applies both within project spaces and in public spaces
35
- when an individual is representing the project or its community.
36
-
37
- Instances of abusive, harassing, or otherwise unacceptable behavior may be
38
- reported by contacting a project maintainer at [email]. All
39
- complaints will be reviewed and investigated and will result in a response that
40
- is deemed necessary and appropriate to the circumstances. Maintainers are
41
- obligated to maintain confidentiality with regard to the reporter of an
42
- incident.
43
-
44
- This Code of Conduct is adapted from the [Contributor Covenant][homepage],
45
- version 1.3.0, available at
46
- [http://contributor-covenant.org/version/1/3/0/][version]
47
-
48
- [homepage]: http://contributor-covenant.org
49
- [version]: http://contributor-covenant.org/version/1/3/0/
data/Gemfile DELETED
@@ -1,14 +0,0 @@
1
- source 'https://rubygems.org'
2
-
3
- gemspec
4
-
5
- group :test do
6
- gem 'simplecov', '~> 0.12.0'
7
- gem 'coveralls', '~> 0.8.17'
8
- end
9
-
10
- if RUBY_VERSION > '2.1.0'
11
- group :perf do
12
- gem 'memory_profiler', '~> 0.9.8'
13
- end
14
- end
@@ -1,26 +0,0 @@
1
- ---
2
- install:
3
- - SET PATH=C:\Ruby%ruby_version%\bin;%PATH%
4
- - ruby --version
5
- - gem --version
6
- - bundle install
7
- build: off
8
- test_script:
9
- - bundle exec rake ci
10
- environment:
11
- matrix:
12
- - ruby_version: "200"
13
- - ruby_version: "200-x64"
14
- - ruby_version: "21"
15
- - ruby_version: "21-x64"
16
- - ruby_version: "22"
17
- - ruby_version: "22-x64"
18
- - ruby_version: "23"
19
- - ruby_version: "23-x64"
20
- - ruby_version: "24"
21
- - ruby_version: "24-x64"
22
- - ruby_version: "25"
23
- - ruby_version: "25-x64"
24
- matrix:
25
- allow_failures:
26
- - ruby_version: "25"
@@ -1,11 +0,0 @@
1
- # encoding: utf-8
2
- #
3
- require 'memory_profiler'
4
- require 'tty-command'
5
-
6
- report = MemoryProfiler.report do
7
- cmd = TTY::Command.new(color: false)
8
- cmd.run("echo 'hello world!'")
9
- end
10
-
11
- report.pretty_print(to_file: 'memory_report.txt')