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>
This commit is contained in:
@@ -9,6 +9,7 @@ import (
|
||||
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" {
|
||||
@@ -25,10 +26,28 @@ func main() {
|
||||
}
|
||||
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(err)
|
||||
panic(fmt.Sprintf("build.Import failed: %v", err))
|
||||
}
|
||||
fmt.Printf("Package: %s\n", pkg.ImportPath)
|
||||
fmt.Printf("Success! go/build works with llgo\n")
|
||||
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")
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user