-
Notifications
You must be signed in to change notification settings - Fork 24
/
modified_test.go
62 lines (50 loc) · 1.24 KB
/
modified_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
55
56
57
58
59
60
61
62
package main
import (
"fmt"
"path/filepath"
"runtime"
"strings"
"testing"
"golang.org/x/tools/go/buildutil"
"golang.org/x/tools/go/packages/packagestest"
)
const contents = `package somepkg
import "fmt"
const (
Zero = iota
One
Two
)
const Three = 3
func main() {
fmt.Println(Zero, Three, Two, Three)
}
`
func TestModified(t *testing.T) {
dir := filepath.Join(".", "testdata", "package")
mods := []packagestest.Module{
{Name: "somepkg", Files: packagestest.MustCopyFileTree(dir)},
}
packagestest.TestAll(t, func(t *testing.T, exporter packagestest.Exporter) {
if exporter == packagestest.Modules && !modulesSupported() {
t.Skip("Skipping modules test on", runtime.Version())
}
exported := packagestest.Export(t, exporter, mods)
defer exported.Cleanup()
teardown := setup(exported.Config)
defer teardown()
path := exported.File("somepkg", "const.go")
archive := fmt.Sprintf("%s\n%d\n%s", path, len(contents), contents)
overlay, err := buildutil.ParseOverlayArchive(strings.NewReader(archive))
if err != nil {
t.Fatalf("couldn't parse overlay: %v", err)
}
d, err := Run(path, 114, overlay)
if err != nil {
t.Fatal(err)
}
if n := d.Name; n != "Three" {
t.Errorf("got const %s, want Three", n)
}
})
}