mirror of
https://github.com/Llewellynvdm/fzf.git
synced 2024-06-16 06:02:22 +00:00
parent
ee9d88b637
commit
a9811addaa
18
main_test.go
18
main_test.go
|
@ -1,6 +1,7 @@
|
||||||
package main
|
package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"bytes"
|
||||||
"fmt"
|
"fmt"
|
||||||
"go/ast"
|
"go/ast"
|
||||||
"go/build"
|
"go/build"
|
||||||
|
@ -10,6 +11,7 @@ import (
|
||||||
"go/types"
|
"go/types"
|
||||||
"io/fs"
|
"io/fs"
|
||||||
"os"
|
"os"
|
||||||
|
"os/exec"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
"sort"
|
"sort"
|
||||||
"strings"
|
"strings"
|
||||||
|
@ -17,6 +19,20 @@ import (
|
||||||
)
|
)
|
||||||
|
|
||||||
func loadPackages(t *testing.T) []*build.Package {
|
func loadPackages(t *testing.T) []*build.Package {
|
||||||
|
// If GOROOT is not set, use `go env GOROOT` to determine it since it
|
||||||
|
// performs more work than just runtime.GOROOT(). For context, running
|
||||||
|
// the tests with the "-trimpath" flag causes GOROOT to not be set.
|
||||||
|
ctxt := &build.Default
|
||||||
|
if ctxt.GOROOT == "" {
|
||||||
|
cmd := exec.Command("go", "env", "GOROOT")
|
||||||
|
out, err := cmd.CombinedOutput()
|
||||||
|
out = bytes.TrimSpace(out)
|
||||||
|
if err != nil {
|
||||||
|
t.Fatalf("error running command: %q: %v\n%s", cmd.Args, err, out)
|
||||||
|
}
|
||||||
|
ctxt.GOROOT = string(out)
|
||||||
|
}
|
||||||
|
|
||||||
wd, err := os.Getwd()
|
wd, err := os.Getwd()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
|
@ -38,7 +54,7 @@ func loadPackages(t *testing.T) []*build.Package {
|
||||||
if d.Type().IsRegular() && filepath.Ext(name) == ".go" && !strings.HasSuffix(name, "_test.go") {
|
if d.Type().IsRegular() && filepath.Ext(name) == ".go" && !strings.HasSuffix(name, "_test.go") {
|
||||||
dir := filepath.Dir(path)
|
dir := filepath.Dir(path)
|
||||||
if !seen[dir] {
|
if !seen[dir] {
|
||||||
pkg, err := build.ImportDir(dir, build.ImportComment)
|
pkg, err := ctxt.ImportDir(dir, build.ImportComment)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("%s: %s", dir, err)
|
return fmt.Errorf("%s: %s", dir, err)
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue
Block a user