"io/fs"
"os"
"path/filepath"
+ "slices"
+ "sort"
"strings"
"sync"
"testing"
// This short test does NOT ensure that the vendored contents match
// the unmodified contents of the corresponding dependency versions.
t.Run(m.Path+"(quick)", func(t *testing.T) {
+ t.Logf("module %s in directory %s", m.Path, m.Dir)
+
if m.hasVendor {
// Load all of the packages in the module to ensure that their
// dependencies are vendored. If any imported package is missing,
// 'go list -deps' will fail when attempting to load it.
cmd := testenv.Command(t, goBin, "list", "-mod=vendor", "-deps", "./...")
- cmd.Env = append(os.Environ(), "GO111MODULE=on", "GOWORK=off")
cmd.Dir = m.Dir
+ cmd.Env = append(cmd.Environ(), "GO111MODULE=on", "GOWORK=off")
cmd.Stderr = new(strings.Builder)
_, err := cmd.Output()
if err != nil {
// There is no vendor directory, so the module must have no dependencies.
// Check that the list of active modules contains only the main module.
cmd := testenv.Command(t, goBin, "list", "-mod=readonly", "-m", "all")
- cmd.Env = append(os.Environ(), "GO111MODULE=on", "GOWORK=off")
cmd.Dir = m.Dir
+ cmd.Env = append(cmd.Environ(), "GO111MODULE=on", "GOWORK=off")
cmd.Stderr = new(strings.Builder)
out, err := cmd.Output()
if err != nil {
}
t.Run(m.Path+"(thorough)", func(t *testing.T) {
+ t.Logf("module %s in directory %s", m.Path, m.Dir)
+
defer func() {
if t.Failed() {
// The test failed, which means it's possible the GOROOT copy
Env: append(append(os.Environ(), modcacheEnv...),
// Set GOROOT.
"GOROOT="+gorootCopyDir,
- // Explicitly override PWD and clear GOROOT_FINAL so that GOROOT=gorootCopyDir is definitely used.
- "PWD="+filepath.Join(gorootCopyDir, rel),
+ // Explicitly clear GOROOT_FINAL so that GOROOT=gorootCopyDir is definitely used.
"GOROOT_FINAL=",
// Add GOROOTcopy/bin and bundleDir to front of PATH.
"PATH="+filepath.Join(gorootCopyDir, "bin")+string(filepath.ListSeparator)+
// deemed safe to share for the purpose of the TestAllDependencies test.
func makeGOROOTCopy(t *testing.T) string {
t.Helper()
+
gorootCopyDir := t.TempDir()
err := filepath.Walk(testenv.GOROOT(t), func(src string, info os.FileInfo, err error) error {
if err != nil {
if err != nil {
t.Fatal(err)
}
+ t.Logf("copied GOROOT from %s to %s", testenv.GOROOT(t), gorootCopyDir)
return gorootCopyDir
}
t.Helper()
cmd := testenv.Command(t, args[0], args[1:]...)
cmd.Dir = r.Dir
- cmd.Env = r.Env
+ cmd.Env = slices.Clip(r.Env)
+ if r.Dir != "" {
+ cmd.Env = append(cmd.Env, "PWD="+r.Dir)
+ }
out, err := cmd.CombinedOutput()
if err != nil {
t.Logf("> %s\n", strings.Join(args, " "))
// Use 'go list' to describe the module contained in this directory (but
// not its dependencies).
cmd := testenv.Command(t, goBin, "list", "-json", "-m")
- cmd.Env = append(os.Environ(), "GO111MODULE=on", "GOWORK=off")
cmd.Dir = dir
+ cmd.Env = append(cmd.Environ(), "GO111MODULE=on", "GOWORK=off")
cmd.Stderr = new(strings.Builder)
out, err := cmd.Output()
if err != nil {
break
}
}
+ sort.Slice(goroot.modules, func(i, j int) bool {
+ return goroot.modules[i].Dir < goroot.modules[j].Dir
+ })
})
if goroot.err != nil {
t.Fatal(goroot.err)