Pārlūkot izejas kodu

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 gadus atpakaļ
vecāks
revīzija
f8f10df842
1 mainītis faili ar 9 papildinājumiem un 0 dzēšanām
  1. 9
    0
      profile/profile_test.go

+ 9
- 0
profile/profile_test.go Parādīt failu

@@ -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)