Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 9 additions & 1 deletion starlarktest/starlarktest.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import (
"bytes"
"fmt"
"go/build"
"os"
"path/filepath"
"regexp"
"sync"
Expand Down Expand Up @@ -133,5 +134,12 @@ func freeze(thread *starlark.Thread, _ *starlark.Builtin, args starlark.Tuple, k
// 'go build', under which a test runs in its package directory,
// and Blaze, under which a test runs in the root of the tree.
var DataFile = func(pkgdir, filename string) string {
return filepath.Join(build.Default.GOPATH, "src/go.starlark.net", pkgdir, filename)
rel := filepath.Join("go.starlark.net", pkgdir, filename)
for _, p := range build.Default.SrcDirs() {
full := filepath.Join(p, rel)
if _, err := os.Stat(full); err == nil {
return full
}
}
panic(fmt.Sprintf("could not find %s", rel))
}
10 changes: 1 addition & 9 deletions syntax/parse_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,7 @@ import (
"bufio"
"bytes"
"fmt"
"go/build"
"io/ioutil"
"path/filepath"
"reflect"
"strings"
"testing"
Expand Down Expand Up @@ -481,14 +479,8 @@ File
}
}

// dataFile is the same as starlarktest.DataFile.
// We make a copy to avoid a dependency cycle.
var dataFile = func(pkgdir, filename string) string {
return filepath.Join(build.Default.GOPATH, "src/go.starlark.net", pkgdir, filename)
}

func BenchmarkParse(b *testing.B) {
filename := dataFile("syntax", "testdata/scan.star")
filename := starlarktest.DataFile("syntax", "testdata/scan.star")
Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is already used by this file in TestParseErrors above.

b.StopTimer()
data, err := ioutil.ReadFile(filename)
if err != nil {
Expand Down
10 changes: 9 additions & 1 deletion syntax/scan_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (
"fmt"
"go/build"
"io/ioutil"
"os"
"path/filepath"
"testing"
)
Expand Down Expand Up @@ -228,7 +229,14 @@ pass`, "pass newline pass EOF"}, // consecutive newlines are consolidated
// dataFile is the same as starlarktest.DataFile.
// We make a copy to avoid a dependency cycle.
var dataFile = func(pkgdir, filename string) string {
return filepath.Join(build.Default.GOPATH, "src/go.starlark.net", pkgdir, filename)
rel := filepath.Join("go.starlark.net", pkgdir, filename)
for _, p := range build.Default.SrcDirs() {
full := filepath.Join(p, rel)
if _, err := os.Stat(full); err == nil {
return full
}
}
panic(fmt.Sprintf("could not find %s", rel))
}

func BenchmarkScan(b *testing.B) {
Expand Down