Skip to content

Commit 9decddb

Browse files
tannevaledclaude
andcommitted
test(vm): cover the two helper branches the coverage gate named
The per-function coverage ratchet (#734) failed this branch on both POSIX lanes with exactly what it is for: -- NEWLY BELOW 100% (2) -- internal/vm/method_reflect.go aliasBuiltinS 75.0% (was fully covered) internal/vm/numeric_edges.go guardArgc 96.7% (was fully covered) Both are in the new code, and neither is reachable from a call site, which is why the local suite was green: * aliasBuiltinS's panic arm. The panic test tabled aliasBuiltin and defineBuiltinSecondName but not the two SINGLETON helpers, whose own `if !ok` is a separate statement. Both are tabled now, which also pins that the message names the right qualifier -- "Probe#absent" for an instance method, "Probe.absent" for a singleton one. * guardArgc's "this definition is already handled" skip. No current call site reaches it: the one in numeric_edges.go lists imaginary, real and rectangular, whose sharers (imag, rect) are not themselves in the list. So it is tested directly rather than left to a future caller to find. Double-wrapping would not break the guard, but it would leave the second name pointing at a record the first no longer holds, which is the exact identity defect this branch exists to fix -- so the test asserts the shared definition and #original_name survive guarding both names. The same test also pins that guardArgc SKIPS a name the table does not hold rather than panicking, unlike the alias helpers: it is a post-hoc wrapper over whatever was registered, and some registrations are platform-dependent (fork/exec are absent under wasm). The two shapes differ on purpose. Measured with the CI toolchain (go1.27.1, CGO_ENABLED=0): all six helpers -- aliasBuiltin, aliasBuiltinS, defineBuiltinSecondName, defineBuiltinSecondNameS, secondNameIn, guardArgc -- at 100.0% from these tests alone. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
1 parent df43680 commit 9decddb

1 file changed

Lines changed: 47 additions & 1 deletion

File tree

‎internal/vm/wave55_alias_sites_test.go‎

Lines changed: 47 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@ package vm
77
import (
88
"strings"
99
"testing"
10+
11+
"github.com/go-embedded-ruby/ruby/internal/object"
1012
)
1113

1214
// TestBuiltinSecondNameReportsItself: MRI gives most of the pairs that look like
@@ -269,15 +271,20 @@ func TestAliasHelpersPanicOnAMissingOldName(t *testing.T) {
269271
}{
270272
{"aliasBuiltin", func(c *RClass) { aliasBuiltin(c, "new_name", "absent") }},
271273
{"defineBuiltinSecondName", func(c *RClass) { defineBuiltinSecondName(c, "new_name", "absent") }},
274+
{"aliasBuiltinS", func(c *RClass) { aliasBuiltinS(c, "new_name", "absent") }},
275+
{"defineBuiltinSecondNameS", func(c *RClass) { defineBuiltinSecondNameS(c, "new_name", "absent") }},
272276
} {
273277
t.Run(tc.name, func(t *testing.T) {
274-
cls := &RClass{name: "Probe", methods: map[string]*Method{}}
278+
cls := &RClass{name: "Probe", methods: map[string]*Method{}, smethods: map[string]*Method{}}
275279
defer func() {
276280
r := recover()
277281
if r == nil {
278282
t.Fatalf("%s returned quietly for an absent old name; it must panic", tc.name)
279283
}
280284
msg, _ := r.(string)
285+
// The qualifier differs by table -- "Probe#absent" for an instance
286+
// method, "Probe.absent" for a singleton one -- so the message is
287+
// checked by its parts rather than as one string.
281288
for _, want := range []string{tc.name, "Probe", "absent", "new_name"} {
282289
if !strings.Contains(msg, want) {
283290
t.Errorf("panic message %q does not name %q", msg, want)
@@ -288,3 +295,42 @@ func TestAliasHelpersPanicOnAMissingOldName(t *testing.T) {
288295
})
289296
}
290297
}
298+
299+
// TestArityGuardHandlesEachDefinitionOnce: guardArgc carries its wrapper to every
300+
// name over one definition, so a names list that happens to contain two of those
301+
// names must not wrap the second a second time. No current call site does -- the
302+
// one in numeric_edges.go lists imaginary, real and rectangular, whose sharers
303+
// (imag, rect) are not themselves in the list -- so the skip is reachable only
304+
// from here, and it is tested here rather than left to a future caller to
305+
// discover. Double-wrapping would not break the guard, but it would leave the
306+
// second name pointing at a record the first no longer holds, which is the
307+
// identity defect this whole change is about.
308+
func TestArityGuardHandlesEachDefinitionOnce(t *testing.T) {
309+
body := func(_ *VM, self object.Value, _ []object.Value, _ *Proc) object.Value {
310+
return object.IntValue(7)
311+
}
312+
cls := &RClass{name: "Probe", methods: map[string]*Method{}, smethods: map[string]*Method{}}
313+
cls.define("canonical", body)
314+
defineBuiltinSecondName(cls, "second", "canonical")
315+
316+
// Both names in the list, so the second one is already marked done.
317+
guardNoArg(cls, "canonical", "second")
318+
319+
a, b := cls.methods["canonical"], cls.methods["second"]
320+
if methodDefKey(a) != methodDefKey(b) {
321+
t.Errorf("guarding both names split the definition: canonical and second no longer share it")
322+
}
323+
if got := methodOriginalName(b); got != "second" {
324+
t.Errorf("second#original_name = %q after guarding, want %q", got, "second")
325+
}
326+
if !a.argc.declared || !b.argc.declared {
327+
t.Errorf("the guard declared arity on %v/%v, want both", a.argc.declared, b.argc.declared)
328+
}
329+
// And a name the table does not hold is skipped, not panicked on: guardArgc
330+
// is a post-hoc wrapper over whatever was registered, and some registrations
331+
// are platform-dependent (fork/exec are absent under wasm).
332+
guardNoArg(cls, "never_registered")
333+
if _, ok := cls.methods["never_registered"]; ok {
334+
t.Errorf("guardArgc invented a method for a name that was not registered")
335+
}
336+
}

0 commit comments

Comments
 (0)