Commit f67bb046 authored by Kirill Smelkov's avatar Kirill Smelkov

.

parent c9762c3f
......@@ -416,25 +416,6 @@ func removeFile(path string) error {
return os.Remove(path)
}
/*
// writer is interface for gotrace output operations
// made for testing
type writer interface {
writeFile(path string, data []byte) error
removeFile(path string) error
}
type fsWriter struct{}
func (fsWriter) writeFile(path string, data []byte) error {
return writeFile(path, data)
}
func (fsWriter) removeFile(path string) error {
return removeFile(path)
}
*/
type Buffer struct {
bytes.Buffer
}
......@@ -468,7 +449,7 @@ func (s StrSet) Itemv() []string {
}
// tracegen generates code according to tracing directives in a package @ pkgpath
func tracegen(pkgpath string, buildCtx *build.Context, w writer) error {
func tracegen(pkgpath string, buildCtx *build.Context) error {
// XXX typechecking is much slower than parsing + we don't need to
// load anything except the package in question
// TODO -> use just AST parsing for loading?
......@@ -566,7 +547,7 @@ func tracegen(pkgpath string, buildCtx *build.Context, w writer) error {
// write output to ztrace.go
fulltext := append(prologue.Bytes(), text.Bytes()...)
err = w.writeFile(filepath.Join(pkgdir, "ztrace.go"), fulltext)
err = writeFile(filepath.Join(pkgdir, "ztrace.go"), fulltext)
if err != nil {
log.Fatal(err)
}
......@@ -574,13 +555,13 @@ func tracegen(pkgpath string, buildCtx *build.Context, w writer) error {
// write empty ztrace.s so go:linkname works, if there are trace imports
ztrace_s := filepath.Join(pkgdir, "ztrace.s")
if len(pkg.Importv) == 0 {
err = w.removeFile(ztrace_s)
err = removeFile(ztrace_s)
} else {
text.Reset()
text.WriteString(magic)
text.emit("// empty .s so `go build` does not use -complete for go:linkname to work")
err = w.writeFile(ztrace_s, text.Bytes())
err = writeFile(ztrace_s, text.Bytes())
}
if err != nil {
......@@ -610,7 +591,7 @@ TODO ...
}
pkgpath := argv[0]
err := tracegen(pkgpath, build.Default)
err := tracegen(pkgpath, &build.Default)
if err != nil {
log.Fatal(err)
}
......
......@@ -2,26 +2,15 @@ package main
import (
"go/build"
"io/ioutil"
"os"
"path/filepath"
"runtime"
"strings"
"testing"
)
/*
// memWriter saves in memory filesystem modifications gotrace wanted to made
type memWriter struct {
wrote map[string]string // path -> data
removed StrSet
}
func (mw *memWriter) writeFile(path string, data []byte) error {
mw.wrote[path] = string(data)
return nil
}
func (mw *memWriter) removeFile(path) error {
mw.removed.Add(path)
return nil
}
*/
"lab.nexedi.com/kirr/go123/exc"
)
func xglob(t *testing.T, pattern string) []string {
t.Helper()
......@@ -41,20 +30,20 @@ const (
// prepareTestTree copies files from src to dst recursively processing *.ok and *.rm depending on mode
// dst should not initially exist
func prepareTestTree(src, dst string, mode prepareMode) error {
func prepareTestTree(src, dst string, mode TreePrepareMode) error {
err := os.MkdirAll(dst, 0777)
if err != nil {
return err
}
filepath.Walk(src, func(srcpath string, info os.FileInfo, err error) error {
return filepath.Walk(src, func(srcpath string, info os.FileInfo, err error) error {
dstpath := dst + "/" + strings.TrimPrefix(srcpath, src)
if info.IsDir() {
err := os.Mkdir(dstpath, 0777)
if err != nil {
return err
}
return cpR(srcpath, dstpath)
return prepareTestTree(srcpath, dstpath, mode)
}
var isOk, isRm bool
......@@ -62,7 +51,7 @@ func prepareTestTree(src, dst string, mode prepareMode) error {
isOk = true
dstpath = strings.TrimSuffix(dstpath, ".ok")
}
if strings.hasSuffix(srcpath, ".rm") {
if strings.HasSuffix(srcpath, ".rm") {
isRm = true
dstpath = strings.TrimSuffix(dstpath, ".rm")
}
......@@ -73,13 +62,13 @@ func prepareTestTree(src, dst string, mode prepareMode) error {
}
switch mode {
case prepareGolden:
case TreePrepareGolden:
// no removed files in golden tree
if isRm {
return nil
}
case prepareWork:
case TreePrepareWork:
// no ok files initially in work tree
if isOk {
return nil
......@@ -99,8 +88,8 @@ func prepareTestTree(src, dst string, mode prepareMode) error {
})
}
xprepareTree(t *testing.T, src, dst string, mode prepareMode) {
err := prepareTestTree(src, dst)
func xprepareTree(src, dst string, mode TreePrepareMode) {
err := prepareTestTree(src, dst, mode)
exc.Raiseif(err)
}
......@@ -118,12 +107,12 @@ func TestGoTraceGen(t *testing.T) {
xprepareTree("testdata", work, TreePrepareWork)
// test build context with GOPATH set to work tree
var tBuildCtx = build.Context{
var tBuildCtx = &build.Context{
GOARCH: "amd64",
GOOS: "linux",
GOROOT: runtime.GOROOT(),
GOPATH: work,
Compiler: runtime.Compiler(),
Compiler: runtime.Compiler,
}
// XXX autodetect (go list ?)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment