Update runner examples to spxrunner#142
Conversation
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #142 +/- ##
==========================================
+ Coverage 54.28% 55.03% +0.75%
==========================================
Files 13 13
Lines 1179 1201 +22
==========================================
+ Hits 640 661 +21
- Misses 520 521 +1
Partials 19 19 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
There was a problem hiding this comment.
Code Review
This pull request introduces a new runner directive to the gop.mod file, allowing users to specify a custom runner for their projects. The changes include the definition of the Runner struct, logic for parsing the directive within the modfile package, and comprehensive test cases for both valid and invalid usage. A review comment suggests enforcing a maximum of two arguments for the runner directive to ensure consistency and prevent misleading configurations.
| if len(args) < 1 { | ||
| errorf("usage: runner runnerCmdPkgPath [version]") | ||
| return | ||
| } |
There was a problem hiding this comment.
The current implementation doesn't check for the maximum number of arguments. A runner statement with more than two arguments (e.g., runner path version extra) will be partially processed, with the extra arguments being ignored. This can be misleading and is inconsistent with how other directives like import are handled.
It's better to enforce that runner has at most two arguments. You could also add a new test case for this scenario to ensure correctness.
| if len(args) < 1 { | |
| errorf("usage: runner runnerCmdPkgPath [version]") | |
| return | |
| } | |
| if len(args) < 1 || len(args) > 2 { | |
| errorf("usage: runner runnerCmdPkgPath [version]") | |
| return | |
| } | |
| runnerVer := "" | ||
| if len(args) > 1 { | ||
| runnerVer, err = parseString(&args[1]) | ||
| if err != nil { |
There was a problem hiding this comment.
parseString only unquotes the value — it performs no semver/module-version format validation. An arbitrary string like "foobar" or "2.0.1" (missing the v prefix) is silently accepted. Peer directives such as xgo validate their version against modfile.GoVersionRE. Consider calling semver.IsValid from golang.org/x/mod/semver here, or at minimum document that no format enforcement is applied.
| if proj.Runner != nil { | ||
| errorf("repeated runner statement") | ||
| return | ||
| } |
There was a problem hiding this comment.
There is no upper-bound guard (len(args) > 2). A directive like runner github.com/foo v1.0 extraToken silently drops extraToken. Other directives (e.g. xgo) reject extraneous arguments. Consider adding:
if len(args) > 2 {
errorf("usage: runner runnerCmdPkgPath [version]")
return
}| // per project is allowed. | ||
| // Example: runner github.com/goplus/spx/v2/cmd/spxrunner | ||
| // Example with version: runner github.com/goplus/spx/v2/cmd/spxrunner v2.0.1 | ||
| // The optional version must be written as the second argument, not as path@version. |
There was a problem hiding this comment.
The comment warns against path@version syntax, but isPkgPath only checks for a non-empty string not starting with . or _. A path containing @ (e.g. github.com/foo/bar@v2) passes validation silently and is stored as-is in Runner.Path. Either enforce the restriction in parsePkgPath, or update the doc to clarify it's guidance only.
| runner github.com/goplus/spx/v2/cmd/spxrunner v2.0.1 | ||
|
|
||
| require ( | ||
| github.com/ajstarks/svgo v0.0.0-20210927141636-6d70534b1098 |
There was a problem hiding this comment.
goxmodSpx2 now includes a runner directive, but TestParse2 never asserts that the parsed Runner fields are correct. A test like:
if proj.Runner == nil || proj.Runner.Path != "github.com/goplus/spx/v2/cmd/spxrunner" || proj.Runner.Version != "v2.0.1" {
t.Fatal("unexpected Runner:", proj.Runner)
}would ensure the happy path is actually exercised and guard against silent regressions.
|
Clean implementation that mirrors existing |
modfile: clarify runner command package syntax
99b18ab to
46215c6
Compare
modfile: clarify runner command package syntax