fix(build):test all pkg with llgo test ./...

This commit is contained in:
luoliwoshang
2025-06-24 11:57:49 +08:00
parent 6df688e62e
commit b469fc990f

View File

@@ -252,7 +252,7 @@ func Do(args []string, conf *Config) ([]Package, error) {
output := conf.OutFile != "" output := conf.OutFile != ""
export, err := crosscompile.Use(conf.Goos, conf.Goarch, IsWasiThreadsEnabled(), IsRpathChangeEnabled()) export, err := crosscompile.Use(conf.Goos, conf.Goarch, IsWasiThreadsEnabled(), IsRpathChangeEnabled())
check(err) check(err)
ctx := &context{env, cfg, progSSA, prog, dedup, patches, make(map[string]none), initial, mode, 0, output, make(map[*packages.Package]bool), make(map[*packages.Package]bool), conf, export} ctx := &context{env, cfg, progSSA, prog, dedup, patches, make(map[string]none), initial, mode, 0, output, make(map[*packages.Package]bool), make(map[*packages.Package]bool), conf, export, false}
pkgs, err := buildAllPkgs(ctx, initial, verbose) pkgs, err := buildAllPkgs(ctx, initial, verbose)
check(err) check(err)
if mode == ModeGen { if mode == ModeGen {
@@ -282,6 +282,10 @@ func Do(args []string, conf *Config) ([]Package, error) {
} }
} }
if mode == ModeTest && ctx.testFail {
mockable.Exit(1)
}
return dpkg, nil return dpkg, nil
} }
@@ -342,6 +346,8 @@ type context struct {
buildConf *Config buildConf *Config
crossCompile crosscompile.Export crossCompile crosscompile.Export
testFail bool
} }
func (c *context) compiler() *clang.Cmd { func (c *context) compiler() *clang.Cmd {
@@ -587,7 +593,9 @@ func linkMainPkg(ctx *context, pkg *packages.Package, pkgs []*aPackage, global l
if s := cmd.ProcessState; s != nil { if s := cmd.ProcessState; s != nil {
exitCode := s.ExitCode() exitCode := s.ExitCode()
fmt.Fprintf(os.Stderr, "%s: exit code %d\n", app, exitCode) fmt.Fprintf(os.Stderr, "%s: exit code %d\n", app, exitCode)
mockable.Exit(exitCode) if !ctx.testFail && exitCode != 0 {
ctx.testFail = true
}
} }
case ModeRun: case ModeRun:
args := make([]string, 0, len(conf.RunArgs)+1) args := make([]string, 0, len(conf.RunArgs)+1)