-
Notifications
You must be signed in to change notification settings - Fork 46
Closed
Description
Overview
This proposal outlines the implementation of two standard go test flags for llgo test to improve compatibility with Go tooling.
Flags to Implement
| Flag | Description |
|---|---|
-o file |
Compile test binary to named file |
-c |
Compile test binary but do not run it |
Flag Details
-o file
Compile test binary to the specified file. Test still runs unless -c is specified.
- If
fileends in/or is a directory, writespkg.testin that directory - Errors when used with multiple packages
- Shared with build command using the existing
OutputFilevariable
-c
Compile test binary to pkg.test in current directory but do not run it.
- Output location can be changed with
-oflag - Useful for cross-compilation and CI workflows
Design Decisions
Shared Output File Variable
Use the existing OutputFile variable for both build and test commands.
Reason: Simplifies implementation and avoids duplication. The -o flag has the same semantics in both contexts.
Implementation:
func AddTestFlags(fs *flag.FlagSet) {
fs.StringVar(&OutputFile, "o", "", "Compile test binary to the named file")
fs.BoolVar(&CompileOnly, "c", false, "Compile test binary but do not run it")
}Implementation Plan
Modified Files
cmd/internal/flags/flags.go:
- Add
CompileOnlyvariable - Use existing
OutputFilevariable (no new variable needed) - Create
AddTestFlags()function - Update
UpdateConfig()for ModeTest
cmd/internal/test/test.go:
- Call
flags.AddTestFlags()in init
internal/build/build.go:
- Add
CompileOnlyfield to Config struct
internal/build/run.go:
- Check
CompileOnlyand skip execution when true
Example Usage
# Compile test binary without running
llgo test -c .
# Compile to specific file
llgo test -c -o mytest.test .
# Compile to specific output and run
llgo test -o mytest.test .Compatibility
- ✅ All changes are additive and backward compatible
- ✅ Works with embedded targets (e.g., rp2040, wasi)
- ✅ Works with emulator mode
- ✅ No breaking changes to existing behavior
Related
- Comprehensive proposal: Proposal: Add 'go test' Flags Implementation Details #1447 (covers additional flags
-argsand-json) - Implementation PR: [CLOSE] Implement go test flags: -o and -c (#1447) #1448
This is a simplified, focused proposal for the core compilation flags. Additional flags (-args, -json) will be proposed separately.
Metadata
Metadata
Assignees
Labels
No labels