dev_commands 0.0.40 → 0.0.41

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 6b0ae71e6301b33d4c845fea6ce37380f17c8a52
4
- data.tar.gz: 542e659e0926fa75fddbcde08f0d7da7fcd7e019
3
+ metadata.gz: ddb5e7dbeac67f1bff9a6f4025e85497c9a001d3
4
+ data.tar.gz: 4a1887451dcf5ad54eee8d5c0b592d8127567673
5
5
  SHA512:
6
- metadata.gz: 7bc5e4fac606037686c6cfc7e8bf49058ad64f2e73d37f2bb0bcd07f7211d2e7eaf0a1a9dda205d5e08ae1452f72045c15affc94648bbea293169079930282ee
7
- data.tar.gz: 4c6f3584e5347f6ddd92c601a3e84445a18269549f46114f5b0b216d57da2ae833a51cf8a5e22384172fd27b7c53a618db2ae74a81b958ae73318c9edf883491
6
+ metadata.gz: baaf2c25cae9277a5c558d3809ff4117a518008cafa0a72479f7ed68f03e2da2a3943aa2aa41b3bd9a414edeb81b6fef6e2f619feb892b3b8c6748e5be8d383f
7
+ data.tar.gz: 3a139999d22aaf6ec49ad4705ac29889f2e63d29ff001300d5c4bb0b0160f1668dbea64b913ccdfdd844db8831bd726f546ffe3151e84f78d573e8ceaa191757
data/lib/command.rb CHANGED
@@ -74,7 +74,11 @@ class Command < Hash
74
74
  self[:end_time] = Time.now
75
75
  else
76
76
  require_relative 'timeout.rb'
77
- self[:output] = run_with_timeout(self[:input], self[:timeout], 1)
77
+ #puts run_with_timeout(self[:input], self[:timeout], 1).to_s
78
+ #self[:output] = run_with_timeout(self[:input], self[:timeout], 1)
79
+ result=run_with_timeout(self[:input], self[:timeout], 1)
80
+ self[:output]=result[0]
81
+ self[:exit_code]=result[1]
78
82
 
79
83
  self[:elapsed] = timer.elapsed_str
80
84
  self[:end_time] = Time.now
data/lib/timeout.rb CHANGED
@@ -1,5 +1,6 @@
1
1
  ############################################################################
2
- # The following code was copied from https://gist.github.com/lpar/1032297
2
+ # The following code is based on code originally copied from
3
+ # https://gist.github.com/lpar/1032297
3
4
  # Gist title: lpar/timeout.rb
4
5
  ############################################################################
5
6
  # Runs a specified shell command in a separate thread.
@@ -12,6 +13,7 @@
12
13
  # If you think you can do it with Ruby's Timeout module, think again.
13
14
  def run_with_timeout(command, timeout, tick)
14
15
  output = ''
16
+ exit_code=1
15
17
  begin
16
18
  # Start task in another thread, which spawns a process
17
19
  stdin, stderrout, thread = Open3.popen2e(command)
@@ -32,6 +34,7 @@ def run_with_timeout(command, timeout, tick)
32
34
  break
33
35
  end
34
36
  end
37
+
35
38
  # Give Ruby time to clean up the other thread
36
39
  sleep 1
37
40
 
@@ -39,10 +42,13 @@ def run_with_timeout(command, timeout, tick)
39
42
  # We need to kill the process, because killing the thread leaves
40
43
  # the process alive but detached, annoyingly enough.
41
44
  Process.kill("TERM", pid)
45
+ else
46
+ exit_code=thread.value
42
47
  end
43
- ensure
48
+
49
+ ensure
44
50
  stdin.close if stdin
45
51
  stderrout.close if stderrout
46
52
  end
47
- return output
53
+ return [output,exit_code]
48
54
  end
data/spec/command_spec.rb CHANGED
@@ -80,7 +80,7 @@ describe Command do
80
80
  f.puts " puts 'rake_test'"
81
81
  f.puts "end"
82
82
  }
83
- cmd=Command.new({ :input => 'rake', :quiet => true})
83
+ cmd=Command.new({ :input => 'rake', :quiet => true, :timeout => 2 })
84
84
  cmd[:directory]=dir
85
85
  cmd.execute
86
86
  FileUtils.rm_r("#{File.dirname(__FILE__)}/tmp")
@@ -105,6 +105,11 @@ describe Command do
105
105
  cmd[:directory]=dir
106
106
  cmd.execute
107
107
  expect(cmd[:exit_code]).not_to eq(0)
108
+
109
+ cmd=Command.new({ :input => 'rake bogus', :timeout => 3, :ignore_failure => true, :quiet => true})
110
+ cmd[:directory]=dir
111
+ cmd.execute
112
+ expect(cmd[:exit_code]).not_to eq(0)
108
113
  end
109
114
 
110
115
  it "should be able to execute an array of commands" do
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: dev_commands
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.40
4
+ version: 0.0.41
5
5
  platform: ruby
6
6
  authors:
7
7
  - Lou Parslow