Repository navigation
fix(tool): take each command's target spellings in check, build and test (#589) - #593
Conversation
|
Thanks for your first pull request! Before it is merged:
|
houko
left a comment
There was a problem hiding this comment.
Thanks for taking this on. The check/build side looks right to me: expandTargets is the single place all three callers go through, android leaving out android_x64 matches all, and the docs, help texts and skill references are updated together. The new tests pass. A few things on the test side need to change before this can go in.
1. -activate rejects an arch-qualified macOS target. runTests checks opts.activate && opts.target != "macos" before it normalizes the target, so nsgo test -target macos_arm64 -activate fails with test: -activate goes with -target macos. The PR description says -activate and -fps see the plain name, but that's only true for -fps. Normalizing first, as the very first thing in runTests, fixes it. Please add a test for this case.
2. Any suffix is accepted. normalizeTestTarget only looks at what comes before the first _, so windows_foo, macos_ and linux_riscv64 all quietly become windows, macos and linux. The issue asks for an unknown name to list the accepted names. Please accept only the names in targets from build.go, so the two commands agree on what's valid.
3. The architecture is dropped without a word. buildTargetRunner builds the desktop targets for runtime.GOARCH (testtarget.go, the macos/windows/linux cases), and Android test builds always use GOARCH=arm64. So -target windows_arm64 on an x64 Windows host runs x64 tests and reports a pass, and -target android_x64 runs arm64. If someone asks for an architecture that won't actually run, they should hear about it. Either honor it where the host can run it, or reject a name whose architecture isn't the one the target uses here and say which name to use instead. The issue's Proposal covers this: "runs the windows target on that architecture where it can, or says which name to use".
4. Changelog reference. Entries reference the pull request and its author, as in (#79 by @togotop). This one should be (#593 by @dhruv1220), not (#589 by @houko).
A small one while you're in there: testtarget.go and build.go both import os, and the new loops name a variable os, which shadows the package. goos would read better.
I ran the new tests and probed these cases on Linux at bd1c4fc: the PR's tests pass, and items 1 to 3 reproduce as described.
…nable architectures (nsgo-dev#593) Address houko's review on nsgo-dev#593: - runTests normalizes -target first, via a new checkTestTarget, so -activate sees the plain name: `test -target macos_arm64 -activate` now works. TestActivateNeedsMacOSTarget drops "all", which is not a test target and now errors as unknown. - normalizeTestTarget accepts only the arch-qualified names in build.go's targets, so windows_foo, macos_ and linux_riscv64 are refused with the accepted names listed. - A spelling whose architecture the target cannot run is refused, naming the spelling to use: a desktop target runs this machine's architecture, Android's tests always run arm64. TestCheckTestTarget covers this host-independently. - CHANGELOG entry now references (nsgo-dev#593 by @dhruv1220). - `os` loop variables in testtarget.go and build.go renamed to `goos`, so they no longer shadow the os package. Both new/changed tests fail with the old normalize logic and with the arch check disabled. `go tool nsgo check` passes; `go tool nsgo test ./cmd/nsgo/` is 277 passed, 0 failed.
|
Thanks for the review — all four items plus the rename are addressed in c1c830a:
Also renamed the
|
|
Thanks, all four items and the rename are in. I ran One thing to fix: since the architecture check went in, the docs say a little more than the tool does. Optional: the architecture check runs before the host check, so on Linux |
Since #593 added checkTestTargetArch, nsgo test -target accepts an arch-qualified name only for the architecture the target runs on here (this machine's for desktops, arm64 for Android) and refuses the other, but the building guide, its zh mirror, the skill and the -target help still said any arch name simply means its OS.
Since #593 added checkTestTargetArch, nsgo test -target accepts an arch-qualified name only for the architecture the target runs on here (this machine's for desktops, arm64 for Android) and refuses the other, but the building guide, its zh mirror, the skill and the -target help still said any arch name simply means its OS.
Summary
Fixes #589:
nsgo check -target windowsfailed withunknown target "windows", whilensgo test -target windowstakes the plain OS name — the commands spelled targets differently, so verifying a cross-platform change meant learning two vocabularies and retyping the flag.Each command now takes the other's spelling:
nsgo check -target,nsgo build -targetandnsgo.yaml'sbuild.targetsaccept a bare OS name:windowsvets/buildswindows_arm64andwindows_x64,linuxandmacosthe same, andandroidisandroid_arm64only, as the x86_64 build needs an NDK (the same exclusionallalready makes). The expansion lives inexpandTargets, so all three callers agree.nsgo test -targetaccepts an arch-qualified name:windows_x64runs thewindowstarget, and likewise for macOS, Linux and Android. The target is normalized once at the top ofrunTests, so-activateand-fpsstill see the plain name.checkalready did throughexpandTargets, andtestnow validates up front instead of surfacingvetEnv's bareunknown targetfrom deep inside the listing step.Also updates the three
-targethelp texts, the Building docs (en and zh) and thensgoskill references, and adds a CHANGELOG line. While touchingskills/nsgo/references/testing.md, itsnsgo test -targetexample dropped a staleor all:testnever acceptedall.Targets
core,base,ui,tsx, thensgotool)Screenshots
None — nothing visible changes.
Verification
go tool nsgo check— passed (checked catalogs, vetted, vetted the dev client)go tool nsgo test ./cmd/nsgo/— full package suite: 276 passed, 0 failed, 20 skippedgo tool nsgo test -target <target>on the targets above — the newTestCheckBareOSTargetvetswindowsandlinuxthrough the realcheckon this Linux host;test -targetruns need a host of that OS and are covered byTestNormalizeTestTargetandTestRunTestsUnknownTargetListsNames.New tests, all failing before the fix and passing after it:
TestExpandTargetsBareOS/TestExpandTargetsBareOSDropsDuplicates(cmd/nsgo/build_test.go):windows/linux/macosexpand to both architectures,androidtoandroid_arm64, duplicates dropped.TestCheckBareOSTarget(cmd/nsgo/check_test.go):checkwithwindowsandlinuxvets both architectures of each.TestNormalizeTestTarget/TestRunTestsUnknownTargetListsNames(cmd/nsgo/test_test.go): arch-qualified spellings map to their OS, and an unknown test target errors listing the accepted names.Checklist
fix(linux): keep the caret after a paste; a squash merge uses it as the commit subject.CHANGELOG.md'sUnreleasedhas a line for a capability users can see.Review follow-up (c1c830a)
Addresses houko's review of 2026-11-18:
-targetis normalized first, via a newcheckTestTargetat the top ofrunTests, so-activatesees the plain name:test -target macos_arm64 -activatenow works.TestActivateNeedsMacOSTargetdropsall, which is not a test target and now errors as unknown.normalizeTestTargetaccepts only the arch-qualified names inbuild.go'stargets, sowindows_foo,macos_andlinux_riscv64are refused with the accepted names listed.arm64.TestCheckTestTargetcovers this host-independently.(#593 by @dhruv1220); theosloop variables intesttarget.goandbuild.goare nowgoos.Verification for this commit:
go tool nsgo checkpassed;go tool nsgo test ./cmd/nsgo/is 277 passed, 0 failed, 20 skipped, on a Linux host. The new/changed tests fail with the old normalize logic and with the arch check disabled.