getopt 1.6.0 → 1.7.1

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.
@@ -1,122 +1,130 @@
1
+ # frozen_string_literal: true
2
+
1
3
  ###################################################################
2
4
  # test_getopt_std.rb
3
5
  #
4
- # Test suite for the Getopt::Std class. You should run this test
6
+ # Test suite for the Getopt::described_class class. You should run this test
5
7
  # via the 'rake test' task.
6
8
  ###################################################################
7
9
  require 'rspec'
8
10
  require 'getopt/std'
9
- include Getopt
10
11
 
11
12
  RSpec.describe Getopt::Std do
12
- example "version" do
13
- expect(Std::VERSION).to eq('1.6.0')
14
- expect(Std::VERSION).to be_frozen
13
+ after do
14
+ ARGV.clear
15
15
  end
16
16
 
17
- example "getopts basic functionality" do
18
- expect(Std).to respond_to(:getopts)
19
- expect{ Std.getopts("ID") }.not_to raise_error
20
- expect(Std.getopts("ID")).to be_kind_of(Hash)
17
+ example 'version' do
18
+ expect(described_class::VERSION).to eq('1.7.1')
19
+ expect(described_class::VERSION).to be_frozen
21
20
  end
22
21
 
23
- example "getopts with separated switches" do
24
- ARGV.push("-I", "-D")
25
- expect(Std.getopts("ID")).to eq({"I"=>true, "D"=>true})
22
+ example 'getopts basic functionality' do
23
+ expect(described_class).to respond_to(:getopts)
24
+ expect{ described_class.getopts('ID') }.not_to raise_error
25
+ expect(described_class.getopts('ID')).to be_a(Hash)
26
+ end
27
+
28
+ example 'getopts with separated switches' do
29
+ ARGV.push('-I', '-D')
30
+ expect(described_class.getopts('ID')).to eq({'I' => true, 'D' => true})
26
31
  end
27
32
 
28
33
  # Inspired by RF bug #23477
29
- example "getopts with arguments that match switch are ok" do
30
- ARGV.push("-d", "d")
31
- expect(Std.getopts("d:")).to eq({"d" => "d"})
34
+ example 'getopts with arguments that match switch are ok' do
35
+ ARGV.push('-d', 'd')
36
+ expect(described_class.getopts('d:')).to eq({'d' => 'd'})
37
+
38
+ ARGV.push('-d', 'ad')
39
+ expect(described_class.getopts('d:')).to eq({'d' => 'ad'})
32
40
 
33
- ARGV.push("-d", "ad")
34
- expect(Std.getopts("d:")).to eq({"d" => "ad"})
41
+ ARGV.push('-a', 'ad')
42
+ expect(described_class.getopts('d:a:')).to eq({'a' => 'ad'})
35
43
 
36
- ARGV.push("-a", "ad")
37
- expect(Std.getopts("d:a:")).to eq({"a" => "ad"})
44
+ ARGV.push('-a', 'da')
45
+ expect(described_class.getopts('d:a:')).to eq({'a' => 'da'})
38
46
 
39
- ARGV.push("-a", "da")
40
- expect(Std.getopts("d:a:")).to eq({"a" => "da"})
47
+ ARGV.push('-a', 'd')
48
+ expect(described_class.getopts('d:a:')).to eq({'a' => 'd'})
41
49
 
42
- ARGV.push("-a", "d")
43
- expect(Std.getopts("d:a:")).to eq({"a" => "d"})
50
+ ARGV.push('-a', 'dad')
51
+ expect(described_class.getopts('d:a:')).to eq({'a' => 'dad'})
44
52
 
45
- ARGV.push("-a", "dad")
46
- expect(Std.getopts("d:a:")).to eq({"a" => "dad"})
53
+ ARGV.push('-d', 'd', '-a', 'a')
54
+ expect(described_class.getopts('d:a:')).to eq({'d' => 'd', 'a' => 'a'})
55
+ end
47
56
 
48
- ARGV.push("-d", "d", "-a", "a")
49
- expect(Std.getopts("d:a:")).to eq({"d" => "d", "a" => "a"})
57
+ example 'getopts with joined switches' do
58
+ ARGV.push('-ID')
59
+ expect(described_class.getopts('ID')).to eq({'I' => true, 'D' => true})
50
60
  end
51
61
 
52
- example "getopts with joined switches" do
53
- ARGV.push("-ID")
54
- expect(Std.getopts("ID")).to eq({"I"=>true, "D"=>true})
62
+ example 'getopts accepts question mark as a switch' do
63
+ ARGV.push('-?')
64
+ expect(described_class.getopts('?')).to eq({'?' => true})
55
65
  end
56
66
 
57
- example "getopts with separated switches and mandatory argument" do
58
- ARGV.push("-o", "hello", "-I", "-D")
59
- expect(Std.getopts("o:ID")).to eq({"o"=>"hello", "I"=>true, "D"=>true})
67
+ example 'getopts with separated switches and mandatory argument' do
68
+ ARGV.push('-o', 'hello', '-I', '-D')
69
+ expect(described_class.getopts('o:ID')).to eq({'o' => 'hello', 'I' => true, 'D' => true})
60
70
  end
61
71
 
62
- example "getopts with joined switches and mandatory argument" do
63
- ARGV.push("-IDo", "hello")
64
- expect( Std.getopts("o:ID")).to eq({"o"=>"hello", "I"=>true, "D"=>true})
72
+ example 'getopts with joined switches and mandatory argument' do
73
+ ARGV.push('-IDo', 'hello')
74
+ expect(described_class.getopts('o:ID')).to eq({'o' => 'hello', 'I' => true, 'D' => true})
65
75
  end
66
76
 
67
- example "getopts with no arguments" do
68
- expect{ Std.getopts("ID") }.not_to raise_error
69
- expect(Std.getopts("ID")).to eq({})
70
- expect(Std.getopts("ID")["I"]).to be_nil
71
- expect(Std.getopts("ID")["D"]).to be_nil
77
+ example 'getopts with no arguments' do
78
+ expect{ described_class.getopts('ID') }.not_to raise_error
79
+ expect(described_class.getopts('ID')).to eq({})
80
+ expect(described_class.getopts('ID')['I']).to be_nil
81
+ expect(described_class.getopts('ID')['D']).to be_nil
72
82
  end
73
83
 
74
84
  # If a switch that accepts an argument appears more than once, the values
75
85
  # are rolled into an array.
76
- example "getopts with switch repeated" do
77
- ARGV.push("-I", "-I", "-o", "hello", "-o", "world")
78
- expect( Std.getopts("o:ID")).to eq({"o" => ["hello","world"], "I"=>true})
86
+ example 'getopts with switch repeated' do
87
+ ARGV.push('-I', '-I', '-o', 'hello', '-o', 'world')
88
+ expect(described_class.getopts('o:ID')).to eq({'o' => ['hello', 'world'], 'I' => true})
79
89
  end
80
90
 
81
91
  # EXPECTED ERRORS
82
92
 
83
- example "getopts raises expected errors when passing a switch to another switch" do
84
- ARGV.push("-d", "-d")
85
- expect{ Std.getopts("d:a:") }.to raise_error(Getopt::Std::Error)
86
-
87
- ARGV.push("-d", "-a")
88
- expect{ Std.getopts("d:a:") }.to raise_error(Getopt::Std::Error)
93
+ example 'getopts raises expected errors when passing a switch to another switch' do
94
+ msg = "cannot use switch '-d' as argument to another switch"
89
95
 
90
- ARGV.push("-a", "-d")
91
- expect{ Std.getopts("d:a:") }.to raise_error(Getopt::Std::Error)
96
+ ARGV.push('-d', '-d')
97
+ expect{ described_class.getopts('d:a:') }.to raise_error(Getopt::Std::Error)
92
98
 
93
- ARGV.push("-d", "-d")
94
- expect{ Std.getopts("d:a:") }.to raise_error(Getopt::Std::Error, "cannot use switch '-d' as argument to another switch")
95
- end
99
+ ARGV.push('-d', '-a')
100
+ expect{ described_class.getopts('d:a:') }.to raise_error(Getopt::Std::Error)
96
101
 
97
- example "getopts raises expected errors if argument is missing" do
98
- ARGV.push("-ID")
99
- expect{ Std.getopts("I:D") }.to raise_error(Std::Error)
102
+ ARGV.push('-a', '-d')
103
+ expect{ described_class.getopts('d:a:') }.to raise_error(Getopt::Std::Error)
100
104
 
101
- ARGV.push("-ID")
102
- expect{ Std.getopts("ID:") }.to raise_error(Std::Error)
105
+ ARGV.push('-d', '-d')
106
+ expect{ described_class.getopts('d:a:') }.to raise_error(Getopt::Std::Error, msg)
103
107
  end
104
108
 
105
- example "getopts raises expected errors if there are extra arguments" do
106
- ARGV.push("-I", "-D", "-X")
107
- expect{ Std.getopts("ID") }.to raise_error(Std::Error)
109
+ example 'getopts raises expected errors if argument is missing' do
110
+ ARGV.push('-ID')
111
+ expect{ described_class.getopts('I:D') }.to raise_error(Getopt::Std::Error)
108
112
 
109
- ARGV.push("-IDX")
110
- expect{ Std.getopts("ID") }.to raise_error(Std::Error, "invalid option 'X'")
113
+ ARGV.push('-ID')
114
+ expect{ described_class.getopts('ID:') }.to raise_error(Getopt::Std::Error)
111
115
  end
112
116
 
113
- example "getopts raises expected errors with invalid or no arguments" do
114
- expect{ Std.getopts }.to raise_error(ArgumentError)
115
- expect{ Std.getopts(0) }.to raise_error(NoMethodError)
116
- expect{ Std.getopts(nil) }.to raise_error(NoMethodError)
117
+ example 'getopts raises expected errors if there are extra arguments' do
118
+ ARGV.push('-I', '-D', '-X')
119
+ expect{ described_class.getopts('ID') }.to raise_error(Getopt::Std::Error)
120
+
121
+ ARGV.push('-IDX')
122
+ expect{ described_class.getopts('ID') }.to raise_error(Getopt::Std::Error, "invalid option 'X'")
117
123
  end
118
124
 
119
- after do
120
- ARGV.clear
125
+ example 'getopts raises expected errors with invalid or no arguments' do
126
+ expect{ described_class.getopts }.to raise_error(ArgumentError)
127
+ expect{ described_class.getopts(0) }.to raise_error(NoMethodError)
128
+ expect{ described_class.getopts(nil) }.to raise_error(NoMethodError)
121
129
  end
122
130
  end
data.tar.gz.sig CHANGED
Binary file
metadata CHANGED
@@ -1,11 +1,10 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: getopt
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.6.0
4
+ version: 1.7.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Daniel J. Berger
8
- autorequire:
9
8
  bindir: bin
10
9
  cert_chain:
11
10
  - |
@@ -35,7 +34,7 @@ cert_chain:
35
34
  ORVCZpRuCPpmC8qmqxUnARDArzucjaclkxjLWvCVHeFa9UP7K3Nl9oTjJNv+7/jM
36
35
  WZs4eecIcUc4tKdHxcAJ0MO/Dkqq7hGaiHpwKY76wQ1+8xAh
37
36
  -----END CERTIFICATE-----
38
- date: 2021-03-02 00:00:00.000000000 Z
37
+ date: 1980-01-02 00:00:00.000000000 Z
39
38
  dependencies:
40
39
  - !ruby/object:Gem::Dependency
41
40
  name: rake
@@ -65,6 +64,34 @@ dependencies:
65
64
  - - "~>"
66
65
  - !ruby/object:Gem::Version
67
66
  version: '3.9'
67
+ - !ruby/object:Gem::Dependency
68
+ name: rubocop
69
+ requirement: !ruby/object:Gem::Requirement
70
+ requirements:
71
+ - - ">="
72
+ - !ruby/object:Gem::Version
73
+ version: '0'
74
+ type: :development
75
+ prerelease: false
76
+ version_requirements: !ruby/object:Gem::Requirement
77
+ requirements:
78
+ - - ">="
79
+ - !ruby/object:Gem::Version
80
+ version: '0'
81
+ - !ruby/object:Gem::Dependency
82
+ name: rubocop-rspec
83
+ requirement: !ruby/object:Gem::Requirement
84
+ requirements:
85
+ - - ">="
86
+ - !ruby/object:Gem::Version
87
+ version: '0'
88
+ type: :development
89
+ prerelease: false
90
+ version_requirements: !ruby/object:Gem::Requirement
91
+ requirements:
92
+ - - ">="
93
+ - !ruby/object:Gem::Version
94
+ version: '0'
68
95
  description: |2
69
96
  The getopt library provides two different command line option parsers.
70
97
  They are meant as easier and more convenient replacements for the
@@ -99,11 +126,13 @@ licenses:
99
126
  metadata:
100
127
  homepage_uri: https://github.com/djberg96/getopt
101
128
  bug_tracker_uri: https://github.com/djberg96/getopt/issues
102
- changelog_uri: https://github.com/djberg96/getopt/blob/master/CHANGES
129
+ changelog_uri: https://github.com/djberg96/getopt/blob/main/CHANGES.md
103
130
  documentation_uri: https://github.com/djberg96/getopt/wiki
104
131
  source_code_uri: https://github.com/djberg96/getopt
105
132
  wiki_uri: https://github.com/djberg96/getopt/wiki
106
- post_install_message:
133
+ rubygems_mfa_required: 'true'
134
+ github_repo: https://github.com/djberg96/getopt
135
+ funding_uri: https://github.com/sponsors/djberg96
107
136
  rdoc_options: []
108
137
  require_paths:
109
138
  - lib
@@ -118,10 +147,9 @@ required_rubygems_version: !ruby/object:Gem::Requirement
118
147
  - !ruby/object:Gem::Version
119
148
  version: '0'
120
149
  requirements: []
121
- rubygems_version: 3.0.3
122
- signing_key:
150
+ rubygems_version: 4.0.6
123
151
  specification_version: 4
124
152
  summary: Getopt::Std and Getopt::Long option parsers for Ruby
125
153
  test_files:
126
- - spec/getopt_std_spec.rb
127
154
  - spec/getopt_long_spec.rb
155
+ - spec/getopt_std_spec.rb
metadata.gz.sig CHANGED
Binary file