-
Notifications
You must be signed in to change notification settings - Fork 10
Update runner examples to spxrunner #142
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -32,6 +32,18 @@ type Compiler struct { | |||||||||||||||||||
| Version string | ||||||||||||||||||||
| } | ||||||||||||||||||||
|
|
||||||||||||||||||||
| // A Runner is the runner statement that specifies a custom runner for the project. | ||||||||||||||||||||
| // The runner directive must appear after a project statement and only one runner | ||||||||||||||||||||
| // 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. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The comment warns against |
||||||||||||||||||||
| type Runner struct { | ||||||||||||||||||||
| Path string // command package path of the runner | ||||||||||||||||||||
| Version string // optional version of the runner command package | ||||||||||||||||||||
| Syntax *Line | ||||||||||||||||||||
| } | ||||||||||||||||||||
|
|
||||||||||||||||||||
| // A File is the parsed, interpreted form of a gox.mod file. | ||||||||||||||||||||
| type File struct { | ||||||||||||||||||||
| XGo *XGo | ||||||||||||||||||||
|
|
@@ -83,6 +95,7 @@ type Project struct { | |||||||||||||||||||
| Works []*Class // work class of classfile | ||||||||||||||||||||
| PkgPaths []string // package paths of classfile and optional inline-imported packages. | ||||||||||||||||||||
| Import []*Import // auto-imported packages | ||||||||||||||||||||
| Runner *Runner // custom runner | ||||||||||||||||||||
| Syntax *Line | ||||||||||||||||||||
| } | ||||||||||||||||||||
|
|
||||||||||||||||||||
|
|
@@ -319,6 +332,34 @@ usage: class [-embed -prefix=Prefix] *.workExt WorkClass [WorkPrototype]`, sw) | |||||||||||||||||||
| errorf("usage: import [name] pkgPath") | ||||||||||||||||||||
| return | ||||||||||||||||||||
| } | ||||||||||||||||||||
| case "runner": | ||||||||||||||||||||
| proj := f.proj() | ||||||||||||||||||||
| if proj == nil { | ||||||||||||||||||||
| errorf("runner must declare after a project definition") | ||||||||||||||||||||
| return | ||||||||||||||||||||
| } | ||||||||||||||||||||
| if proj.Runner != nil { | ||||||||||||||||||||
| errorf("repeated runner statement") | ||||||||||||||||||||
| return | ||||||||||||||||||||
| } | ||||||||||||||||||||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. There is no upper-bound guard ( if len(args) > 2 {
errorf("usage: runner runnerCmdPkgPath [version]")
return
} |
||||||||||||||||||||
| if len(args) < 1 { | ||||||||||||||||||||
| errorf("usage: runner runnerCmdPkgPath [version]") | ||||||||||||||||||||
| return | ||||||||||||||||||||
| } | ||||||||||||||||||||
|
Comment on lines
+345
to
+348
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The current implementation doesn't check for the maximum number of arguments. A It's better to enforce that
Suggested change
|
||||||||||||||||||||
| runnerPath, err := parsePkgPath(&args[0]) | ||||||||||||||||||||
| if err != nil { | ||||||||||||||||||||
| wrapError(err) | ||||||||||||||||||||
| return | ||||||||||||||||||||
| } | ||||||||||||||||||||
| runnerVer := "" | ||||||||||||||||||||
| if len(args) > 1 { | ||||||||||||||||||||
| runnerVer, err = parseString(&args[1]) | ||||||||||||||||||||
| if err != nil { | ||||||||||||||||||||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||||||||||||||||||||
| wrapError(err) | ||||||||||||||||||||
| return | ||||||||||||||||||||
| } | ||||||||||||||||||||
| } | ||||||||||||||||||||
| proj.Runner = &Runner{Path: runnerPath, Version: runnerVer, Syntax: line} | ||||||||||||||||||||
| default: | ||||||||||||||||||||
| if strict { | ||||||||||||||||||||
| errorf("unknown directive: %s", verb) | ||||||||||||||||||||
|
|
||||||||||||||||||||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
goxmodSpx2now includes arunnerdirective, butTestParse2never asserts that the parsedRunnerfields are correct. A test like:would ensure the happy path is actually exercised and guard against silent regressions.