Skip to content

Commit c4f6ec9

Browse files
committed
[GR-14806] Update specs.
PullRequest: truffleruby/825
2 parents bd37f6d + 9724de5 commit c4f6ec9

File tree

314 files changed

+7091
-8131
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

314 files changed

+7091
-8131
lines changed

spec/mspec/lib/mspec/helpers/io.rb

Lines changed: 2 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -65,8 +65,6 @@ def inspect
6565
# with any Ruby object). The file descriptor can safely be passed
6666
# to IO.new without creating a Ruby object alias to the fd.
6767
def new_fd(name, mode="w:utf-8")
68-
mode = options_or_mode(mode)
69-
7068
if mode.kind_of? Hash
7169
if mode.key? :mode
7270
mode = mode[:mode]
@@ -75,41 +73,15 @@ def new_fd(name, mode="w:utf-8")
7573
end
7674
end
7775

78-
IO.sysopen name, fmode(mode)
76+
IO.sysopen name, mode
7977
end
8078

8179
# Creates an IO instance for a temporary file name. The file
8280
# must be deleted.
8381
def new_io(name, mode="w:utf-8")
84-
IO.new new_fd(name, options_or_mode(mode)), options_or_mode(mode)
82+
IO.new new_fd(name, mode), mode
8583
end
8684

8785
def find_unused_fd
8886
Dir.entries("/dev/fd").map(&:to_i).max + 1
8987
end
90-
91-
# This helper simplifies passing file access modes regardless of
92-
# whether the :encoding feature is enabled. Only the access specifier
93-
# itself will be returned if :encoding is not enabled. Otherwise,
94-
# the full mode string will be returned (i.e. the helper is a no-op).
95-
def fmode(mode)
96-
if FeatureGuard.enabled? :encoding
97-
mode
98-
else
99-
mode.split(':').first
100-
end
101-
end
102-
103-
# This helper simplifies passing file access modes or options regardless of
104-
# whether the :encoding feature is enabled. Only the access specifier itself
105-
# will be returned if :encoding is not enabled. Otherwise, the full mode
106-
# string or option will be returned (i.e. the helper is a no-op).
107-
def options_or_mode(oom)
108-
return fmode(oom) if oom.kind_of? String
109-
110-
if FeatureGuard.enabled? :encoding
111-
oom
112-
else
113-
fmode(oom[:mode] || "r:utf-8")
114-
end
115-
end

spec/mspec/lib/mspec/utils/options.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -384,7 +384,7 @@ def randomize
384384
def repeat
385385
on("-R", "--repeat", "NUMBER",
386386
"Repeatedly run an example NUMBER times") do |o|
387-
MSpec.repeat = o.to_i
387+
MSpec.repeat = Integer(o)
388388
end
389389
end
390390

spec/mspec/spec/helpers/io_spec.rb

Lines changed: 2 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@
6464
fd = new_fd @name
6565
fd.should be_kind_of(Integer)
6666

67-
@io = IO.new fd, fmode('w:utf-8')
67+
@io = IO.new fd, 'w:utf-8'
6868
@io.sync = true
6969
@io.print "io data"
7070

@@ -76,7 +76,7 @@
7676
fd = new_fd @name, { :mode => 'w:utf-8' }
7777
fd.should be_kind_of(Integer)
7878

79-
@io = IO.new fd, fmode('w:utf-8')
79+
@io = IO.new fd, 'w:utf-8'
8080
@io.sync = true
8181
@io.print "io data"
8282

@@ -134,41 +134,3 @@
134134
IO.read(@name).should == "io data"
135135
end
136136
end
137-
138-
describe Object, "#fmode" do
139-
it "returns the argument unmodified if :encoding feature is enabled" do
140-
FeatureGuard.should_receive(:enabled?).with(:encoding).and_return(true)
141-
fmode("rb:binary:utf-8").should == "rb:binary:utf-8"
142-
end
143-
144-
it "returns only the file access mode if :encoding feature is not enabled" do
145-
FeatureGuard.should_receive(:enabled?).with(:encoding).and_return(false)
146-
fmode("rb:binary:utf-8").should == "rb"
147-
end
148-
end
149-
150-
describe Object, "#options_or_mode" do
151-
describe "if passed a Hash" do
152-
it "returns a mode string if :encoding feature is not enabled" do
153-
FeatureGuard.should_receive(:enabled?).with(:encoding).twice.and_return(false)
154-
options_or_mode(:mode => "rb:binary").should == "rb"
155-
end
156-
157-
it "returns a Hash if :encoding feature is enabled" do
158-
FeatureGuard.should_receive(:enabled?).with(:encoding).and_return(true)
159-
options_or_mode(:mode => "rb:utf-8").should == { :mode => "rb:utf-8" }
160-
end
161-
end
162-
163-
describe "if passed a String" do
164-
it "returns only the file access mode if :encoding feature is not enabled" do
165-
FeatureGuard.should_receive(:enabled?).with(:encoding).and_return(false)
166-
options_or_mode("rb:binary:utf-8").should == "rb"
167-
end
168-
169-
it "returns the argument unmodified if :encoding feature is enabled" do
170-
FeatureGuard.should_receive(:enabled?).with(:encoding).and_return(true)
171-
options_or_mode("rb:binary:utf-8").should == "rb:binary:utf-8"
172-
end
173-
end
174-
end

spec/mspec/tool/remove_old_guards.rb

Lines changed: 29 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
1-
# Remove old version guards in ruby/spec
1+
# Removes old version guards in ruby/spec.
2+
# Run it from the ruby/spec repository root.
3+
# The argument is the new minimum supported version.
24

35
def dedent(line)
46
if line.start_with?(" ")
@@ -8,9 +10,13 @@ def dedent(line)
810
end
911
end
1012

13+
def each_spec_file(&block)
14+
Dir["*/**/*.rb"].each(&block)
15+
end
16+
1117
def remove_guards(guard, keep)
12-
Dir["*/**/*.rb"].each do |file|
13-
contents = File.read(file)
18+
each_spec_file do |file|
19+
contents = File.binread(file)
1420
if contents =~ guard
1521
puts file
1622
lines = contents.lines.to_a
@@ -31,11 +37,29 @@ def remove_guards(guard, keep)
3137
lines[first..last] = []
3238
end
3339
end
34-
File.write file, lines.join
40+
File.binwrite file, lines.join
41+
end
42+
end
43+
end
44+
45+
def search(regexp)
46+
each_spec_file do |file|
47+
contents = File.binread(file)
48+
if contents =~ regexp
49+
puts file
50+
contents.each_line do |line|
51+
if line =~ regexp
52+
puts line
53+
end
54+
end
3555
end
3656
end
3757
end
3858

39-
version = (ARGV[0] || "2.3")
59+
version = Regexp.escape(ARGV.fetch(0))
4060
remove_guards(/ruby_version_is ["']#{version}["'] do/, true)
4161
remove_guards(/ruby_version_is ["'][0-9.]*["']...["']#{version}["'] do/, false)
62+
remove_guards(/ruby_bug "#\d+", ["'][0-9.]*["']...["']#{version}["'] do/, true)
63+
64+
search(/["']#{version}["']/)
65+
search(/^\s*#.+#{version}/)

spec/mspec/tool/sync/sync-rubyspec.rb

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,9 @@
1818

1919
MSPEC = ARGV.delete('--mspec')
2020

21+
CHECK_LAST_MERGE = ENV['CHECK_LAST_MERGE'] != 'false'
22+
TEST_TRUNK = ENV['TEST_TRUNK'] != 'false'
23+
2124
MSPEC_REPO = File.expand_path("../../..", __FILE__)
2225
raise MSPEC_REPO if !Dir.exist?(MSPEC_REPO) or !Dir.exist?("#{MSPEC_REPO}/.git")
2326

@@ -144,7 +147,7 @@ def rebase_commits(impl)
144147

145148
commit_date = Time.at(Integer(commit_timestamp))
146149
days_since_last_merge = (NOW-commit_date) / 86400
147-
if days_since_last_merge > 60
150+
if CHECK_LAST_MERGE and days_since_last_merge > 60
148151
raise "#{days_since_last_merge.floor} days since last merge, probably wrong commit"
149152
end
150153

@@ -177,7 +180,7 @@ def test_new_specs
177180

178181
run_test[min_version]
179182
run_test[max_version]
180-
run_test["trunk"]
183+
run_test["trunk"] if TEST_TRUNK
181184
end
182185
end
183186

spec/mspec/tool/tag_from_output.rb

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
# Adds tags based on error and failures output (e.g., from a CI log),
2+
# without running any spec code.
3+
4+
tags_dir = %w[
5+
spec/tags
6+
spec/tags/ruby
7+
].find { |dir| Dir.exist?("#{dir}/language") }
8+
abort 'Could not find tags directory' unless tags_dir
9+
10+
output = ARGF.readlines
11+
# Remove leading "[exec] " from JRuby logs
12+
output = output.map { |line| line.sub(/^\[exec\] /, '') }
13+
14+
NUMBER = /^\d+\)$/
15+
ERROR_OR_FAILED = / (ERROR|FAILED)$/
16+
SPEC_FILE = /^(\/.+_spec\.rb)\:\d+/
17+
18+
failures = output.slice_before(NUMBER).select { |number, error_line, *rest|
19+
number =~ NUMBER and error_line =~ ERROR_OR_FAILED
20+
}.each { |number, error_line, *rest|
21+
description = error_line.match(ERROR_OR_FAILED).pre_match
22+
23+
spec_file = rest.find { |line| line =~ SPEC_FILE }
24+
spec_file = spec_file[SPEC_FILE, 1]
25+
prefix = spec_file.index('spec/ruby')
26+
spec_file = spec_file[prefix..-1]
27+
28+
tags_file = spec_file.sub('spec/ruby/', "#{tags_dir}/").sub(/_spec\.rb$/, '_tags.txt')
29+
30+
dir = File.dirname(tags_file)
31+
Dir.mkdir(dir) unless Dir.exist?(dir)
32+
33+
tag_line = "fails:#{description}"
34+
unless File.exist?(tags_file) and File.readlines(tags_file, chomp: true).include?(tag_line)
35+
File.open(tags_file, 'a') do |f|
36+
f.puts tag_line
37+
end
38+
end
39+
}

spec/ruby/.travis.yml

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -3,20 +3,18 @@ language: ruby
33
install:
44
- git clone https://github.com/ruby/mspec.git ../mspec
55
script:
6-
- ../mspec/bin/mspec $MSPEC_OPTS
6+
- CHECK_LEAKS=true ../mspec/bin/mspec
77
matrix:
88
include:
9+
- name: Running each spec twice
10+
rvm: 2.5.5
11+
script:
12+
- CHECK_LEAKS=true ../mspec/bin/mspec -R2 -ff
13+
- rvm: 2.4.6
914
- rvm: 2.5.5
10-
env: MSPEC_OPTS="-R2 -ff"
11-
- rvm: 2.3.8
12-
- rvm: 2.4.5
13-
env: CHECK_LEAKS=true
14-
- rvm: 2.5.5
15-
env: CHECK_LEAKS=true
16-
- rvm: 2.6.2
17-
env: CHECK_LEAKS=true
18-
- env: RUBOCOP=true
19-
rvm: 2.4.5
15+
- rvm: 2.6.3
16+
- name: RuboCop Lint Checks
17+
rvm: 2.4.6
2018
script:
2119
- gem install rubocop:0.61.0
2220
- rubocop

spec/ruby/CONTRIBUTING.md

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -144,11 +144,11 @@ end
144144

145145

146146
# Combining guards
147-
guard -> { platform_is :windows and ruby_version_is ""..."2.3" } do
148-
# Windows and RUBY_VERSION < 2.3
147+
guard -> { platform_is :windows and ruby_version_is ""..."2.5" } do
148+
# Windows and RUBY_VERSION < 2.5
149149
end
150150

151-
guard_not -> { platform_is :windows and ruby_version_is ""..."2.3" } do
151+
guard_not -> { platform_is :windows and ruby_version_is ""..."2.5" } do
152152
# The opposite
153153
end
154154

@@ -170,20 +170,20 @@ If an implementation does not support some feature, simply tag the related specs
170170

171171
### Shared Specs
172172

173-
Often throughout Ruby, identical functionality is used by different methods and modules. In order
173+
Often throughout Ruby, identical functionality is used by different methods and modules. In order
174174
to avoid duplication of specs, we have shared specs that are re-used in other specs. The use is a
175175
bit tricky however, so let's go over it.
176176

177177
Commonly, if a shared spec is only reused within its own module, the shared spec will live within a
178-
shared directory inside that module's directory. For example, the `core/hash/shared/key.rb` spec is
178+
shared directory inside that module's directory. For example, the `core/hash/shared/key.rb` spec is
179179
only used by `Hash` specs, and so it lives inside `core/hash/shared/`.
180180

181181
When a shared spec is used across multiple modules or classes, it lives within the `shared/` directory.
182-
An example of this is the `shared/file/socket.rb` which is used by `core/file/socket_spec.rb`,
182+
An example of this is the `shared/file/socket.rb` which is used by `core/file/socket_spec.rb`,
183183
`core/filetest/socket_spec.rb`, and `core/file/state/socket_spec.rb` and so it lives in the root `shared/`.
184184

185185
Defining a shared spec involves adding a `shared: true` option to the top-level `describe` block. This
186-
will signal not to run the specs directly by the runner. Shared specs have access to two instance
186+
will signal not to run the specs directly by the runner. Shared specs have access to two instance
187187
variables from the implementor spec: `@method` and `@object`, which the implementor spec will pass in.
188188

189189
Here's an example of a snippet of a shared spec and two specs which integrates it:

spec/ruby/README.md

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,8 @@ ruby/spec is known to be tested in these implementations for every commit:
2828
* [TruffleRuby](https://github.com/oracle/truffleruby/tree/master/spec/ruby)
2929
* [Opal](https://github.com/opal/opal/tree/master/spec)
3030

31-
ruby/spec describes the behavior of Ruby 2.3 and more recent Ruby versions.
32-
More precisely, every latest stable MRI release should [pass](https://travis-ci.org/ruby/spec) all specs of ruby/spec (2.3.x, 2.4.x, 2.5.x, 2.6.x, etc), and those are tested in TravisCI.
31+
ruby/spec describes the behavior of Ruby 2.4 and more recent Ruby versions.
32+
More precisely, every latest stable MRI release should [pass](https://travis-ci.org/ruby/spec) all specs of ruby/spec (2.4.x, 2.5.x, 2.6.x, etc), and those are tested in TravisCI.
3333

3434
The specs are synchronized both ways around once a month by @eregon between ruby/spec, MRI, JRuby and TruffleRuby.
3535
Each of these repositories has a full copy of the specs under `spec/ruby` to ease editing specs.
@@ -49,6 +49,7 @@ For older specs try these commits:
4949
* Ruby 2.0.0-p647 - [Suite](https://github.com/ruby/spec/commit/245862558761d5abc676843ef74f86c9bcc8ea8d) using [MSpec](https://github.com/ruby/mspec/commit/f90efa068791064f955de7a843e96e2d7d3041c2) (may encounter 2 failures)
5050
* Ruby 2.1.9 - [Suite](https://github.com/ruby/spec/commit/f029e65241374386077ac500add557ae65069b55) using [MSpec](https://github.com/ruby/mspec/commit/55568ea3918c6380e64db8c567d732fa5781efed)
5151
* Ruby 2.2.10 - [Suite](https://github.com/ruby/spec/commit/cbaa0e412270c944df0c2532fc500c920dba0e92) using [MSpec](https://github.com/ruby/mspec/commit/d84d7668449e96856c5f6bac8cb1526b6d357ce3)
52+
* Ruby 2.3.8 - [Suite](https://github.com/ruby/spec/commit/dc733114d8ae66a3368ba3a98422c50147a76ba5) using [MSpec](https://github.com/ruby/mspec/commit/4599bc195fb109f2a482a01c32a7d659518369ea)
5253

5354
### Running the specs
5455

spec/ruby/command_line/feature_spec.rb

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -37,15 +37,6 @@
3737
ruby_exe("p 'foo'.frozen?", options: "--disable-frozen-string-literal").chomp.should == "false"
3838
end
3939

40-
ruby_version_is "2.6" do
41-
it "can be used with jit" do
42-
ruby_exe("p RubyVM::MJIT.enabled?", options: "--enable=jit").chomp.should == "true"
43-
ruby_exe("p RubyVM::MJIT.enabled?", options: "--disable=jit").chomp.should == "false"
44-
ruby_exe("p RubyVM::MJIT.enabled?", options: "--enable-jit").chomp.should == "true"
45-
ruby_exe("p RubyVM::MJIT.enabled?", options: "--disable-jit").chomp.should == "false"
46-
end
47-
end
48-
4940
it "can be used with all" do
5041
e = "p [defined?(Gem), defined?(DidYouMean), $VERBOSE, 'foo'.frozen?]"
5142
env = {'RUBYOPT' => '-w'}

0 commit comments

Comments
 (0)