Skip to content

Commit

Permalink
Showing 181 changed files with 1,491 additions and 905 deletions.
1 change: 1 addition & 0 deletions core/src/main/java/org/jruby/util/cli/Options.java
Original file line number Diff line number Diff line change
@@ -264,6 +264,7 @@ public class Options {
public static final Option<Boolean> TRUFFLE_EXCEPTIONS_PRINT_JAVA = bool(TRUFFLE, "truffle.exceptions.print_java", false, "Print Java exceptions at the point of translating them to Ruby exceptions.");
public static final Option<Boolean> TRUFFLE_EXCEPTIONS_PRINT_UNCAUGHT_JAVA = bool(TRUFFLE, "truffle.exceptions.print_uncaught_java", false, "Print uncaught Java exceptions at the point of translating them to Ruby exceptions.");
public static final Option<Boolean> TRUFFLE_BACKTRACES_HIDE_CORE_FILES = bool(TRUFFLE, "truffle.backtraces.hide_core_files", true, "Hide core source files in backtraces, like MRI does.");
public static final Option<Integer> TRUFFLE_BACKTRACES_LIMIT = integer(TRUFFLE, "truffle.backtraces.limit", 9999, "Limit the size of Ruby backtraces.");
public static final Option<Boolean> TRUFFLE_INCLUDE_CORE_FILE_CALLERS_IN_SET_TRACE_FUNC = bool(TRUFFLE, "truffle.set_trace_func.include_core_file_callers", false, "Include internal core library calls in set_trace_func output.");

public static final Option<Boolean> TRUFFLE_METRICS_TIME = bool(TRUFFLE, "truffle.metrics.time", false, "Print the time at various stages of VM operation.");
7 changes: 4 additions & 3 deletions spec/ruby/.travis.yml
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
sudo: false
language: ruby
rvm:
- 2.0.0-p647
- 2.1.7
- 2.2.3
- 2.0.0-p648
- 2.1.8
- 2.2.4
- ruby-head
install:
- git clone https://github.com/ruby/mspec.git ../mspec
6 changes: 3 additions & 3 deletions spec/ruby/CONTRIBUTING.md
Original file line number Diff line number Diff line change
@@ -37,7 +37,7 @@ Specify `core` or `library` as the `base`.

#### Finding unspecified core methods

This is very easy, just run the command below in your `rubyspec` directory.
This is very easy, just run the command below in your `spec` directory.
`ruby` must be a recent version of MRI.

$ ruby --disable-gem ../mspec/bin/mkspec
@@ -56,8 +56,8 @@ In general, the usage of guards should be minimized as possible.
The following guards are deprecated and should not be used in new code:
* `not_compliant_on`: Simply tag the spec as failing instead.
If it makes sense to test part of the example, split it (an example should have only one or a few `should`).
* `compliant_on` / `deviates_on`: RubySpec defines common behavior and not implementation details.
Use the implementation suite of tests/specs for these.
* `compliant_on` / `deviates_on`: The Ruby Spec Suite defines common behavior and not implementation details.
Use the implementation test suite for these.

### Style

41 changes: 30 additions & 11 deletions spec/ruby/README.md
Original file line number Diff line number Diff line change
@@ -1,33 +1,44 @@
# RubySpec
# The Ruby Spec Suite

[![Build Status](https://travis-ci.org/ruby/rubyspec.svg)](https://travis-ci.org/ruby/rubyspec)
[![Build Status](https://travis-ci.org/ruby/spec.svg)](https://travis-ci.org/ruby/spec)

RubySpec is an executable specification for the Ruby programming language.
The specs describe the Ruby language syntax as well as the core and standard library classes.
The Ruby Spec Suite is a test suite for the behavior of the Ruby programming language.

The RubySpec files are written using a RSpec-like syntax.
MSpec is the purpose-built framework for running RubySpec.
It is not a standardized specification like the ISO one, and does not aim to become one.
Instead, it is a practical tool to describe and test the behavior of Ruby with code.

Every example code has a textual description, which presents several advantages:

* It is easier to understand the intent of the author
* It documents how recent versions of Ruby should behave
* It helps Ruby implementations to agree on a common behavior

The specs are written with syntax similar to RSpec 2.
They are run with MSpec, the purpose-built framework for running the Ruby Spec Suite.
For more information, see the [MSpec](http://github.com/ruby/mspec) project.

The specs describe the [language syntax](language/), the [core library](core/) and the [standard library](library/).
The language specs are grouped by keyword while the core and standard library specs are grouped by class and method.

### Running the specs

First, clone this repository:

$ git clone https://github.com/ruby/rubyspec.git
$ git clone https://github.com/ruby/spec.git

Then move to it:

$ cd rubyspec
$ cd spec

Clone [MSpec](http://github.com/ruby/mspec):

$ git clone https://github.com/ruby/mspec.git ../mspec

And run the RubySpec suite:
And run the spec suite:

$ ../mspec/bin/mspec

This will execute all the RubySpec specs using the executable named `ruby` on your current PATH.
This will execute all the specs using the executable named `ruby` on your current PATH.

### Running Specs with a Specific Ruby Implementation

@@ -59,4 +70,12 @@ In similar fashion, the following commands run the respective specs:

### Contributing

See [CONTRIBUTING.md](https://github.com/ruby/rubyspec/blob/master/CONTRIBUTING.md).
See [CONTRIBUTING.md](https://github.com/ruby/spec/blob/master/CONTRIBUTING.md).

### History and RubySpec

This project was originally born from [Rubinius](https://github.com/rubinius/rubinius) tests being converted to the spec style.
These specs were later extracted to their own project, RubySpec, with a specific vision and principles.
At the end of 2014, Brian Shirai, the creator of RubySpec, decided to [end RubySpec](http://rubinius.com/2014/12/31/matz-s-ruby-developers-don-t-use-rubyspec/).
A couple months later, the different repositories were merged and [the project was revived](http://eregon.github.io/rubyspec/2015/07/29/rubyspec-is-reborn.html).
On 12 January 2016, the name was changed to "The Ruby Spec Suite" for clarity and to let the RubySpec ideology rest in peace.
19 changes: 15 additions & 4 deletions spec/ruby/core/array/shared/inspect.rb
Original file line number Diff line number Diff line change
@@ -81,11 +81,22 @@
array.send(@method).encoding.name.should == "US-ASCII"
end

it "raises if inspected result is not default external encoding" do
utf_16be = mock("utf_16be")
utf_16be.should_receive(:inspect).and_return("utf_16be".encode!(Encoding::UTF_16BE))
ruby_version_is ''...'2.3' do
it "raises if inspected result is not default external encoding" do
utf_16be = mock("utf_16be")
utf_16be.should_receive(:inspect).and_return(%<"utf_16be \u3042">.encode!(Encoding::UTF_16BE))

lambda { [utf_16be].send(@method) }.should raise_error(Encoding::CompatibilityError)
lambda { [utf_16be].send(@method) }.should raise_error(Encoding::CompatibilityError)
end
end

ruby_version_is '2.3' do
it "raises if inspected result is not default external encoding" do
utf_16be = mock("utf_16be")
utf_16be.should_receive(:inspect).and_return(%<"utf_16be \u3042">.encode!(Encoding::UTF_16BE))

[utf_16be].send(@method).should == '["utf_16be \u3042"]'
end
end
end
end
9 changes: 9 additions & 0 deletions spec/ruby/core/basicobject/instance_eval_spec.rb
Original file line number Diff line number Diff line change
@@ -150,4 +150,13 @@ class B; end
(1 << 64).instance_eval { def foo; end }
end.should raise_error(TypeError)
end

it "evaluates procs originating from methods" do
def meth(arg); arg; end

m = method(:meth)
obj = Object.new

obj.instance_eval(&m).should == obj
end
end
65 changes: 11 additions & 54 deletions spec/ruby/core/bignum/size_spec.rb
Original file line number Diff line number Diff line change
@@ -2,60 +2,17 @@

describe "Bignum#size" do
ruby_version_is "2.1" do
it "returns the number of bytes whose number of bytes is larger than the size of allocated binum data" do
(256**7).size.should >= 8
(256**8).size.should >= 9
(256**9).size.should >= 10
(256**10).size.should >= 10
(256**10-1).size.should >= 9
(256**11).size.should >= 12
(256**12).size.should >= 13
(256**20-1).size.should >= 20
(256**40-1).size.should >= 40
end
end

ruby_version_is ""..."2.1" do
compliant_on :ironruby do
it "returns the number of bytes in the machine representation in multiples of sizeof(BDIGIT) which is 4 where long long is 64 bit" do
(256**7).size.should == 8
(256**8).size.should == 12
(256**9).size.should == 12
(256**10).size.should == 12
(256**10-1).size.should == 12
(256**11).size.should == 12
(256**12).size.should == 16
(256**20-1).size.should == 20
(256**40-1).size.should == 40
end
end

deviates_on :rubinius, :jruby do
it "returns the number of bytes in the machine representation" do
(256**7).size .should == 8
(256**8).size .should == 9
(256**9).size .should == 10
(256**10).size .should == 11
(256**10-1).size.should == 10
(256**11).size .should == 12
(256**12).size .should == 13
(256**20-1).size .should == 20
(256**40-1).size .should == 40
end
end

deviates_on :maglev do
it "returns the number of bytes in the machine representation in multiples of four" do
(256**7).size .should == 8
(256**8).size .should == 16
(256**9).size .should == 16
(256**10).size .should == 16
(256**10-1).size.should == 16
(256**11).size .should == 16
(256**12).size .should == 20
(256**20-1).size.should == 24
(256**40-1).size.should == 44
end
it "returns the number of bytes required to hold the unsigned bignum data" do
# that is, n such that 256 * n <= val.abs < 256 * (n+1)
(256**7).size.should == 8
(256**8).size.should == 9
(256**9).size.should == 10
(256**10).size.should == 11
(256**10-1).size.should == 10
(256**11).size.should == 12
(256**12).size.should == 13
(256**20-1).size.should == 20
(256**40-1).size.should == 40
end
end
end
14 changes: 6 additions & 8 deletions spec/ruby/core/comparable/equal_value_spec.rb
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
require File.expand_path('../../../spec_helper', __FILE__)
require File.expand_path('../fixtures/classes', __FILE__)

no_silent_rescue = "2.3"

describe "Comparable#==" do
a = b = nil
before :each do
@@ -50,13 +48,13 @@
a.should_receive(:<=>).once.and_return("abc")
end

ruby_version_is ""...no_silent_rescue do
ruby_version_is ""..."2.3" do
it "returns false" do
(a == b).should be_false
end
end

ruby_version_is no_silent_rescue do
ruby_version_is "2.3" do
it "raises an ArgumentError" do
lambda { (a == b) }.should raise_error(ArgumentError)
end
@@ -69,14 +67,14 @@
a.should_receive(:<=>).once.and_raise(StandardError)
end

ruby_version_is ""...no_silent_rescue do
ruby_version_is ""..."2.3" do
# Behaviour confirmed by MRI test suite
it "returns false" do
(a == b).should be_false
end
end

ruby_version_is no_silent_rescue do
ruby_version_is "2.3" do
it "lets it go through" do
lambda { (a == b) }.should raise_error(StandardError)
end
@@ -89,13 +87,13 @@
a.should_receive(:<=>).once.and_raise(TypeError)
end

ruby_version_is ""...no_silent_rescue do
ruby_version_is ""..."2.3" do
it "returns false" do
(a == b).should be_false
end
end

ruby_version_is no_silent_rescue do
ruby_version_is "2.3" do
it "lets it go through" do
lambda { (a == b) }.should raise_error(TypeError)
end
27 changes: 17 additions & 10 deletions spec/ruby/core/dir/pwd_spec.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
# -*- encoding: utf-8 -*-
require File.expand_path('../../../spec_helper', __FILE__)
require File.expand_path('../fixtures/common', __FILE__)
require File.expand_path('../shared/pwd', __FILE__)
@@ -12,19 +13,25 @@
end

it_behaves_like :dir_pwd, :pwd
end

it "correctly displays dirs with unicode characters in them" do
DirSpecs.clear_dirs
describe "Dir.pwd" do
before :each do
@name = tmp("あ").force_encoding('binary')
@fs_encoding = Encoding.find('filesystem')
end

begin
str = [0xe9].pack 'U' # Unicode é
Dir.mkdir str
File.exist?(str).should == true
after :each do
rm_r @name
end

old_pwd = Dir.pwd
Dir.chdir(str) { Dir.pwd.force_encoding('UTF-8').should == File.join(old_pwd, str) }
ensure
DirSpecs.clear_dirs
it "correctly handles dirs with unicode characters in them" do
Dir.mkdir @name
Dir.chdir @name do
if @fs_encoding == Encoding::UTF_8
Dir.pwd.encoding.should == Encoding::UTF_8
end
Dir.pwd.force_encoding('binary').should == @name
end
end
end
3 changes: 1 addition & 2 deletions spec/ruby/core/encoding/converter/primitive_convert_spec.rb
Original file line number Diff line number Diff line change
@@ -86,8 +86,7 @@
end

it "accepts an options hash" do
@ec.primitive_convert("","",nil,nil, {after_output: true})\
.should_not raise_error(ArgumentError)
@ec.primitive_convert("","",nil,nil, {after_output: true}).should == :finished
end

it "sets the destination buffer's encoding to the destination encoding if the conversion suceeded" do
9 changes: 9 additions & 0 deletions spec/ruby/core/enumerable/chunk_spec.rb
Original file line number Diff line number Diff line change
@@ -72,6 +72,15 @@
end
end

ruby_version_is "2.3" do
it "does not accept arguments" do
e = EnumerableSpecs::Numerous.new(1, 2, 3)
lambda {
e.chunk(1) {}
}.should raise_error(ArgumentError)
end
end

it 'returned Enumerator size returns nil' do
e = EnumerableSpecs::NumerousWithSize.new(1, 2, 3, 2, 1)
enum = e.chunk { |x| true }
38 changes: 38 additions & 0 deletions spec/ruby/core/enumerable/chunk_while_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
require File.expand_path('../../../spec_helper', __FILE__)
require File.expand_path('../fixtures/classes', __FILE__)

ruby_version_is "2.3" do
describe "Enumerable#chunk_while" do
before :each do
ary = [10, 9, 7, 6, 4, 3, 2, 1]
@enum = EnumerableSpecs::Numerous.new *ary
@result = @enum.chunk_while { |i, j| i - 1 == j }
@enum_length = ary.length
end

context "when given a block" do
it "returns an enumerator" do
@result.should be_an_instance_of(enumerator_class)
end

it "splits chunks between adjacent elements i and j where the block returns false" do
@result.to_a.should == [[10, 9], [7, 6], [4, 3, 2, 1]]
end

it "calls the block for length of the receiver enumerable minus one times" do
times_called = 0
@enum.chunk_while do |i, j|
times_called += 1
i - 1 == j
end.to_a
times_called.should == (@enum_length - 1)
end
end

context "when not given a block" do
it "raises an ArgumentError" do
lambda { @enum.chunk_while }.should raise_error(ArgumentError)
end
end
end
end
Loading

0 comments on commit 58fbf9d

Please sign in to comment.