fix(testrun): pass the jvm the flag that silences the jdk 24 unsafe warning

This commit is contained in:
pj committed 2026-09-05 16:40:27 +05:30
1 parent 7b44b0c9a9
commit 8c31e2bf6f
2 files changed
+61 -7

No files matched your search

+41
View File
@@ -4,7 +4,10 @@ import (
"context"
"errors"
"io"
"os"
"os/exec"
"path/filepath"
"slices"
"strings"
"testing"
"time"
@@ -305,3 +308,41 @@ func TestResolveIOSTargetDeviceResolutionErrorSurfaces(t *testing.T) {
t.Fatal("expected the device-resolution error to surface")
}
}
func fakeJava(t *testing.T, script string) {
t.Helper()
directory := t.TempDir()
path := filepath.Join(directory, "java")
if err := os.WriteFile(path, []byte("#!/bin/sh\n"+script+"\n"), 0o755); err != nil {
t.Fatalf("write fake java: %v", err)
}
t.Setenv("PATH", directory)
}
func TestSidecarArgumentsSilencesTheUnsafeWarningOnAJvmThatTakesTheFlag(t *testing.T) {
fakeJava(t, "exit 0")
args := sidecarArguments(context.Background(), "/tmp/sidecar.jar", 51129, "android", "663c91b1")
want := []string{
"--sun-misc-unsafe-memory-access=allow",
"-jar", "/tmp/sidecar.jar",
"--port", "51129",
"--platform", "android",
"--serial", "663c91b1",
}
if !slices.Equal(args, want) {
t.Fatalf("sidecar argv = %q, want %q", args, want)
}
}
func TestSidecarArgumentsOmitsTheFlagAJvmBefore23WouldRefuseToStartWith(t *testing.T) {
fakeJava(t, `case "$1" in --sun-misc-unsafe-memory-access=*) echo "Unrecognized option: $1" >&2; exit 1;; esac; exit 0`)
args := sidecarArguments(context.Background(), "/tmp/sidecar.jar", 51129, "android", "")
want := []string{"-jar", "/tmp/sidecar.jar", "--port", "51129", "--platform", "android"}
if !slices.Equal(args, want) {
t.Fatalf("sidecar argv = %q, want %q", args, want)
}
}