mirror of
https://github.com/ruby/ruby.git
synced 2022-11-09 12:17:21 -05:00
Update to ruby/spec@09fa86c
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@64565 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
parent
a641384815
commit
8180b5bfc0
54 changed files with 606 additions and 111 deletions
|
@ -5,6 +5,8 @@ AllCops:
|
|||
DisplayCopNames: true
|
||||
Exclude:
|
||||
- command_line/fixtures/bad_syntax.rb
|
||||
- language/fixtures/utf16-le-bom.rb
|
||||
- language/fixtures/utf16-be-bom.rb
|
||||
DisabledByDefault: true
|
||||
|
||||
Layout/TrailingWhitespace:
|
||||
|
|
|
@ -110,12 +110,6 @@ Lint/RescueException:
|
|||
- 'language/rescue_spec.rb'
|
||||
- 'library/erb/filename_spec.rb'
|
||||
|
||||
# Offense count: 1
|
||||
# Cop supports --auto-correct.
|
||||
Lint/ScriptPermission:
|
||||
Exclude:
|
||||
- 'command_line/fixtures/bin/launcher.rb'
|
||||
|
||||
# Offense count: 2
|
||||
# Configuration parameters: IgnoreImplicitReferences.
|
||||
Lint/ShadowedArgument:
|
||||
|
|
|
@ -1,3 +1,5 @@
|
|||
require_relative '../spec_helper'
|
||||
|
||||
describe "The -a command line option" do
|
||||
before :each do
|
||||
@names = fixture __FILE__, "full_names.txt"
|
||||
|
|
33
spec/ruby/command_line/dash_encoding_spec.rb
Normal file
33
spec/ruby/command_line/dash_encoding_spec.rb
Normal file
|
@ -0,0 +1,33 @@
|
|||
require_relative '../spec_helper'
|
||||
|
||||
describe 'The --encoding command line option' do
|
||||
before :each do
|
||||
@test_string = "print [Encoding.default_external.name, Encoding.default_internal&.name].inspect"
|
||||
end
|
||||
|
||||
describe 'sets Encoding.default_external and optionally Encoding.default_internal' do
|
||||
it "if given a single encoding with an =" do
|
||||
ruby_exe(@test_string, options: '--disable-gems --encoding=big5').should == [Encoding::Big5.name, nil].inspect
|
||||
end
|
||||
|
||||
it "if given a single encoding as a separate argument" do
|
||||
ruby_exe(@test_string, options: '--disable-gems --encoding big5').should == [Encoding::Big5.name, nil].inspect
|
||||
end
|
||||
|
||||
it "if given two encodings with an =" do
|
||||
ruby_exe(@test_string, options: '--disable-gems --encoding=big5:utf-32be').should == [Encoding::Big5.name, Encoding::UTF_32BE.name].inspect
|
||||
end
|
||||
|
||||
it "if given two encodings as a separate argument" do
|
||||
ruby_exe(@test_string, options: '--disable-gems --encoding big5:utf-32be').should == [Encoding::Big5.name, Encoding::UTF_32BE.name].inspect
|
||||
end
|
||||
|
||||
it "if given two encodings as a separate argument" do
|
||||
ruby_exe(@test_string, options: '--disable-gems --encoding big5:utf-32be').should == [Encoding::Big5.name, Encoding::UTF_32BE.name].inspect
|
||||
end
|
||||
end
|
||||
|
||||
it "does not accept a third encoding" do
|
||||
ruby_exe(@test_string, options: '--disable-gems --encoding big5:utf-32be:utf-32le', args: '2>&1').should =~ /extra argument for --encoding: utf-32le/
|
||||
end
|
||||
end
|
15
spec/ruby/command_line/dash_external_encoding_spec.rb
Normal file
15
spec/ruby/command_line/dash_external_encoding_spec.rb
Normal file
|
@ -0,0 +1,15 @@
|
|||
require_relative '../spec_helper'
|
||||
|
||||
describe 'The --external-encoding command line option sets Encoding.default_external' do
|
||||
before :each do
|
||||
@test_string = "print Encoding.default_external.name"
|
||||
end
|
||||
|
||||
it "if given an encoding with an =" do
|
||||
ruby_exe(@test_string, options: '--external-encoding=big5').should == Encoding::Big5.name
|
||||
end
|
||||
|
||||
it "if given an encoding as a separate argument" do
|
||||
ruby_exe(@test_string, options: '--external-encoding big5').should == Encoding::Big5.name
|
||||
end
|
||||
end
|
15
spec/ruby/command_line/dash_internal_encoding_spec.rb
Normal file
15
spec/ruby/command_line/dash_internal_encoding_spec.rb
Normal file
|
@ -0,0 +1,15 @@
|
|||
require_relative '../spec_helper'
|
||||
|
||||
describe 'The --internal-encoding command line option sets Encoding.default_internal' do
|
||||
before :each do
|
||||
@test_string = "print Encoding.default_internal.name"
|
||||
end
|
||||
|
||||
it "if given an encoding with an =" do
|
||||
ruby_exe(@test_string, options: '--internal-encoding=big5').should == Encoding::Big5.name
|
||||
end
|
||||
|
||||
it "if given an encoding as a separate argument" do
|
||||
ruby_exe(@test_string, options: '--internal-encoding big5').should == Encoding::Big5.name
|
||||
end
|
||||
end
|
|
@ -1,3 +1,5 @@
|
|||
require_relative '../spec_helper'
|
||||
|
||||
describe "The -n command line option" do
|
||||
before :each do
|
||||
@names = fixture __FILE__, "names.txt"
|
||||
|
|
|
@ -1,3 +1,5 @@
|
|||
require_relative '../spec_helper'
|
||||
|
||||
describe "The -p command line option" do
|
||||
before :each do
|
||||
@names = fixture __FILE__, "names.txt"
|
||||
|
|
|
@ -1,3 +1,5 @@
|
|||
require_relative '../spec_helper'
|
||||
|
||||
describe "ruby -E" do
|
||||
it "sets the external encoding with '-E external'" do
|
||||
result = ruby_exe("print Encoding.default_external", options: '-E euc-jp')
|
||||
|
|
|
@ -1,3 +1,5 @@
|
|||
require_relative '../spec_helper'
|
||||
|
||||
describe "the -F command line option" do
|
||||
before :each do
|
||||
@passwd = fixture __FILE__, "passwd_file.txt"
|
||||
|
|
|
@ -1,33 +1,66 @@
|
|||
describe 'The -K command line option sets __ENCODING__' do
|
||||
it "to Encoding::ASCII_8BIT with -Ka" do
|
||||
ruby_exe("print __ENCODING__", options: '-Ka').should == Encoding::ASCII_8BIT.to_s
|
||||
require_relative '../spec_helper'
|
||||
|
||||
describe 'The -K command line option' do
|
||||
before :each do
|
||||
@test_string = "print [__ENCODING__&.name, Encoding.default_external&.name, Encoding.default_internal&.name].inspect"
|
||||
end
|
||||
|
||||
it "to Encoding::ASCII_8BIT with -KA" do
|
||||
ruby_exe("print __ENCODING__", options: '-KA').should == Encoding::ASCII_8BIT.to_s
|
||||
describe 'sets __ENCODING__ and Encoding.default_external' do
|
||||
it "to Encoding::ASCII_8BIT with -Ka" do
|
||||
ruby_exe(@test_string, options: '-Ka').should ==
|
||||
[Encoding::ASCII_8BIT.name, Encoding::ASCII_8BIT.name, nil].inspect
|
||||
end
|
||||
|
||||
it "to Encoding::ASCII_8BIT with -KA" do
|
||||
ruby_exe(@test_string, options: '-KA').should ==
|
||||
[Encoding::ASCII_8BIT.name, Encoding::ASCII_8BIT.name, nil].inspect
|
||||
end
|
||||
|
||||
it "to Encoding::ASCII_8BIT with -Kn" do
|
||||
ruby_exe(@test_string, options: '-Kn').should ==
|
||||
[Encoding::ASCII_8BIT.name, Encoding::ASCII_8BIT.name, nil].inspect
|
||||
end
|
||||
|
||||
it "to Encoding::ASCII_8BIT with -KN" do
|
||||
ruby_exe(@test_string, options: '-KN').should ==
|
||||
[Encoding::ASCII_8BIT.name, Encoding::ASCII_8BIT.name, nil].inspect
|
||||
end
|
||||
|
||||
it "to Encoding::EUC_JP with -Ke" do
|
||||
ruby_exe(@test_string, options: '-Ke').should ==
|
||||
[Encoding::EUC_JP.name, Encoding::EUC_JP.name, nil].inspect
|
||||
end
|
||||
|
||||
it "to Encoding::EUC_JP with -KE" do
|
||||
ruby_exe(@test_string, options: '-KE').should ==
|
||||
[Encoding::EUC_JP.name, Encoding::EUC_JP.name, nil].inspect
|
||||
end
|
||||
|
||||
it "to Encoding::UTF_8 with -Ku" do
|
||||
ruby_exe(@test_string, options: '-Ku').should ==
|
||||
[Encoding::UTF_8.name, Encoding::UTF_8.name, nil].inspect
|
||||
end
|
||||
|
||||
it "to Encoding::UTF_8 with -KU" do
|
||||
ruby_exe(@test_string, options: '-KU').should ==
|
||||
[Encoding::UTF_8.name, Encoding::UTF_8.name, nil].inspect
|
||||
end
|
||||
|
||||
it "to Encoding::Windows_31J with -Ks" do
|
||||
ruby_exe(@test_string, options: '-Ks').should ==
|
||||
[Encoding::Windows_31J.name, Encoding::Windows_31J.name, nil].inspect
|
||||
end
|
||||
|
||||
it "to Encoding::Windows_31J with -KS" do
|
||||
ruby_exe(@test_string, options: '-KS').should ==
|
||||
[Encoding::Windows_31J.name, Encoding::Windows_31J.name, nil].inspect
|
||||
end
|
||||
end
|
||||
|
||||
it "to Encoding::EUC_JP with -Ke" do
|
||||
ruby_exe("print __ENCODING__", options: '-Ke').should == Encoding::EUC_JP.to_s
|
||||
end
|
||||
|
||||
it "to Encoding::EUC_JP with -KE" do
|
||||
ruby_exe("print __ENCODING__", options: '-KE').should == Encoding::EUC_JP.to_s
|
||||
end
|
||||
|
||||
it "to Encoding::UTF_8 with -Ku" do
|
||||
ruby_exe("print __ENCODING__", options: '-Ku').should == Encoding::UTF_8.to_s
|
||||
end
|
||||
|
||||
it "to Encoding::UTF_8 with -KU" do
|
||||
ruby_exe("print __ENCODING__", options: '-KU').should == Encoding::UTF_8.to_s
|
||||
end
|
||||
|
||||
it "to Encoding::Windows_31J with -Ks" do
|
||||
ruby_exe("print __ENCODING__", options: '-Ks').should == Encoding::Windows_31J.to_s
|
||||
end
|
||||
|
||||
it "to Encoding::Windows_31J with -KS" do
|
||||
ruby_exe("print __ENCODING__", options: '-KS').should == Encoding::Windows_31J.to_s
|
||||
platform_is_not :windows do
|
||||
it "ignores unknown codes" do
|
||||
ruby_exe(@test_string, options: '-KZ').should ==
|
||||
[Encoding::UTF_8.name, Encoding::UTF_8.name, nil].inspect
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -1,3 +1,5 @@
|
|||
require_relative '../spec_helper'
|
||||
|
||||
describe "ruby -U" do
|
||||
it "sets Encoding.default_internal to UTF-8" do
|
||||
ruby_exe('print Encoding.default_internal.name',
|
||||
|
|
|
@ -1,3 +1,5 @@
|
|||
require_relative '../spec_helper'
|
||||
|
||||
describe "The -x command line option" do
|
||||
it "runs code after the first /\#!.*ruby.*/-ish line in target file" do
|
||||
embedded_ruby = fixture __FILE__, "bin/embedded_ruby.txt"
|
||||
|
|
0
spec/ruby/command_line/fixtures/bin/launcher.rb
Normal file → Executable file
0
spec/ruby/command_line/fixtures/bin/launcher.rb
Normal file → Executable file
|
@ -214,6 +214,7 @@ describe "Kernel#eval" do
|
|||
ruby_exe(code).chomp.should == "a,b,c,e,LocalJumpError,f"
|
||||
end
|
||||
|
||||
# See language/magic_comment_spec.rb for more magic comments specs
|
||||
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
|
||||
|
|
13
spec/ruby/core/kernel/fixtures/singleton_methods.rb
Normal file
13
spec/ruby/core/kernel/fixtures/singleton_methods.rb
Normal file
|
@ -0,0 +1,13 @@
|
|||
module SingletonMethodsSpecs
|
||||
module Prepended
|
||||
def mspec_test_kernel_singleton_methods
|
||||
end
|
||||
public :mspec_test_kernel_singleton_methods
|
||||
end
|
||||
|
||||
::Module.prepend Prepended
|
||||
|
||||
module SelfExtending
|
||||
extend self
|
||||
end
|
||||
end
|
|
@ -36,6 +36,19 @@ describe :kernel_singleton_methods_modules, shared: true do
|
|||
it "does not return any included methods for a class including a module" do
|
||||
ReflectSpecs::D.singleton_methods(*@object).should include(:ds_pro, :ds_pub)
|
||||
end
|
||||
|
||||
it "for a module does not return methods in a module prepended to Module itself" do
|
||||
require_relative 'fixtures/singleton_methods'
|
||||
mod = SingletonMethodsSpecs::SelfExtending
|
||||
mod.method(:mspec_test_kernel_singleton_methods).owner.should == SingletonMethodsSpecs::Prepended
|
||||
|
||||
ancestors = mod.singleton_class.ancestors
|
||||
ancestors[0...2].should == [ mod.singleton_class, mod ]
|
||||
ancestors.should include(SingletonMethodsSpecs::Prepended)
|
||||
|
||||
# Do not search prepended modules of `Module`, as that's a non-singleton class
|
||||
mod.singleton_methods.should == []
|
||||
end
|
||||
end
|
||||
|
||||
describe :kernel_singleton_methods_supers, shared: true do
|
||||
|
@ -145,7 +158,6 @@ describe "Kernel#singleton_methods" do
|
|||
it_behaves_like :kernel_singleton_methods_supers, nil, true
|
||||
it_behaves_like :kernel_singleton_methods_modules, nil, true
|
||||
it_behaves_like :kernel_singleton_methods_private_supers, nil, true
|
||||
|
||||
end
|
||||
|
||||
describe "when passed false" do
|
||||
|
|
|
@ -594,6 +594,30 @@ describe "Module#refine" do
|
|||
end
|
||||
end
|
||||
|
||||
it 'and alias aliases a method within a refinement module, but not outside it' do
|
||||
Module.new do
|
||||
using Module.new {
|
||||
refine Array do
|
||||
alias :orig_count :count
|
||||
end
|
||||
}
|
||||
[1,2].orig_count.should == 2
|
||||
end
|
||||
lambda { [1,2].orig_count }.should raise_error(NoMethodError)
|
||||
end
|
||||
|
||||
it 'and alias_method aliases a method within a refinement module, but not outside it' do
|
||||
Module.new do
|
||||
using Module.new {
|
||||
refine Array do
|
||||
alias_method :orig_count, :count
|
||||
end
|
||||
}
|
||||
[1,2].orig_count.should == 2
|
||||
end
|
||||
lambda { [1,2].orig_count }.should raise_error(NoMethodError)
|
||||
end
|
||||
|
||||
# Refinements are inherited by module inclusion.
|
||||
# That is, using activates all refinements in the ancestors of the specified module.
|
||||
# Refinements in a descendant have priority over refinements in an ancestor.
|
||||
|
|
|
@ -158,9 +158,28 @@ platform_is_not :windows do
|
|||
$?.exitstatus.should == 0
|
||||
end
|
||||
|
||||
it "returns 'DEFAULT' for the initial SIGINT handler" do
|
||||
ruby_exe('print trap(:INT) { abort }').should == 'DEFAULT'
|
||||
end
|
||||
|
||||
it "returns SYSTEM_DEFAULT if passed DEFAULT and no handler was ever set" do
|
||||
Signal.trap("PROF", "DEFAULT").should == "SYSTEM_DEFAULT"
|
||||
end
|
||||
|
||||
it "accepts 'SYSTEM_DEFAULT' and uses the OS handler for SIGPIPE" do
|
||||
code = <<-RUBY
|
||||
p Signal.trap('PIPE', 'SYSTEM_DEFAULT')
|
||||
r, w = IO.pipe
|
||||
r.close
|
||||
loop { w.write("a"*1024) }
|
||||
RUBY
|
||||
out = ruby_exe(code)
|
||||
status = $?
|
||||
out.should == "nil\n"
|
||||
status.signaled?.should == true
|
||||
status.termsig.should be_kind_of(Integer)
|
||||
Signal.signame(status.termsig).should == "PIPE"
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
|
|
|
@ -44,6 +44,11 @@ class MSpecScript
|
|||
[/_spec.rb$/, '_tags.txt']
|
||||
]
|
||||
|
||||
set :toplevel_constants_excludes, [
|
||||
/\wSpecs?$/,
|
||||
/^CS_CONST\d/,
|
||||
]
|
||||
|
||||
# Enable features
|
||||
MSpec.enable_feature :fiber
|
||||
MSpec.enable_feature :fiber_library
|
||||
|
|
2
spec/ruby/language/fixtures/bytes_magic_comment.rb
Normal file
2
spec/ruby/language/fixtures/bytes_magic_comment.rb
Normal file
|
@ -0,0 +1,2 @@
|
|||
# encoding: big5
|
||||
$magic_comment_result = '§A¦n'.bytes.inspect
|
2
spec/ruby/language/fixtures/case_magic_comment.rb
Normal file
2
spec/ruby/language/fixtures/case_magic_comment.rb
Normal file
|
@ -0,0 +1,2 @@
|
|||
# CoDiNg: bIg5
|
||||
$magic_comment_result = __ENCODING__.name
|
2
spec/ruby/language/fixtures/emacs_magic_comment.rb
Normal file
2
spec/ruby/language/fixtures/emacs_magic_comment.rb
Normal file
|
@ -0,0 +1,2 @@
|
|||
# -*- encoding: big5 -*-
|
||||
$magic_comment_result = __ENCODING__.name
|
2
spec/ruby/language/fixtures/magic_comment.rb
Normal file
2
spec/ruby/language/fixtures/magic_comment.rb
Normal file
|
@ -0,0 +1,2 @@
|
|||
# encoding: big5
|
||||
$magic_comment_result = __ENCODING__.name
|
1
spec/ruby/language/fixtures/no_magic_comment.rb
Normal file
1
spec/ruby/language/fixtures/no_magic_comment.rb
Normal file
|
@ -0,0 +1 @@
|
|||
$magic_comment_result = __ENCODING__.name
|
|
@ -0,0 +1,3 @@
|
|||
at_exit {
|
||||
print $magic_comment_result
|
||||
}
|
3
spec/ruby/language/fixtures/second_line_magic_comment.rb
Normal file
3
spec/ruby/language/fixtures/second_line_magic_comment.rb
Normal file
|
@ -0,0 +1,3 @@
|
|||
|
||||
# encoding: big5
|
||||
$magic_comment_result = __ENCODING__.name
|
|
@ -0,0 +1,2 @@
|
|||
1 + 1 # encoding: big5
|
||||
$magic_comment_result = __ENCODING__.name
|
3
spec/ruby/language/fixtures/shebang_magic_comment.rb
Executable file
3
spec/ruby/language/fixtures/shebang_magic_comment.rb
Executable file
|
@ -0,0 +1,3 @@
|
|||
#!/usr/bin/ruby
|
||||
# encoding: big5
|
||||
$magic_comment_result = __ENCODING__.name
|
BIN
spec/ruby/language/fixtures/utf16-be-bom.rb
Normal file
BIN
spec/ruby/language/fixtures/utf16-be-bom.rb
Normal file
Binary file not shown.
BIN
spec/ruby/language/fixtures/utf16-be-nobom.rb
Normal file
BIN
spec/ruby/language/fixtures/utf16-be-nobom.rb
Normal file
Binary file not shown.
BIN
spec/ruby/language/fixtures/utf16-le-bom.rb
Normal file
BIN
spec/ruby/language/fixtures/utf16-le-bom.rb
Normal file
Binary file not shown.
BIN
spec/ruby/language/fixtures/utf16-le-nobom.rb
Normal file
BIN
spec/ruby/language/fixtures/utf16-le-nobom.rb
Normal file
Binary file not shown.
2
spec/ruby/language/fixtures/utf8-bom.rb
Normal file
2
spec/ruby/language/fixtures/utf8-bom.rb
Normal file
|
@ -0,0 +1,2 @@
|
|||
# encoding: utf-8
|
||||
puts 'hello'
|
2
spec/ruby/language/fixtures/utf8-nobom.rb
Normal file
2
spec/ruby/language/fixtures/utf8-nobom.rb
Normal file
|
@ -0,0 +1,2 @@
|
|||
# encoding: utf-8
|
||||
puts 'hello'
|
2
spec/ruby/language/fixtures/vim_magic_comment.rb
Normal file
2
spec/ruby/language/fixtures/vim_magic_comment.rb
Normal file
|
@ -0,0 +1,2 @@
|
|||
# vim: filetype=ruby, fileencoding=big5, tabsize=3, shiftwidth=3
|
||||
$magic_comment_result = __ENCODING__.name
|
|
@ -1,62 +1,88 @@
|
|||
require_relative '../spec_helper'
|
||||
|
||||
describe "Magic comment" do
|
||||
it "is optional" do
|
||||
eval("__ENCODING__").should be_an_instance_of(Encoding)
|
||||
# See core/kernel/eval_spec.rb for more magic comments specs for eval()
|
||||
describe :magic_comments, shared: true do
|
||||
it "are optional" do
|
||||
@object.call('no_magic_comment.rb').should == Encoding::UTF_8.name
|
||||
end
|
||||
|
||||
it "determines __ENCODING__" do
|
||||
eval(<<EOS.force_encoding("US-ASCII")).should == Encoding::ASCII_8BIT
|
||||
# encoding: ASCII-8BIT
|
||||
__ENCODING__
|
||||
EOS
|
||||
end
|
||||
|
||||
it "is case-insensitive" do
|
||||
eval(<<EOS.force_encoding("US-ASCII")).should == Encoding::ASCII_8BIT
|
||||
# CoDiNg: aScIi-8bIt
|
||||
__ENCODING__
|
||||
EOS
|
||||
it "are case-insensitive" do
|
||||
@object.call('case_magic_comment.rb').should == Encoding::Big5.name
|
||||
end
|
||||
|
||||
it "must be at the first line" do
|
||||
eval(<<EOS.force_encoding("US-ASCII")).should == Encoding::US_ASCII
|
||||
|
||||
# encoding: ASCII-8BIT
|
||||
__ENCODING__
|
||||
EOS
|
||||
@object.call('second_line_magic_comment.rb').should == Encoding::UTF_8.name
|
||||
end
|
||||
|
||||
it "must be the first token of the line" do
|
||||
eval(<<EOS.force_encoding("US-ASCII")).should == Encoding::US_ASCII
|
||||
1+1 # encoding: ASCII-8BIT
|
||||
__ENCODING__
|
||||
EOS
|
||||
eval(<<EOS.force_encoding("US-ASCII")).should == Encoding::ASCII_8BIT
|
||||
# encoding: ASCII-8BIT
|
||||
__ENCODING__
|
||||
EOS
|
||||
@object.call('second_token_magic_comment.rb').should == Encoding::UTF_8.name
|
||||
end
|
||||
|
||||
it "can be after the shebang" do
|
||||
eval(<<EOS.force_encoding("US-ASCII")).should == Encoding::ASCII_8BIT
|
||||
#!/usr/bin/ruby -Ku
|
||||
# encoding: ASCII-8BIT
|
||||
__ENCODING__
|
||||
EOS
|
||||
@object.call('shebang_magic_comment.rb').should == Encoding::Big5.name
|
||||
end
|
||||
|
||||
it "can take Emacs style" do
|
||||
eval(<<EOS.force_encoding("US-ASCII")).should == Encoding::ASCII_8BIT
|
||||
# -*- encoding: ascii-8bit -*-
|
||||
__ENCODING__
|
||||
EOS
|
||||
@object.call('emacs_magic_comment.rb').should == Encoding::Big5.name
|
||||
end
|
||||
|
||||
it "can take vim style" do
|
||||
eval(<<EOS.force_encoding("US-ASCII")).should == Encoding::ASCII_8BIT
|
||||
# vim: filetype=ruby, fileencoding=ascii-8bit, tabsize=3, shiftwidth=3
|
||||
__ENCODING__
|
||||
EOS
|
||||
@object.call('vim_magic_comment.rb').should == Encoding::Big5.name
|
||||
end
|
||||
|
||||
it "determine __ENCODING__" do
|
||||
@object.call('magic_comment.rb').should == Encoding::Big5.name
|
||||
end
|
||||
|
||||
it "do not cause bytes to be mangled by passing them through the wrong encoding" do
|
||||
@object.call('bytes_magic_comment.rb').should == [167, 65, 166, 110].inspect
|
||||
end
|
||||
end
|
||||
|
||||
describe "Magic comments" do
|
||||
platform_is_not :windows do
|
||||
describe "in stdin" do
|
||||
it_behaves_like :magic_comments, nil, -> file {
|
||||
print_at_exit = fixture(__FILE__, "print_magic_comment_result_at_exit.rb")
|
||||
ruby_exe(nil, args: "< #{fixture(__FILE__, file)}", options: "-r#{print_at_exit}")
|
||||
}
|
||||
end
|
||||
|
||||
describe "in an -e argument" do
|
||||
it_behaves_like :magic_comments, nil, -> file {
|
||||
print_at_exit = fixture(__FILE__, "print_magic_comment_result_at_exit.rb")
|
||||
# Use UTF-8, as it is the default source encoding for files
|
||||
code = File.read(fixture(__FILE__, file), encoding: 'utf-8')
|
||||
IO.popen([*ruby_exe, "-r", print_at_exit, "-e", code], &:read)
|
||||
}
|
||||
end
|
||||
end
|
||||
|
||||
describe "in the main file" do
|
||||
it_behaves_like :magic_comments, nil, -> file {
|
||||
print_at_exit = fixture(__FILE__, "print_magic_comment_result_at_exit.rb")
|
||||
ruby_exe(fixture(__FILE__, file), options: "-r#{print_at_exit}")
|
||||
}
|
||||
end
|
||||
|
||||
describe "in a loaded file" do
|
||||
it_behaves_like :magic_comments, nil, -> file {
|
||||
load fixture(__FILE__, file)
|
||||
$magic_comment_result
|
||||
}
|
||||
end
|
||||
|
||||
describe "in a required file" do
|
||||
it_behaves_like :magic_comments, nil, -> file {
|
||||
require fixture(__FILE__, file)
|
||||
$magic_comment_result
|
||||
}
|
||||
end
|
||||
|
||||
describe "in an eval" do
|
||||
it_behaves_like :magic_comments, nil, -> file {
|
||||
# Use UTF-8, as it is the default source encoding for files
|
||||
eval(File.read(fixture(__FILE__, file), encoding: 'utf-8'))
|
||||
}
|
||||
end
|
||||
end
|
||||
|
|
|
@ -252,7 +252,11 @@ describe 'Optional variable assignments' do
|
|||
end
|
||||
|
||||
describe 'using compunded constants' do
|
||||
before do
|
||||
before :each do
|
||||
Object.send(:remove_const, :A) if defined? Object::A
|
||||
end
|
||||
|
||||
after :each do
|
||||
Object.send(:remove_const, :A) if defined? Object::A
|
||||
end
|
||||
|
||||
|
|
|
@ -23,6 +23,18 @@ describe "The DATA constant" do
|
|||
str.chomp.should == "data only"
|
||||
end
|
||||
|
||||
it "returns a File object with the right offset" do
|
||||
ruby_exe(fixture(__FILE__, "data_offset.rb")).should == "File\n121\n"
|
||||
end
|
||||
|
||||
it "is set even if there is no data after __END__" do
|
||||
ruby_exe(fixture(__FILE__, "empty_data.rb")).should == "31\n\"\"\n"
|
||||
end
|
||||
|
||||
it "is set even if there is no newline after __END__" do
|
||||
ruby_exe(fixture(__FILE__, "no_newline_data.rb")).should == "30\n\"\"\n"
|
||||
end
|
||||
|
||||
it "rewinds to the head of the main script" do
|
||||
ruby_exe(fixture(__FILE__, "data5.rb")).chomp.should == "DATA.rewind"
|
||||
end
|
||||
|
|
12
spec/ruby/language/predefined/fixtures/data_offset.rb
Normal file
12
spec/ruby/language/predefined/fixtures/data_offset.rb
Normal file
|
@ -0,0 +1,12 @@
|
|||
# some comment
|
||||
|
||||
foo = <<HEREDOC
|
||||
some heredoc to make the
|
||||
spec more interesting
|
||||
HEREDOC
|
||||
|
||||
p DATA.class
|
||||
p DATA.pos
|
||||
|
||||
__END__
|
||||
data offset
|
3
spec/ruby/language/predefined/fixtures/empty_data.rb
Normal file
3
spec/ruby/language/predefined/fixtures/empty_data.rb
Normal file
|
@ -0,0 +1,3 @@
|
|||
p DATA.pos
|
||||
p DATA.read
|
||||
__END__
|
|
@ -0,0 +1,3 @@
|
|||
p DATA.pos
|
||||
p DATA.read
|
||||
__END__
|
97
spec/ruby/language/safe_spec.rb
Normal file
97
spec/ruby/language/safe_spec.rb
Normal file
|
@ -0,0 +1,97 @@
|
|||
require_relative '../spec_helper'
|
||||
|
||||
describe "The $SAFE variable" do
|
||||
|
||||
ruby_version_is "2.6" do
|
||||
after :each do
|
||||
$SAFE = 0
|
||||
end
|
||||
end
|
||||
|
||||
it "is 0 by default" do
|
||||
$SAFE.should == 0
|
||||
proc {
|
||||
$SAFE.should == 0
|
||||
}.call
|
||||
end
|
||||
|
||||
it "can be set to 0" do
|
||||
proc {
|
||||
$SAFE = 0
|
||||
$SAFE.should == 0
|
||||
}.call
|
||||
end
|
||||
|
||||
it "can be set to 1" do
|
||||
proc {
|
||||
$SAFE = 1
|
||||
$SAFE.should == 1
|
||||
}.call
|
||||
end
|
||||
|
||||
[2, 3, 4].each do |n|
|
||||
it "cannot be set to #{n}" do
|
||||
lambda {
|
||||
proc {
|
||||
$SAFE = n
|
||||
}.call
|
||||
}.should raise_error(ArgumentError, /\$SAFE=2 to 4 are obsolete/)
|
||||
end
|
||||
end
|
||||
|
||||
ruby_version_is ""..."2.6" do
|
||||
it "cannot be set to values below 0" do
|
||||
lambda {
|
||||
proc {
|
||||
$SAFE = -100
|
||||
}.call
|
||||
}.should raise_error(SecurityError, /tried to downgrade safe level from 0 to -100/)
|
||||
end
|
||||
end
|
||||
|
||||
it "cannot be set to values above 4" do
|
||||
lambda {
|
||||
proc {
|
||||
$SAFE = 100
|
||||
}.call
|
||||
}.should raise_error(ArgumentError, /\$SAFE=2 to 4 are obsolete/)
|
||||
end
|
||||
|
||||
ruby_version_is ""..."2.6" do
|
||||
it "cannot be manually lowered" do
|
||||
proc {
|
||||
$SAFE = 1
|
||||
lambda {
|
||||
$SAFE = 0
|
||||
}.should raise_error(SecurityError, /tried to downgrade safe level from 1 to 0/)
|
||||
}.call
|
||||
end
|
||||
|
||||
it "is automatically lowered when leaving a proc" do
|
||||
$SAFE.should == 0
|
||||
proc {
|
||||
$SAFE = 1
|
||||
}.call
|
||||
$SAFE.should == 0
|
||||
end
|
||||
|
||||
it "is automatically lowered when leaving a lambda" do
|
||||
$SAFE.should == 0
|
||||
lambda {
|
||||
$SAFE = 1
|
||||
}.call
|
||||
$SAFE.should == 0
|
||||
end
|
||||
end
|
||||
|
||||
it "can be read when default from Thread#safe_level" do
|
||||
Thread.current.safe_level.should == 0
|
||||
end
|
||||
|
||||
it "can be read when modified from Thread#safe_level" do
|
||||
proc {
|
||||
$SAFE = 1
|
||||
Thread.current.safe_level.should == 1
|
||||
}.call
|
||||
end
|
||||
end
|
41
spec/ruby/language/source_encoding_spec.rb
Normal file
41
spec/ruby/language/source_encoding_spec.rb
Normal file
|
@ -0,0 +1,41 @@
|
|||
require_relative '../spec_helper'
|
||||
|
||||
describe "Source files" do
|
||||
|
||||
describe "encoded in UTF-8 without a BOM" do
|
||||
it "can be parsed" do
|
||||
ruby_exe(fixture(__FILE__, "utf8-nobom.rb"), args: "2>&1").should == "hello\n"
|
||||
end
|
||||
end
|
||||
|
||||
describe "encoded in UTF-8 with a BOM" do
|
||||
it "can be parsed" do
|
||||
ruby_exe(fixture(__FILE__, "utf8-bom.rb"), args: "2>&1").should == "hello\n"
|
||||
end
|
||||
end
|
||||
|
||||
describe "encoded in UTF-16 LE without a BOM" do
|
||||
it "are parsed because empty as they contain a NUL byte before the encoding comment" do
|
||||
ruby_exe(fixture(__FILE__, "utf16-le-nobom.rb"), args: "2>&1").should == ""
|
||||
end
|
||||
end
|
||||
|
||||
describe "encoded in UTF-16 LE with a BOM" do
|
||||
it "are invalid because they contain an invalid UTF-8 sequence before the encoding comment" do
|
||||
ruby_exe(fixture(__FILE__, "utf16-le-bom.rb"), args: "2>&1").should =~ /invalid multibyte char/
|
||||
end
|
||||
end
|
||||
|
||||
describe "encoded in UTF-16 BE without a BOM" do
|
||||
it "are parsed as empty because they contain a NUL byte before the encoding comment" do
|
||||
ruby_exe(fixture(__FILE__, "utf16-be-nobom.rb"), args: "2>&1").should == ""
|
||||
end
|
||||
end
|
||||
|
||||
describe "encoded in UTF-16 BE with a BOM" do
|
||||
it "are invalid because they contain an invalid UTF-8 sequence before the encoding comment" do
|
||||
ruby_exe(fixture(__FILE__, "utf16-be-bom.rb"), args: "2>&1").should =~ /invalid multibyte char/
|
||||
end
|
||||
end
|
||||
|
||||
end
|
14
spec/ruby/library/etc/confstr_spec.rb
Normal file
14
spec/ruby/library/etc/confstr_spec.rb
Normal file
|
@ -0,0 +1,14 @@
|
|||
require File.expand_path('../../../spec_helper', __FILE__)
|
||||
require 'etc'
|
||||
|
||||
platform_is_not :windows do
|
||||
describe "Etc.confstr" do
|
||||
it "returns a String for Etc::CS_PATH" do
|
||||
Etc.confstr(Etc::CS_PATH).should be_an_instance_of(String)
|
||||
end
|
||||
|
||||
it "raises Errno::EINVAL for unknown configuration variables" do
|
||||
-> { Etc.confstr(-1) }.should raise_error(Errno::EINVAL)
|
||||
end
|
||||
end
|
||||
end
|
|
@ -6,6 +6,15 @@ describe "Etc.group" do
|
|||
it_behaves_like :etc_on_windows, :group
|
||||
|
||||
platform_is_not :windows do
|
||||
it "returns a Etc::Group struct" do
|
||||
group = Etc.group
|
||||
begin
|
||||
group.should be_an_instance_of(Etc::Group)
|
||||
ensure
|
||||
Etc.endgrent
|
||||
end
|
||||
end
|
||||
|
||||
it "raises a RuntimeError for parallel iteration" do
|
||||
proc {
|
||||
Etc.group do | group |
|
||||
|
|
15
spec/ruby/library/etc/passwd_spec.rb
Normal file
15
spec/ruby/library/etc/passwd_spec.rb
Normal file
|
@ -0,0 +1,15 @@
|
|||
require File.expand_path('../../../spec_helper', __FILE__)
|
||||
require 'etc'
|
||||
|
||||
platform_is_not :windows do
|
||||
describe "Etc.passwd" do
|
||||
it "returns a Etc::Passwd struct" do
|
||||
passwd = Etc.passwd
|
||||
begin
|
||||
passwd.should be_an_instance_of(Etc::Passwd)
|
||||
ensure
|
||||
Etc.endpwent
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
31
spec/ruby/library/etc/sysconf_spec.rb
Normal file
31
spec/ruby/library/etc/sysconf_spec.rb
Normal file
|
@ -0,0 +1,31 @@
|
|||
require File.expand_path('../../../spec_helper', __FILE__)
|
||||
require 'etc'
|
||||
|
||||
platform_is_not :windows do
|
||||
describe "Etc.sysconf" do
|
||||
def should_be_integer_or_nil(value)
|
||||
if value.nil?
|
||||
value.should == nil
|
||||
else
|
||||
value.should be_kind_of(Integer)
|
||||
end
|
||||
end
|
||||
|
||||
it "returns the value of POSIX.1 system configuration variables" do
|
||||
Etc.sysconf(Etc::SC_ARG_MAX).should be_kind_of(Integer)
|
||||
should_be_integer_or_nil(Etc.sysconf(Etc::SC_CHILD_MAX))
|
||||
Etc.sysconf(Etc::SC_HOST_NAME_MAX).should be_kind_of(Integer)
|
||||
Etc.sysconf(Etc::SC_LOGIN_NAME_MAX).should be_kind_of(Integer)
|
||||
Etc.sysconf(Etc::SC_NGROUPS_MAX).should be_kind_of(Integer)
|
||||
Etc.sysconf(Etc::SC_CLK_TCK).should be_kind_of(Integer)
|
||||
Etc.sysconf(Etc::SC_OPEN_MAX).should be_kind_of(Integer)
|
||||
Etc.sysconf(Etc::SC_PAGESIZE).should be_kind_of(Integer)
|
||||
Etc.sysconf(Etc::SC_RE_DUP_MAX).should be_kind_of(Integer)
|
||||
Etc.sysconf(Etc::SC_STREAM_MAX).should be_kind_of(Integer)
|
||||
should_be_integer_or_nil(Etc.sysconf(Etc::SC_SYMLOOP_MAX))
|
||||
Etc.sysconf(Etc::SC_TTY_NAME_MAX).should be_kind_of(Integer)
|
||||
Etc.sysconf(Etc::SC_TZNAME_MAX).should be_kind_of(Integer)
|
||||
Etc.sysconf(Etc::SC_VERSION).should be_kind_of(Integer)
|
||||
end
|
||||
end
|
||||
end
|
8
spec/ruby/library/etc/sysconfdir_spec.rb
Normal file
8
spec/ruby/library/etc/sysconfdir_spec.rb
Normal file
|
@ -0,0 +1,8 @@
|
|||
require File.expand_path('../../../spec_helper', __FILE__)
|
||||
require 'etc'
|
||||
|
||||
describe "Etc.sysconfdir" do
|
||||
it "returns a String" do
|
||||
Etc.sysconfdir.should be_an_instance_of(String)
|
||||
end
|
||||
end
|
8
spec/ruby/library/etc/systmpdir_spec.rb
Normal file
8
spec/ruby/library/etc/systmpdir_spec.rb
Normal file
|
@ -0,0 +1,8 @@
|
|||
require File.expand_path('../../../spec_helper', __FILE__)
|
||||
require 'etc'
|
||||
|
||||
describe "Etc.systmpdir" do
|
||||
it "returns a String" do
|
||||
Etc.systmpdir.should be_an_instance_of(String)
|
||||
end
|
||||
end
|
|
@ -53,42 +53,44 @@ describe 'Socket#connect_address' do
|
|||
end
|
||||
end
|
||||
|
||||
describe 'using a socket bound to ::' do
|
||||
before do
|
||||
@sock = Socket.new(:INET6, :STREAM)
|
||||
@sock.bind(Socket.sockaddr_in(0, '::'))
|
||||
end
|
||||
guard -> { SocketSpecs.ipv6_available? } do
|
||||
describe 'using a socket bound to ::' do
|
||||
before do
|
||||
@sock = Socket.new(:INET6, :STREAM)
|
||||
@sock.bind(Socket.sockaddr_in(0, '::'))
|
||||
end
|
||||
|
||||
after do
|
||||
@sock.close
|
||||
end
|
||||
after do
|
||||
@sock.close
|
||||
end
|
||||
|
||||
it 'returns an Addrinfo' do
|
||||
@sock.connect_address.should be_an_instance_of(Addrinfo)
|
||||
end
|
||||
it 'returns an Addrinfo' do
|
||||
@sock.connect_address.should be_an_instance_of(Addrinfo)
|
||||
end
|
||||
|
||||
it 'uses ::1 as the IP address' do
|
||||
@sock.connect_address.ip_address.should == '::1'
|
||||
end
|
||||
it 'uses ::1 as the IP address' do
|
||||
@sock.connect_address.ip_address.should == '::1'
|
||||
end
|
||||
|
||||
it 'uses the correct port number' do
|
||||
@sock.connect_address.ip_port.should > 0
|
||||
end
|
||||
it 'uses the correct port number' do
|
||||
@sock.connect_address.ip_port.should > 0
|
||||
end
|
||||
|
||||
it 'uses AF_INET6 as the address family' do
|
||||
@sock.connect_address.afamily.should == Socket::AF_INET6
|
||||
end
|
||||
it 'uses AF_INET6 as the address family' do
|
||||
@sock.connect_address.afamily.should == Socket::AF_INET6
|
||||
end
|
||||
|
||||
it 'uses PF_INET6 as the address family' do
|
||||
@sock.connect_address.pfamily.should == Socket::PF_INET6
|
||||
end
|
||||
it 'uses PF_INET6 as the address family' do
|
||||
@sock.connect_address.pfamily.should == Socket::PF_INET6
|
||||
end
|
||||
|
||||
it 'uses SOCK_STREAM as the socket type' do
|
||||
@sock.connect_address.socktype.should == Socket::SOCK_STREAM
|
||||
end
|
||||
it 'uses SOCK_STREAM as the socket type' do
|
||||
@sock.connect_address.socktype.should == Socket::SOCK_STREAM
|
||||
end
|
||||
|
||||
it 'uses 0 as the protocol' do
|
||||
@sock.connect_address.protocol.should == 0
|
||||
it 'uses 0 as the protocol' do
|
||||
@sock.connect_address.protocol.should == 0
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
|
|
|
@ -50,7 +50,7 @@ module SocketSpecs
|
|||
def self.ipv6_available?
|
||||
@ipv6_available ||= begin
|
||||
server = TCPServer.new('::1', 0)
|
||||
rescue Errno::EADDRNOTAVAIL
|
||||
rescue Errno::EADDRNOTAVAIL, SocketError
|
||||
:no
|
||||
else
|
||||
server.close
|
||||
|
|
|
@ -20,7 +20,7 @@ void sample_wrapped_struct_mark(void* st) {
|
|||
}
|
||||
|
||||
VALUE sdaf_alloc_func(VALUE klass) {
|
||||
struct sample_wrapped_struct* bar = (struct sample_wrapped_struct *)malloc(sizeof(struct sample_wrapped_struct));
|
||||
struct sample_wrapped_struct* bar = malloc(sizeof(struct sample_wrapped_struct));
|
||||
bar->foo = 42;
|
||||
return Data_Wrap_Struct(klass, &sample_wrapped_struct_mark, &sample_wrapped_struct_free, bar);
|
||||
}
|
||||
|
@ -33,7 +33,7 @@ VALUE sdaf_get_struct(VALUE self) {
|
|||
}
|
||||
|
||||
VALUE sws_wrap_struct(VALUE self, VALUE val) {
|
||||
struct sample_wrapped_struct* bar = (struct sample_wrapped_struct *)malloc(sizeof(struct sample_wrapped_struct));
|
||||
struct sample_wrapped_struct* bar = malloc(sizeof(struct sample_wrapped_struct));
|
||||
bar->foo = FIX2INT(val);
|
||||
return Data_Wrap_Struct(rb_cObject, &sample_wrapped_struct_mark, &sample_wrapped_struct_free, bar);
|
||||
}
|
||||
|
@ -59,7 +59,7 @@ VALUE sws_get_struct_data_ptr(VALUE self, VALUE obj) {
|
|||
|
||||
VALUE sws_change_struct(VALUE self, VALUE obj, VALUE new_val) {
|
||||
struct sample_wrapped_struct *old_struct, *new_struct;
|
||||
new_struct = (struct sample_wrapped_struct *)malloc(sizeof(struct sample_wrapped_struct));
|
||||
new_struct = malloc(sizeof(struct sample_wrapped_struct));
|
||||
new_struct->foo = FIX2INT(new_val);
|
||||
old_struct = RDATA(obj)->data;
|
||||
free(old_struct);
|
||||
|
|
|
@ -64,7 +64,7 @@ end
|
|||
describe "C-API Struct function" do
|
||||
before :each do
|
||||
@s = CApiStructSpecs.new
|
||||
@struct = @s.rb_struct_define_under(CApiStructSpecs, "CAPIStruct", "a", "b", "c")
|
||||
@struct = @s.rb_struct_define_under(CApiStructSpecs, "CAPIStructUnder", "a", "b", "c")
|
||||
end
|
||||
|
||||
describe "rb_struct_define_under" do
|
||||
|
@ -80,11 +80,15 @@ describe "C-API Struct function" do
|
|||
|
||||
it "has a value of nil for the member of a newly created instance" do
|
||||
# Verify that attributes are on an instance basis
|
||||
CApiStructSpecs::CAPIStruct.new.b.should be_nil
|
||||
CApiStructSpecs::CAPIStructUnder.new.b.should be_nil
|
||||
end
|
||||
|
||||
it "does not create a constant scoped under Struct for the named Struct" do
|
||||
Struct.should_not have_constant(:CAPIStructUnder)
|
||||
end
|
||||
|
||||
it "creates a constant scoped under the namespace of the given class" do
|
||||
CApiStructSpecs.should have_constant(:CAPIStruct)
|
||||
CApiStructSpecs.should have_constant(:CAPIStructUnder)
|
||||
end
|
||||
|
||||
it "returns the member names as Symbols" do
|
||||
|
|
Loading…
Reference in a new issue