Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 5 additions & 3 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -103,8 +103,10 @@ jobs:
GOWASIRUNTIME: wazero
run: |
GOOS=wasip1 GOARCH=wasm go vet ./cmd/rbgo ./internal/vm
# Exercise the wasm build-tagged statSys (internal/vm/filestat_wasm.go)
# by running its covering test as a wasm binary under wazero.
# Two things run as a wasm binary under wazero: the wasm build-tagged
# statSys (internal/vm/filestat_wasm.go), and the end-to-end claim that
# a program with an observable effect has one. The build steps above
# prove the module links; only this proves it interprets.
GOOS=wasip1 GOARCH=wasm go test -c -o vm.test.wasm ./internal/vm
"$(go env GOPATH)/bin/wazero" run -mount=/tmp:/tmp -env TMPDIR=/tmp \
vm.test.wasm -test.run 'TestStatSysExtract' -test.v
vm.test.wasm -test.run 'TestStatSysExtract|TestRunsAProgramOnThisHost' -test.v
48 changes: 48 additions & 0 deletions internal/vm/runs_a_program_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
package vm

import (
"strings"
"testing"

"github.com/go-embedded-ruby/ruby/internal/compiler"
"github.com/go-ruby-parser/parser"
)

// TestRunsAProgramOnThisHost is the smallest claim an interpreter can make: a
// program with an observable effect has one. Parse, compile, run, and look for
// the string the program printed — no fixture, no golden file, nothing that can
// pass while the VM produces nothing.
//
// It is written to be run on every host the project targets, and the wasip1
// lane in ci.yml runs exactly this test under wazero. That is deliberate: a
// build gate proves the module links, not that it interprets. This one costs a
// couple of hundred milliseconds and would have caught, in CI, a wasm build
// that loads and then quietly does nothing.
//
// (It came out of a false alarm worth recording: rbgo appeared not to run
// programs at all under wasip1 — silent CLI, and this very test hanging inside
// vm.New. The stall was in the host runtime, wasmer 7.2.1, whose stopping point
// moved between identical runs; the same .wasm file passes under wazero in
// 0.07s. Hence the runtime named in CI.)
func TestRunsAProgramOnThisHost(t *testing.T) {
prog, err := parser.Parse("puts 'HELLO-FROM-VM'\n")
if err != nil {
t.Fatalf("parse: %v", err)
}
iseq, err := compiler.Compile(prog)
if err != nil {
t.Fatalf("compile: %v", err)
}
if len(iseq.Insns) == 0 {
t.Fatal("compiled to zero instructions")
}

var out strings.Builder
m := New(&out)
if _, err := m.Run(iseq); err != nil {
t.Fatalf("run: %v", err)
}
if got := out.String(); !strings.Contains(got, "HELLO-FROM-VM") {
t.Fatalf("the program produced no output: %q (%d instructions)", got, len(iseq.Insns))
}
}