Skip to content

Commit b851608

Browse files
committed
[GR-14806] Update specs
PullRequest: truffleruby/3214
2 parents 8f5d1fc + f5d4634 commit b851608

File tree

13 files changed

+97
-76
lines changed

13 files changed

+97
-76
lines changed

spec/mspec/lib/mspec/commands/mspec.rb

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ def options(argv = ARGV)
2525
config[:command] = argv.shift if ["ci", "run", "tag"].include?(argv[0])
2626

2727
options = MSpecOptions.new "mspec [COMMAND] [options] (FILE|DIRECTORY|GLOB)+", 30, config
28+
@options = options
2829

2930
options.doc " The mspec command sets up and invokes the sub-commands"
3031
options.doc " (see below) to enable, for instance, running the specs"
@@ -110,8 +111,9 @@ def run
110111
if config[:multi]
111112
exit multi_exec(argv)
112113
else
113-
$stderr.puts "$ #{argv.join(' ')}"
114-
$stderr.flush
114+
log = config[:options].include?('--error-output') ? $stdout : $stderr
115+
log.puts "$ #{argv.join(' ')}"
116+
log.flush
115117
exec(*argv, close_others: false)
116118
end
117119
end

spec/mspec/lib/mspec/runner/formatters/base.rb

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
require 'mspec/expectations/expectations'
22
require 'mspec/runner/actions/timer'
33
require 'mspec/runner/actions/tally'
4+
require 'mspec/utils/options'
45

56
if ENV['CHECK_LEAKS']
67
require 'mspec/runner/actions/leakchecker'
@@ -18,10 +19,17 @@ def initialize(out = nil)
1819

1920
@count = 0 # For subclasses
2021

21-
if out.nil?
22+
if out
23+
@out = File.open out, "w"
24+
else
2225
@out = $stdout
26+
end
27+
28+
err = MSpecOptions.latest && MSpecOptions.latest.config[:error_output]
29+
if err
30+
@err = (err == 'stderr') ? $stderr : File.open(err, "w")
2331
else
24-
@out = File.open out, "w"
32+
@err = @out
2533
end
2634
end
2735

@@ -115,9 +123,9 @@ def finish
115123

116124
def print_exception(exc, count)
117125
outcome = exc.failure? ? "FAILED" : "ERROR"
118-
print "\n#{count})\n#{exc.description} #{outcome}\n"
119-
print exc.message, "\n"
120-
print exc.backtrace, "\n"
126+
@err.print "\n#{count})\n#{exc.description} #{outcome}\n"
127+
@err.print exc.message, "\n"
128+
@err.print exc.backtrace, "\n"
121129
end
122130

123131
# A convenience method to allow printing to different outputs.

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

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,10 @@ class OptionError < Exception; end
3232
# Raised if an unrecognized option is encountered.
3333
class ParseError < Exception; end
3434

35+
class << self
36+
attr_accessor :latest
37+
end
38+
3539
attr_accessor :config, :banner, :width, :options
3640

3741
def initialize(banner = "", width = 30, config = nil)
@@ -46,7 +50,7 @@ def initialize(banner = "", width = 30, config = nil)
4650
@extra << x
4751
}
4852

49-
yield self if block_given?
53+
MSpecOptions.latest = self
5054
end
5155

5256
# Registers an option. Acceptable formats for arguments are:
@@ -311,6 +315,11 @@ def formatters
311315
"Write formatter output to FILE") do |f|
312316
config[:output] = f
313317
end
318+
319+
on("--error-output", "FILE",
320+
"Write error output of failing specs to FILE, or $stderr if value is 'stderr'.") do |f|
321+
config[:error_output] = f
322+
end
314323
end
315324

316325
def filters

spec/ruby/.mspec.constants

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,7 @@ EvalBindingProcA
7373
Exception2MessageMapper
7474
ExceptionForMatrix
7575
Fcntl
76+
Fiddle
7677
FileStat
7778
FileUtils
7879
Find

spec/ruby/core/dir/read_spec.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -56,9 +56,9 @@
5656
Encoding.default_external = Encoding::SHIFT_JIS
5757
shift_jis_entries = []
5858
begin
59-
Dir.open(File.join(DirSpecs.mock_dir, 'special')) do |dir|
59+
Dir.open(File.join(DirSpecs.mock_dir, 'special')) do |d|
6060
-> {
61-
while entry = dir.read
61+
while entry = d.read
6262
shift_jis_entries << entry
6363
end
6464
}.should_not raise_error

spec/ruby/core/exception/interrupt_spec.rb

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -49,10 +49,12 @@
4949
out.should == "Interrupt: #{Signal.list["INT"]}\n"
5050
end
5151

52-
it "shows the backtrace and has a signaled exit status" do
53-
err = IO.popen([*ruby_exe, '-e', 'Process.kill :INT, Process.pid; sleep'], err: [:child, :out], &:read)
54-
$?.termsig.should == Signal.list.fetch('INT')
55-
err.should.include? ': Interrupt'
56-
err.should.include? "from -e:1:in `<main>'"
52+
platform_is_not :windows do
53+
it "shows the backtrace and has a signaled exit status" do
54+
err = IO.popen([*ruby_exe, '-e', 'Process.kill :INT, Process.pid; sleep'], err: [:child, :out], &:read)
55+
$?.termsig.should == Signal.list.fetch('INT')
56+
err.should.include? ': Interrupt'
57+
err.should.include? "from -e:1:in `<main>'"
58+
end
5759
end
5860
end

spec/ruby/core/rational/minus_spec.rb

Lines changed: 46 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,51 @@
1-
require_relative '../../shared/rational/minus'
1+
require_relative '../../spec_helper'
22
require_relative '../../shared/rational/arithmetic_exception_in_coerce'
33

44
describe "Rational#-" do
5-
it_behaves_like :rational_minus, :-
65
it_behaves_like :rational_arithmetic_exception_in_coerce, :-
6+
7+
it "calls #coerce on the passed argument with self" do
8+
rational = Rational(3, 4)
9+
obj = mock("Object")
10+
obj.should_receive(:coerce).with(rational).and_return([1, 2])
11+
12+
rational - obj
13+
end
14+
15+
it "calls #- on the coerced Rational with the coerced Object" do
16+
rational = Rational(3, 4)
17+
18+
coerced_rational = mock("Coerced Rational")
19+
coerced_rational.should_receive(:-).and_return(:result)
20+
21+
coerced_obj = mock("Coerced Object")
22+
23+
obj = mock("Object")
24+
obj.should_receive(:coerce).and_return([coerced_rational, coerced_obj])
25+
26+
(rational - obj).should == :result
27+
end
28+
end
29+
30+
describe "Rational#- passed a Rational" do
31+
it "returns the result of subtracting other from self as a Rational" do
32+
(Rational(3, 4) - Rational(0, 1)).should eql(Rational(3, 4))
33+
(Rational(3, 4) - Rational(1, 4)).should eql(Rational(1, 2))
34+
35+
(Rational(3, 4) - Rational(2, 1)).should eql(Rational(-5, 4))
36+
end
37+
end
38+
39+
describe "Rational#- passed a Float" do
40+
it "returns the result of subtracting other from self as a Float" do
41+
(Rational(3, 4) - 0.2).should eql(0.55)
42+
(Rational(3, 4) - 2.5).should eql(-1.75)
43+
end
44+
end
45+
46+
describe "Rational#- passed an Integer" do
47+
it "returns the result of subtracting other from self as a Rational" do
48+
(Rational(3, 4) - 1).should eql(Rational(-1, 4))
49+
(Rational(3, 4) - 2).should eql(Rational(-5, 4))
50+
end
751
end

spec/ruby/core/string/shared/to_sym.rb

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,15 @@
5353
sym.to_s.should == binary_string
5454
end
5555

56+
it "ignores exising symbols with different encoding" do
57+
source = "fée"
58+
59+
iso_symbol = source.force_encoding(Encoding::ISO_8859_1).send(@method)
60+
iso_symbol.encoding.should == Encoding::ISO_8859_1
61+
binary_symbol = source.force_encoding(Encoding::BINARY).send(@method)
62+
binary_symbol.encoding.should == Encoding::BINARY
63+
end
64+
5665
it "raises an EncodingError for UTF-8 String containing invalid bytes" do
5766
invalid_utf8 = "\xC3"
5867
invalid_utf8.should_not.valid_encoding?

spec/ruby/language/predefined_spec.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1324,6 +1324,7 @@ def obj.foo2; yield; end
13241324

13251325
it "returns what will be loaded without actual loading, .so file" do
13261326
require 'rbconfig'
1327+
skip "no dynamically loadable standard extension" if RbConfig::CONFIG["EXTSTATIC"] == "static"
13271328

13281329
extension, path = $LOAD_PATH.resolve_feature_path('etc')
13291330
extension.should == :so

spec/ruby/library/date/iso8601_spec.rb

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -17,20 +17,11 @@
1717
d.should == Date.civil(-4712, 1, 1)
1818
end
1919

20-
it "parses a Symbol into a Date object" do
21-
d = Date.iso8601(:'2015-10-15')
22-
d.should == Date.civil(2015, 10, 15)
23-
end
24-
2520
it "parses a StringSubclass into a Date object" do
2621
d = Date.iso8601(Class.new(String).new("-4712-01-01"))
2722
d.should == Date.civil(-4712, 1, 1)
2823
end
2924

30-
it "raises an ArgumentError when passed a Symbol without a valid Date" do
31-
-> { Date.iso8601(:test) }.should raise_error(ArgumentError)
32-
end
33-
3425
it "raises a TypeError when passed an Object" do
3526
-> { Date.iso8601(Object.new) }.should raise_error(TypeError)
3627
end

0 commit comments

Comments
 (0)