Skip to content

Commit f42cce2

Browse files
committed
test:LLGO_RPATH_CHANGE
1 parent ca49e60 commit f42cce2

File tree

1 file changed

+20
-21
lines changed

1 file changed

+20
-21
lines changed

_cmptest/llcppgend_test.go

Lines changed: 20 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -71,13 +71,15 @@ func testFrom(t *testing.T, tc testCase, gen bool) {
7171
t.Fatal(err)
7272
}
7373

74-
cmd := command("llcppg", resultDir, "-v", "-mod="+tc.modpath)
75-
lockGoVersion(cmd, conanDir)
74+
cmd := command(resultDir, "llcppg", "-v", "-mod="+tc.modpath)
75+
cmd.Env = append(cmd.Env, goVerEnv())
76+
cmd.Env = append(cmd.Env, pcPathEnv(conanDir)...)
7677

7778
err = cmd.Run()
7879
if err != nil {
7980
t.Fatal(err)
8081
}
82+
8183
// llcppg.symb.json is a middle file
8284
os.Remove(filepath.Join(resultDir, config.LLCPPG_SYMB))
8385

@@ -86,10 +88,8 @@ func testFrom(t *testing.T, tc testCase, gen bool) {
8688
os.Rename(resultDir, dir)
8789
} else {
8890
// check the result is the same as the expected result
89-
diffCmd := exec.Command("git", "diff", "--no-index", dir, resultDir)
90-
diffCmd.Dir = wd
91-
diffCmd.Stdout = os.Stdout
92-
diffCmd.Stderr = os.Stderr
91+
// when have diff,will got exit code 1
92+
diffCmd := command(wd, "git", "diff", "--no-index", dir, resultDir)
9393
err = diffCmd.Run()
9494
if err != nil {
9595
t.Fatal(err)
@@ -100,20 +100,20 @@ func testFrom(t *testing.T, tc testCase, gen bool) {
100100

101101
// pkgpath is the filepath use to replace the import path in demo's go.mod
102102
func runDemos(t *testing.T, demosPath string, pkgname, pkgpath, pcPath string) {
103-
goMod := command("go", demosPath, "mod", "init", "test")
103+
goMod := command(demosPath, "go", "mod", "init", "test")
104104
err := goMod.Run()
105105
if err != nil {
106106
t.Fatal(err)
107107
}
108108
defer os.Remove(filepath.Join(demosPath, "go.mod"))
109109

110-
replace := command("go", demosPath, "mod", "edit", "-replace", pkgname+"="+pkgpath)
110+
replace := command(demosPath, "go", "mod", "edit", "-replace", pkgname+"="+pkgpath)
111111
err = replace.Run()
112112
if err != nil {
113113
t.Fatal(err)
114114
}
115115

116-
tidy := command("go", demosPath, "mod", "tidy")
116+
tidy := command(demosPath, "go", "mod", "tidy")
117117
err = tidy.Run()
118118
if err != nil {
119119
t.Fatal(err)
@@ -130,8 +130,9 @@ func runDemos(t *testing.T, demosPath string, pkgname, pkgpath, pcPath string) {
130130
continue
131131
}
132132
demoPath := filepath.Join(demosPath, demo.Name())
133-
demoCmd := command("llgo", demosPath, "run", demoPath)
134-
setPath(demoCmd, pcPath)
133+
demoCmd := command(demosPath, "llgo", "run", demoPath)
134+
demoCmd.Env = append(demoCmd.Env, "LLGO_RPATH_CHANGE=on")
135+
demoCmd.Env = append(demoCmd.Env, pcPathEnv(pcPath)...)
135136
err = demoCmd.Run()
136137
if err != nil {
137138
t.Fatal(err)
@@ -147,20 +148,18 @@ func appendPCPath(path string) string {
147148
return path
148149
}
149150

150-
// lockGoVersion locks current Go version to `llcppgGoVersion` via GOTOOLCHAIN
151-
func lockGoVersion(cmd *exec.Cmd, pcPath string) {
152-
// don't change global settings, use temporary environment.
153-
// see issue: https://github.com/goplus/llpkgstore/issues/18
154-
setPath(cmd, pcPath)
155-
cmd.Env = append(cmd.Env, fmt.Sprintf("GOTOOLCHAIN=go%s", llcppgGoVersion))
151+
// env for pkg-config
152+
func pcPathEnv(path string) []string {
153+
pcPath := fmt.Sprintf("PKG_CONFIG_PATH=%s", appendPCPath(path))
154+
return append(os.Environ(), pcPath)
156155
}
157156

158-
func setPath(cmd *exec.Cmd, path string) {
159-
pcPath := fmt.Sprintf("PKG_CONFIG_PATH=%s", appendPCPath(path))
160-
cmd.Env = append(os.Environ(), pcPath)
157+
// control the go version in output version
158+
func goVerEnv() string {
159+
return fmt.Sprintf("GOTOOLCHAIN=go%s", llcppgGoVersion)
161160
}
162161

163-
func command(app string, dir string, args ...string) *exec.Cmd {
162+
func command(dir string, app string, args ...string) *exec.Cmd {
164163
cmd := exec.Command(app, args...)
165164
cmd.Dir = dir
166165
cmd.Stdout = os.Stdout

0 commit comments

Comments
 (0)