build: make llgen, cltest, gentests call build.Do

This commit is contained in:
Li Jie
2024-11-26 11:20:15 +08:00
parent 25bc84817a
commit d879d0d924
11 changed files with 87 additions and 172 deletions

View File

@@ -50,7 +50,7 @@ func InitDebug() {
llssa.SetDebug(llssa.DbgFlagAll)
}
func FromDir(t *testing.T, sel, relDir string, byLLGen bool) {
func FromDir(t *testing.T, sel, relDir string) {
dir, err := os.Getwd()
if err != nil {
t.Fatal("Getwd failed:", err)
@@ -66,7 +66,7 @@ func FromDir(t *testing.T, sel, relDir string, byLLGen bool) {
continue
}
t.Run(name, func(t *testing.T) {
testFrom(t, dir+"/"+name, sel, byLLGen)
testFrom(t, dir+"/"+name, sel)
})
}
}
@@ -121,12 +121,11 @@ func isDbgSymEnabled(flagsFile string) bool {
return false
}
func testFrom(t *testing.T, pkgDir, sel string, byLLGen bool) {
func testFrom(t *testing.T, pkgDir, sel string) {
if sel != "" && !strings.Contains(pkgDir, sel) {
return
}
log.Println("Parsing", pkgDir)
in := pkgDir + "/in.go"
out := pkgDir + "/out.ll"
dbg := isDbgSymEnabled(pkgDir + "/flags.txt")
if dbg {
@@ -139,12 +138,8 @@ func testFrom(t *testing.T, pkgDir, sel string, byLLGen bool) {
t.Fatal("ReadFile failed:", err)
}
expected := string(b)
if byLLGen {
if v := llgen.GenFrom(in); v != expected && expected != ";" { // expected == ";" means skipping out.ll
t.Fatalf("\n==> got:\n%s\n==> expected:\n%s\n", v, expected)
}
} else {
TestCompileEx(t, nil, in, expected, dbg)
if v := llgen.GenFrom(pkgDir); v != expected && expected != ";" { // expected == ";" means skipping out.ll
t.Fatalf("\n==> got:\n%s\n==> expected:\n%s\n", v, expected)
}
}

View File

@@ -30,34 +30,37 @@ func testCompile(t *testing.T, src, expected string) {
}
func TestFromTestgo(t *testing.T) {
cltest.FromDir(t, "", "./_testgo", false)
cltest.FromDir(t, "", "./_testgo")
}
func TestFromTestpy(t *testing.T) {
cltest.FromDir(t, "", "./_testpy", false)
cltest.FromDir(t, "", "./_testpy")
}
func TestFromTestlibgo(t *testing.T) {
cltest.FromDir(t, "", "./_testlibgo", true)
cltest.FromDir(t, "", "./_testlibgo")
}
func TestFromTestlibc(t *testing.T) {
cltest.FromDir(t, "", "./_testlibc", true)
cltest.FromDir(t, "", "./_testlibc")
}
func TestFromTestrt(t *testing.T) {
cl.SetDebug(cl.DbgFlagAll)
cltest.FromDir(t, "", "./_testrt", true)
cltest.FromDir(t, "", "./_testrt")
cl.SetDebug(0)
}
func TestFromTestdata(t *testing.T) {
cltest.FromDir(t, "", "./_testdata", false)
cltest.FromDir(t, "", "./_testdata")
}
func TestGoPkgMath(t *testing.T) {
conf := build.NewDefaultConf(build.ModeInstall)
build.Do([]string{"math"}, conf)
_, err := build.Do([]string{"math"}, conf)
if err != nil {
t.Fatal(err)
}
}
func TestVar(t *testing.T) {