Skip to content

Commit

Permalink
Removed dummy testing package
Browse files Browse the repository at this point in the history
  • Loading branch information
dave committed Dec 3, 2018
1 parent ab0d940 commit 5a24b9a
Show file tree
Hide file tree
Showing 12 changed files with 151 additions and 19 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -288,7 +288,7 @@ The [Load](https://godoc.org/github.com/dave/dst/decorator#Load) convenience fun

```go
// Create a simple module in a temporary directory
dir, err := dummy.TempDir(map[string]string{
dir, err := tempDir(map[string]string{
"go.mod": "module root",
"main.go": "package main \n\n func main() {}",
})
Expand Down
5 changes: 2 additions & 3 deletions decorations_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ import (

"github.com/dave/dst"
"github.com/dave/dst/decorator"
"github.com/dave/dst/decorator/dummy"
"github.com/dave/dst/decorator/resolver/goast"
"github.com/dave/dst/decorator/resolver/gopackages"
"github.com/dave/dst/decorator/resolver/gotypes"
Expand Down Expand Up @@ -168,7 +167,7 @@ func ExampleManualImports() {
func ExampleImports() {

// Create a simple module in a temporary directory
dir, err := dummy.TempDir(map[string]string{
dir, err := tempDir(map[string]string{
"go.mod": "module root",
"main.go": "package main \n\n func main() {}",
})
Expand Down Expand Up @@ -219,7 +218,7 @@ func ExampleImports() {
func ExampleGoTypesImport() {

// Create a simple module in a temporary directory
dir, err := dummy.TempDir(map[string]string{
dir, err := tempDir(map[string]string{
"go.mod": "module root",
"main.go": `package main
Expand Down
3 changes: 1 addition & 2 deletions decorator/decorator_resolver_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import (
"testing"

"github.com/dave/dst"
"github.com/dave/dst/decorator/dummy"
"golang.org/x/tools/go/packages"
)

Expand Down Expand Up @@ -80,7 +79,7 @@ func TestDecoratorResolver(t *testing.T) {
t.Skip()
}

root, err := dummy.TempDir(test.src)
root, err := tempDir(test.src)
if err != nil {
t.Fatal(err)
}
Expand Down
3 changes: 1 addition & 2 deletions decorator/resolver/gobuild/resolver_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import (
"path/filepath"
"testing"

"github.com/dave/dst/decorator/dummy"
"github.com/dave/dst/decorator/resolver"
"github.com/dave/dst/decorator/resolver/gobuild"
)
Expand All @@ -26,7 +25,7 @@ func TestRestorerResolver(t *testing.T) {
"main2/main2.go": "package main \n\n func main(){}",
"a/a.go": "package a2 \n\n func A(){}",
}
bc, err := dummy.BuildContext(src)
bc, err := buildContext(src)
if err != nil {
t.Fatal(err)
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package dummy
package gobuild_test

import (
"bytes"
Expand All @@ -13,7 +13,7 @@ import (
"gopkg.in/src-d/go-billy.v4/memfs"
)

func BuildContext(m map[string]string) (*build.Context, error) {
func buildContext(m map[string]string) (*build.Context, error) {

goroot := "/goroot/"
gopath := "/gopath/"
Expand Down
3 changes: 1 addition & 2 deletions decorator/resolver/gopackages/resolver_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import (
"path/filepath"
"testing"

"github.com/dave/dst/decorator/dummy"
"github.com/dave/dst/decorator/resolver"
"github.com/dave/dst/decorator/resolver/gopackages"
)
Expand All @@ -27,7 +26,7 @@ func TestRestorerResolver(t *testing.T) {
"go.mod": "module root",
}
var err error
root, err = dummy.TempDir(src)
root, err = tempDir(src)
if err != nil {
t.Fatal(err)
}
Expand Down
46 changes: 46 additions & 0 deletions decorator/resolver/gopackages/util_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
package gopackages_test

import (
"fmt"
"go/format"
"io/ioutil"
"os"
"path/filepath"
"strings"
)

func tempDir(m map[string]string) (dir string, err error) {
if dir, err = ioutil.TempDir("", ""); err != nil {
return
}
for fpathrel, src := range m {
if strings.HasSuffix(fpathrel, "/") {
// just a dir
if err = os.MkdirAll(filepath.Join(dir, fpathrel), 0777); err != nil {
return
}
} else {
fpath := filepath.Join(dir, fpathrel)
fdir, _ := filepath.Split(fpath)
if err = os.MkdirAll(fdir, 0777); err != nil {
return
}

var formatted []byte
if strings.HasSuffix(fpath, ".go") {
formatted, err = format.Source([]byte(src))
if err != nil {
err = fmt.Errorf("formatting %s: %v", fpathrel, err)
return
}
} else {
formatted = []byte(src)
}

if err = ioutil.WriteFile(fpath, formatted, 0666); err != nil {
return
}
}
}
return
}
3 changes: 1 addition & 2 deletions decorator/resolver/gotypes/resolver_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import (
"path/filepath"
"testing"

"github.com/dave/dst/decorator/dummy"
"github.com/dave/dst/decorator/resolver/gotypes"
"golang.org/x/tools/go/packages"
)
Expand Down Expand Up @@ -123,7 +122,7 @@ func TestDecoratorResolver(t *testing.T) {
t.Skip()
}

root, err := dummy.TempDir(test.src)
root, err := tempDir(test.src)
if err != nil {
t.Fatal(err)
}
Expand Down
46 changes: 46 additions & 0 deletions decorator/resolver/gotypes/util_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
package gotypes_test

import (
"fmt"
"go/format"
"io/ioutil"
"os"
"path/filepath"
"strings"
)

func tempDir(m map[string]string) (dir string, err error) {
if dir, err = ioutil.TempDir("", ""); err != nil {
return
}
for fpathrel, src := range m {
if strings.HasSuffix(fpathrel, "/") {
// just a dir
if err = os.MkdirAll(filepath.Join(dir, fpathrel), 0777); err != nil {
return
}
} else {
fpath := filepath.Join(dir, fpathrel)
fdir, _ := filepath.Split(fpath)
if err = os.MkdirAll(fdir, 0777); err != nil {
return
}

var formatted []byte
if strings.HasSuffix(fpath, ".go") {
formatted, err = format.Source([]byte(src))
if err != nil {
err = fmt.Errorf("formatting %s: %v", fpathrel, err)
return
}
} else {
formatted = []byte(src)
}

if err = ioutil.WriteFile(fpath, formatted, 0666); err != nil {
return
}
}
}
return
}
5 changes: 2 additions & 3 deletions decorator/restorer_resolver_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ import (
"testing"

"github.com/dave/dst"
"github.com/dave/dst/decorator/dummy"
"github.com/dave/dst/decorator/resolver/gopackages"
"golang.org/x/tools/go/packages"
)
Expand Down Expand Up @@ -1090,7 +1089,7 @@ func TestRestorerResolver(t *testing.T) {
t.Skip()
}

rootDir, err := dummy.TempDir(test.src)
rootDir, err := tempDir(test.src)
if err != nil {
t.Fatal(err)
}
Expand Down Expand Up @@ -1471,7 +1470,7 @@ func TestRestorerDecorationResolver(t *testing.T) {
t.Fatalf("code changed after gofmt. before: \n%s\nafter:\n%s", test.src["main/main.go"], string(expected))
}

rootDir, err := dummy.TempDir(test.src)
rootDir, err := tempDir(test.src)
if err != nil {
t.Fatal(err)
}
Expand Down
46 changes: 46 additions & 0 deletions decorator/util_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
package decorator

import (
"fmt"
"go/format"
"io/ioutil"
"os"
"path/filepath"
"strings"
)

func tempDir(m map[string]string) (dir string, err error) {
if dir, err = ioutil.TempDir("", ""); err != nil {
return
}
for fpathrel, src := range m {
if strings.HasSuffix(fpathrel, "/") {
// just a dir
if err = os.MkdirAll(filepath.Join(dir, fpathrel), 0777); err != nil {
return
}
} else {
fpath := filepath.Join(dir, fpathrel)
fdir, _ := filepath.Split(fpath)
if err = os.MkdirAll(fdir, 0777); err != nil {
return
}

var formatted []byte
if strings.HasSuffix(fpath, ".go") {
formatted, err = format.Source([]byte(src))
if err != nil {
err = fmt.Errorf("formatting %s: %v", fpathrel, err)
return
}
} else {
formatted = []byte(src)
}

if err = ioutil.WriteFile(fpath, formatted, 0666); err != nil {
return
}
}
}
return
}
4 changes: 2 additions & 2 deletions decorator/dummy/tempdir.go → util_test.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package dummy
package dst_test

import (
"fmt"
Expand All @@ -9,7 +9,7 @@ import (
"strings"
)

func TempDir(m map[string]string) (dir string, err error) {
func tempDir(m map[string]string) (dir string, err error) {
if dir, err = ioutil.TempDir("", ""); err != nil {
return
}
Expand Down

0 comments on commit 5a24b9a

Please sign in to comment.