github.com/kekek/gb@v0.4.5-0.20170222120241-d4ba64b0b297/project_test.go (about) 1 package gb 2 3 import ( 4 "io" 5 "os" 6 "path/filepath" 7 "testing" 8 ) 9 10 type testproject struct { 11 *testing.T 12 project 13 } 14 15 func testProject(t *testing.T) Project { 16 cwd := getwd(t) 17 root := filepath.Join(cwd, "testdata") 18 return &testproject{ 19 t, 20 project{ 21 rootdir: root, 22 }, 23 } 24 } 25 26 func tempProject(t *testing.T) *testproject { 27 return &testproject{ 28 t, 29 project{ 30 rootdir: mktemp(t), 31 }, 32 } 33 } 34 35 func (t *testproject) tempfile(path, contents string) string { 36 dir, file := filepath.Split(path) 37 dir = filepath.Join(t.rootdir, dir) 38 if err := os.MkdirAll(dir, 0755); err != nil { 39 t.Fatal(err) 40 } 41 path = filepath.Join(dir, file) 42 f, err := os.Create(path) 43 if err != nil { 44 t.Fatal(err) 45 } 46 if _, err := io.WriteString(f, contents); err != nil { 47 f.Close() 48 t.Fatal(err) 49 } 50 if err := f.Close(); err != nil { 51 t.Fatal(err) 52 } 53 return path 54 }