Skip to content

Commit

Permalink
Merge pull request #139 in G/truffleruby from update-specs to master
Browse files Browse the repository at this point in the history
* commit '93751374d3560803b4a65edae2f3cf71b6f3b177':
  Add tags for new failing specs
  Update to ruby/spec@5f7b4a6
  • Loading branch information
eregon committed Jun 14, 2018
2 parents 423261a + 9375137 commit fbb4838
Show file tree
Hide file tree
Showing 34 changed files with 1,241 additions and 292 deletions.
18 changes: 11 additions & 7 deletions spec/ruby/appveyor.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,20 @@ version: "{build}"
clone_depth: 5
init:
# To avoid duplicated executables in PATH, see https://github.com/ruby/spec/pull/468
- set PATH=C:\ruby%RUBY_VERSION%\bin;C:\Program Files\7-Zip;C:\Program Files\AppVeyor\BuildAgent;C:\Program Files\Git\cmd;C:\Windows\system32;C:\Program Files;C:\Windows
- set PATH=C:\Ruby%ruby_version%\bin;C:\Program Files\7-Zip;C:\Program Files\AppVeyor\BuildAgent;C:\Program Files\Git\cmd;C:\Windows\system32;C:\Program Files;C:\Windows
# Loads trunk build and updates MSYS2 / MinGW to most recent gcc compiler
- if %ruby_version%==_trunk (
appveyor DownloadFile https://ci.appveyor.com/api/projects/MSP-Greg/ruby-loco/artifacts/ruby_trunk.7z -FileName C:\ruby_trunk.7z &
7z x C:\ruby_trunk.7z -oC:\ruby_trunk & C:\ruby_trunk\trunk_msys2.cmd)
- ps: |
if ($env:ruby_version -eq '_trunk') {
$trunk_uri = 'https://ci.appveyor.com/api/projects/MSP-Greg/ruby-loco/artifacts/ruby_trunk.7z'
(New-Object Net.WebClient).DownloadFile($trunk_uri, 'C:\ruby_trunk.7z')
7z.exe x C:\ruby_trunk.7z -oC:\Ruby_trunk
}
environment:
matrix:
- RUBY_VERSION: 23-x64
- RUBY_VERSION: 24-x64
- RUBY_VERSION: _trunk # So the folder name is ruby_trunk
- ruby_version: 24-x64
- ruby_version: 25-x64
- ruby_version: _trunk # So the folder name is ruby_trunk
install:
- git clone https://github.com/ruby/mspec.git ../mspec
build: off
Expand Down
28 changes: 15 additions & 13 deletions spec/ruby/command_line/dash_upper_i_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@

it "adds the path at the front of $LOAD_PATH" do
lines = ruby_exe(@script, options: "-I fixtures").lines
if File.basename(ruby_exe[0]) == "miniruby"
if PlatformGuard.implementation? :ruby
# In a MRI checkout, $PWD ends up as the first entry in $LOAD_PATH.
# So just assert that it's at the beginning.
idx = lines.index { |l| l.include?("fixtures") }
Expand All @@ -31,19 +31,21 @@
end
end

describe "The -I command line option" do
before :each do
@script = fixture __FILE__, "loadpath.rb"
@fixtures = File.dirname(@script)
@symlink = tmp("loadpath_symlink")
File.symlink(@fixtures, @symlink)
end
platform_is_not :windows do
describe "The -I command line option" do
before :each do
@script = fixture __FILE__, "loadpath.rb"
@fixtures = File.dirname(@script)
@symlink = tmp("loadpath_symlink")
File.symlink(@fixtures, @symlink)
end

after :each do
rm_r @symlink
end
after :each do
rm_r @symlink
end

it "does not expand symlinks" do
ruby_exe(@script, options: "-I #{@symlink}").lines.should include "#{@symlink}\n"
it "does not expand symlinks" do
ruby_exe(@script, options: "-I #{@symlink}").lines.should include "#{@symlink}\n"
end
end
end
101 changes: 85 additions & 16 deletions spec/ruby/core/enumerable/all_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,11 @@
require_relative 'fixtures/classes'

describe "Enumerable#all?" do

before :each do
@enum = EnumerableSpecs::Numerous.new
@empty = EnumerableSpecs::Empty.new()
@enum1 = [0, 1, 2, -1]
@enum2 = [nil, false, true]
@enum1 = EnumerableSpecs::Numerous.new(0, 1, 2, -1)
@enum2 = EnumerableSpecs::Numerous.new(nil, false, true)
end

it "always returns true on empty enumeration" do
Expand All @@ -21,6 +20,21 @@
{}.all? { nil }.should == true
end

it "raises an ArgumentError when more than 1 argument is provided" do
lambda { @enum.all?(1, 2, 3) }.should raise_error(ArgumentError)
lambda { [].all?(1, 2, 3) }.should raise_error(ArgumentError)
lambda { {}.all?(1, 2, 3) }.should raise_error(ArgumentError)
end

ruby_version_is ""..."2.5" do
it "raises an ArgumentError when any arguments provided" do
lambda { @enum.all?(Proc.new {}) }.should raise_error(ArgumentError)
lambda { @enum.all?(nil) }.should raise_error(ArgumentError)
lambda { @empty.all?(1) }.should raise_error(ArgumentError)
lambda { @enum1.all?(1) {} }.should raise_error(ArgumentError)
end
end

it "does not hide exceptions out of #each" do
lambda {
EnumerableSpecs::ThrowingEach.new.all?
Expand Down Expand Up @@ -58,16 +72,6 @@
multi = EnumerableSpecs::YieldsMultiWithFalse.new
multi.all?.should be_true
end

ruby_version_is "2.5" do
describe "given a pattern argument" do
# This spec should be replaced by more extensive ones
it "returns true iff all match that pattern" do
@enum.all?(Integer).should == true
@enum2.all?(NilClass).should == false
end
end
end
end

describe "with block" do
Expand Down Expand Up @@ -117,14 +121,79 @@

it "gathers initial args as elements when each yields multiple" do
multi = EnumerableSpecs::YieldsMulti.new
multi.all? {|e| !(Array === e) }.should be_true
yielded = []
multi.all? { |e| yielded << e }.should == true
yielded.should == [1, 3, 6]
end

it "yields multiple arguments when each yields multiple" do
multi = EnumerableSpecs::YieldsMulti.new
yielded = []
multi.all? {|e, i| yielded << [e, i] }
yielded.should == [[1, 2], [3, 4], [6, 7]]
multi.all? { |*args| yielded << args }.should == true
yielded.should == [[1, 2], [3, 4, 5], [6, 7, 8, 9]]
end
end

ruby_version_is "2.5" do
describe 'when given a pattern argument' do
it "calls `===` on the pattern the return value " do
pattern = EnumerableSpecs::Pattern.new { |x| x >= 0 }
@enum1.all?(pattern).should == false
pattern.yielded.should == [[0], [1], [2], [-1]]
end

it "ignores block" do
@enum2.all?(NilClass) { raise }.should == false
[1, 2, nil].all?(NilClass) { raise }.should == false
{a: 1}.all?(Array) { raise }.should == true
end

it "always returns true on empty enumeration" do
@empty.all?(Integer).should == true
[].all?(Integer).should == true
{}.all?(NilClass).should == true
end

it "does not hide exceptions out of #each" do
lambda {
EnumerableSpecs::ThrowingEach.new.all?(Integer)
}.should raise_error(RuntimeError)
end

it "returns true if the pattern never returns false or nil" do
pattern = EnumerableSpecs::Pattern.new { |x| 42 }
@enum.all?(pattern).should == true

[1, 42, 3].all?(pattern).should == true

pattern = EnumerableSpecs::Pattern.new { |x| Array === x }
{a: 1, b: 2}.all?(pattern).should == true
end

it "returns false if the pattern ever returns false or nil" do
pattern = EnumerableSpecs::Pattern.new { |x| x >= 0 }
@enum1.all?(pattern).should == false
pattern.yielded.should == [[0], [1], [2], [-1]]

[1, 2, 3, -1].all?(pattern).should == false

pattern = EnumerableSpecs::Pattern.new { |x| x[1] >= 0 }
{a: 1, b: -1}.all?(pattern).should == false
end

it "does not hide exceptions out of pattern#===" do
pattern = EnumerableSpecs::Pattern.new { raise "from pattern" }
lambda {
@enum.all?(pattern)
}.should raise_error(RuntimeError)
end

it "calls the pattern with gathered array when yielded with multiple arguments" do
multi = EnumerableSpecs::YieldsMulti.new
pattern = EnumerableSpecs::Pattern.new { true }
multi.all?(pattern).should == true
pattern.yielded.should == [[[1, 2]], [[3, 4, 5]], [[6, 7, 8, 9]]]
end
end
end
end
42 changes: 14 additions & 28 deletions spec/ruby/core/enumerable/any_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@
describe "Enumerable#any?" do
before :each do
@enum = EnumerableSpecs::Numerous.new
@empty = EnumerableSpecs::Empty.new()
@enum1 = [0, 1, 2, -1]
@enum2 = [nil, false, true]
@empty = EnumerableSpecs::Empty.new
@enum1 = EnumerableSpecs::Numerous.new(0, 1, 2, -1)
@enum2 = EnumerableSpecs::Numerous.new(nil, false, true)
end

it "always returns false on empty enumeration" do
Expand Down Expand Up @@ -86,7 +86,7 @@
@enum2.any? { |i| i == nil }.should == true
end

it "any? should return false if the block never returns other than false or nil" do
it "returns false if the block never returns other than false or nil" do
@enum.any? { false }.should == false
@enum.any? { nil }.should == false

Expand Down Expand Up @@ -134,32 +134,21 @@

it "gathers initial args as elements when each yields multiple" do
multi = EnumerableSpecs::YieldsMulti.new
multi.any? {|e| e == 1 }.should be_true
yielded = []
multi.any? { |e| yielded << e; false }.should == false
yielded.should == [1, 3, 6]
end

it "yields multiple arguments when each yields multiple" do
multi = EnumerableSpecs::YieldsMulti.new
yielded = []
multi.any? {|e, i| yielded << [e, i] }
yielded.should == [[1, 2]]
multi.any? { |*args| yielded << args; false }.should == false
yielded.should == [[1, 2], [3, 4, 5], [6, 7, 8, 9]]
end

end

ruby_version_is "2.5" do
describe 'when given a pattern argument' do
class EnumerableSpecs::Pattern
attr_reader :yielded
def initialize(&block)
@block = block
@yielded = []
end
def ===(*args)
@yielded << args
@block.call(*args)
end
end

it "calls `===` on the pattern the return value " do
pattern = EnumerableSpecs::Pattern.new { |x| x == 2 }
@enum1.any?(pattern).should == true
Expand Down Expand Up @@ -195,7 +184,7 @@ def ===(*args)
{a: 1, b: 2}.any?(pattern).should == true
end

it "any? should return false if the block never returns other than false or nil" do
it "returns false if the block never returns other than false or nil" do
pattern = EnumerableSpecs::Pattern.new { |x| nil }
@enum1.any?(pattern).should == false
pattern.yielded.should == [[0], [1], [2], [-1]]
Expand All @@ -204,21 +193,18 @@ def ===(*args)
{a: 1}.any?(pattern).should == false
end

it "does not hide exceptions out of the block" do
it "does not hide exceptions out of pattern#===" do
pattern = EnumerableSpecs::Pattern.new { raise "from pattern" }
lambda {
@enum.any?(pattern)
}.should raise_error(RuntimeError)
end

it "calls the pattern with gathered array when yielded with multiple arguments" do
multi = EnumerableSpecs::YieldsMulti.new
pattern = EnumerableSpecs::Pattern.new { false }
EnumerableSpecs::YieldsMixed2.new.any?(pattern).should == false
pattern.yielded.should == EnumerableSpecs::YieldsMixed2.gathered_yields.map { |x| [x] }

pattern = EnumerableSpecs::Pattern.new { false }
{a: 1, b: 2}.any?(pattern).should == false
pattern.yielded.should == [[[:a, 1]], [[:b, 2]]]
multi.any?(pattern).should == false
pattern.yielded.should == [[[1, 2]], [[3, 4, 5]], [[6, 7, 8, 9]]]
end
end
end
Expand Down
14 changes: 14 additions & 0 deletions spec/ruby/core/enumerable/fixtures/classes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -328,4 +328,18 @@ def map(&block)
EnumerableMapping.new(self, block)
end
end

class Pattern
attr_reader :yielded

def initialize(&block)
@block = block
@yielded = []
end

def ===(*args)
@yielded << args
@block.call(*args)
end
end
end # EnumerableSpecs utility classes
Loading

0 comments on commit fbb4838

Please sign in to comment.