summaryrefslogtreecommitdiff
path: root/libgo/go/cmd/go/internal/load/pkg_test.go
diff options
context:
space:
mode:
Diffstat (limited to 'libgo/go/cmd/go/internal/load/pkg_test.go')
-rw-r--r--libgo/go/cmd/go/internal/load/pkg_test.go44
1 files changed, 27 insertions, 17 deletions
diff --git a/libgo/go/cmd/go/internal/load/pkg_test.go b/libgo/go/cmd/go/internal/load/pkg_test.go
index 9ddc20d0500..1e59fb989c5 100644
--- a/libgo/go/cmd/go/internal/load/pkg_test.go
+++ b/libgo/go/cmd/go/internal/load/pkg_test.go
@@ -5,39 +5,49 @@ import (
"testing"
)
-func TestDefaultExecName(t *testing.T) {
+func TestPkgDefaultExecName(t *testing.T) {
oldModulesEnabled := cfg.ModulesEnabled
defer func() { cfg.ModulesEnabled = oldModulesEnabled }()
for _, tt := range []struct {
in string
+ files []string
wantMod string
wantGopath string
}{
- {"example.com/mycmd", "mycmd", "mycmd"},
- {"example.com/mycmd/v0", "v0", "v0"},
- {"example.com/mycmd/v1", "v1", "v1"},
- {"example.com/mycmd/v2", "mycmd", "v2"}, // Semantic import versioning, use second last element in module mode.
- {"example.com/mycmd/v3", "mycmd", "v3"}, // Semantic import versioning, use second last element in module mode.
- {"mycmd", "mycmd", "mycmd"},
- {"mycmd/v0", "v0", "v0"},
- {"mycmd/v1", "v1", "v1"},
- {"mycmd/v2", "mycmd", "v2"}, // Semantic import versioning, use second last element in module mode.
- {"v0", "v0", "v0"},
- {"v1", "v1", "v1"},
- {"v2", "v2", "v2"},
+ {"example.com/mycmd", []string{}, "mycmd", "mycmd"},
+ {"example.com/mycmd/v0", []string{}, "v0", "v0"},
+ {"example.com/mycmd/v1", []string{}, "v1", "v1"},
+ {"example.com/mycmd/v2", []string{}, "mycmd", "v2"}, // Semantic import versioning, use second last element in module mode.
+ {"example.com/mycmd/v3", []string{}, "mycmd", "v3"}, // Semantic import versioning, use second last element in module mode.
+ {"mycmd", []string{}, "mycmd", "mycmd"},
+ {"mycmd/v0", []string{}, "v0", "v0"},
+ {"mycmd/v1", []string{}, "v1", "v1"},
+ {"mycmd/v2", []string{}, "mycmd", "v2"}, // Semantic import versioning, use second last element in module mode.
+ {"v0", []string{}, "v0", "v0"},
+ {"v1", []string{}, "v1", "v1"},
+ {"v2", []string{}, "v2", "v2"},
+ {"command-line-arguments", []string{"output.go", "foo.go"}, "output", "output"},
} {
{
cfg.ModulesEnabled = true
- gotMod := DefaultExecName(tt.in)
+ pkg := new(Package)
+ pkg.ImportPath = tt.in
+ pkg.GoFiles = tt.files
+ pkg.Internal.CmdlineFiles = len(tt.files) > 0
+ gotMod := pkg.DefaultExecName()
if gotMod != tt.wantMod {
- t.Errorf("DefaultExecName(%q) in module mode = %v; want %v", tt.in, gotMod, tt.wantMod)
+ t.Errorf("pkg.DefaultExecName with ImportPath = %q in module mode = %v; want %v", tt.in, gotMod, tt.wantMod)
}
}
{
cfg.ModulesEnabled = false
- gotGopath := DefaultExecName(tt.in)
+ pkg := new(Package)
+ pkg.ImportPath = tt.in
+ pkg.GoFiles = tt.files
+ pkg.Internal.CmdlineFiles = len(tt.files) > 0
+ gotGopath := pkg.DefaultExecName()
if gotGopath != tt.wantGopath {
- t.Errorf("DefaultExecName(%q) in gopath mode = %v; want %v", tt.in, gotGopath, tt.wantGopath)
+ t.Errorf("pkg.DefaultExecName with ImportPath = %q in gopath mode = %v; want %v", tt.in, gotGopath, tt.wantGopath)
}
}
}