Add LOOP_VINFO_MAX_VECT_FACTOR
[official-gcc.git] / libgo / go / cmd / go / vcs_test.go
blobc73f5d0e85b41b53a1fffccdcf0697959a012855
1 // Copyright 2014 The Go Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style
3 // license that can be found in the LICENSE file.
5 package main
7 import (
8 "errors"
9 "internal/testenv"
10 "io/ioutil"
11 "os"
12 "path"
13 "path/filepath"
14 "testing"
17 // Test that RepoRootForImportPath creates the correct RepoRoot for a given importPath.
18 // TODO(cmang): Add tests for SVN and BZR.
19 func TestRepoRootForImportPath(t *testing.T) {
20 testenv.MustHaveExternalNetwork(t)
22 tests := []struct {
23 path string
24 want *repoRoot
27 "github.com/golang/groupcache",
28 &repoRoot{
29 vcs: vcsGit,
30 repo: "https://github.com/golang/groupcache",
33 // IBM DevOps Services tests
35 "hub.jazz.net/git/user1/pkgname",
36 &repoRoot{
37 vcs: vcsGit,
38 repo: "https://hub.jazz.net/git/user1/pkgname",
42 "hub.jazz.net/git/user1/pkgname/submodule/submodule/submodule",
43 &repoRoot{
44 vcs: vcsGit,
45 repo: "https://hub.jazz.net/git/user1/pkgname",
49 "hub.jazz.net",
50 nil,
53 "hub2.jazz.net",
54 nil,
57 "hub.jazz.net/someotherprefix",
58 nil,
61 "hub.jazz.net/someotherprefix/user1/pkgname",
62 nil,
64 // Spaces are not valid in user names or package names
66 "hub.jazz.net/git/User 1/pkgname",
67 nil,
70 "hub.jazz.net/git/user1/pkg name",
71 nil,
73 // Dots are not valid in user names
75 "hub.jazz.net/git/user.1/pkgname",
76 nil,
79 "hub.jazz.net/git/user/pkg.name",
80 &repoRoot{
81 vcs: vcsGit,
82 repo: "https://hub.jazz.net/git/user/pkg.name",
85 // User names cannot have uppercase letters
87 "hub.jazz.net/git/USER/pkgname",
88 nil,
90 // OpenStack tests
92 "git.openstack.org/openstack/swift",
93 &repoRoot{
94 vcs: vcsGit,
95 repo: "https://git.openstack.org/openstack/swift",
98 // Trailing .git is less preferred but included for
99 // compatibility purposes while the same source needs to
100 // be compilable on both old and new go
102 "git.openstack.org/openstack/swift.git",
103 &repoRoot{
104 vcs: vcsGit,
105 repo: "https://git.openstack.org/openstack/swift.git",
109 "git.openstack.org/openstack/swift/go/hummingbird",
110 &repoRoot{
111 vcs: vcsGit,
112 repo: "https://git.openstack.org/openstack/swift",
116 "git.openstack.org",
117 nil,
120 "git.openstack.org/openstack",
121 nil,
123 // Spaces are not valid in package name
125 "git.apache.org/package name/path/to/lib",
126 nil,
128 // Should have ".git" suffix
130 "git.apache.org/package-name/path/to/lib",
131 nil,
134 "git.apache.org/package-name.git",
135 &repoRoot{
136 vcs: vcsGit,
137 repo: "https://git.apache.org/package-name.git",
141 "git.apache.org/package-name_2.x.git/path/to/lib",
142 &repoRoot{
143 vcs: vcsGit,
144 repo: "https://git.apache.org/package-name_2.x.git",
149 for _, test := range tests {
150 got, err := repoRootForImportPath(test.path, secure)
151 want := test.want
153 if want == nil {
154 if err == nil {
155 t.Errorf("RepoRootForImport(%q): Error expected but not received", test.path)
157 continue
159 if err != nil {
160 t.Errorf("RepoRootForImport(%q): %v", test.path, err)
161 continue
163 if got.vcs.name != want.vcs.name || got.repo != want.repo {
164 t.Errorf("RepoRootForImport(%q) = VCS(%s) Repo(%s), want VCS(%s) Repo(%s)", test.path, got.vcs, got.repo, want.vcs, want.repo)
169 // Test that vcsFromDir correctly inspects a given directory and returns the right VCS and root.
170 func TestFromDir(t *testing.T) {
171 tempDir, err := ioutil.TempDir("", "vcstest")
172 if err != nil {
173 t.Fatal(err)
175 defer os.RemoveAll(tempDir)
177 for j, vcs := range vcsList {
178 dir := filepath.Join(tempDir, "example.com", vcs.name, "."+vcs.cmd)
179 if j&1 == 0 {
180 err := os.MkdirAll(dir, 0755)
181 if err != nil {
182 t.Fatal(err)
184 } else {
185 err := os.MkdirAll(filepath.Dir(dir), 0755)
186 if err != nil {
187 t.Fatal(err)
189 f, err := os.Create(dir)
190 if err != nil {
191 t.Fatal(err)
193 f.Close()
196 want := repoRoot{
197 vcs: vcs,
198 root: path.Join("example.com", vcs.name),
200 var got repoRoot
201 got.vcs, got.root, err = vcsFromDir(dir, tempDir)
202 if err != nil {
203 t.Errorf("FromDir(%q, %q): %v", dir, tempDir, err)
204 continue
206 if got.vcs.name != want.vcs.name || got.root != want.root {
207 t.Errorf("FromDir(%q, %q) = VCS(%s) Root(%s), want VCS(%s) Root(%s)", dir, tempDir, got.vcs, got.root, want.vcs, want.root)
212 func TestIsSecure(t *testing.T) {
213 tests := []struct {
214 vcs *vcsCmd
215 url string
216 secure bool
218 {vcsGit, "http://example.com/foo.git", false},
219 {vcsGit, "https://example.com/foo.git", true},
220 {vcsBzr, "http://example.com/foo.bzr", false},
221 {vcsBzr, "https://example.com/foo.bzr", true},
222 {vcsSvn, "http://example.com/svn", false},
223 {vcsSvn, "https://example.com/svn", true},
224 {vcsHg, "http://example.com/foo.hg", false},
225 {vcsHg, "https://example.com/foo.hg", true},
226 {vcsGit, "ssh://user@example.com/foo.git", true},
227 {vcsGit, "user@server:path/to/repo.git", false},
228 {vcsGit, "user@server:", false},
229 {vcsGit, "server:repo.git", false},
230 {vcsGit, "server:path/to/repo.git", false},
231 {vcsGit, "example.com:path/to/repo.git", false},
232 {vcsGit, "path/that/contains/a:colon/repo.git", false},
233 {vcsHg, "ssh://user@example.com/path/to/repo.hg", true},
236 for _, test := range tests {
237 secure := test.vcs.isSecure(test.url)
238 if secure != test.secure {
239 t.Errorf("%s isSecure(%q) = %t; want %t", test.vcs, test.url, secure, test.secure)
244 func TestIsSecureGitAllowProtocol(t *testing.T) {
245 tests := []struct {
246 vcs *vcsCmd
247 url string
248 secure bool
250 // Same as TestIsSecure to verify same behavior.
251 {vcsGit, "http://example.com/foo.git", false},
252 {vcsGit, "https://example.com/foo.git", true},
253 {vcsBzr, "http://example.com/foo.bzr", false},
254 {vcsBzr, "https://example.com/foo.bzr", true},
255 {vcsSvn, "http://example.com/svn", false},
256 {vcsSvn, "https://example.com/svn", true},
257 {vcsHg, "http://example.com/foo.hg", false},
258 {vcsHg, "https://example.com/foo.hg", true},
259 {vcsGit, "user@server:path/to/repo.git", false},
260 {vcsGit, "user@server:", false},
261 {vcsGit, "server:repo.git", false},
262 {vcsGit, "server:path/to/repo.git", false},
263 {vcsGit, "example.com:path/to/repo.git", false},
264 {vcsGit, "path/that/contains/a:colon/repo.git", false},
265 {vcsHg, "ssh://user@example.com/path/to/repo.hg", true},
266 // New behavior.
267 {vcsGit, "ssh://user@example.com/foo.git", false},
268 {vcsGit, "foo://example.com/bar.git", true},
269 {vcsHg, "foo://example.com/bar.hg", false},
270 {vcsSvn, "foo://example.com/svn", false},
271 {vcsBzr, "foo://example.com/bar.bzr", false},
274 defer os.Unsetenv("GIT_ALLOW_PROTOCOL")
275 os.Setenv("GIT_ALLOW_PROTOCOL", "https:foo")
276 for _, test := range tests {
277 secure := test.vcs.isSecure(test.url)
278 if secure != test.secure {
279 t.Errorf("%s isSecure(%q) = %t; want %t", test.vcs, test.url, secure, test.secure)
284 func TestMatchGoImport(t *testing.T) {
285 tests := []struct {
286 imports []metaImport
287 path string
288 mi metaImport
289 err error
292 imports: []metaImport{
293 {Prefix: "example.com/user/foo", VCS: "git", RepoRoot: "https://example.com/repo/target"},
295 path: "example.com/user/foo",
296 mi: metaImport{Prefix: "example.com/user/foo", VCS: "git", RepoRoot: "https://example.com/repo/target"},
299 imports: []metaImport{
300 {Prefix: "example.com/user/foo", VCS: "git", RepoRoot: "https://example.com/repo/target"},
302 path: "example.com/user/foo/",
303 mi: metaImport{Prefix: "example.com/user/foo", VCS: "git", RepoRoot: "https://example.com/repo/target"},
306 imports: []metaImport{
307 {Prefix: "example.com/user/foo", VCS: "git", RepoRoot: "https://example.com/repo/target"},
308 {Prefix: "example.com/user/fooa", VCS: "git", RepoRoot: "https://example.com/repo/target"},
310 path: "example.com/user/foo",
311 mi: metaImport{Prefix: "example.com/user/foo", VCS: "git", RepoRoot: "https://example.com/repo/target"},
314 imports: []metaImport{
315 {Prefix: "example.com/user/foo", VCS: "git", RepoRoot: "https://example.com/repo/target"},
316 {Prefix: "example.com/user/fooa", VCS: "git", RepoRoot: "https://example.com/repo/target"},
318 path: "example.com/user/fooa",
319 mi: metaImport{Prefix: "example.com/user/fooa", VCS: "git", RepoRoot: "https://example.com/repo/target"},
322 imports: []metaImport{
323 {Prefix: "example.com/user/foo", VCS: "git", RepoRoot: "https://example.com/repo/target"},
324 {Prefix: "example.com/user/foo/bar", VCS: "git", RepoRoot: "https://example.com/repo/target"},
326 path: "example.com/user/foo/bar",
327 err: errors.New("should not be allowed to create nested repo"),
330 imports: []metaImport{
331 {Prefix: "example.com/user/foo", VCS: "git", RepoRoot: "https://example.com/repo/target"},
332 {Prefix: "example.com/user/foo/bar", VCS: "git", RepoRoot: "https://example.com/repo/target"},
334 path: "example.com/user/foo/bar/baz",
335 err: errors.New("should not be allowed to create nested repo"),
338 imports: []metaImport{
339 {Prefix: "example.com/user/foo", VCS: "git", RepoRoot: "https://example.com/repo/target"},
340 {Prefix: "example.com/user/foo/bar", VCS: "git", RepoRoot: "https://example.com/repo/target"},
342 path: "example.com/user/foo/bar/baz/qux",
343 err: errors.New("should not be allowed to create nested repo"),
346 imports: []metaImport{
347 {Prefix: "example.com/user/foo", VCS: "git", RepoRoot: "https://example.com/repo/target"},
348 {Prefix: "example.com/user/foo/bar", VCS: "git", RepoRoot: "https://example.com/repo/target"},
350 path: "example.com/user/foo/bar/baz/",
351 err: errors.New("should not be allowed to create nested repo"),
354 imports: []metaImport{
355 {Prefix: "example.com/user/foo", VCS: "git", RepoRoot: "https://example.com/repo/target"},
356 {Prefix: "example.com/user/foo/bar", VCS: "git", RepoRoot: "https://example.com/repo/target"},
358 path: "example.com",
359 err: errors.New("pathologically short path"),
362 imports: []metaImport{
363 {Prefix: "example.com/user/foo", VCS: "git", RepoRoot: "https://example.com/repo/target"},
365 path: "different.example.com/user/foo",
366 err: errors.New("meta tags do not match import path"),
370 for _, test := range tests {
371 mi, err := matchGoImport(test.imports, test.path)
372 if mi != test.mi {
373 t.Errorf("unexpected metaImport; got %v, want %v", mi, test.mi)
376 got := err
377 want := test.err
378 if (got == nil) != (want == nil) {
379 t.Errorf("unexpected error; got %v, want %v", got, want)