瀏覽代碼

pprof: fix tests on Windows

Skip TestSymbolizationPath (seems too Unix-specific).
Fix others with golden output to adjust for Windows file name syntax.
Russ Cox 8 年之前
父節點
當前提交
7eb5ba977f
共有 4 個檔案被更改,包括 18 行新增0 行删除
  1. 5
    0
      internal/driver/driver_test.go
  2. 5
    0
      internal/driver/fetch_test.go
  3. 4
    0
      internal/proftest/proftest.go
  4. 4
    0
      internal/report/report_test.go

+ 5
- 0
internal/driver/driver_test.go 查看文件

20
 	"io/ioutil"
20
 	"io/ioutil"
21
 	"os"
21
 	"os"
22
 	"regexp"
22
 	"regexp"
23
+	"runtime"
23
 	"strconv"
24
 	"strconv"
24
 	"strings"
25
 	"strings"
25
 	"testing"
26
 	"testing"
162
 			t.Errorf("reading solution file %s: %v", solution, err)
163
 			t.Errorf("reading solution file %s: %v", solution, err)
163
 			continue
164
 			continue
164
 		}
165
 		}
166
+		if runtime.GOOS == "windows" {
167
+			sbuf = bytes.Replace(sbuf, []byte("testdata/"), []byte("testdata\\"), -1)
168
+			sbuf = bytes.Replace(sbuf, []byte("/path/to/"), []byte("\\path\\to\\"), -1)
169
+		}
165
 
170
 
166
 		if flags[0] == "svg" {
171
 		if flags[0] == "svg" {
167
 			b = removeScripts(b)
172
 			b = removeScripts(b)

+ 5
- 0
internal/driver/fetch_test.go 查看文件

23
 	"path/filepath"
23
 	"path/filepath"
24
 	"reflect"
24
 	"reflect"
25
 	"regexp"
25
 	"regexp"
26
+	"runtime"
26
 	"testing"
27
 	"testing"
27
 	"time"
28
 	"time"
28
 
29
 
32
 )
33
 )
33
 
34
 
34
 func TestSymbolizationPath(t *testing.T) {
35
 func TestSymbolizationPath(t *testing.T) {
36
+	if runtime.GOOS == "windows" {
37
+		t.Skip("test assumes Unix paths")
38
+	}
39
+
35
 	// Save environment variables to restore after test
40
 	// Save environment variables to restore after test
36
 	saveHome := os.Getenv("HOME")
41
 	saveHome := os.Getenv("HOME")
37
 	savePath := os.Getenv("PPROF_BINARY_PATH")
42
 	savePath := os.Getenv("PPROF_BINARY_PATH")

+ 4
- 0
internal/proftest/proftest.go 查看文件

52
 		// Ignore that failure as long as we get output.
52
 		// Ignore that failure as long as we get output.
53
 		err = nil
53
 		err = nil
54
 	}
54
 	}
55
+	if err != nil {
56
+		data = []byte(fmt.Sprintf("diff failed: %v\nb1: %q\nb2: %q\n", err, b1, b2))
57
+		err = nil
58
+	}
55
 	return
59
 	return
56
 }
60
 }
57
 
61
 

+ 4
- 0
internal/report/report_test.go 查看文件

18
 	"bytes"
18
 	"bytes"
19
 	"io/ioutil"
19
 	"io/ioutil"
20
 	"regexp"
20
 	"regexp"
21
+	"runtime"
21
 	"testing"
22
 	"testing"
22
 
23
 
23
 	"github.com/google/pprof/internal/binutils"
24
 	"github.com/google/pprof/internal/binutils"
76
 		if err != nil {
77
 		if err != nil {
77
 			t.Fatalf("%s: %v", tc.want, err)
78
 			t.Fatalf("%s: %v", tc.want, err)
78
 		}
79
 		}
80
+		if runtime.GOOS == "windows" {
81
+			gold = bytes.Replace(gold, []byte("testdata/"), []byte("testdata\\"), -1)
82
+		}
79
 		if string(b.String()) != string(gold) {
83
 		if string(b.String()) != string(gold) {
80
 			d, err := proftest.Diff(gold, b.Bytes())
84
 			d, err := proftest.Diff(gold, b.Bytes())
81
 			if err != nil {
85
 			if err != nil {