From 8e3d76b7eaa9b51dad85b4ae3ec62386d245bfe3 Mon Sep 17 00:00:00 2001 From: Li Jie Date: Sat, 14 Sep 2024 18:13:18 +0800 Subject: [PATCH] gentests and cltest supports flags.txt (currently just -dbg used) --- chore/gentests/gentests.go | 30 ++++++++++++++++++++++++++---- cl/cltest/cltest.go | 19 +++++++++++++++++++ 2 files changed, 45 insertions(+), 4 deletions(-) diff --git a/chore/gentests/gentests.go b/chore/gentests/gentests.go index 576a2aee..cc7d5692 100644 --- a/chore/gentests/gentests.go +++ b/chore/gentests/gentests.go @@ -21,6 +21,7 @@ import ( "os" "strings" + "github.com/goplus/llgo/cl" "github.com/goplus/llgo/internal/llgen" "github.com/goplus/llgo/ssa" "github.com/goplus/mod" @@ -41,6 +42,20 @@ func main() { llgenDir(dir+"/cl/_testdata", "") } +func isDbgSymEnabled(flagsFile string) bool { + data, err := os.ReadFile(flagsFile) + if err != nil { + return false + } + toks := strings.Split(strings.Join(strings.Split(string(data), "\n"), " "), " ") + for _, tok := range toks { + if tok == "-dbg" { + return true + } + } + return false +} + func llgenDir(dir string, pkgPath ...string) { fis, err := os.ReadDir(dir) check(err) @@ -49,10 +64,17 @@ func llgenDir(dir string, pkgPath ...string) { if !fi.IsDir() || strings.HasPrefix(name, "_") { continue } - testDir := dir + "/" + name - fmt.Fprintln(os.Stderr, "llgen", testDir) - os.Chdir(testDir) - llgen.SmartDoFile("in.go", pkgPath...) + func() { + testDir := dir + "/" + name + fmt.Fprintln(os.Stderr, "llgen", testDir) + os.Chdir(testDir) + dbg := isDbgSymEnabled("flags.txt") + if dbg { + cl.EnableDebugSymbols() + } + defer cl.DisableDebugSymbols() + llgen.SmartDoFile("in.go", pkgPath...) + }() } } diff --git a/cl/cltest/cltest.go b/cl/cltest/cltest.go index 5d4c2913..9ce09eb1 100644 --- a/cl/cltest/cltest.go +++ b/cl/cltest/cltest.go @@ -107,6 +107,20 @@ func Pkg(t *testing.T, pkgPath, outFile string) { } } +func isDbgSymEnabled(flagsFile string) bool { + data, err := os.ReadFile(flagsFile) + if err != nil { + return false + } + toks := strings.Split(strings.Join(strings.Split(string(data), "\n"), " "), " ") + for _, tok := range toks { + if tok == "-dbg" { + return true + } + } + return false +} + func testFrom(t *testing.T, pkgDir, sel string, byLLGen bool) { if sel != "" && !strings.Contains(pkgDir, sel) { return @@ -114,6 +128,11 @@ func testFrom(t *testing.T, pkgDir, sel string, byLLGen bool) { log.Println("Parsing", pkgDir) in := pkgDir + "/in.go" out := pkgDir + "/out.ll" + dbg := isDbgSymEnabled(pkgDir + "/flags.txt") + if dbg { + cl.EnableDebugSymbols() + } + defer cl.DisableDebugSymbols() b, err := os.ReadFile(out) if err != nil { t.Fatal("ReadFile failed:", err)