mirror of
				https://github.com/go-delve/delve.git
				synced 2025-10-31 10:47:27 +08:00 
			
		
		
		
	cmd/dlv: Fix tests for use with modules
This commit is contained in:
		 Derek Parker
					Derek Parker
				
			
				
					committed by
					
						 Alessandro Arzilli
						Alessandro Arzilli
					
				
			
			
				
	
			
			
			 Alessandro Arzilli
						Alessandro Arzilli
					
				
			
						parent
						
							89c8da65b6
						
					
				
				
					commit
					91953dd49c
				
			| @ -43,17 +43,19 @@ func assertNoError(err error, t testing.TB, s string) { | |||||||
| 	} | 	} | ||||||
| } | } | ||||||
|  |  | ||||||
| func goPath(name string) string { | func projectRoot() string { | ||||||
| 	if val := os.Getenv(name); val != "" { | 	wd, err := os.Getwd() | ||||||
| 		// Use first GOPATH entry if there are multiple. | 	if err != nil { | ||||||
| 		return filepath.SplitList(val)[0] | 		panic(err) | ||||||
| 	} | 	} | ||||||
|  | 	if strings.Contains(wd, os.Getenv("GOPATH")) { | ||||||
| 	val, err := exec.Command("go", "env", name).Output() | 		return filepath.Join(os.Getenv("GOPATH"), "src", "github.com", "derekparker", "delve") | ||||||
|  | 	} | ||||||
|  | 	val, err := exec.Command("go", "list", "-m", "-f", "{{ .Dir }}").Output() | ||||||
| 	if err != nil { | 	if err != nil { | ||||||
| 		panic(err) // the Go tool was tested to work earlier | 		panic(err) // the Go tool was tested to work earlier | ||||||
| 	} | 	} | ||||||
| 	return filepath.SplitList(strings.TrimSpace(string(val)))[0] | 	return strings.TrimSuffix(string(val), "\n") | ||||||
| } | } | ||||||
|  |  | ||||||
| func TestBuild(t *testing.T) { | func TestBuild(t *testing.T) { | ||||||
| @ -61,7 +63,7 @@ func TestBuild(t *testing.T) { | |||||||
| 	var err error | 	var err error | ||||||
|  |  | ||||||
| 	cmd := exec.Command("go", "run", "scripts/make.go", "build") | 	cmd := exec.Command("go", "run", "scripts/make.go", "build") | ||||||
| 	cmd.Dir = filepath.Join(goPath("GOPATH"), "src", "github.com", "derekparker", "delve") | 	cmd.Dir = projectRoot() | ||||||
| 	out, err := cmd.CombinedOutput() | 	out, err := cmd.CombinedOutput() | ||||||
| 	if err != nil { | 	if err != nil { | ||||||
| 		t.Fatalf("makefile error: %v\noutput %s\n", err, string(out)) | 		t.Fatalf("makefile error: %v\noutput %s\n", err, string(out)) | ||||||
| @ -201,7 +203,7 @@ func TestOutput(t *testing.T) { | |||||||
| } | } | ||||||
|  |  | ||||||
| func checkAutogenDoc(t *testing.T, filename, gencommand string, generated []byte) { | func checkAutogenDoc(t *testing.T, filename, gencommand string, generated []byte) { | ||||||
| 	saved := slurpFile(t, os.ExpandEnv(fmt.Sprintf("$GOPATH/src/github.com/derekparker/delve/%s", filename))) | 	saved := slurpFile(t, filepath.Join(projectRoot(), filename)) | ||||||
|  |  | ||||||
| 	if len(saved) != len(generated) { | 	if len(saved) != len(generated) { | ||||||
| 		t.Fatalf("%s: needs to be regenerated; run %s", filename, gencommand) | 		t.Fatalf("%s: needs to be regenerated; run %s", filename, gencommand) | ||||||
|  | |||||||
		Reference in New Issue
	
	Block a user