diff --git a/ql/test/library-tests/semmle/go/GoModExpr/ExcludeLines.expected b/ql/test/library-tests/semmle/go/GoModExpr/ExcludeLines.expected new file mode 100644 index 00000000000..d23727f1726 --- /dev/null +++ b/ql/test/library-tests/semmle/go/GoModExpr/ExcludeLines.expected @@ -0,0 +1,3 @@ +| pkg1/go.mod:10:1:10:44 | go.mod exclude line | module | github.com/github/codeql-go | v1.23.1 | +| pkg2/go.mod:14:2:14:35 | go.mod exclude line | module | github.com/sirupsen/logrus | v1.4.2 | +| pkg2/go.mod:15:2:15:37 | go.mod exclude line | module | github.com/github/codeql-go | v1.23.1 | diff --git a/ql/test/library-tests/semmle/go/GoModExpr/ExcludeLines.ql b/ql/test/library-tests/semmle/go/GoModExpr/ExcludeLines.ql new file mode 100644 index 00000000000..dfd2262b9b7 --- /dev/null +++ b/ql/test/library-tests/semmle/go/GoModExpr/ExcludeLines.ql @@ -0,0 +1,5 @@ +import go + +from GoModExcludeLine excl, GoModModuleLine mod +where excl.getFile() = mod.getFile() +select excl, mod.getPath(), excl.getPath(), excl.getVer() diff --git a/ql/test/library-tests/semmle/go/GoModExpr/ReplaceLines.expected b/ql/test/library-tests/semmle/go/GoModExpr/ReplaceLines.expected new file mode 100644 index 00000000000..e69de29bb2d diff --git a/ql/test/library-tests/semmle/go/GoModExpr/ReplaceLines.ql b/ql/test/library-tests/semmle/go/GoModExpr/ReplaceLines.ql new file mode 100644 index 00000000000..0e82e2eea9d --- /dev/null +++ b/ql/test/library-tests/semmle/go/GoModExpr/ReplaceLines.ql @@ -0,0 +1,11 @@ +import go + +from GoModReplaceLine repl, GoModModuleLine mod, string repVer +where + repl.getFile() = mod.getFile() and + ( + repVer = repl.getReplacementVer() or + repVer = "no version" + ) +select repl, mod.getPath(), repl.getOriginalPath(), repl.getReplacementPath(), + repl.getReplacementVer() diff --git a/ql/test/library-tests/semmle/go/GoModExpr/RequireLines.expected b/ql/test/library-tests/semmle/go/GoModExpr/RequireLines.expected new file mode 100644 index 00000000000..df5da59bc87 --- /dev/null +++ b/ql/test/library-tests/semmle/go/GoModExpr/RequireLines.expected @@ -0,0 +1,5 @@ +| pkg1/go.mod:6:2:6:67 | go.mod require line | module | github.com/github/codeql-go | v1.23.2-0.20200302182241-5e71a04fdf30 | +| pkg1/go.mod:7:2:7:55 | go.mod require line | module | golang.org/x/tools | v0.0.0-20200109174759-ac4f524c1612 | +| pkg2/go.mod:7:1:7:38 | go.mod require line | module | github.com/gorilla/mux | v1.7.4 | +| pkg2/go.mod:9:2:9:35 | go.mod require line | module | github.com/sirupsen/logrus | v1.4.1 | +| pkg2/go.mod:10:2:10:40 | go.mod require line | module | github.com/Masterminds/squirrel | v1.2.0 | diff --git a/ql/test/library-tests/semmle/go/GoModExpr/RequireLines.ql b/ql/test/library-tests/semmle/go/GoModExpr/RequireLines.ql new file mode 100644 index 00000000000..84854191b65 --- /dev/null +++ b/ql/test/library-tests/semmle/go/GoModExpr/RequireLines.ql @@ -0,0 +1,5 @@ +import go + +from GoModRequireLine req, GoModModuleLine mod +where req.getFile() = mod.getFile() +select req, mod.getPath(), req.getPath(), req.getVer() diff --git a/ql/test/library-tests/semmle/go/GoModExpr/pkg1/go.mod b/ql/test/library-tests/semmle/go/GoModExpr/pkg1/go.mod new file mode 100644 index 00000000000..3416d3f0204 --- /dev/null +++ b/ql/test/library-tests/semmle/go/GoModExpr/pkg1/go.mod @@ -0,0 +1,10 @@ +module codeql-go-tests/gomod/dep1 + +go 1.14 + +require ( + github.com/github/codeql-go v1.23.2-0.20200302182241-5e71a04fdf30 + golang.org/x/tools v0.0.0-20200109174759-ac4f524c1612 +) + +exclude github.com/github/codeql-go v1.23.1 diff --git a/ql/test/library-tests/semmle/go/GoModExpr/pkg1/pkg1.go b/ql/test/library-tests/semmle/go/GoModExpr/pkg1/pkg1.go new file mode 100644 index 00000000000..e071a1255a5 --- /dev/null +++ b/ql/test/library-tests/semmle/go/GoModExpr/pkg1/pkg1.go @@ -0,0 +1,16 @@ +package pkg1 + +import ( + "fmt" + + "github.com/github/codeql-go/extractor/dbscheme" + "github.com/github/codeql-go/extractor/trap" + "golang.org/x/tools/go/packages" +) + +func usePkgs() { + fmt.Println(packages.NeedImports) + fmt.Println(dbscheme.LabelObjectType.Index()) + var lbl trap.Label + fmt.Println(lbl) +} diff --git a/ql/test/library-tests/semmle/go/GoModExpr/pkg2/go.mod b/ql/test/library-tests/semmle/go/GoModExpr/pkg2/go.mod new file mode 100644 index 00000000000..db778428e12 --- /dev/null +++ b/ql/test/library-tests/semmle/go/GoModExpr/pkg2/go.mod @@ -0,0 +1,16 @@ +module codeql-go-tests/gomod/dep2 + +go 1.14 + +replace github.com/Masterminds/squirrel => ../squirrel + +require github.com/gorilla/mux v1.7.4 +require ( + github.com/sirupsen/logrus v1.4.1 + github.com/Masterminds/squirrel v1.2.0 +) + +exclude ( + github.com/sirupsen/logrus v1.4.2 + github.com/github/codeql-go v1.23.1 +) diff --git a/ql/test/library-tests/semmle/go/GoModExpr/pkg2/pkg2.go b/ql/test/library-tests/semmle/go/GoModExpr/pkg2/pkg2.go new file mode 100644 index 00000000000..16c3a325211 --- /dev/null +++ b/ql/test/library-tests/semmle/go/GoModExpr/pkg2/pkg2.go @@ -0,0 +1,13 @@ +package pkg2 + +import ( + "fmt" + + "github.com/Masterminds/squirrel" + "github.com/gorilla/mux" + "github.com/sirupsen/logrus" +) + +func useDeps() { + +} diff --git a/ql/test/library-tests/semmle/go/GoModExpr/squirrel/LICENSE b/ql/test/library-tests/semmle/go/GoModExpr/squirrel/LICENSE new file mode 100644 index 00000000000..74c20a2b970 --- /dev/null +++ b/ql/test/library-tests/semmle/go/GoModExpr/squirrel/LICENSE @@ -0,0 +1,23 @@ +Squirrel +The Masterminds +Copyright (C) 2014-2015, Lann Martin +Copyright (C) 2015-2016, Google +Copyright (C) 2015, Matt Farina and Matt Butcher + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in +all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +THE SOFTWARE. diff --git a/ql/test/library-tests/semmle/go/GoModExpr/squirrel/README.md b/ql/test/library-tests/semmle/go/GoModExpr/squirrel/README.md new file mode 100644 index 00000000000..d51962ba840 --- /dev/null +++ b/ql/test/library-tests/semmle/go/GoModExpr/squirrel/README.md @@ -0,0 +1,3 @@ +This is a simple stub for https://github.com/Masterminds/squirrel, strictly for use in query testing. + +See the LICENSE file in this folder for information about the licensing of the original library. diff --git a/ql/test/library-tests/semmle/go/GoModExpr/squirrel/go.mod b/ql/test/library-tests/semmle/go/GoModExpr/squirrel/go.mod new file mode 100644 index 00000000000..78405f23173 --- /dev/null +++ b/ql/test/library-tests/semmle/go/GoModExpr/squirrel/go.mod @@ -0,0 +1,3 @@ +module github.com/github/codeql-go/ql/test/library-tests/semmle/go/GoModExpr/squirrel + +go 1.14 diff --git a/ql/test/library-tests/semmle/go/GoModExpr/squirrel/squirrel.go b/ql/test/library-tests/semmle/go/GoModExpr/squirrel/squirrel.go new file mode 100644 index 00000000000..78a19d3a6f2 --- /dev/null +++ b/ql/test/library-tests/semmle/go/GoModExpr/squirrel/squirrel.go @@ -0,0 +1,24 @@ +package squirrel + +type StatementBuilderType struct{} + +func Expr(e string, args ...interface{}) string { + return Expr(e, args...) +} + +var StatementBuilder = &StatementBuilderType{} + +func (b *StatementBuilderType) Insert(table string) *StatementBuilderType { + return b +} + +func (b *StatementBuilderType) Columns(columns ...string) *StatementBuilderType { + return b +} + +func (b *StatementBuilderType) Values(strings ...string) *StatementBuilderType { + return b +} + +func (b *StatementBuilderType) Exec() { +}