mirror of
https://github.com/ruby/ruby.git
synced 2022-11-09 12:17:21 -05:00
Move spec/rubyspec to spec/ruby for consistency
* Other ruby implementations use the spec/ruby directory. [Misc #13792] [ruby-core:82287] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@59979 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
parent
75bfc6440d
commit
1d15d5f080
4370 changed files with 0 additions and 0 deletions
7
spec/ruby/library/getoptlong/each_option_spec.rb
Normal file
7
spec/ruby/library/getoptlong/each_option_spec.rb
Normal file
|
@ -0,0 +1,7 @@
|
|||
require File.expand_path('../../../spec_helper', __FILE__)
|
||||
require 'getoptlong'
|
||||
require File.expand_path('../shared/each', __FILE__)
|
||||
|
||||
describe "GetoptLong#each_option" do
|
||||
it_behaves_like(:getoptlong_each, :each_option)
|
||||
end
|
7
spec/ruby/library/getoptlong/each_spec.rb
Normal file
7
spec/ruby/library/getoptlong/each_spec.rb
Normal file
|
@ -0,0 +1,7 @@
|
|||
require File.expand_path('../../../spec_helper', __FILE__)
|
||||
require 'getoptlong'
|
||||
require File.expand_path('../shared/each', __FILE__)
|
||||
|
||||
describe "GetoptLong#each" do
|
||||
it_behaves_like(:getoptlong_each, :each)
|
||||
end
|
23
spec/ruby/library/getoptlong/error_message_spec.rb
Normal file
23
spec/ruby/library/getoptlong/error_message_spec.rb
Normal file
|
@ -0,0 +1,23 @@
|
|||
require File.expand_path('../../../spec_helper', __FILE__)
|
||||
require 'getoptlong'
|
||||
|
||||
describe "GetoptLong#error_message" do
|
||||
it "returns nil if no error occurred" do
|
||||
opts = GetoptLong.new
|
||||
opts.error_message.should == nil
|
||||
end
|
||||
|
||||
it "returns the error message of the last error that occurred" do
|
||||
argv [] do
|
||||
opts = GetoptLong.new
|
||||
opts.quiet = true
|
||||
opts.get
|
||||
-> {
|
||||
opts.ordering = GetoptLong::PERMUTE
|
||||
}.should raise_error(ArgumentError) { |e|
|
||||
e.message.should == "argument error"
|
||||
opts.error_message.should == "argument error"
|
||||
}
|
||||
end
|
||||
end
|
||||
end
|
7
spec/ruby/library/getoptlong/get_option_spec.rb
Normal file
7
spec/ruby/library/getoptlong/get_option_spec.rb
Normal file
|
@ -0,0 +1,7 @@
|
|||
require File.expand_path('../../../spec_helper', __FILE__)
|
||||
require 'getoptlong'
|
||||
require File.expand_path('../shared/get', __FILE__)
|
||||
|
||||
describe "GetoptLong#get_option" do
|
||||
it_behaves_like(:getoptlong_get, :get_option)
|
||||
end
|
7
spec/ruby/library/getoptlong/get_spec.rb
Normal file
7
spec/ruby/library/getoptlong/get_spec.rb
Normal file
|
@ -0,0 +1,7 @@
|
|||
require File.expand_path('../../../spec_helper', __FILE__)
|
||||
require 'getoptlong'
|
||||
require File.expand_path('../shared/get', __FILE__)
|
||||
|
||||
describe "GetoptLong#get" do
|
||||
it_behaves_like(:getoptlong_get, :get)
|
||||
end
|
28
spec/ruby/library/getoptlong/initialize_spec.rb
Normal file
28
spec/ruby/library/getoptlong/initialize_spec.rb
Normal file
|
@ -0,0 +1,28 @@
|
|||
require File.expand_path('../../../spec_helper', __FILE__)
|
||||
require 'getoptlong'
|
||||
|
||||
describe "GetoptLong#initialize" do
|
||||
it "sets ordering to REQUIRE_ORDER if ENV['POSIXLY_CORRECT'] is set" do
|
||||
begin
|
||||
old_env_value = ENV["POSIXLY_CORRECT"]
|
||||
ENV["POSIXLY_CORRECT"] = ""
|
||||
|
||||
opt = GetoptLong.new
|
||||
opt.ordering.should == GetoptLong::REQUIRE_ORDER
|
||||
ensure
|
||||
ENV["POSIXLY_CORRECT"] = old_env_value
|
||||
end
|
||||
end
|
||||
|
||||
it "sets ordering to PERMUTE if ENV['POSIXLY_CORRECT'] is not set" do
|
||||
begin
|
||||
old_env_value = ENV["POSIXLY_CORRECT"]
|
||||
ENV["POSIXLY_CORRECT"] = nil
|
||||
|
||||
opt = GetoptLong.new
|
||||
opt.ordering.should == GetoptLong::PERMUTE
|
||||
ensure
|
||||
ENV["POSIXLY_CORRECT"] = old_env_value
|
||||
end
|
||||
end
|
||||
end
|
38
spec/ruby/library/getoptlong/ordering_spec.rb
Normal file
38
spec/ruby/library/getoptlong/ordering_spec.rb
Normal file
|
@ -0,0 +1,38 @@
|
|||
require File.expand_path('../../../spec_helper', __FILE__)
|
||||
require 'getoptlong'
|
||||
|
||||
describe "GetoptLong#ordering=" do
|
||||
it "raises an ArgumentError if called after processing has started" do
|
||||
argv [ "--size", "10k", "--verbose" ] do
|
||||
opts = GetoptLong.new([ '--size', GetoptLong::REQUIRED_ARGUMENT ],
|
||||
[ '--verbose', GetoptLong::NO_ARGUMENT ])
|
||||
opts.quiet = true
|
||||
opts.get
|
||||
|
||||
lambda {
|
||||
opts.ordering = GetoptLong::PERMUTE
|
||||
}.should raise_error(ArgumentError)
|
||||
end
|
||||
end
|
||||
|
||||
it "raises an ArgumentError if given an invalid value" do
|
||||
opts = GetoptLong.new
|
||||
|
||||
lambda {
|
||||
opts.ordering = 12345
|
||||
}.should raise_error(ArgumentError)
|
||||
end
|
||||
|
||||
it "does not allow changing ordering to PERMUTE if ENV['POSIXLY_CORRECT'] is set" do
|
||||
begin
|
||||
old_env_value = ENV['POSIXLY_CORRECT']
|
||||
ENV['POSIXLY_CORRECT'] = ""
|
||||
|
||||
opts = GetoptLong.new
|
||||
opts.ordering = GetoptLong::PERMUTE
|
||||
opts.ordering.should == GetoptLong::REQUIRE_ORDER
|
||||
ensure
|
||||
ENV['POSIXLY_CORRECT'] = old_env_value
|
||||
end
|
||||
end
|
||||
end
|
98
spec/ruby/library/getoptlong/set_options_spec.rb
Normal file
98
spec/ruby/library/getoptlong/set_options_spec.rb
Normal file
|
@ -0,0 +1,98 @@
|
|||
require File.expand_path('../../../spec_helper', __FILE__)
|
||||
require 'getoptlong'
|
||||
|
||||
describe "GetoptLong#set_options" do
|
||||
before :each do
|
||||
@opts = GetoptLong.new
|
||||
end
|
||||
|
||||
it "allows setting command line options" do
|
||||
argv ["--size", "10k", "-v", "arg1", "arg2"] do
|
||||
@opts.set_options(
|
||||
["--size", GetoptLong::REQUIRED_ARGUMENT],
|
||||
["--verbose", "-v", GetoptLong::NO_ARGUMENT]
|
||||
)
|
||||
|
||||
@opts.get.should == ["--size", "10k"]
|
||||
@opts.get.should == ["--verbose", ""]
|
||||
@opts.get.should == nil
|
||||
end
|
||||
end
|
||||
|
||||
it "discards previously defined command line options" do
|
||||
argv ["--size", "10k", "-v", "arg1", "arg2"] do
|
||||
@opts.set_options(
|
||||
["--size", GetoptLong::REQUIRED_ARGUMENT],
|
||||
["--verbose", "-v", GetoptLong::NO_ARGUMENT]
|
||||
)
|
||||
|
||||
@opts.set_options(
|
||||
["-s", "--size", GetoptLong::REQUIRED_ARGUMENT],
|
||||
["-v", GetoptLong::NO_ARGUMENT]
|
||||
)
|
||||
|
||||
@opts.get.should == ["-s", "10k"]
|
||||
@opts.get.should == ["-v", ""]
|
||||
@opts.get.should == nil
|
||||
end
|
||||
end
|
||||
|
||||
it "raises an ArgumentError if too many argument flags where given" do
|
||||
argv [] do
|
||||
lambda {
|
||||
@opts.set_options(["--size", GetoptLong::NO_ARGUMENT, GetoptLong::REQUIRED_ARGUMENT])
|
||||
}.should raise_error(ArgumentError)
|
||||
end
|
||||
end
|
||||
|
||||
it "raises a RuntimeError if processing has already started" do
|
||||
argv [] do
|
||||
@opts.get
|
||||
lambda {
|
||||
@opts.set_options()
|
||||
}.should raise_error(RuntimeError)
|
||||
end
|
||||
end
|
||||
|
||||
it "raises an ArgumentError if no argument flag was given" do
|
||||
argv [] do
|
||||
lambda {
|
||||
@opts.set_options(["--size"])
|
||||
}.should raise_error(ArgumentError)
|
||||
end
|
||||
end
|
||||
|
||||
it "raises an ArgumentError if one of the given arguments is not an Array" do
|
||||
argv [] do
|
||||
lambda {
|
||||
@opts.set_options(
|
||||
["--size", GetoptLong::REQUIRED_ARGUMENT],
|
||||
"test")
|
||||
}.should raise_error(ArgumentError)
|
||||
end
|
||||
end
|
||||
|
||||
it "raises an ArgumentError if the same option is given twice" do
|
||||
argv [] do
|
||||
lambda {
|
||||
@opts.set_options(
|
||||
["--size", GetoptLong::NO_ARGUMENT],
|
||||
["--size", GetoptLong::OPTIONAL_ARGUMENT])
|
||||
}.should raise_error(ArgumentError)
|
||||
|
||||
lambda {
|
||||
@opts.set_options(
|
||||
["--size", GetoptLong::NO_ARGUMENT],
|
||||
["-s", "--size", GetoptLong::OPTIONAL_ARGUMENT])
|
||||
}.should raise_error(ArgumentError)
|
||||
end
|
||||
end
|
||||
|
||||
it "raises an ArgumentError if the given option is invalid" do
|
||||
argv [] do
|
||||
lambda {
|
||||
@opts.set_options(["-size", GetoptLong::NO_ARGUMENT])
|
||||
}.should raise_error(ArgumentError)
|
||||
end
|
||||
end
|
||||
end
|
18
spec/ruby/library/getoptlong/shared/each.rb
Normal file
18
spec/ruby/library/getoptlong/shared/each.rb
Normal file
|
@ -0,0 +1,18 @@
|
|||
describe :getoptlong_each, shared: true do
|
||||
before :each do
|
||||
@opts = GetoptLong.new(
|
||||
[ '--size', '-s', GetoptLong::REQUIRED_ARGUMENT ],
|
||||
[ '--verbose', '-v', GetoptLong::NO_ARGUMENT ],
|
||||
[ '--query', '-q', GetoptLong::NO_ARGUMENT ],
|
||||
[ '--check', '--valid', '-c', GetoptLong::NO_ARGUMENT ]
|
||||
)
|
||||
end
|
||||
|
||||
it "passes each argument/value pair to the block" do
|
||||
argv [ "--size", "10k", "-v", "-q", "a.txt", "b.txt" ] do
|
||||
pairs = []
|
||||
@opts.send(@method) { |arg, val| pairs << [ arg, val ] }
|
||||
pairs.should == [ [ "--size", "10k" ], [ "--verbose", "" ], [ "--query", ""] ]
|
||||
end
|
||||
end
|
||||
end
|
64
spec/ruby/library/getoptlong/shared/get.rb
Normal file
64
spec/ruby/library/getoptlong/shared/get.rb
Normal file
|
@ -0,0 +1,64 @@
|
|||
describe :getoptlong_get, shared: true do
|
||||
before :each do
|
||||
@opts = GetoptLong.new(
|
||||
[ '--size', '-s', GetoptLong::REQUIRED_ARGUMENT ],
|
||||
[ '--verbose', '-v', GetoptLong::NO_ARGUMENT ],
|
||||
[ '--query', '-q', GetoptLong::NO_ARGUMENT ],
|
||||
[ '--check', '--valid', '-c', GetoptLong::NO_ARGUMENT ]
|
||||
)
|
||||
@opts.quiet = true # silence using $deferr
|
||||
end
|
||||
|
||||
it "returns the next option name and its argument as an Array" do
|
||||
argv [ "--size", "10k", "-v", "-q", "a.txt", "b.txt" ] do
|
||||
@opts.send(@method).should == [ "--size", "10k" ]
|
||||
@opts.send(@method).should == [ "--verbose", "" ]
|
||||
@opts.send(@method).should == [ "--query", ""]
|
||||
@opts.send(@method).should == nil
|
||||
end
|
||||
end
|
||||
|
||||
it "shifts ARGV on each call" do
|
||||
argv [ "--size", "10k", "-v", "-q", "a.txt", "b.txt" ] do
|
||||
@opts.send(@method)
|
||||
ARGV.should == [ "-v", "-q", "a.txt", "b.txt" ]
|
||||
|
||||
@opts.send(@method)
|
||||
ARGV.should == [ "-q", "a.txt", "b.txt" ]
|
||||
|
||||
@opts.send(@method)
|
||||
ARGV.should == [ "a.txt", "b.txt" ]
|
||||
|
||||
@opts.send(@method)
|
||||
ARGV.should == [ "a.txt", "b.txt" ]
|
||||
end
|
||||
end
|
||||
|
||||
it "terminates processing when encountering '--'" do
|
||||
argv [ "--size", "10k", "--", "-v", "-q", "a.txt", "b.txt" ] do
|
||||
@opts.send(@method)
|
||||
ARGV.should == ["--", "-v", "-q", "a.txt", "b.txt"]
|
||||
|
||||
@opts.send(@method)
|
||||
ARGV.should == ["-v", "-q", "a.txt", "b.txt"]
|
||||
|
||||
@opts.send(@method)
|
||||
ARGV.should == ["-v", "-q", "a.txt", "b.txt"]
|
||||
end
|
||||
end
|
||||
|
||||
it "raises a if an argument was required, but none given" do
|
||||
argv [ "--size" ] do
|
||||
lambda { @opts.send(@method) }.should raise_error(GetoptLong::MissingArgument)
|
||||
end
|
||||
end
|
||||
|
||||
ruby_version_is "2.5" do
|
||||
# https://bugs.ruby-lang.org/issues/13858
|
||||
it "returns multiline argument" do
|
||||
argv [ "--size=\n10k\n" ] do
|
||||
@opts.send(@method).should == [ "--size", "\n10k\n" ]
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
30
spec/ruby/library/getoptlong/terminate_spec.rb
Normal file
30
spec/ruby/library/getoptlong/terminate_spec.rb
Normal file
|
@ -0,0 +1,30 @@
|
|||
require File.expand_path('../../../spec_helper', __FILE__)
|
||||
require 'getoptlong'
|
||||
|
||||
describe "GetoptLong#terminate" do
|
||||
before :each do
|
||||
@opts = GetoptLong.new(
|
||||
[ '--size', '-s', GetoptLong::REQUIRED_ARGUMENT ],
|
||||
[ '--verbose', '-v', GetoptLong::NO_ARGUMENT ],
|
||||
[ '--query', '-q', GetoptLong::NO_ARGUMENT ],
|
||||
[ '--check', '--valid', '-c', GetoptLong::NO_ARGUMENT ]
|
||||
)
|
||||
end
|
||||
|
||||
it "terminates option proccessing" do
|
||||
argv [ "--size", "10k", "-v", "-q", "a.txt", "b.txt" ] do
|
||||
@opts.get.should == [ "--size", "10k" ]
|
||||
@opts.terminate
|
||||
@opts.get.should == nil
|
||||
end
|
||||
end
|
||||
|
||||
it "returns self when option processsing is terminated" do
|
||||
@opts.terminate.should == @opts
|
||||
end
|
||||
|
||||
it "returns nil when option processing was already terminated" do
|
||||
@opts.terminate
|
||||
@opts.terminate.should == nil
|
||||
end
|
||||
end
|
17
spec/ruby/library/getoptlong/terminated_spec.rb
Normal file
17
spec/ruby/library/getoptlong/terminated_spec.rb
Normal file
|
@ -0,0 +1,17 @@
|
|||
require File.expand_path('../../../spec_helper', __FILE__)
|
||||
require 'getoptlong'
|
||||
|
||||
describe "GetoptLong#terminated?" do
|
||||
it "returns true if option processing has terminated" do
|
||||
argv [ "--size", "10k" ] do
|
||||
opts = GetoptLong.new(["--size", GetoptLong::REQUIRED_ARGUMENT])
|
||||
opts.terminated?.should == false
|
||||
|
||||
opts.get.should == ["--size", "10k"]
|
||||
opts.terminated?.should == false
|
||||
|
||||
opts.get.should == nil
|
||||
opts.terminated?.should == true
|
||||
end
|
||||
end
|
||||
end
|
Loading…
Add table
Add a link
Reference in a new issue