Skip to content

Commit 6cf20bc

Browse files
committed
Replace fragile code with a constant.
1 parent 5f881fc commit 6cf20bc

File tree

1 file changed

+4
-13
lines changed

1 file changed

+4
-13
lines changed

stack_test.go

Lines changed: 4 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ package stack_test
33
import (
44
"fmt"
55
"io/ioutil"
6-
"os"
76
"path"
87
"path/filepath"
98
"runtime"
@@ -12,6 +11,8 @@ import (
1211
"gopkg.in/stack.v0"
1312
)
1413

14+
const importPath = "github.com/go-stack/stack"
15+
1516
type testType struct{}
1617

1718
func (tt testType) testMethod() (c stack.Call, pc uintptr, file string, line int, ok bool) {
@@ -30,23 +31,13 @@ func TestCallFormat(t *testing.T) {
3031
if !ok {
3132
t.Fatal("runtime.Caller(0) failed")
3233
}
33-
34-
gopathSrc := filepath.Join(os.Getenv("GOPATH"), "src")
35-
relFile, err := filepath.Rel(gopathSrc, file)
36-
if err != nil {
37-
t.Fatalf("failed to determine path relative to GOPATH: %v", err)
38-
}
39-
relFile = filepath.ToSlash(relFile)
34+
relFile := path.Join(importPath, filepath.Base(file))
4035

4136
c2, pc2, file2, line2, ok2 := testType{}.testMethod()
4237
if !ok2 {
4338
t.Fatal("runtime.Caller(0) failed")
4439
}
45-
relFile2, err := filepath.Rel(gopathSrc, file)
46-
if err != nil {
47-
t.Fatalf("failed to determine path relative to GOPATH: %v", err)
48-
}
49-
relFile2 = filepath.ToSlash(relFile2)
40+
relFile2 := path.Join(importPath, filepath.Base(file2))
5041

5142
data := []struct {
5243
c stack.Call

0 commit comments

Comments
 (0)