system_run 1.0.3 → 1.0.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
  SHA1:
3
- metadata.gz: 82b98b36722d6fefa40acc60c9e71a3e88c4917a
4
- data.tar.gz: 42d53eaffdc0d376a6541d8e6398c8fde8e0e6ed
3
+ metadata.gz: '09165cc586c5e9e6a426c8d3f1023c8c52832fc1'
4
+ data.tar.gz: c98f9942b45f1ab1507cea015c8ce708c38cba63
5
5
  SHA512:
6
- metadata.gz: 805bb4f14de0dd05d69833a367452c891f5439cea6078602bc3d136f65c99ecd38dbf1e10301005b36e1849003e513e368cba3a7eb92a87906202a7a46b32532
7
- data.tar.gz: f79a1e1ed744aea047fdc737a0d086bfaaea857286ddaca287b0b3e28cd4b562cf4eded8fba549ee9c4cbc90257396553879cc7aca2f5fc9c364cdd78a2d54b7
6
+ metadata.gz: 3b7584fd8a06083a5ff26fb74758375912730651597d0a5d812954c35bcedd86f75057157b468a433ec775d875570e397de91690676a2a5b8a5cc5e9333129a1
7
+ data.tar.gz: a198096b443c4071a0f245c9b2283c1751eaeecc4f7d6cf67346462f5be9138b2d07a73a4eb65680ac5685ba353120bfabb90832a8a9732f1e0545b106bfbc84
@@ -0,0 +1,51 @@
1
+ # encoding: utf-8
2
+ require 'timeout'
3
+ require 'tempfile'
4
+
5
+ module System
6
+ def self.run(cmd, *args, timeout: nil, env: {}, capture: :default, file: nil, cwd: '.', on_timeout: nil, **kwargs)
7
+ cmd = cmd.dup << ' ' << args.join(' ')
8
+ env = env.dup.map { |k, v| [k.to_s, v.to_s] }.to_h
9
+
10
+ unless file.nil? || file.all? { |f| f.is_a?(File) || f.is_a?(Tempfile) }
11
+ raise ArgumentError, 'file(s) must be instance of File or Tempfile'
12
+ end
13
+
14
+ unless capture != :default || file.nil? || file.is_a?(Array) && file.size == 2
15
+ raise ArgumentError, 'invalid file redirects for default capture, expected array of two'
16
+ end
17
+
18
+ out, err = case capture
19
+ when :default then file ? [file.first, file.last] : [Tempfile.new('sysrun-out'), Tempfile.new('sysrun-err')]
20
+ when :out then [file || Tempfile.new('sysrun-out'), '/dev/null']
21
+ when :err then ['/dev/null', file || Tempfile.new('sysrun-err')]
22
+ when :both then [file || Tempfile.new('sysrun-outerr')] * 2
23
+ else raise ArgumentError, "unknown capture: #{capture}"
24
+ end
25
+
26
+ pid = spawn env, cmd, out: out, err: err, chdir: cwd, **kwargs
27
+ status = wait_or_kill pid, timeout, on_timeout
28
+ [out, err].each { |f| f.rewind if f.respond_to? :rewind }
29
+
30
+ file ? status : case capture
31
+ when :default then [status, out.read, err.read]
32
+ when :out, :both then [status, out.read]
33
+ when :err then [status, err.read]
34
+ end
35
+ ensure
36
+ [out, err].each { |f| f.unlink if f.is_a?(Tempfile) && f.path&.include?('sysrun') }
37
+ end
38
+
39
+ def self.wait_or_kill(pid, timeout=nil, on_timeout=nil)
40
+ begin
41
+ Timeout::timeout(timeout) { Process.wait pid }
42
+ rescue Timeout::Error
43
+ on_timeout ? on_timeout.call(pid) : Process.kill(9, pid)
44
+ Process.wait pid
45
+ end
46
+
47
+ $?
48
+ end
49
+
50
+ private_class_method :wait_or_kill
51
+ end
@@ -0,0 +1,103 @@
1
+ # This file was generated by the `rspec --init` command. Conventionally, all
2
+ # specs live under a `spec` directory, which RSpec adds to the `$LOAD_PATH`.
3
+ # The generated `.rspec` file contains `--require spec_helper` which will cause
4
+ # this file to always be loaded, without a need to explicitly require it in any
5
+ # files.
6
+ #
7
+ # Given that it is always loaded, you are encouraged to keep this file as
8
+ # light-weight as possible. Requiring heavyweight dependencies from this file
9
+ # will add to the boot time of your test suite on EVERY test run, even for an
10
+ # individual file that may not need all of that loaded. Instead, consider making
11
+ # a separate helper file that requires the additional dependencies and performs
12
+ # the additional setup, and require it from the spec files that actually need
13
+ # it.
14
+ #
15
+ # The `.rspec` file also contains a few flags that are not defaults but that
16
+ # users commonly want.
17
+ #
18
+ # See http://rubydoc.info/gems/rspec-core/RSpec/Core/Configuration
19
+ RSpec.configure do |config|
20
+ # rspec-expectations config goes here. You can use an alternate
21
+ # assertion/expectation library such as wrong or the stdlib/minitest
22
+ # assertions if you prefer.
23
+ config.expect_with :rspec do |expectations|
24
+ # This option will default to `true` in RSpec 4. It makes the `description`
25
+ # and `failure_message` of custom matchers include text for helper methods
26
+ # defined using `chain`, e.g.:
27
+ # be_bigger_than(2).and_smaller_than(4).description
28
+ # # => "be bigger than 2 and smaller than 4"
29
+ # ...rather than:
30
+ # # => "be bigger than 2"
31
+ expectations.include_chain_clauses_in_custom_matcher_descriptions = true
32
+ end
33
+
34
+ # rspec-mocks config goes here. You can use an alternate test double
35
+ # library (such as bogus or mocha) by changing the `mock_with` option here.
36
+ config.mock_with :rspec do |mocks|
37
+ # Prevents you from mocking or stubbing a method that does not exist on
38
+ # a real object. This is generally recommended, and will default to
39
+ # `true` in RSpec 4.
40
+ mocks.verify_partial_doubles = true
41
+ end
42
+
43
+ # This option will default to `:apply_to_host_groups` in RSpec 4 (and will
44
+ # have no way to turn it off -- the option exists only for backwards
45
+ # compatibility in RSpec 3). It causes shared context metadata to be
46
+ # inherited by the metadata hash of host groups and examples, rather than
47
+ # triggering implicit auto-inclusion in groups with matching metadata.
48
+ config.shared_context_metadata_behavior = :apply_to_host_groups
49
+
50
+ # The settings below are suggested to provide a good initial experience
51
+ # with RSpec, but feel free to customize to your heart's content.
52
+ =begin
53
+ # This allows you to limit a spec run to individual examples or groups
54
+ # you care about by tagging them with `:focus` metadata. When nothing
55
+ # is tagged with `:focus`, all examples get run. RSpec also provides
56
+ # aliases for `it`, `describe`, and `context` that include `:focus`
57
+ # metadata: `fit`, `fdescribe` and `fcontext`, respectively.
58
+ config.filter_run_when_matching :focus
59
+
60
+ # Allows RSpec to persist some state between runs in order to support
61
+ # the `--only-failures` and `--next-failure` CLI options. We recommend
62
+ # you configure your source control system to ignore this file.
63
+ config.example_status_persistence_file_path = "spec/examples.txt"
64
+
65
+ # Limits the available syntax to the non-monkey patched syntax that is
66
+ # recommended. For more details, see:
67
+ # - http://rspec.info/blog/2012/06/rspecs-new-expectation-syntax/
68
+ # - http://www.teaisaweso.me/blog/2013/05/27/rspecs-new-message-expectation-syntax/
69
+ # - http://rspec.info/blog/2014/05/notable-changes-in-rspec-3/#zero-monkey-patching-mode
70
+ config.disable_monkey_patching!
71
+
72
+ # This setting enables warnings. It's recommended, but in some cases may
73
+ # be too noisy due to issues in dependencies.
74
+ config.warnings = true
75
+
76
+ # Many RSpec users commonly either run the entire suite or an individual
77
+ # file, and it's useful to allow more verbose output when running an
78
+ # individual spec file.
79
+ if config.files_to_run.one?
80
+ # Use the documentation formatter for detailed output,
81
+ # unless a formatter has already been configured
82
+ # (e.g. via a command-line flag).
83
+ config.default_formatter = 'doc'
84
+ end
85
+
86
+ # Print the 10 slowest examples and example groups at the
87
+ # end of the spec run, to help surface which specs are running
88
+ # particularly slow.
89
+ config.profile_examples = 10
90
+
91
+ # Run specs in random order to surface order dependencies. If you find an
92
+ # order dependency and want to debug it, you can fix the order by providing
93
+ # the seed, which is printed after each run.
94
+ # --seed 1234
95
+ config.order = :random
96
+
97
+ # Seed global randomization in this process using the `--seed` CLI option.
98
+ # Setting this allows you to use `--seed` to deterministically reproduce
99
+ # test failures related to randomization by passing the same `--seed` value
100
+ # as the one that triggered the failure.
101
+ Kernel.srand config.seed
102
+ =end
103
+ end
@@ -1,13 +1,13 @@
1
1
  Gem::Specification.new do |s|
2
2
  s.name = "system_run"
3
- s.version = "1.0.3"
3
+ s.version = "1.0.4"
4
4
  s.platform = Gem::Platform::RUBY
5
5
  s.license = "MIT"
6
6
  s.summary = "Tiny wrapper for running commands. Inspired by systemu."
7
7
 
8
8
  s.description = "see https://github.com/biederfrau/system_run"
9
9
 
10
- s.files = Dir['lib/**/*,spec/*}'] + %w(LICENSE Rakefile system_run.gemspec README.md)
10
+ s.files = Dir['{lib/**/*,spec/*}'] + %w(LICENSE Rakefile system_run.gemspec README.md)
11
11
  s.require_path = 'lib'
12
12
  s.extra_rdoc_files = ['README.md']
13
13
  s.test_files = Dir['spec/system_run_spec*.rb']
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: system_run
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.3
4
+ version: 1.0.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Sonja Biedermann
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2017-02-17 00:00:00.000000000 Z
11
+ date: 2017-12-31 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rspec
@@ -34,6 +34,8 @@ files:
34
34
  - LICENSE
35
35
  - README.md
36
36
  - Rakefile
37
+ - lib/system_run.rb
38
+ - spec/spec_helper.rb
37
39
  - spec/system_run_spec.rb
38
40
  - system_run.gemspec
39
41
  homepage: https://github.com/biederfrau/system_run
@@ -56,7 +58,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
56
58
  version: '0'
57
59
  requirements: []
58
60
  rubyforge_project:
59
- rubygems_version: 2.5.1
61
+ rubygems_version: 2.5.2
60
62
  signing_key:
61
63
  specification_version: 4
62
64
  summary: Tiny wrapper for running commands. Inspired by systemu.