diff options
author | eregon <eregon@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2018-06-27 12:30:05 +0000 |
---|---|---|
committer | eregon <eregon@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2018-06-27 12:30:05 +0000 |
commit | 9dc121cc577ae7a010bca7efedb79088e3cf7331 (patch) | |
tree | c11a153c7eac91a1e19ed058d5c28f0f7d583622 /spec/ruby/core | |
parent | fc1f3f14d386b557281ff9a8f19da060befe182e (diff) | |
download | ruby-9dc121cc577ae7a010bca7efedb79088e3cf7331.tar.gz |
Update to ruby/spec@a454137
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@63768 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'spec/ruby/core')
35 files changed, 149 insertions, 34 deletions
diff --git a/spec/ruby/core/class/inherited_spec.rb b/spec/ruby/core/class/inherited_spec.rb index 0ec0d84f6e..fb7fb8e75a 100644 --- a/spec/ruby/core/class/inherited_spec.rb +++ b/spec/ruby/core/class/inherited_spec.rb @@ -99,4 +99,3 @@ describe "Class.inherited" do end end - diff --git a/spec/ruby/core/enumerable/zip_spec.rb b/spec/ruby/core/enumerable/zip_spec.rb index d5a059bc5d..1212911697 100644 --- a/spec/ruby/core/enumerable/zip_spec.rb +++ b/spec/ruby/core/enumerable/zip_spec.rb @@ -39,4 +39,3 @@ describe "Enumerable#zip" do end end - diff --git a/spec/ruby/core/env/shared/key.rb b/spec/ruby/core/env/shared/key.rb index 5e6c21840f..c40a56093e 100644 --- a/spec/ruby/core/env/shared/key.rb +++ b/spec/ruby/core/env/shared/key.rb @@ -11,5 +11,3 @@ describe :env_key, shared: true do ENV.send(@method, "should_never_be_set").should be_nil end end - - diff --git a/spec/ruby/core/exception/uncaught_throw_error_spec.rb b/spec/ruby/core/exception/uncaught_throw_error_spec.rb index f4300441a5..57f391d755 100644 --- a/spec/ruby/core/exception/uncaught_throw_error_spec.rb +++ b/spec/ruby/core/exception/uncaught_throw_error_spec.rb @@ -16,4 +16,3 @@ describe "UncaughtThrowError#tag" do end end end - diff --git a/spec/ruby/core/float/shared/arithmetic_exception_in_coerce.rb b/spec/ruby/core/float/shared/arithmetic_exception_in_coerce.rb index 71b540f752..19a02572d8 100644 --- a/spec/ruby/core/float/shared/arithmetic_exception_in_coerce.rb +++ b/spec/ruby/core/float/shared/arithmetic_exception_in_coerce.rb @@ -31,4 +31,3 @@ describe :float_arithmetic_exception_in_coerce, shared: true do end end end - diff --git a/spec/ruby/core/float/shared/comparison_exception_in_coerce.rb b/spec/ruby/core/float/shared/comparison_exception_in_coerce.rb index 6d6f14da30..f8ded53644 100644 --- a/spec/ruby/core/float/shared/comparison_exception_in_coerce.rb +++ b/spec/ruby/core/float/shared/comparison_exception_in_coerce.rb @@ -33,4 +33,3 @@ describe :float_comparison_exception_in_coerce, shared: true do end end end - diff --git a/spec/ruby/core/hash/clone_spec.rb b/spec/ruby/core/hash/clone_spec.rb index bb726e3ec4..6c96fc0c67 100644 --- a/spec/ruby/core/hash/clone_spec.rb +++ b/spec/ruby/core/hash/clone_spec.rb @@ -10,4 +10,3 @@ describe "Hash#clone" do clone.should_not equal hash end end - diff --git a/spec/ruby/core/hash/has_key_spec.rb b/spec/ruby/core/hash/has_key_spec.rb index 55f17d9ccb..4af53579e5 100644 --- a/spec/ruby/core/hash/has_key_spec.rb +++ b/spec/ruby/core/hash/has_key_spec.rb @@ -5,4 +5,3 @@ require_relative 'shared/key' describe "Hash#has_key?" do it_behaves_like :hash_key_p, :has_key? end - diff --git a/spec/ruby/core/hash/has_value_spec.rb b/spec/ruby/core/hash/has_value_spec.rb index 72663d0806..39f1627fd3 100644 --- a/spec/ruby/core/hash/has_value_spec.rb +++ b/spec/ruby/core/hash/has_value_spec.rb @@ -5,4 +5,3 @@ require_relative 'shared/value' describe "Hash#has_value?" do it_behaves_like :hash_value_p, :has_value? end - diff --git a/spec/ruby/core/hash/value_spec.rb b/spec/ruby/core/hash/value_spec.rb index f8cb72bb4a..0ab16a5d1b 100644 --- a/spec/ruby/core/hash/value_spec.rb +++ b/spec/ruby/core/hash/value_spec.rb @@ -5,4 +5,3 @@ require_relative 'shared/value' describe "Hash#value?" do it_behaves_like :hash_value_p, :value? end - diff --git a/spec/ruby/core/integer/abs_spec.rb b/spec/ruby/core/integer/abs_spec.rb index 7509a83a7e..c40356db12 100644 --- a/spec/ruby/core/integer/abs_spec.rb +++ b/spec/ruby/core/integer/abs_spec.rb @@ -4,4 +4,3 @@ require_relative 'shared/abs' describe "Integer#abs" do it_behaves_like :integer_abs, :abs end - diff --git a/spec/ruby/core/integer/divide_spec.rb b/spec/ruby/core/integer/divide_spec.rb index 6fe509b62c..2d49307628 100644 --- a/spec/ruby/core/integer/divide_spec.rb +++ b/spec/ruby/core/integer/divide_spec.rb @@ -93,4 +93,3 @@ describe "Integer#/" do end end end - diff --git a/spec/ruby/core/integer/equal_value_spec.rb b/spec/ruby/core/integer/equal_value_spec.rb index b527f16b1e..67a73713af 100644 --- a/spec/ruby/core/integer/equal_value_spec.rb +++ b/spec/ruby/core/integer/equal_value_spec.rb @@ -4,4 +4,3 @@ require_relative 'shared/equal' describe "Integer#==" do it_behaves_like :integer_equal, :== end - diff --git a/spec/ruby/core/integer/gt_spec.rb b/spec/ruby/core/integer/gt_spec.rb index 2a3488cb49..14c51c9acc 100644 --- a/spec/ruby/core/integer/gt_spec.rb +++ b/spec/ruby/core/integer/gt_spec.rb @@ -47,4 +47,3 @@ describe "Integer#>" do end end end - diff --git a/spec/ruby/core/integer/gte_spec.rb b/spec/ruby/core/integer/gte_spec.rb index ce379a07e3..3d5c48faa5 100644 --- a/spec/ruby/core/integer/gte_spec.rb +++ b/spec/ruby/core/integer/gte_spec.rb @@ -47,4 +47,3 @@ describe "Integer#>=" do end end end - diff --git a/spec/ruby/core/integer/lt_spec.rb b/spec/ruby/core/integer/lt_spec.rb index f687e0381f..a33a297d8b 100644 --- a/spec/ruby/core/integer/lt_spec.rb +++ b/spec/ruby/core/integer/lt_spec.rb @@ -49,4 +49,3 @@ describe "Integer#<" do end end end - diff --git a/spec/ruby/core/integer/lte_spec.rb b/spec/ruby/core/integer/lte_spec.rb index f9fc417640..1d3ecea2ac 100644 --- a/spec/ruby/core/integer/lte_spec.rb +++ b/spec/ruby/core/integer/lte_spec.rb @@ -52,4 +52,3 @@ describe "Integer#<=" do end end end - diff --git a/spec/ruby/core/integer/magnitude_spec.rb b/spec/ruby/core/integer/magnitude_spec.rb index 8820c83891..48cf1a8534 100644 --- a/spec/ruby/core/integer/magnitude_spec.rb +++ b/spec/ruby/core/integer/magnitude_spec.rb @@ -4,4 +4,3 @@ require_relative 'shared/abs' describe "Integer#magnitude" do it_behaves_like :integer_abs, :magnitude end - diff --git a/spec/ruby/core/integer/minus_spec.rb b/spec/ruby/core/integer/minus_spec.rb index ff933b974f..84db427172 100644 --- a/spec/ruby/core/integer/minus_spec.rb +++ b/spec/ruby/core/integer/minus_spec.rb @@ -47,4 +47,3 @@ describe "Integer#-" do end end end - diff --git a/spec/ruby/core/integer/multiply_spec.rb b/spec/ruby/core/integer/multiply_spec.rb index 68e7dd8fae..1683b0c96e 100644 --- a/spec/ruby/core/integer/multiply_spec.rb +++ b/spec/ruby/core/integer/multiply_spec.rb @@ -49,4 +49,3 @@ describe "Integer#*" do end end end - diff --git a/spec/ruby/core/integer/plus_spec.rb b/spec/ruby/core/integer/plus_spec.rb index d41077450d..2880840bc1 100644 --- a/spec/ruby/core/integer/plus_spec.rb +++ b/spec/ruby/core/integer/plus_spec.rb @@ -47,4 +47,3 @@ describe "Integer#+" do end end end - diff --git a/spec/ruby/core/io/pos_spec.rb b/spec/ruby/core/io/pos_spec.rb index ca0a761c8f..e6cda2643d 100644 --- a/spec/ruby/core/io/pos_spec.rb +++ b/spec/ruby/core/io/pos_spec.rb @@ -9,4 +9,3 @@ end describe "IO#pos=" do it_behaves_like :io_set_pos, :pos= end - diff --git a/spec/ruby/core/io/print_spec.rb b/spec/ruby/core/io/print_spec.rb index a4a069361e..0dd48344ce 100644 --- a/spec/ruby/core/io/print_spec.rb +++ b/spec/ruby/core/io/print_spec.rb @@ -51,4 +51,3 @@ describe IO, "#print" do lambda { IOSpecs.closed_io.print("stuff") }.should raise_error(IOError) end end - diff --git a/spec/ruby/core/io/shared/write.rb b/spec/ruby/core/io/shared/write.rb index 9490a848d7..bca96da81c 100644 --- a/spec/ruby/core/io/shared/write.rb +++ b/spec/ruby/core/io/shared/write.rb @@ -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 diff --git a/spec/ruby/core/kernel/eql_spec.rb b/spec/ruby/core/kernel/eql_spec.rb index 83185b824a..e62a601a79 100644 --- a/spec/ruby/core/kernel/eql_spec.rb +++ b/spec/ruby/core/kernel/eql_spec.rb @@ -8,4 +8,3 @@ describe "Kernel#eql?" do it_behaves_like :object_equal, :eql? end - diff --git a/spec/ruby/core/kernel/eval_spec.rb b/spec/ruby/core/kernel/eval_spec.rb index ad06af7b05..fbae8ff3c7 100644 --- a/spec/ruby/core/kernel/eval_spec.rb +++ b/spec/ruby/core/kernel/eval_spec.rb @@ -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 + Vπ = 3.14 +end +CODE + code.encoding.should == Encoding::BINARY + eval(code) + EvalSpecs.constants(false).should include(:"Vπ") + EvalSpecs::Vπ.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 diff --git a/spec/ruby/core/kernel/lambda_spec.rb b/spec/ruby/core/kernel/lambda_spec.rb index b27a88e85a..52f340dde5 100644 --- a/spec/ruby/core/kernel/lambda_spec.rb +++ b/spec/ruby/core/kernel/lambda_spec.rb @@ -83,4 +83,3 @@ describe "Kernel.lambda" do KernelSpecs::Lambda.new.outer.should == :good end end - diff --git a/spec/ruby/core/kernel/printf_spec.rb b/spec/ruby/core/kernel/printf_spec.rb index 53ee6419c6..ca88082694 100644 --- a/spec/ruby/core/kernel/printf_spec.rb +++ b/spec/ruby/core/kernel/printf_spec.rb @@ -58,4 +58,3 @@ describe "Kernel.printf" do end end end - diff --git a/spec/ruby/core/module/protected_spec.rb b/spec/ruby/core/module/protected_spec.rb index c2c7ab083d..985e4621c5 100644 --- a/spec/ruby/core/module/protected_spec.rb +++ b/spec/ruby/core/module/protected_spec.rb @@ -53,4 +53,3 @@ describe "Module#protected" do end.should raise_error(NameError) end end - diff --git a/spec/ruby/core/string/clone_spec.rb b/spec/ruby/core/string/clone_spec.rb index 6259cf89ef..f8d40423f0 100644 --- a/spec/ruby/core/string/clone_spec.rb +++ b/spec/ruby/core/string/clone_spec.rb @@ -55,4 +55,3 @@ describe "String#clone" do clone.should == "string" end end - diff --git a/spec/ruby/core/string/percent_spec.rb b/spec/ruby/core/string/percent_spec.rb index 2ddcab7907..e701def344 100644 --- a/spec/ruby/core/string/percent_spec.rb +++ b/spec/ruby/core/string/percent_spec.rb @@ -11,4 +11,3 @@ describe "String#%" do format % args } end - diff --git a/spec/ruby/core/systemexit/initialize_spec.rb b/spec/ruby/core/systemexit/initialize_spec.rb index 3156ff52c1..2cebaa7993 100644 --- a/spec/ruby/core/systemexit/initialize_spec.rb +++ b/spec/ruby/core/systemexit/initialize_spec.rb @@ -24,4 +24,3 @@ describe "SystemExit#initialize" do s.status.should == 0 end end - diff --git a/spec/ruby/core/thread/run_spec.rb b/spec/ruby/core/thread/run_spec.rb index 2472269df8..f86f793489 100644 --- a/spec/ruby/core/thread/run_spec.rb +++ b/spec/ruby/core/thread/run_spec.rb @@ -6,4 +6,3 @@ require_relative 'shared/wakeup' describe "Thread#run" do it_behaves_like :thread_wakeup, :run end - diff --git a/spec/ruby/core/time/_dump_spec.rb b/spec/ruby/core/time/_dump_spec.rb index 04afec0879..6941a1531f 100644 --- a/spec/ruby/core/time/_dump_spec.rb +++ b/spec/ruby/core/time/_dump_spec.rb @@ -53,4 +53,3 @@ describe "Time#_dump" do t.send(:_dump).should == "\364\001\031\200\313\000\020\004" end end - diff --git a/spec/ruby/core/tracepoint/callee_id_spec.rb b/spec/ruby/core/tracepoint/callee_id_spec.rb index be441bdef0..39a7413648 100644 --- a/spec/ruby/core/tracepoint/callee_id_spec.rb +++ b/spec/ruby/core/tracepoint/callee_id_spec.rb @@ -17,4 +17,3 @@ ruby_version_is '2.4' do end end end - |