Skip to content

Commit f5bde7e

Browse files
committed
[GR-14806] Update specs.
PullRequest: truffleruby/869
2 parents 3b887a1 + aa5e213 commit f5bde7e

File tree

27 files changed

+330
-647
lines changed

27 files changed

+330
-647
lines changed

spec/mspec/tool/tag_from_output.rb

100644100755
Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
#!/usr/bin/env ruby
2+
13
# Adds tags based on error and failures output (e.g., from a CI log),
24
# without running any spec code.
35

@@ -8,14 +10,12 @@
810
abort 'Could not find tags directory' unless tags_dir
911

1012
output = ARGF.readlines
11-
# Remove leading "[exec] " from JRuby logs
12-
output = output.map { |line| line.sub(/^\[exec\] /, '') }
1313

1414
NUMBER = /^\d+\)$/
1515
ERROR_OR_FAILED = / (ERROR|FAILED)$/
1616
SPEC_FILE = /^(\/.+_spec\.rb)\:\d+/
1717

18-
failures = output.slice_before(NUMBER).select { |number, error_line, *rest|
18+
output.slice_before(NUMBER).select { |number, error_line, *rest|
1919
number =~ NUMBER and error_line =~ ERROR_OR_FAILED
2020
}.each { |number, error_line, *rest|
2121
description = error_line.match(ERROR_OR_FAILED).pre_match
@@ -31,9 +31,8 @@
3131
Dir.mkdir(dir) unless Dir.exist?(dir)
3232

3333
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
34+
lines = File.exist?(tags_file) ? File.readlines(tags_file, chomp: true) : []
35+
unless lines.include?(tag_line)
36+
File.write(tags_file, (lines + [tag_line]).join("\n") + "\n")
3837
end
3938
}
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
require_relative '../../spec_helper'
2+
require_relative 'fixtures/classes'
3+
4+
ruby_version_is '2.7' do
5+
describe 'Enumerable#filter_map' do
6+
before :each do
7+
@numerous = EnumerableSpecs::Numerous.new(*(1..8).to_a)
8+
end
9+
10+
it 'returns an empty array if there are no elements' do
11+
EnumerableSpecs::Empty.new.filter_map { true }.should == []
12+
end
13+
14+
it 'returns an array with truthy results of passing each element to block' do
15+
@numerous.filter_map { |i| i * 2 if i.even? }.should == [4, 8, 12, 16]
16+
@numerous.filter_map { |i| i * 2 }.should == [2, 4, 6, 8, 10, 12, 14, 16]
17+
@numerous.filter_map { 0 }.should == [0, 0, 0, 0, 0, 0, 0, 0]
18+
@numerous.filter_map { false }.should == []
19+
@numerous.filter_map { nil }.should == []
20+
end
21+
22+
it 'returns an enumerator when no block given' do
23+
@numerous.filter_map.should be_an_instance_of(Enumerator)
24+
end
25+
end
26+
end

spec/ruby/core/enumerable/shared/find.rb

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,10 @@
4949
@empty.send(@method, fail_proc) {|e| true}.should == "yay"
5050
end
5151

52+
it "ignores the ifnone argument when nil" do
53+
@numerous.send(@method, nil) {|e| false }.should == nil
54+
end
55+
5256
it "passes through the values yielded by #each_with_index" do
5357
[:a, :b].each_with_index.send(@method) { |x, i| ScratchPad << [x, i]; nil }
5458
ScratchPad.recorded.should == [[:a, 0], [:b, 1]]

spec/ruby/core/exception/backtrace_spec.rb

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,4 +65,19 @@
6565
e.backtrace[0].should == "backtrace first"
6666
end
6767
end
68+
69+
it "returns the same array after duping" do
70+
begin
71+
raise
72+
rescue RuntimeError => err
73+
bt = err.backtrace
74+
err.dup.backtrace.should equal(bt)
75+
76+
new_bt = ['hi']
77+
err.set_backtrace new_bt
78+
79+
err.backtrace.should == new_bt
80+
err.dup.backtrace.should equal(new_bt)
81+
end
82+
end
6883
end
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
require_relative '../../spec_helper'
2+
3+
describe "FrozenError" do
4+
ruby_version_is "2.5" do
5+
it "is a subclass of RuntimeError" do
6+
RuntimeError.should be_ancestor_of(FrozenError)
7+
end
8+
end
9+
end
10+
11+
describe "FrozenError.new" do
12+
ruby_version_is "2.7" do
13+
it "should take optional receiver argument" do
14+
o = Object.new
15+
FrozenError.new("msg", o).receiver.should equal(o)
16+
end
17+
end
18+
end
19+
20+
describe "FrozenError#receiver" do
21+
ruby_version_is "2.7" do
22+
it "should return frozen object that modification was attempted on" do
23+
o = Object.new.freeze
24+
begin
25+
def o.x; end
26+
rescue => e
27+
e.should be_kind_of(FrozenError)
28+
e.receiver.should equal(o)
29+
else
30+
raise
31+
end
32+
end
33+
end
34+
end

spec/ruby/core/file/expand_path_spec.rb

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -225,6 +225,8 @@
225225
user = ENV.delete("USER")
226226
begin
227227
Etc.getlogin != nil
228+
rescue
229+
false
228230
ensure
229231
ENV["USER"] = user
230232
end

spec/ruby/core/hash/constructor_spec.rb

Lines changed: 20 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -42,13 +42,26 @@
4242
Hash[ary].should == { a: :b }
4343
end
4444

45-
it "ignores elements that are not arrays" do
46-
-> {
47-
Hash[[:a]].should == {}
48-
}.should complain(/ignoring wrong elements/)
49-
-> {
50-
Hash[[:nil]].should == {}
51-
}.should complain(/ignoring wrong elements/)
45+
ruby_version_is "" ... "2.7" do
46+
it "ignores elements that are not arrays" do
47+
-> {
48+
Hash[[:a]].should == {}
49+
}.should complain(/ignoring wrong elements/)
50+
-> {
51+
Hash[[:nil]].should == {}
52+
}.should complain(/ignoring wrong elements/)
53+
end
54+
end
55+
56+
ruby_version_is "2.7" do
57+
it "raises for elements that are not arrays" do
58+
-> {
59+
Hash[[:a]].should == {}
60+
}.should raise_error(ArgumentError)
61+
-> {
62+
Hash[[:nil]].should == {}
63+
}.should raise_error(ArgumentError)
64+
end
5265
end
5366

5467
it "raises an ArgumentError for arrays of more than 2 elements" do

spec/ruby/core/marshal/dump_spec.rb

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -449,14 +449,13 @@ def obj.foo; end
449449
zone = ":\tzoneI\"\bAST\x06:\x06EF" # Last is 'F' (US-ASCII)
450450
[ "#{base}#{offset}#{zone}", "#{base}#{zone}#{offset}" ].should include(dump)
451451
end
452-
453-
it "dumps the zone, but not the offset if zone is UTC" do
454-
dump = Marshal.dump(@utc)
455-
zone = ":\tzoneI\"\bUTC\x06:\x06EF" # Last is 'F' (US-ASCII)
456-
dump.should == "\x04\bIu:\tTime\r#{@utc_dump}\x06#{zone}"
457-
end
458452
end
459453

454+
it "dumps the zone, but not the offset if zone is UTC" do
455+
dump = Marshal.dump(@utc)
456+
zone = ":\tzoneI\"\bUTC\x06:\x06EF" # Last is 'F' (US-ASCII)
457+
dump.should == "\x04\bIu:\tTime\r#{@utc_dump}\x06#{zone}"
458+
end
460459
end
461460

462461
describe "with an Exception" do

spec/ruby/core/module/autoload_spec.rb

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -449,6 +449,9 @@ module ModuleSpecs::Autoload::Q
449449
it "does not load the file when accessing the constants table of the module" do
450450
ModuleSpecs::Autoload.autoload :P, @non_existent
451451
ModuleSpecs::Autoload.const_defined?(:P).should be_true
452+
ruby_bug "[Bug #15780]", ""..."2.7" do
453+
ModuleSpecs::Autoload.const_defined?("P").should be_true
454+
end
452455
end
453456

454457
it "loads the file when opening a module that is the autoloaded constant" do

spec/ruby/core/module/name_spec.rb

Lines changed: 37 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,34 @@
1515
it "is not nil for a nested module created with the module keyword" do
1616
m = Module.new
1717
module m::N; end
18-
m::N.name.should =~ /#<Module:0x[0-9a-f]+>::N/
18+
m::N.name.should =~ /\A#<Module:0x[0-9a-f]+>::N\z/
19+
end
20+
21+
it "changes when the module is reachable through a constant path" do
22+
m = Module.new
23+
module m::N; end
24+
m::N.name.should =~ /\A#<Module:0x\h+>::N\z/
25+
ModuleSpecs::Anonymous::WasAnnon = m::N
26+
m::N.name.should == "ModuleSpecs::Anonymous::WasAnnon"
27+
end
28+
29+
it "is set after it is removed from a constant" do
30+
module ModuleSpecs
31+
module ModuleToRemove
32+
end
33+
34+
mod = ModuleToRemove
35+
remove_const(:ModuleToRemove)
36+
mod.name.should == "ModuleSpecs::ModuleToRemove"
37+
end
38+
end
39+
40+
it "is set after it is removed from a constant under an anonymous module" do
41+
m = Module.new
42+
module m::Child; end
43+
child = m::Child
44+
m.send(:remove_const, :Child)
45+
child.name.should =~ /\A#<Module:0x\h+>::Child\z/
1946
end
2047

2148
it "is set when opened with the module keyword" do
@@ -40,6 +67,15 @@ module m::N; end
4067
m.name.should == "ModuleSpecs::Anonymous::B"
4168
end
4269

70+
it "is not modified when assigned to a different anonymous module" do
71+
m = Module.new
72+
module m::M; end
73+
first_name = m::M.name.dup
74+
module m::N; end
75+
m::N::F = m::M
76+
m::M.name.should == first_name
77+
end
78+
4379
# http://bugs.ruby-lang.org/issues/6067
4480
it "is set with a conditional assignment to a nested constant" do
4581
eval("ModuleSpecs::Anonymous::F ||= Module.new")

0 commit comments

Comments
 (0)