From efd11643f01e78cf1f7912ee0a9c6a30075835bb Mon Sep 17 00:00:00 2001 From: tannevaled Date: Sun, 6 Sep 2026 13:02:24 +0200 Subject: [PATCH 1/2] conformance: implement the complain/output mspec matchers, floor to 19009 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The ratchet shim stubbed complain/output/output_to_fd as SpecSkip, so every example using `.should_not complain`, `.should complain(/…/)` or `.should output(…)` was skipped — 68 corpus files use complain, 12 use output. Implement ComplainMatcher and OutputMatcher (capture $stderr/$stdout via StringIO around the block, match a String exactly or a Regexp, honour complain's verbose: keyword), mirroring mspec's matchers. rbgo already supports $stdout/$stderr reassignment to a StringIO (wave-11), so the capture is exact. output_to_fd (real fd redirection) stays unsupported. Measured 19009 passing on the pinned corpus (up from 18790, +219), files loaded 2164 / failed-to-load 42 both unchanged (no load regression). CI's ratchet runs at TIMEOUT=60 (more lenient than the local 25s), so it measures at least the local total. Co-Authored-By: Claude Opus 4.8 --- scripts/conformance/rubyspec/FLOOR | 2 +- scripts/conformance/rubyspec/spec_helper.rb | 57 ++++++++++++++++++++- 2 files changed, 56 insertions(+), 3 deletions(-) diff --git a/scripts/conformance/rubyspec/FLOOR b/scripts/conformance/rubyspec/FLOOR index 2f49cedb..55d69a0e 100644 --- a/scripts/conformance/rubyspec/FLOOR +++ b/scripts/conformance/rubyspec/FLOOR @@ -1 +1 @@ -18790 +19009 diff --git a/scripts/conformance/rubyspec/spec_helper.rb b/scripts/conformance/rubyspec/spec_helper.rb index 93426777..9d833c23 100644 --- a/scripts/conformance/rubyspec/spec_helper.rb +++ b/scripts/conformance/rubyspec/spec_helper.rb @@ -112,8 +112,61 @@ def matches?(array) def failure_message; @bad || "be_computed_by(#{@sym}) mismatch"; end end def be_computed_by(sym, *extra); BeComputedByMatcher.new(sym, *extra); end -def complain(*a); raise SpecSkip, "complain matcher unsupported"; end -def output(*a); raise SpecSkip, "output matcher unsupported"; end +# complain: the block should (or should_not) write a warning to $stderr. An +# optional String (exact) or Regexp (match) constrains the warning text; the +# verbose: keyword runs the block under that $VERBOSE. Mirrors mspec's +# ComplainMatcher (mspec/lib/mspec/matchers/complain.rb). +class ComplainMatcher + def initialize(pat, verbose); @pat, @verbose = pat, verbose; end + def matches?(callable) + require "stringio" + old_err, $stderr = $stderr, StringIO.new + set_v = !@verbose.nil? + old_v = $VERBOSE if set_v + $VERBOSE = @verbose if set_v + begin + callable.call + ensure + $VERBOSE = old_v if set_v + out = $stderr.string + $stderr = old_err + end + if @pat.nil? + !out.empty? + elsif @pat.is_a?(Regexp) + !!(out =~ @pat) + else + out == @pat + end + end + def failure_message; "expected a warning#{@pat ? " matching #{@pat.inspect}" : ''}"; end +end +def complain(pat = nil, verbose: nil); ComplainMatcher.new(pat, verbose); end + +# output: capture $stdout (and, with a second argument, $stderr) around the block +# and match each against a String (exact) or Regexp. Mirrors mspec's +# OutputMatcher. output_to_fd (real fd redirection) stays unsupported. +class OutputMatcher + def initialize(out, err); @out, @err = out, err; end + def matches?(callable) + require "stringio" + oo, $stdout = $stdout, StringIO.new + oe, $stderr = $stderr, StringIO.new + begin + callable.call + ensure + so, se = $stdout.string, $stderr.string + $stdout, $stderr = oo, oe + end + ok = true + ok &&= match_stream(@out, so) unless @out.nil? + ok &&= match_stream(@err, se) unless @err.nil? + ok + end + def match_stream(pat, s); pat.is_a?(Regexp) ? !!(s =~ pat) : (s == pat); end + def failure_message; "output did not match"; end +end +def output(out = nil, err = nil); OutputMatcher.new(out, err); end def output_to_fd(*a); raise SpecSkip, "output_to_fd matcher unsupported"; end class RaiseMatcher From ef56c67cf72edc44da1c5ae6ecdc7d2ce4b7f6c0 Mon Sep 17 00:00:00 2001 From: tannevaled Date: Sun, 6 Sep 2026 13:22:19 +0200 Subject: [PATCH 2/2] conformance: make complain matcher faithful to mspec, floor 19008 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Read ruby/mspec's lib/mspec/matchers/complain.rb: the real matcher runs the block under $VERBOSE = false by default (or the given verbose: value) and still requires a non-empty warning even after a constraining pattern matches (it ends on warning.empty? ? false : true). Our lenient version left $VERBOSE at the ambient level and returned the bare pattern comparison, which counted one example that only passes because the matcher was looser than real mspec — a false pass masking an rbgo warning-level nonconformance. Faithful total is 19008 (one honest example below the lenient 19009). Also drops a peer-added always-true ComplainMatcher stub that this class fully overrode, leaving a single coherent definition. Co-Authored-By: Claude Opus 4.8 --- scripts/conformance/rubyspec/FLOOR | 2 +- scripts/conformance/rubyspec/spec_helper.rb | 30 ++++++++++----------- 2 files changed, 15 insertions(+), 17 deletions(-) diff --git a/scripts/conformance/rubyspec/FLOOR b/scripts/conformance/rubyspec/FLOOR index 55d69a0e..e0279337 100644 --- a/scripts/conformance/rubyspec/FLOOR +++ b/scripts/conformance/rubyspec/FLOOR @@ -1 +1 @@ -19009 +19008 diff --git a/scripts/conformance/rubyspec/spec_helper.rb b/scripts/conformance/rubyspec/spec_helper.rb index 9d833c23..f9bbade1 100644 --- a/scripts/conformance/rubyspec/spec_helper.rb +++ b/scripts/conformance/rubyspec/spec_helper.rb @@ -70,12 +70,6 @@ def matches?(actual) def failure_message; "expected to be close to #{@exp} (+/- #{@tol})"; end end -class ComplainMatcher - def initialize(*a); end - def matches?(actual); actual.call if actual.respond_to?(:call); true; end - def failure_message; "complain"; end -end - TOLERANCE = 0.00003 # Faithful to real mspec (mspec/lib/mspec/matchers/be_close.rb): a top-level # (Object) constant, generously large "to account for GC, context switches, @@ -121,23 +115,27 @@ def initialize(pat, verbose); @pat, @verbose = pat, verbose; end def matches?(callable) require "stringio" old_err, $stderr = $stderr, StringIO.new - set_v = !@verbose.nil? - old_v = $VERBOSE if set_v - $VERBOSE = @verbose if set_v + # mspec runs the block under $VERBOSE = false by default, or the given + # verbose: value; it never leaves the ambient level in place. + old_v = $VERBOSE + $VERBOSE = @verbose.nil? ? false : @verbose begin callable.call ensure - $VERBOSE = old_v if set_v + $VERBOSE = old_v out = $stderr.string $stderr = old_err end - if @pat.nil? - !out.empty? - elsif @pat.is_a?(Regexp) - !!(out =~ @pat) - else - out == @pat + # A constraining pattern must match, but a warning is still required: mspec + # ends on `warning.empty? ? false : true` even after a successful match. + unless @pat.nil? + if @pat.is_a?(Regexp) + return false unless out =~ @pat + else + return false unless out == @pat + end end + !out.empty? end def failure_message; "expected a warning#{@pat ? " matching #{@pat.inspect}" : ''}"; end end