-
Notifications
You must be signed in to change notification settings - Fork 0
/
gotypeconverter_test.go
54 lines (44 loc) · 1.29 KB
/
gotypeconverter_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
package gotypeconverter
import (
"flag"
"fmt"
"io/ioutil"
"os"
"testing"
"github.com/fuji8/gotypeconverter/ui"
"github.com/google/go-cmp/cmp"
"github.com/gostaticanalysis/codegen/codegentest"
"golang.org/x/tools/go/packages"
)
var flagUpdate bool
func TestMain(m *testing.M) {
flag.BoolVar(&flagUpdate, "update", false, "update the golden files")
flag.Parse()
os.Exit(m.Run())
}
// func TestGenerator(t *testing.T) {
// Gen.Flags.Set("s", "SRC")
// Gen.Flags.Set("d", "DST")
// ui.TmpFilePath = codegentest.TestData() + "/src/a/tmp.go"
// rs := codegentest.Run(t, codegentest.TestData(), Generator, "a")
// codegentest.Golden(t, rs, flagUpdate)
// }
func TestGenerator(t *testing.T) {
Gen.Flags.Set("s", "SRC")
Gen.Flags.Set("d", "DST")
ui.TmpFilePath = codegentest.TestData() + "/src/a/tmp.go"
pkgs, _ := packages.Load(&packages.Config{
Mode: packages.LoadAllSyntax,
Dir: codegentest.TestData() + "/src/a",
}, "a")
got, _ := run(pkgs)
fpath := fmt.Sprintf("%s.golden", codegentest.TestData()+"/src/a/gotypeconverter")
gf, err := ioutil.ReadFile(fpath)
if err != nil {
t.Fatal("unexpected error:", err)
}
if diff := cmp.Diff(string(gf), got); diff != "" {
gname := "gotypeconverter"
t.Errorf("%s's output is different from the golden file(%s):\n%s", gname, fpath, diff)
}
}