@@ -32,12 +32,21 @@ var testCases = []testCase{
3232 },
3333 demosDir : "./testdata/cjson/demo" ,
3434 },
35+ {
36+ modpath : "github.com/goplus/llcppg/_cmptest/testdata/cjson/1.7.17/cjson" ,
37+ dir : "./testdata/cjson/1.7.17" ,
38+ pkg : upstream.Package {Name : "cjson" , Version : "1.7.17" },
39+ config : map [string ]string {
40+ "options" : "utils=True" ,
41+ },
42+ demosDir : "./testdata/cjson/demo" ,
43+ },
3544}
3645
3746func TestEnd2End (t * testing.T ) {
3847 for _ , tc := range testCases {
3948 tc := tc
40- t .Run (tc .pkg .Name , func (t * testing.T ) {
49+ t .Run (fmt . Sprintf ( "%s/%s" , tc .pkg .Name , tc . pkg . Version ) , func (t * testing.T ) {
4150 t .Parallel ()
4251 testFrom (t , tc , false )
4352 })
@@ -71,7 +80,7 @@ func testFrom(t *testing.T, tc testCase, gen bool) {
7180 t .Fatal (err )
7281 }
7382
74- cmd := command (resultDir , "llcppg" , "-v" , "- mod="+ tc .modpath )
83+ cmd := command (resultDir , "llcppg" , "-mod=" + tc .modpath )
7584 cmd .Env = append (cmd .Env , goVerEnv ())
7685 cmd .Env = append (cmd .Env , pcPathEnv (conanDir )... )
7786
@@ -100,27 +109,32 @@ func testFrom(t *testing.T, tc testCase, gen bool) {
100109
101110// pkgpath is the filepath use to replace the import path in demo's go.mod
102111func runDemos (t * testing.T , demosPath string , pkgname , pkgpath , pcPath string ) {
103- goMod := command (demosPath , "go" , "mod" , "init" , "test" )
104- err := goMod .Run ()
112+ tempDemosPath , err := os .MkdirTemp ("" , "llcppg_end2end_test_demos_*" )
105113 if err != nil {
106114 t .Fatal (err )
107115 }
108- defer os .Remove (filepath .Join (demosPath , "go.mod" ))
116+ defer os .RemoveAll (tempDemosPath )
117+ os .CopyFS (tempDemosPath , os .DirFS (demosPath ))
109118
110- replace := command (demosPath , "go" , "mod" , "edit" , "-replace" , pkgname + "=" + pkgpath )
119+ goMod := command (tempDemosPath , "go" , "mod" , "init" , "test" )
120+ err = goMod .Run ()
121+ if err != nil {
122+ t .Fatal (err )
123+ }
124+
125+ replace := command (tempDemosPath , "go" , "mod" , "edit" , "-replace" , pkgname + "=" + pkgpath )
111126 err = replace .Run ()
112127 if err != nil {
113128 t .Fatal (err )
114129 }
115130
116- tidy := command (demosPath , "go" , "mod" , "tidy" )
131+ tidy := command (tempDemosPath , "go" , "mod" , "tidy" )
117132 err = tidy .Run ()
118133 if err != nil {
119134 t .Fatal (err )
120135 }
121- defer os .Remove (filepath .Join (demosPath , "go.sum" ))
122136
123- demos , err := os .ReadDir (demosPath )
137+ demos , err := os .ReadDir (tempDemosPath )
124138 if err != nil {
125139 t .Fatal (err )
126140 }
@@ -129,9 +143,9 @@ func runDemos(t *testing.T, demosPath string, pkgname, pkgpath, pcPath string) {
129143 if ! demo .IsDir () {
130144 continue
131145 }
132- demoPath := filepath .Join (demosPath , demo .Name ())
133- demoCmd := command (demosPath , "llgo" , "run" , demoPath )
134- demoCmd .Env = append (demoCmd .Env , "LLGO_RPATH_CHANGE=on" )
146+ demoPath := filepath .Join (tempDemosPath , demo .Name ())
147+ demoCmd := command (demoPath , "llgo" , "run" , "." )
148+ demoCmd .Env = append (demoCmd .Env , llgoEnv () ... )
135149 demoCmd .Env = append (demoCmd .Env , pcPathEnv (pcPath )... )
136150 err = demoCmd .Run ()
137151 if err != nil {
@@ -148,6 +162,14 @@ func appendPCPath(path string) string {
148162 return path
149163}
150164
165+ // llgo env
166+ func llgoEnv () []string {
167+ return []string {
168+ // for https://github.com/goplus/llgo/issues/1135
169+ "LLGO_RPATH_CHANGE=on" ,
170+ }
171+ }
172+
151173// env for pkg-config
152174func pcPathEnv (path string ) []string {
153175 pcPath := fmt .Sprintf ("PKG_CONFIG_PATH=%s" , appendPCPath (path ))
0 commit comments