forked from constabulary/gb
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathproject_test.go
54 lines (49 loc) · 847 Bytes
/
project_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 gb
import (
"io"
"os"
"path/filepath"
"testing"
)
type testproject struct {
*testing.T
project
}
func testProject(t *testing.T) Project {
cwd := getwd(t)
root := filepath.Join(cwd, "testdata")
return &testproject{
t,
project{
rootdir: root,
},
}
}
func tempProject(t *testing.T) *testproject {
return &testproject{
t,
project{
rootdir: mktemp(t),
},
}
}
func (t *testproject) tempfile(path, contents string) string {
dir, file := filepath.Split(path)
dir = filepath.Join(t.rootdir, dir)
if err := os.MkdirAll(dir, 0755); err != nil {
t.Fatal(err)
}
path = filepath.Join(dir, file)
f, err := os.Create(path)
if err != nil {
t.Fatal(err)
}
if _, err := io.WriteString(f, contents); err != nil {
f.Close()
t.Fatal(err)
}
if err := f.Close(); err != nil {
t.Fatal(err)
}
return path
}