Skip to content

Proposal: Add -o and -c flags to llgo test #1453

@xgopilot

Description

@xgopilot

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 file ends in / or is a directory, writes pkg.test in that directory
  • Errors when used with multiple packages
  • Shared with build command using the existing OutputFile variable

-c

Compile test binary to pkg.test in current directory but do not run it.

  • Output location can be changed with -o flag
  • 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 CompileOnly variable
  • Use existing OutputFile variable (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 CompileOnly field to Config struct

internal/build/run.go:

  • Check CompileOnly and 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


This is a simplified, focused proposal for the core compilation flags. Additional flags (-args, -json) will be proposed separately.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions