|
@@ -16,6 +16,7 @@ package profile
|
16
|
16
|
|
17
|
17
|
import (
|
18
|
18
|
"bytes"
|
|
19
|
+ "flag"
|
19
|
20
|
"fmt"
|
20
|
21
|
"io/ioutil"
|
21
|
22
|
"path/filepath"
|
|
@@ -27,6 +28,8 @@ import (
|
27
|
28
|
"github.com/google/pprof/internal/proftest"
|
28
|
29
|
)
|
29
|
30
|
|
|
31
|
+var update = flag.Bool("update", false, "Update the golden files")
|
|
32
|
+
|
30
|
33
|
func TestParse(t *testing.T) {
|
31
|
34
|
const path = "testdata/"
|
32
|
35
|
|
|
@@ -57,6 +60,12 @@ func TestParse(t *testing.T) {
|
57
|
60
|
|
58
|
61
|
js := p.String()
|
59
|
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
|
69
|
gold, err := ioutil.ReadFile(goldFilename)
|
61
|
70
|
if err != nil {
|
62
|
71
|
t.Fatalf("%s: %v", source, err)
|