Skip to content

Commit 46c553e

Browse files
committed
Go: Add test case for go.mod file without a Go version
1 parent a961e27 commit 46c553e

File tree

9 files changed

+76
-0
lines changed

9 files changed

+76
-0
lines changed
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
{
2+
"markdownMessage": "A single `go.mod` file was found.\n\n`go.mod`",
3+
"severity": "note",
4+
"source": {
5+
"extractorName": "go",
6+
"id": "go/autobuilder/single-root-go-mod-found",
7+
"name": "A single `go.mod` file was found in the root"
8+
},
9+
"visibility": {
10+
"cliSummaryTable": false,
11+
"statusPage": false,
12+
"telemetry": true
13+
}
14+
}
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
# go get has been observed to sometimes fail when multiple tests try to simultaneously fetch the same package.
2+
goget
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
require golang.org/x/net v0.0.0-20200505041828-1ed23360d12c
2+
3+
module test
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
2+
golang.org/x/net v0.0.0-20200505041828-1ed23360d12c h1:zJ0mtu4jCalhKg6Oaukv6iIkb+cOvDrajDH9DH46Q4M=
3+
golang.org/x/net v0.0.0-20200505041828-1ed23360d12c/go.mod h1:qpuaurCH72eLCgpAm/N6yyVIVM9cpaDIP3A8BGJEC5A=
4+
golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
5+
golang.org/x/sys v0.0.0-20200323222414-85ca7c5b95cd h1:xhmwyvizuTgC2qz7ZlMluP20uW+C3Rm0FD/WLDX8884=
6+
golang.org/x/sys v0.0.0-20200323222414-85ca7c5b95cd/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
7+
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
package subdir
2+
3+
func Add(a, b int) int {
4+
return a + b
5+
}
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
package test
2+
3+
import (
4+
"test/subdir"
5+
6+
"golang.org/x/net/ipv4"
7+
)
8+
9+
func test() {
10+
11+
header := ipv4.Header{}
12+
header.Version = subdir.Add(2, 2)
13+
14+
}
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
extractedFiles
2+
| src/go.mod:0:0:0:0 | src/go.mod |
3+
| src/subdir/add.go:0:0:0:0 | src/subdir/add.go |
4+
| src/test.go:0:0:0:0 | src/test.go |
5+
#select
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
import os
2+
import subprocess
3+
4+
from create_database_utils import *
5+
from diagnostics_test_utils import *
6+
7+
# Set up a GOPATH relative to this test's root directory;
8+
# we set os.environ instead of using extra_env because we
9+
# need it to be set for the call to "go clean -modcache" later
10+
goPath = os.path.join(os.path.abspath(os.getcwd()), ".go")
11+
os.environ['GOPATH'] = goPath
12+
run_codeql_database_create([], lang="go", source="src")
13+
14+
check_diagnostics()
15+
16+
# Clean up the temporary GOPATH to prevent Bazel failures next
17+
# time the tests are run; see https://github.com/golang/go/issues/27161
18+
subprocess.call(["go", "clean", "-modcache"])
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
import go
2+
import semmle.go.DiagnosticsReporting
3+
4+
query predicate extractedFiles(File f) { any() }
5+
6+
from string msg, int sev
7+
where reportableDiagnostics(_, msg, sev)
8+
select msg, sev

0 commit comments

Comments
 (0)