Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions internal/env/env.go
Original file line number Diff line number Diff line change
Expand Up @@ -97,12 +97,12 @@ func isLLGoRoot(root string) (string, bool) {
return "", false
}
// Check for go.mod
data, err := os.ReadFile(filepath.Join(root, "go.mod"))
data, err := os.ReadFile(filepath.Join(root, LLGoRuntimePkgName, "go.mod"))
if err != nil {
return "", false
}
// Check module name
if !strings.Contains(string(data), "module "+LLGoCompilerPkg+"\n") {
if !strings.Contains(string(data), "module "+LLGoRuntimePkg+"\n") {
return "", false
}
return root, true
Expand Down
18 changes: 12 additions & 6 deletions internal/env/env_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,10 @@ func TestLLGoRuntimeDir(t *testing.T) {
defer os.Setenv("LLGO_ROOT", origLLGoRoot)

tmpDir := t.TempDir()
goModContent := []byte("module github.com/goplus/llgo\n")
if err := os.WriteFile(filepath.Join(tmpDir, "go.mod"), goModContent, 0644); err != nil {
runtimeDir := filepath.Join(tmpDir, "runtime")
os.MkdirAll(runtimeDir, 0755)
goModContent := []byte("module github.com/goplus/llgo/runtime\n")
if err := os.WriteFile(filepath.Join(runtimeDir, "go.mod"), goModContent, 0644); err != nil {
t.Fatal(err)
}

Expand Down Expand Up @@ -92,8 +94,10 @@ func TestLLGoROOT(t *testing.T) {
defer os.Setenv("LLGO_ROOT", origLLGoRoot)

tmpDir := t.TempDir()
goModContent := []byte("module github.com/goplus/llgo\n")
if err := os.WriteFile(filepath.Join(tmpDir, "go.mod"), goModContent, 0644); err != nil {
runtimeDir := filepath.Join(tmpDir, "runtime")
os.MkdirAll(runtimeDir, 0755)
goModContent := []byte("module github.com/goplus/llgo/runtime\n")
if err := os.WriteFile(filepath.Join(runtimeDir, "go.mod"), goModContent, 0644); err != nil {
t.Fatal(err)
}

Expand Down Expand Up @@ -170,8 +174,10 @@ func TestIsLLGoRoot(t *testing.T) {
// Test with valid path and valid go.mod
t.Run("valid path and go.mod", func(t *testing.T) {
tmpDir := t.TempDir()
goModContent := []byte("module github.com/goplus/llgo\n")
if err := os.WriteFile(filepath.Join(tmpDir, "go.mod"), goModContent, 0644); err != nil {
runtimeDir := filepath.Join(tmpDir, "runtime")
os.MkdirAll(runtimeDir, 0755)
goModContent := []byte("module github.com/goplus/llgo/runtime\n")
if err := os.WriteFile(filepath.Join(runtimeDir, "go.mod"), goModContent, 0644); err != nil {
t.Fatal(err)
}

Expand Down
Loading