Files
llgo/_demo/go/gobuild/demo.go
xgopilot e614edfab4 test: enhance demo to test multiple go/build public functions
Enhanced the demo test to cover more go/build functionality:
- build.Import (existing)
- build.ImportDir (new)
- build.IsLocalImport (new)
- build.Default context verification (existing, improved)

This ensures the go/build patches work correctly across different
public functions, not just Import.

Also ran go fmt to fix formatting issues reported by CI.

🤖 Generated with [codeagent](https://github.com/qbox/codeagent)
Co-authored-by: luoliwoshang <luoliwoshang@users.noreply.github.com>
2025-10-16 11:22:19 +00:00

54 lines
1.4 KiB
Go

package main
import (
"fmt"
"go/build"
"runtime"
)
func main() {
fmt.Printf("runtime.Compiler = %q\n", runtime.Compiler)
// Test 1: Check build.Default context
ctx := build.Default
fmt.Printf("build.Default.Compiler = %q\n", ctx.Compiler)
if ctx.Compiler != "gc" {
panic(fmt.Sprintf("expected build.Default.Compiler to be \"gc\", got %q", ctx.Compiler))
}
if len(ctx.ToolTags) == 0 {
panic("expected build.Default.ToolTags to be non-empty")
}
fmt.Printf("build.Default.ToolTags = %v\n", ctx.ToolTags)
if len(ctx.ReleaseTags) == 0 {
panic("expected build.Default.ReleaseTags to be non-empty")
}
fmt.Printf("build.Default.ReleaseTags count = %d\n", len(ctx.ReleaseTags))
// Test 2: build.Import with FindOnly
pkg, err := build.Import("fmt", "", build.FindOnly)
if err != nil {
panic(fmt.Sprintf("build.Import failed: %v", err))
}
fmt.Printf("build.Import(\"fmt\"): %s\n", pkg.ImportPath)
// Test 3: build.ImportDir
dirPkg, err := build.ImportDir(".", build.FindOnly)
if err != nil {
panic(fmt.Sprintf("build.ImportDir failed: %v", err))
}
fmt.Printf("build.ImportDir(\".\"): %s\n", dirPkg.Name)
// Test 4: build.IsLocalImport
if !build.IsLocalImport("./foo") {
panic("expected \"./foo\" to be a local import")
}
if build.IsLocalImport("fmt") {
panic("expected \"fmt\" not to be a local import")
}
fmt.Printf("build.IsLocalImport works correctly\n")
fmt.Printf("Success! All go/build public functions work with llgo\n")
}