1
0
Fork 0
mirror of https://github.com/ruby/ruby.git synced 2022-11-09 12:17:21 -05:00
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@63768 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
eregon 2018-06-27 12:30:05 +00:00
parent fc1f3f14d3
commit 9dc121cc57
143 changed files with 328 additions and 146 deletions

View file

@ -10,6 +10,11 @@ AllCops:
Layout/TrailingWhitespace:
Enabled: true
Layout/TrailingBlankLines:
Enabled: true
Exclude:
- library/coverage/fixtures/some_class.rb
Lint:
Enabled: true

View file

@ -87,12 +87,10 @@ Lint/MultipleCompare:
# Offense count: 12
Lint/ParenthesesAsGroupedExpression:
Exclude:
- 'command_line/rubyopt_spec.rb'
- 'core/string/fixtures/freeze_magic_comment.rb'
- 'language/block_spec.rb'
- 'language/fixtures/send.rb'
- 'language/method_spec.rb'
- 'library/socket/socket/getaddrinfo_spec.rb'
# Offense count: 1
# Cop supports --auto-correct.

View file

@ -0,0 +1,67 @@
require_relative '../spec_helper'
describe "The RUBYLIB environment variable" do
before :each do
@rubylib, ENV["RUBYLIB"] = ENV["RUBYLIB"], nil
end
after :each do
ENV["RUBYLIB"] = @rubylib
end
it "adds a directory to $LOAD_PATH" do
dir = tmp("rubylib/incl")
ENV["RUBYLIB"] = dir
paths = ruby_exe("puts $LOAD_PATH").lines.map(&:chomp)
paths.should include(dir)
end
it "adds a colon-separated list of directories to $LOAD_PATH" do
dir1, dir2 = tmp("rubylib/incl1"), tmp("rubylib/incl2")
ENV["RUBYLIB"] = "#{dir1}:#{dir2}"
paths = ruby_exe("puts $LOAD_PATH").lines.map(&:chomp)
paths.should include(dir1)
paths.should include(dir2)
paths.index(dir1).should < paths.index(dir2)
end
it "adds the directory at the front of $LOAD_PATH" do
dir = tmp("rubylib/incl_front")
ENV["RUBYLIB"] = dir
paths = ruby_exe("puts $LOAD_PATH").lines.map(&:chomp)
if PlatformGuard.implementation? :ruby
# In a MRI checkout, $PWD and some extra -I entries end up as
# the first entries in $LOAD_PATH. So just assert that it's not last.
idx = paths.index(dir)
idx.should < paths.size-1
else
paths[0].should == dir
end
end
it "adds the directory after directories added by -I" do
dash_i_dir = tmp("dash_I_include")
rubylib_dir = tmp("rubylib_include")
ENV["RUBYLIB"] = rubylib_dir
paths = ruby_exe("puts $LOAD_PATH", options: "-I #{dash_i_dir}").lines.map(&:chomp)
paths.should include(dash_i_dir)
paths.should include(rubylib_dir)
paths.index(dash_i_dir).should < paths.index(rubylib_dir)
end
it "adds the directory after directories added by -I within RUBYOPT" do
rubyopt_dir = tmp("rubyopt_include")
rubylib_dir = tmp("rubylib_include")
ENV["RUBYLIB"] = rubylib_dir
paths = ruby_exe("puts $LOAD_PATH", env: { "RUBYOPT" => "-I#{rubyopt_dir}" }).lines.map(&:chomp)
paths.should include(rubyopt_dir)
paths.should include(rubylib_dir)
paths.index(rubyopt_dir).should < paths.index(rubylib_dir)
end
it "keeps spaces in the value" do
ENV["RUBYLIB"] = " rubylib/incl "
out = ruby_exe("puts $LOAD_PATH")
out.should include(" rubylib/incl ")
end
end

View file

@ -1,11 +1,11 @@
require_relative '../spec_helper'
describe "Processing RUBYOPT" do
before (:each) do
before :each do
@rubyopt, ENV["RUBYOPT"] = ENV["RUBYOPT"], nil
end
after (:each) do
after :each do
ENV["RUBYOPT"] = @rubyopt
end

View file

@ -99,4 +99,3 @@ describe "Class.inherited" do
end
end

View file

@ -39,4 +39,3 @@ describe "Enumerable#zip" do
end
end

View file

@ -11,5 +11,3 @@ describe :env_key, shared: true do
ENV.send(@method, "should_never_be_set").should be_nil
end
end

View file

@ -16,4 +16,3 @@ describe "UncaughtThrowError#tag" do
end
end
end

View file

@ -31,4 +31,3 @@ describe :float_arithmetic_exception_in_coerce, shared: true do
end
end
end

View file

@ -33,4 +33,3 @@ describe :float_comparison_exception_in_coerce, shared: true do
end
end
end

View file

@ -10,4 +10,3 @@ describe "Hash#clone" do
clone.should_not equal hash
end
end

View file

@ -5,4 +5,3 @@ require_relative 'shared/key'
describe "Hash#has_key?" do
it_behaves_like :hash_key_p, :has_key?
end

View file

@ -5,4 +5,3 @@ require_relative 'shared/value'
describe "Hash#has_value?" do
it_behaves_like :hash_value_p, :has_value?
end

View file

@ -5,4 +5,3 @@ require_relative 'shared/value'
describe "Hash#value?" do
it_behaves_like :hash_value_p, :value?
end

View file

@ -4,4 +4,3 @@ require_relative 'shared/abs'
describe "Integer#abs" do
it_behaves_like :integer_abs, :abs
end

View file

@ -93,4 +93,3 @@ describe "Integer#/" do
end
end
end

View file

@ -4,4 +4,3 @@ require_relative 'shared/equal'
describe "Integer#==" do
it_behaves_like :integer_equal, :==
end

View file

@ -47,4 +47,3 @@ describe "Integer#>" do
end
end
end

View file

@ -47,4 +47,3 @@ describe "Integer#>=" do
end
end
end

View file

@ -49,4 +49,3 @@ describe "Integer#<" do
end
end
end

View file

@ -52,4 +52,3 @@ describe "Integer#<=" do
end
end
end

View file

@ -4,4 +4,3 @@ require_relative 'shared/abs'
describe "Integer#magnitude" do
it_behaves_like :integer_abs, :magnitude
end

View file

@ -47,4 +47,3 @@ describe "Integer#-" do
end
end
end

View file

@ -49,4 +49,3 @@ describe "Integer#*" do
end
end
end

View file

@ -47,4 +47,3 @@ describe "Integer#+" do
end
end
end

View file

@ -9,4 +9,3 @@ end
describe "IO#pos=" do
it_behaves_like :io_set_pos, :pos=
end

View file

@ -51,4 +51,3 @@ describe IO, "#print" do
lambda { IOSpecs.closed_io.print("stuff") }.should raise_error(IOError)
end
end

View file

@ -69,4 +69,25 @@ describe :io_write, shared: true do
lambda { IOSpecs.closed_io.send(@method, "hello") }.should raise_error(IOError)
end
describe "on a pipe" do
before :each do
@r, @w = IO.pipe
end
after :each do
@r.close
@w.close
end
it "writes the given String to the pipe" do
@w.send(@method, "foo")
@w.close
@r.read.should == "foo"
end
it "raises Errno::EPIPE if the read end is closed" do
@r.close
-> { @w.send(@method, "foo") }.should raise_error(Errno::EPIPE, "Broken pipe")
end
end
end

View file

@ -8,4 +8,3 @@ describe "Kernel#eql?" do
it_behaves_like :object_equal, :eql?
end

View file

@ -213,4 +213,132 @@ describe "Kernel#eval" do
code = fixture __FILE__, "eval_return_without_lambda.rb"
ruby_exe(code).chomp.should == "a,b,c,e,LocalJumpError,f"
end
describe "with a magic encoding comment" do
it "uses the magic comment encoding for the encoding of literal strings" do
code = "# encoding: UTF-8\n'é'.encoding".b
code.encoding.should == Encoding::BINARY
eval(code).should == Encoding::UTF_8
end
it "uses the magic comment encoding for parsing constants" do
code = <<CODE.b
# encoding: UTF-8
class EvalSpecs
= 3.14
end
CODE
code.encoding.should == Encoding::BINARY
eval(code)
EvalSpecs.constants(false).should include(:"")
EvalSpecs::.should == 3.14
end
it "allows an emacs-style magic comment encoding" do
code = <<CODE.b
# -*- encoding: UTF-8 -*-
class EvalSpecs
Vπemacs = 3.14
end
CODE
code.encoding.should == Encoding::BINARY
eval(code)
EvalSpecs.constants(false).should include(:"Vπemacs")
EvalSpecs::Vπemacs.should == 3.14
end
it "allows spaces before the magic encoding comment" do
code = <<CODE.b
\t \t # encoding: UTF-8
class EvalSpecs
Vπspaces = 3.14
end
CODE
code.encoding.should == Encoding::BINARY
eval(code)
EvalSpecs.constants(false).should include(:"Vπspaces")
EvalSpecs::Vπspaces.should == 3.14
end
it "allows a shebang line before the magic encoding comment" do
code = <<CODE.b
#!/usr/bin/env ruby
# encoding: UTF-8
class EvalSpecs
Vπshebang = 3.14
end
CODE
code.encoding.should == Encoding::BINARY
eval(code)
EvalSpecs.constants(false).should include(:"Vπshebang")
EvalSpecs::Vπshebang.should == 3.14
end
it "allows a shebang line and some spaces before the magic encoding comment" do
code = <<CODE.b
#!/usr/bin/env ruby
# encoding: UTF-8
class EvalSpecs
Vπshebang_spaces = 3.14
end
CODE
code.encoding.should == Encoding::BINARY
eval(code)
EvalSpecs.constants(false).should include(:"Vπshebang_spaces")
EvalSpecs::Vπshebang_spaces.should == 3.14
end
it "allows a magic encoding comment and a subsequent frozen_string_literal magic comment" do
# Make sure frozen_string_literal is not default true
eval("'foo'".b).frozen?.should be_false
code = <<CODE.b
# encoding: UTF-8
# frozen_string_literal: true
class EvalSpecs
Vπstring = "frozen"
end
CODE
code.encoding.should == Encoding::BINARY
eval(code)
EvalSpecs.constants(false).should include(:"Vπstring")
EvalSpecs::Vπstring.should == "frozen"
EvalSpecs::Vπstring.encoding.should == Encoding::UTF_8
EvalSpecs::Vπstring.frozen?.should be_true
end
it "allows a magic encoding comment and a frozen_string_literal magic comment on the same line in emacs style" do
code = <<CODE.b
# -*- encoding: UTF-8; frozen_string_literal: true -*-
class EvalSpecs
Vπsame_line = "frozen"
end
CODE
code.encoding.should == Encoding::BINARY
eval(code)
EvalSpecs.constants(false).should include(:"Vπsame_line")
EvalSpecs::Vπsame_line.should == "frozen"
EvalSpecs::Vπsame_line.encoding.should == Encoding::UTF_8
EvalSpecs::Vπsame_line.frozen?.should be_true
end
it "ignores the magic encoding comment if it is after a frozen_string_literal magic comment" do
code = <<CODE.b
# frozen_string_literal: true
# encoding: UTF-8
class EvalSpecs
Vπfrozen_first = "frozen"
end
CODE
code.encoding.should == Encoding::BINARY
eval(code)
EvalSpecs.constants(false).should_not include(:"Vπfrozen_first")
binary_constant = "Vπfrozen_first".b.to_sym
EvalSpecs.constants(false).should include(binary_constant)
value = EvalSpecs.const_get(binary_constant)
value.should == "frozen"
value.encoding.should == Encoding::BINARY
value.frozen?.should be_true
end
end
end

View file

@ -83,4 +83,3 @@ describe "Kernel.lambda" do
KernelSpecs::Lambda.new.outer.should == :good
end
end

View file

@ -58,4 +58,3 @@ describe "Kernel.printf" do
end
end
end

View file

@ -53,4 +53,3 @@ describe "Module#protected" do
end.should raise_error(NameError)
end
end

View file

@ -55,4 +55,3 @@ describe "String#clone" do
clone.should == "string"
end
end

View file

@ -11,4 +11,3 @@ describe "String#%" do
format % args
}
end

View file

@ -24,4 +24,3 @@ describe "SystemExit#initialize" do
s.status.should == 0
end
end

View file

@ -6,4 +6,3 @@ require_relative 'shared/wakeup'
describe "Thread#run" do
it_behaves_like :thread_wakeup, :run
end

View file

@ -53,4 +53,3 @@ describe "Time#_dump" do
t.send(:_dump).should == "\364\001\031\200\313\000\020\004"
end
end

View file

@ -17,4 +17,3 @@ ruby_version_is '2.4' do
end
end
end

View file

@ -31,4 +31,3 @@ module MetaClassSpecs
class D < C; end
end

View file

@ -32,4 +32,3 @@ describe "BigDecimal#finite?" do
end
end
end

View file

@ -46,4 +46,3 @@ describe "BigDecimal#precs" do
end
end
end

View file

@ -10,4 +10,3 @@ describe "BigDecimal#quo" do
BigDecimal("NaN").quo(BigDecimal("1")).nan?.should == true
end
end

View file

@ -44,4 +44,3 @@ describe "BigDecimal#sign" do
end
end

View file

@ -84,5 +84,3 @@ describe "BigDecimal#split" do
end
end

View file

@ -52,4 +52,3 @@ describe "BigDecimal#to_f" do
@zero_neg.to_f.to_s.should == "-0.0"
end
end

View file

@ -70,4 +70,3 @@ describe "BigDecimal#to_s" do
end
end

View file

@ -15,6 +15,3 @@ describe "BigDecimal#+@" do
fifth.send(:+@).should == fifth
end
end

View file

@ -25,4 +25,3 @@ describe "BigDecimal#zero?" do
end
end

View file

@ -15,4 +15,3 @@ end
# 17 18 19 20 21 22 23
# 24 25 26 27 28 29 30
# 31

View file

@ -13,4 +13,3 @@ describe "Date#gregorian_leap?" do
Date.gregorian_leap?(2002).should be_false
end
end

View file

@ -5,4 +5,3 @@ require_relative 'shared/ordinal'
describe "Date.ordinal" do
it_behaves_like :date_ordinal, :ordinal
end

View file

@ -7,4 +7,3 @@ describe "Date#valid_civil?" do
it_behaves_like :date_valid_civil?, :valid_civil?
end

View file

@ -6,5 +6,3 @@ describe "Date#valid_commercial?" do
it_behaves_like :date_valid_commercial?, :valid_commercial?
end

View file

@ -7,4 +7,3 @@ describe "Date.valid_jd?" do
it_behaves_like :date_valid_jd?, :valid_jd?
end

View file

@ -7,4 +7,3 @@ describe "Date.valid_ordinal?" do
it_behaves_like :date_valid_ordinal?, :valid_ordinal?
end

View file

@ -9,4 +9,3 @@ describe "Digest::MD5#block_length" do
end
end

View file

@ -9,4 +9,3 @@ describe "Digest::MD5#digest_length" do
end
end

View file

@ -35,4 +35,3 @@ describe "Digest::MD5#==" do
end
end

View file

@ -9,4 +9,3 @@ describe "Digest::MD5#inspect" do
end
end

View file

@ -5,4 +5,3 @@ require_relative 'shared/length'
describe "Digest::MD5#length" do
it_behaves_like :md5_length, :length
end

View file

@ -12,4 +12,3 @@ describe "Digest::MD5#reset" do
end
end

View file

@ -5,4 +5,3 @@ require_relative 'shared/length'
describe "Digest::MD5#size" do
it_behaves_like :md5_length, :size
end

View file

@ -9,4 +9,3 @@ describe "Digest::SHA256#block_length" do
end
end

View file

@ -9,4 +9,3 @@ describe "Digest::SHA256#digest_length" do
end
end

View file

@ -34,4 +34,3 @@ describe "Digest::SHA256#==" do
end
end

View file

@ -9,4 +9,3 @@ describe "Digest::SHA256#inspect" do
end
end

View file

@ -5,4 +5,3 @@ require_relative 'shared/length'
describe "Digest::SHA256#length" do
it_behaves_like :sha256_length, :length
end

View file

@ -12,4 +12,3 @@ describe "Digest::SHA256#reset" do
end
end

View file

@ -5,4 +5,3 @@ require_relative 'shared/length'
describe "Digest::SHA256#size" do
it_behaves_like :sha256_length, :size
end

View file

@ -9,4 +9,3 @@ describe "Digest::SHA384#block_length" do
end
end

View file

@ -9,4 +9,3 @@ describe "Digest::SHA384#digest_length" do
end
end

View file

@ -34,4 +34,3 @@ describe "Digest::SHA384#==" do
end
end

View file

@ -9,4 +9,3 @@ describe "Digest::SHA384#inspect" do
end
end

View file

@ -5,4 +5,3 @@ require_relative 'shared/length'
describe "Digest::SHA384#length" do
it_behaves_like :sha384_length, :length
end

View file

@ -12,4 +12,3 @@ describe "Digest::SHA384#reset" do
end
end

View file

@ -5,4 +5,3 @@ require_relative 'shared/length'
describe "Digest::SHA384#size" do
it_behaves_like :sha384_length, :size
end

View file

@ -9,4 +9,3 @@ describe "Digest::SHA512#block_length" do
end
end

View file

@ -9,4 +9,3 @@ describe "Digest::SHA512#digest_length" do
end
end

View file

@ -34,4 +34,3 @@ describe "Digest::SHA512#==" do
end
end

View file

@ -9,4 +9,3 @@ describe "Digest::SHA512#inspect" do
end
end

View file

@ -5,4 +5,3 @@ require_relative 'shared/length'
describe "Digest::SHA512#length" do
it_behaves_like :sha512_length, :length
end

View file

@ -12,4 +12,3 @@ describe "Digest::SHA512#reset" do
end
end

View file

@ -5,4 +5,3 @@ require_relative 'shared/length'
describe "Digest::SHA512#size" do
it_behaves_like :sha512_length, :size
end

View file

@ -94,4 +94,3 @@ END
}.should raise_error(NameError)
end
end

View file

@ -5,4 +5,3 @@ require_relative 'shared/html_escape'
describe "ERB::Util.html_escape" do
it_behaves_like :erb_util_html_escape, :html_escape
end

View file

@ -5,4 +5,3 @@ require_relative 'shared/url_encode'
describe "ERB::Util.u" do
it_behaves_like :erb_util_url_encode, :u
end

View file

@ -42,5 +42,3 @@ describe "IPAddr#ipv4_mapped" do
end
end

View file

@ -6,4 +6,3 @@ require_relative 'shared/request_head'
describe "Net::HTTP#head2" do
it_behaves_like :net_ftp_request_head, :head2
end

View file

@ -74,4 +74,3 @@ describe "Net::HTTP#post" do
end
end
end

View file

@ -6,4 +6,3 @@ require_relative 'shared/each_capitalized'
describe "Net::HTTPHeader#each_capitalized" do
it_behaves_like :net_httpheader_each_capitalized, :each_capitalized
end

View file

@ -83,4 +83,3 @@ describe "Net::HTTPResponse#read_body" do
end
end
end

View file

@ -20,4 +20,3 @@ describe "Pathname#absolute?" do
end
end

View file

@ -12,4 +12,3 @@ describe "Pathname#==" do
end
end

View file

@ -12,4 +12,3 @@ describe "Pathname#hash" do
end
end

View file

@ -16,4 +16,3 @@ describe "Pathname#parent" do
end
end

View file

@ -20,4 +20,3 @@ describe "Pathname#relative?" do
end
end

View file

@ -24,4 +24,3 @@ describe "Pathname#root?" do
end
end

View file

@ -13,4 +13,3 @@ describe "Pathname#sub" do
end
end

View file

@ -0,0 +1,11 @@
require_relative '../../spec_helper'
require 'rbconfig'
describe 'RbConfig::CONFIG values' do
it 'are all strings' do
RbConfig::CONFIG.each do |k, v|
k.should be_kind_of String
v.should be_kind_of String
end
end
end

Some files were not shown because too many files have changed in this diff Show more