瀏覽代碼

Add -update flag that can be used to update golden files. (#467)

This is similar to such flag in driver_test.go and dotgraph_test.go.

I had this change locally for some time, would like to check this in.
Alexey Alexandrov 6 年之前
父節點
當前提交
f8f10df842
共有 1 個文件被更改,包括 9 次插入0 次删除
  1. 9
    0
      profile/profile_test.go

+ 9
- 0
profile/profile_test.go 查看文件

16
 
16
 
17
 import (
17
 import (
18
 	"bytes"
18
 	"bytes"
19
+	"flag"
19
 	"fmt"
20
 	"fmt"
20
 	"io/ioutil"
21
 	"io/ioutil"
21
 	"path/filepath"
22
 	"path/filepath"
27
 	"github.com/google/pprof/internal/proftest"
28
 	"github.com/google/pprof/internal/proftest"
28
 )
29
 )
29
 
30
 
31
+var update = flag.Bool("update", false, "Update the golden files")
32
+
30
 func TestParse(t *testing.T) {
33
 func TestParse(t *testing.T) {
31
 	const path = "testdata/"
34
 	const path = "testdata/"
32
 
35
 
57
 
60
 
58
 		js := p.String()
61
 		js := p.String()
59
 		goldFilename := path + source + ".string"
62
 		goldFilename := path + source + ".string"
63
+		if *update {
64
+			err := ioutil.WriteFile(goldFilename, []byte(js), 0644)
65
+			if err != nil {
66
+				t.Errorf("failed to update the golden file file %q: %v", goldFilename, err)
67
+			}
68
+		}
60
 		gold, err := ioutil.ReadFile(goldFilename)
69
 		gold, err := ioutil.ReadFile(goldFilename)
61
 		if err != nil {
70
 		if err != nil {
62
 			t.Fatalf("%s: %v", source, err)
71
 			t.Fatalf("%s: %v", source, err)