mini-cli 0.4.0 → 0.5.0

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
  SHA256:
3
- metadata.gz: 969a4421172e3cf6a3b6c6ecc294932e825a170de914ac5f19926fcc4e3da674
4
- data.tar.gz: '039fc6a1d177834a3999468142a71a985ef417d179011cbba6b7b57777cb05c8'
3
+ metadata.gz: b366ee44d4b95a00a977cbfdcf3e7cc7aff2cc1d3f72c03e0df2c2858aaf22e8
4
+ data.tar.gz: 8a622678016ca76e554a6b80d40dbea7dd7d6db5a494b5d7dd83944e68d66921
5
5
  SHA512:
6
- metadata.gz: e8fc8a932a4e508327570bb3c4e062950d78b19cbaf87594456e2f5d340a22bcbe2db32bbffd55c76e7e57e2fdb1ca63118d2f20a67976bb60fb3795e9cf372a
7
- data.tar.gz: 3a2d8fa7af6ec17ae701ab0a6505ce03084646540c3cab5a54facb76c5434ad5b29acdbcb9aea35d19e7daa60bdabdb79cf143a8f8a22a2d6af0b6c7d4aeb98e
6
+ metadata.gz: 73a9bee03f689d2f1e7334b6b927ba8cd45efb8422729c1abe93bf9062e26de47886ff0e70dc518ed01eeab7330e8777cd25a2c6fa270d6f16d32c0979de8d8d
7
+ data.tar.gz: cf6679d1245593b36ab18481ea4c83a14da4953cf41e6e849b92951a5dc5301c3603ef42476fe1cab0995d008b5356233f50dc2135f9f3d2530c5a61683560cd
data/lib/mini-cli/run.rb CHANGED
@@ -14,8 +14,22 @@ module MiniCli
14
14
  in_write&.close
15
15
  end
16
16
 
17
+ def run_ruby(*cmd, **run_options)
18
+ require 'shellwords'
19
+ run(Shellwords.join(RUBY_CMD + cmd), **run_options)
20
+ end
21
+
22
+ def run_script(script, status: false, chdir: nil)
23
+ run_ruby(stdin_data: script, status: status, chdir: chdir)
24
+ end
25
+
17
26
  private
18
27
 
28
+ RUBY_CMD =
29
+ %w[--disable gems --disable did_you_mean --disable rubyopt].unshift(
30
+ RbConfig.ruby
31
+ ).freeze
32
+
19
33
  def __run_proc(stdin_data, in_write)
20
34
  return :read unless stdin_data
21
35
  proc do |out|
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module MiniCli
4
- VERSION = '0.4.0'
4
+ VERSION = '0.5.0'
5
5
  end
@@ -1,6 +1,4 @@
1
- #!/usr/bin/env ruby
2
1
  # frozen_string_literal: true
3
-
4
2
  # completely empty command
5
3
 
6
4
  require_relative '../../lib/mini-cli'
@@ -1,6 +1,4 @@
1
- #!/usr/bin/env ruby
2
1
  # frozen_string_literal: true
3
-
4
2
  # demonstrates the call sequence
5
3
 
6
4
  require_relative '../../lib/mini-cli'
@@ -5,14 +5,12 @@ require 'shellwords'
5
5
  require_relative '../helper'
6
6
 
7
7
  class ExecTest < Minitest::Test
8
- parallelize_me!
9
-
10
8
  def test_noop
11
- assert_empty(assert_no_err('noop'))
9
+ assert_empty(assert_no_err('noop.rb'))
12
10
  end
13
11
 
14
12
  def test_noop_help
15
- assert_equal("Usage: noop\n", assert_no_err('noop', '--help'))
13
+ assert_equal("Usage: noop\n", assert_no_err('noop.rb', '--help'))
16
14
  end
17
15
 
18
16
  def test_sequence
@@ -24,7 +22,7 @@ class ExecTest < Minitest::Test
24
22
  'after_2[]',
25
23
  'after_1[]'
26
24
  ]
27
- assert_equal(expected, assert_no_err('sequence').split("\n"))
25
+ assert_equal(expected, assert_no_err('sequence.rb').split("\n"))
28
26
  end
29
27
 
30
28
  def test_sequence_help
@@ -35,7 +33,7 @@ class ExecTest < Minitest::Test
35
33
  '-x, --exit early exit',
36
34
  '-e, --error exit with error'
37
35
  ]
38
- assert_equal(expected, assert_no_err('sequence', '--help').split("\n"))
36
+ assert_equal(expected, assert_no_err('sequence.rb', '--help').split("\n"))
39
37
  end
40
38
 
41
39
  def test_sequence_early_exit
@@ -47,7 +45,7 @@ class ExecTest < Minitest::Test
47
45
  'after_2[]',
48
46
  'after_1[]'
49
47
  ]
50
- assert_equal(expected, assert_no_err('sequence', '-x').split("\n"))
48
+ assert_equal(expected, assert_no_err('sequence.rb', '-x').split("\n"))
51
49
  end
52
50
 
53
51
  def test_sequence_error
@@ -59,7 +57,7 @@ class ExecTest < Minitest::Test
59
57
  'after_2[]',
60
58
  'after_1[]'
61
59
  ]
62
- std, err, status = invoke('sequence', '-e')
60
+ std, err, status = invoke('sequence.rb', '-e')
63
61
  assert_same(42, status.exitstatus)
64
62
  assert_equal("sequence: !error!\n", err)
65
63
  assert_equal(expected, std.split("\n"))
@@ -22,6 +22,8 @@ class MainTest < Test
22
22
  name
23
23
  parse_argv
24
24
  run
25
+ run_ruby
26
+ run_script
25
27
  show_errors=
26
28
  show_errors?
27
29
  show_help
@@ -0,0 +1,43 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative '../helper'
4
+
5
+ class RubyRunTest < Test
6
+ def test_simple
7
+ result = subject.run_script('puts("Hello World")')
8
+ assert_equal("Hello World\n", result)
9
+ end
10
+
11
+ def test_error
12
+ result = subject.run_script('UNDEFINED')
13
+ assert_match(/NameError/, result)
14
+ end
15
+
16
+ def test_chdir
17
+ home = Dir.home
18
+ refute(home == Dir.pwd)
19
+ result = subject.run_script('print Dir.pwd', chdir: home)
20
+ assert_equal(home, result)
21
+ end
22
+
23
+ def test_status
24
+ status, result = subject.run_script('print :Ok', status: true)
25
+ assert_instance_of(Process::Status, status)
26
+ assert(status.success?)
27
+ assert_equal('Ok', result)
28
+ end
29
+
30
+ def test_status_error
31
+ status, result = subject.run_script('print :Err;exit 42', status: true)
32
+ assert_instance_of(Process::Status, status)
33
+ refute(status.success?)
34
+ assert_same(42, status.exitstatus)
35
+ assert_equal('Err', result)
36
+ end
37
+
38
+ def test_stream
39
+ stream = StringIO.new('puts "Hello World"')
40
+ result = subject.run_script(stream)
41
+ assert_equal("Hello World\n", result)
42
+ end
43
+ end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: mini-cli
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.0
4
+ version: 0.5.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Mike Blumtritt
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2021-03-17 00:00:00.000000000 Z
11
+ date: 2021-06-04 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -74,11 +74,12 @@ files:
74
74
  - samples/custom_args.rb
75
75
  - samples/demo.rb
76
76
  - samples/simple.rb
77
- - test/apps/noop
78
- - test/apps/sequence
77
+ - test/apps/noop.rb
78
+ - test/apps/sequence.rb
79
79
  - test/helper.rb
80
80
  - test/mini-cli/exec_test.rb
81
81
  - test/mini-cli/main_test.rb
82
+ - test/mini-cli/ruby_run_test.rb
82
83
  - test/mini-cli/run_test.rb
83
84
  homepage: https://github.com/mblumtritt/mini-cli
84
85
  licenses: []
@@ -100,14 +101,15 @@ required_rubygems_version: !ruby/object:Gem::Requirement
100
101
  - !ruby/object:Gem::Version
101
102
  version: '0'
102
103
  requirements: []
103
- rubygems_version: 3.2.9
104
+ rubygems_version: 3.2.15
104
105
  signing_key:
105
106
  specification_version: 4
106
107
  summary: The lean CLI framework for Ruby
107
108
  test_files:
108
- - test/apps/noop
109
- - test/apps/sequence
109
+ - test/apps/noop.rb
110
+ - test/apps/sequence.rb
110
111
  - test/helper.rb
111
112
  - test/mini-cli/exec_test.rb
112
113
  - test/mini-cli/main_test.rb
114
+ - test/mini-cli/ruby_run_test.rb
113
115
  - test/mini-cli/run_test.rb