qbash 0.4.2 → 0.4.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: 72371631590029a1533bf6e899fa51833c924fd89e070c2747bea4bd1257a906
4
- data.tar.gz: 5855c06aa2c9444779f214783d35d56925fed96ed010c1fb187f4549618e63f2
3
+ metadata.gz: 352743a00eafd7847765e2839c66af94008228e5d614ef58c6e615f855376d20
4
+ data.tar.gz: b61577f89976eabc074146be11a9b8800aeaefdda100c98d4d5abd51a6dba688
5
5
  SHA512:
6
- metadata.gz: 81fe1f8e49f5a706a8a357b5a071513f2f14e83d072e18300e7ec3fd7c15e18280302b77817b0b5f29d123bca871d136df086310cef6c1f5183410a35ff18309
7
- data.tar.gz: 3baeb218d6423e04a2ccb86d02e5717c48c92af3e30833d2ff909ae480681c28db79e5586c7f5fa84691142d94960eeec7f1b2a9a2e26325bcd5e2ca10219036
6
+ metadata.gz: ef6de7a925ffe5b06c44bdca42efb852016dcab80bb52d8c41646e6ef6a306f2e73500e62840dd6d04c24d6545fdf4016e0f55161c0225abbac95ba50c4e2dae
7
+ data.tar.gz: 46d7a56a167241d0deed6dc5596efa2dfbe3dfa96fa1694e9c8cad5003be994f4f686c744122b71f8da4c42aa324ce77b57c6d5c3d4cd7b40061a6f2a5eae08e
data/Gemfile CHANGED
@@ -12,6 +12,7 @@ gem 'minitest-reporters', '~>1.7', require: false
12
12
  gem 'net-ping', '~>2.0', require: false
13
13
  gem 'rake', '~>13.2', require: false
14
14
  gem 'random-port', '~>0.0', require: false
15
+ gem 'rdoc', '~>6.13', require: false
15
16
  gem 'rubocop', '~>1.73', require: false
16
17
  gem 'rubocop-minitest', '>0', require: false
17
18
  gem 'rubocop-performance', '>0', require: false
data/Gemfile.lock CHANGED
@@ -45,6 +45,7 @@ GEM
45
45
  cucumber-messages (> 19, < 28)
46
46
  cucumber-messages (22.0.0)
47
47
  cucumber-tag-expressions (6.1.2)
48
+ date (3.4.1)
48
49
  diff-lcs (1.6.1)
49
50
  docile (1.4.1)
50
51
  elapsed (0.0.1)
@@ -94,12 +95,17 @@ GEM
94
95
  ast (~> 2.4.1)
95
96
  racc
96
97
  prism (1.4.0)
98
+ psych (5.2.5)
99
+ date
100
+ stringio
97
101
  public_suffix (6.0.2)
98
102
  racc (1.8.1)
99
103
  rainbow (3.1.1)
100
104
  rake (13.2.1)
101
105
  random-port (0.7.5)
102
106
  tago (> 0)
107
+ rdoc (6.13.1)
108
+ psych (>= 4.0.0)
103
109
  regexp_parser (2.10.0)
104
110
  rexml (3.4.1)
105
111
  rubocop (1.75.5)
@@ -137,6 +143,7 @@ GEM
137
143
  simplecov (~> 0.19)
138
144
  simplecov-html (0.13.1)
139
145
  simplecov_json_formatter (0.1.4)
146
+ stringio (3.1.7)
140
147
  sys-uname (1.3.1)
141
148
  ffi (~> 1.1)
142
149
  tago (0.1.0)
@@ -171,6 +178,7 @@ DEPENDENCIES
171
178
  qbash!
172
179
  rake (~> 13.2)
173
180
  random-port (~> 0.0)
181
+ rdoc (~> 6.13)
174
182
  rubocop (~> 1.73)
175
183
  rubocop-minitest (> 0)
176
184
  rubocop-performance (> 0)
data/lib/qbash.rb CHANGED
@@ -104,7 +104,7 @@ module Kernel
104
104
  elsif log.respond_to?(mtd)
105
105
  log.__send__(mtd, msg)
106
106
  else
107
- log.print("#{msg}\n")
107
+ log.print(msg)
108
108
  end
109
109
  end
110
110
  logit["+ #{cmd}"]
@@ -137,17 +137,17 @@ module Kernel
137
137
  sout.close
138
138
  watch.join(0.01)
139
139
  watch.kill if watch.alive?
140
- begin
141
- Process.getpgid(pid) # should be dead already (raising Errno::ESRCH)
140
+ attempt = 1
141
+ since = Time.now
142
+ loop do
143
+ Process.kill(0, pid) # should be dead already (raising Errno::ESRCH)
142
144
  Process.kill('TERM', pid) # let's try to kill it
143
- begin
144
- Process.getpgid(pid) # should be dead now (raising Errno::ESRCH)
145
- raise "Process ##{pid} did not terminate after SIGTERM"
146
- rescue Errno::ESRCH
147
- logit["Process ##{pid} killed with SIGTERM"]
148
- end
145
+ logit["Tried to stop ##{pid} with SIGTERM (attempt no.#{attempt}, #{since.ago}): #{cmd}"]
146
+ sleep(0.1)
147
+ attempt += 1
149
148
  rescue Errno::ESRCH
150
- logit["Process ##{pid} exited gracefully"]
149
+ logit["Process ##{pid} gracefully reacted to SIGTERM"] if attempt > 1
150
+ break
151
151
  end
152
152
  else
153
153
  consume.call
data/qbash.gemspec CHANGED
@@ -9,7 +9,7 @@ Gem::Specification.new do |s|
9
9
  s.required_rubygems_version = Gem::Requirement.new('>= 0') if s.respond_to? :required_rubygems_version=
10
10
  s.required_ruby_version = '>=3.2'
11
11
  s.name = 'qbash'
12
- s.version = '0.4.2'
12
+ s.version = '0.4.4'
13
13
  s.license = 'MIT'
14
14
  s.summary = 'Quick Executor of a BASH Command'
15
15
  s.description =
data/test/test__helper.rb CHANGED
@@ -15,8 +15,8 @@ unless SimpleCov.running || ENV['PICKS']
15
15
  SimpleCov::Formatter::CoberturaFormatter
16
16
  ]
17
17
  )
18
- SimpleCov.minimum_coverage 1
19
- SimpleCov.minimum_coverage_by_file 1
18
+ SimpleCov.minimum_coverage 95
19
+ SimpleCov.minimum_coverage_by_file 95
20
20
  SimpleCov.start do
21
21
  add_filter 'test/'
22
22
  add_filter 'vendor/'
data/test/test_qbash.rb CHANGED
@@ -107,6 +107,16 @@ class TestQbash < Minitest::Test
107
107
  refute_includes(buf.to_s, "\n\n")
108
108
  end
109
109
 
110
+ def test_logs_multi_line_print
111
+ buf = Loog::Buffer.new
112
+ pid = nil
113
+ qbash('echo one; echo two', log: buf, accept: nil) do |i|
114
+ sleep(0.1)
115
+ pid = i
116
+ end
117
+ assert_equal(buf.to_s, "+ echo one; echo two\n##{pid}: one\n##{pid}: two\n")
118
+ end
119
+
110
120
  def test_with_both
111
121
  Dir.mktmpdir do |home|
112
122
  stdout, code = qbash("cat #{Shellwords.escape(File.join(home, 'foo.txt'))}", accept: nil, both: true)
@@ -117,18 +127,18 @@ class TestQbash < Minitest::Test
117
127
 
118
128
  def test_exists_after_background_stop
119
129
  stop = false
130
+ pid = nil
120
131
  t =
121
132
  Thread.new do
122
- qbash('trap "" TERM; tail -f /dev/null', accept: nil) do
133
+ qbash('trap "" TERM; sleep 10', accept: nil) do |id|
134
+ pid = id
123
135
  loop { break if stop }
124
136
  end
125
137
  end
126
138
  t.abort_on_exception = true
127
- sleep(0.1)
139
+ sleep(0.01)
128
140
  stop = true
129
- t.join(0.01)
141
+ refute(t.join(0.1))
130
142
  t.kill
131
- sleep(0.01)
132
- refute_predicate(t, :alive?)
133
143
  end
134
144
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: qbash
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.2
4
+ version: 0.4.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Yegor Bugayenko