This repository has been archived by the owner on Aug 21, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathissues_test.go
81 lines (65 loc) · 1.51 KB
/
issues_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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
// Copyright 2017 Tom Thorogood. All rights reserved.
// Use of this source code is governed by a Modified
// BSD License that can be found in the LICENSE file.
package bindata
import (
"bytes"
"context"
"io"
"io/ioutil"
"os"
"os/exec"
"path"
"testing"
"time"
)
type loggerWriter struct{ testing.TB }
func (w *loggerWriter) Write(p []byte) (n int, err error) {
w.Log(string(bytes.TrimRight(p, "\r\n")))
return len(p), nil
}
func TestIssue8(t *testing.T) {
// This test case covers https://github.com/tmthrgd/go-bindata/issues/8.
//
// It generates a file with ~43,000 string concatenations which
// triggers https://golang.org/issue/16394.
if testing.Short() {
t.Skip("skipping in short mode")
}
dir, err := ioutil.TempDir("", "go-bindata-test-")
if err != nil {
t.Fatal(err)
}
defer os.RemoveAll(dir)
f, err := os.Create(path.Join(dir, "issue-8.go"))
if err != nil {
t.Fatal(err)
}
defer f.Close()
if err = (Files{
&testFile{
path: "issue-8.bin",
size: 1 << 20,
},
}).Generate(f, &GenerateOptions{
Package: "main",
}); err != nil {
t.Fatal(err)
}
if _, err = io.WriteString(f, "\nfunc main() {}\n"); err != nil {
t.Fatal(err)
}
if err = f.Close(); err != nil {
t.Fatal(err)
}
ctx, cancel := context.WithTimeout(context.Background(), 15*time.Second)
defer cancel()
cmd := exec.CommandContext(ctx, "go", "build", ".")
cmd.Dir = dir
cmd.Env = os.Environ()
cmd.Stderr = &loggerWriter{t}
cmd.Stdout = cmd.Stderr
if err = cmd.Run(); err != nil {
t.Fatal(err)
}
}