From 7b71b077e1f4a3d5f15ca417a16c3b4dbb629b8b Mon Sep 17 00:00:00 2001 From: Alan Donovan Date: Fri, 28 Sep 2018 09:02:09 -0400 Subject: [PATCH] go/analysis/analysistest: refuse to analyze zero packages It's easy to forget to pass the last argument, in which case the test would silently pass. Change-Id: I95249e1fe8bee75cfaa535fcf723d04f102214fc Reviewed-on: https://go-review.googlesource.com/138395 Reviewed-by: Michael Matloob --- go/analysis/analysistest/analysistest.go | 3 +++ 1 file changed, 3 insertions(+) diff --git a/go/analysis/analysistest/analysistest.go b/go/analysis/analysistest/analysistest.go index 33b28b95..e4e82ce7 100644 --- a/go/analysis/analysistest/analysistest.go +++ b/go/analysis/analysistest/analysistest.go @@ -66,6 +66,9 @@ type Testing interface { // You may wish to call this function from within a (*testing.T).Run // subtest to ensure that errors have adequate contextual description. func Run(t Testing, dir string, a *analysis.Analyzer, pkgnames ...string) { + if pkgnames == nil { + t.Errorf("Run: no packages") + } for _, pkgname := range pkgnames { pkg, err := loadPackage(dir, pkgname) if err != nil {