pkgsrc-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[pkgsrc/trunk]: pkgsrc/pkgtools/pkglint pkgtools/pkglint: update to 19.3.9



details:   https://anonhg.NetBSD.org/pkgsrc/rev/0822bf1a6415
branches:  trunk
changeset: 344362:0822bf1a6415
user:      rillig <rillig%pkgsrc.org@localhost>
date:      Tue Nov 19 06:51:38 2019 +0000

description:
pkgtools/pkglint: update to 19.3.9

Changes since 19.3.8:

Match man pages in ALTERNATIVES with their counterparts in PLIST. In
PLIST files, ${PKGMANDIR} may be abbreviated as a simple "man", but not
in ALTERNATIVES.

diffstat:

 pkgtools/pkglint/Makefile                          |    4 +-
 pkgtools/pkglint/files/alternatives.go             |    3 +
 pkgtools/pkglint/files/alternatives_test.go        |   22 +
 pkgtools/pkglint/files/getopt/getopt_test.go       |    2 +-
 pkgtools/pkglint/files/histogram/histogram_test.go |    2 +-
 pkgtools/pkglint/files/intqa/testnames.go          |  281 ++++++++-----
 pkgtools/pkglint/files/intqa/testnames_test.go     |  432 ++++++++++++++++++--
 pkgtools/pkglint/files/licenses/licenses_test.go   |    2 +-
 pkgtools/pkglint/files/mktypes.go                  |    2 +-
 pkgtools/pkglint/files/pkgsrc.go                   |    2 +-
 pkgtools/pkglint/files/pkgsrc_test.go              |   32 +-
 pkgtools/pkglint/files/pkgver/vercmp_test.go       |    2 +-
 pkgtools/pkglint/files/testnames_test.go           |    4 +-
 pkgtools/pkglint/files/textproc/lexer_test.go      |    2 +-
 pkgtools/pkglint/files/trace/tracing_test.go       |    2 +-
 15 files changed, 616 insertions(+), 178 deletions(-)

diffs (truncated from 1271 to 300 lines):

diff -r 59de702998fb -r 0822bf1a6415 pkgtools/pkglint/Makefile
--- a/pkgtools/pkglint/Makefile Tue Nov 19 05:56:45 2019 +0000
+++ b/pkgtools/pkglint/Makefile Tue Nov 19 06:51:38 2019 +0000
@@ -1,6 +1,6 @@
-# $NetBSD: Makefile,v 1.608 2019/11/17 02:06:01 rillig Exp $
+# $NetBSD: Makefile,v 1.609 2019/11/19 06:51:38 rillig Exp $
 
-PKGNAME=       pkglint-19.3.8
+PKGNAME=       pkglint-19.3.9
 CATEGORIES=    pkgtools
 DISTNAME=      tools
 MASTER_SITES=  ${MASTER_SITE_GITHUB:=golang/}
diff -r 59de702998fb -r 0822bf1a6415 pkgtools/pkglint/files/alternatives.go
--- a/pkgtools/pkglint/files/alternatives.go    Tue Nov 19 05:56:45 2019 +0000
+++ b/pkgtools/pkglint/files/alternatives.go    Tue Nov 19 06:51:38 2019 +0000
@@ -28,6 +28,9 @@
                if plist.Files[plistName] != nil || G.Pkg.vars.IsDefined("ALTERNATIVES_SRC") {
                        return
                }
+               if plist.Files[strings.Replace(plistName, "${PKGMANDIR}", "man", 1)] != nil {
+                       return
+               }
 
                switch {
 
diff -r 59de702998fb -r 0822bf1a6415 pkgtools/pkglint/files/alternatives_test.go
--- a/pkgtools/pkglint/files/alternatives_test.go       Tue Nov 19 05:56:45 2019 +0000
+++ b/pkgtools/pkglint/files/alternatives_test.go       Tue Nov 19 06:51:38 2019 +0000
@@ -106,3 +106,25 @@
 
        t.CheckOutputEmpty()
 }
+
+// When a man page is mentioned in the ALTERNATIVES file, it must use the
+// PKGMANDIR variable. In the PLIST files though, there is some magic
+// in the pkgsrc infrastructure that maps man/ to ${PKGMANDIR}, which
+// leads to a bit less typing.
+//
+// Seen in graphics/py-blockdiag.
+func (s *Suite) Test_CheckFileAlternatives__PLIST_man(c *check.C) {
+       t := s.Init(c)
+
+       t.SetUpPackage("category/package")
+       t.CreateFileLines("category/package/ALTERNATIVES",
+               "@PKGMANDIR@/man1/blockdiag @PREFIX@/@PKGMANDIR@/man1/blockdiag-@PYVERSSUFFIX@.1")
+       t.CreateFileLines("category/package/PLIST",
+               PlistCvsID,
+               "man/man1/blockdiag-${PYVERSSUFFIX}.1")
+       t.FinishSetUp()
+
+       G.Check(t.File("category/package"))
+
+       t.CheckOutputEmpty()
+}
diff -r 59de702998fb -r 0822bf1a6415 pkgtools/pkglint/files/getopt/getopt_test.go
--- a/pkgtools/pkglint/files/getopt/getopt_test.go      Tue Nov 19 05:56:45 2019 +0000
+++ b/pkgtools/pkglint/files/getopt/getopt_test.go      Tue Nov 19 06:51:38 2019 +0000
@@ -411,6 +411,6 @@
 
 func (s *Suite) Test__test_names(c *check.C) {
        ck := intqa.NewTestNameChecker(c.Errorf)
-       ck.Enable(intqa.EAll, -intqa.EMissingTest)
+       ck.Configure("*", "*", "*", -intqa.EMissingTest)
        ck.Check()
 }
diff -r 59de702998fb -r 0822bf1a6415 pkgtools/pkglint/files/histogram/histogram_test.go
--- a/pkgtools/pkglint/files/histogram/histogram_test.go        Tue Nov 19 05:56:45 2019 +0000
+++ b/pkgtools/pkglint/files/histogram/histogram_test.go        Tue Nov 19 06:51:38 2019 +0000
@@ -30,6 +30,6 @@
 
 func (s *Suite) Test__test_names(c *check.C) {
        ck := intqa.NewTestNameChecker(c.Errorf)
-       ck.Enable(intqa.EAll, -intqa.EMissingTest)
+       ck.Configure("*", "*", "*", -intqa.EMissingTest)
        ck.Check()
 }
diff -r 59de702998fb -r 0822bf1a6415 pkgtools/pkglint/files/intqa/testnames.go
--- a/pkgtools/pkglint/files/intqa/testnames.go Tue Nov 19 05:56:45 2019 +0000
+++ b/pkgtools/pkglint/files/intqa/testnames.go Tue Nov 19 06:51:38 2019 +0000
@@ -8,7 +8,8 @@
        "go/token"
        "io"
        "os"
-       "path/filepath"
+       "path"
+       "reflect"
        "sort"
        "strings"
        "unicode"
@@ -17,7 +18,7 @@
 type Error int
 
 const (
-       ENone Error = iota
+       ENone Error = iota + 1
        EAll
 
        // A function or method does not have a corresponding test.
@@ -45,43 +46,47 @@
 type TestNameChecker struct {
        errorf func(format string, args ...interface{})
 
-       ignoredFiles []string
-       order        int
+       filters []filter
+       order   int
 
        testees []*testee
        tests   []*test
 
-       errorsMask uint64
-       errors     []string
-       out        io.Writer
+       errors []string
+       out    io.Writer
 }
 
 // NewTestNameChecker creates a new checker.
-// By default, all errors are disabled; call Enable to enable them.
+// By default, all errors are enabled;
+// call Configure to disable them selectively.
 func NewTestNameChecker(errorf func(format string, args ...interface{})) *TestNameChecker {
-       return &TestNameChecker{errorf: errorf, out: os.Stderr}
-}
+       ck := TestNameChecker{errorf: errorf, out: os.Stderr}
+
+       // For test fixtures from https://gopkg.in/check/v1.
+       ck.Configure("*_test.go", "*", "SetUpTest", -EMissingTest)
+       ck.Configure("*_test.go", "*", "TearDownTest", -EMissingTest)
 
-func (ck *TestNameChecker) IgnoreFiles(fileGlob string) {
-       ck.ignoredFiles = append(ck.ignoredFiles, fileGlob)
+       // See https://github.com/rillig/gobco.
+       ck.Configure("gobco_*.go", "gobco*", "*", -EMissingTest)
+       ck.Configure("gobco_*.go", "", "gobco*", -EMissingTest)
+
+       return &ck
 }
 
-func (ck *TestNameChecker) Enable(errors ...Error) {
-       for _, err := range errors {
-               if err == ENone {
-                       ck.errorsMask = 0
-               } else if err == EAll {
-                       ck.errorsMask = ^uint64(0)
-               } else if err < 0 {
-                       ck.errorsMask &= ^(uint64(1) << -uint(err))
-               } else {
-                       ck.errorsMask |= uint64(1) << uint(err)
-               }
-       }
+// Configure sets the errors that are activated for the given code,
+// specified by shell patterns like in path.Match.
+//
+// All rules are applied in order. Later rules overwrite earlier rules.
+//
+// Individual errors can be enabled by giving their constant and disabled
+// by negating them, such as -EMissingTestee. To reset everything, use
+// either EAll or ENone.
+func (ck *TestNameChecker) Configure(filenames, typeNames, funcNames string, errors ...Error) {
+       ck.filters = append(ck.filters, filter{filenames, typeNames, funcNames, errors})
 }
 
 func (ck *TestNameChecker) Check() {
-       ck.load()
+       ck.load(".")
        ck.checkTestees()
        ck.checkTests()
        ck.checkOrder()
@@ -89,29 +94,18 @@
 }
 
 // load loads all type, function and method names from the current package.
-func (ck *TestNameChecker) load() {
+func (ck *TestNameChecker) load(dir string) {
+
        fileSet := token.NewFileSet()
-       pkgs, err := parser.ParseDir(fileSet, ".", nil, 0)
+       pkgs, err := parser.ParseDir(fileSet, dir, nil, 0)
        if err != nil {
                panic(err)
        }
 
-       var pkgnames []string
-       for pkgname := range pkgs {
-               pkgnames = append(pkgnames, pkgname)
-       }
-       sort.Strings(pkgnames)
-
-       for _, pkgname := range pkgnames {
+       for _, pkgname := range sortedKeys(pkgs) {
                files := pkgs[pkgname].Files
 
-               var filenames []string
-               for filename := range files {
-                       filenames = append(filenames, filename)
-               }
-               sort.Strings(filenames)
-
-               for _, filename := range filenames {
+               for _, filename := range sortedKeys(files) {
                        file := files[filename]
                        for _, decl := range file.Decls {
                                ck.loadDecl(decl, filename)
@@ -131,7 +125,7 @@
                        switch spec := spec.(type) {
                        case *ast.TypeSpec:
                                typeName := spec.Name.Name
-                               ck.addCode(code{filename, typeName, "", ck.nextOrder()})
+                               ck.addCode(code{filename, typeName, "", 0})
                        }
                }
 
@@ -145,16 +139,28 @@
                                typeName = typeExpr.(*ast.Ident).Name
                        }
                }
-               ck.addCode(code{filename, typeName, decl.Name.Name, ck.nextOrder()})
+               funcName := decl.Name.Name
+               ck.addCode(code{filename, typeName, funcName, 0})
        }
 }
 
 func (ck *TestNameChecker) addCode(code code) {
-       isTest := strings.HasSuffix(code.file, "_test.go") &&
-               code.Type != "" &&
-               strings.HasPrefix(code.Func, "Test")
+       if code.isTestScope() && code.isFunc() && code.Func == "TestMain" {
+               // This is not a test for Main, but a wrapper function of the test.
+               // Therefore it is completely ignored.
+               // See https://golang.org/pkg/testing/#hdr-Main.
+               //
+               // Among others, this function is created by
+               // https://github.com/rillig/gobco when measuring the branch
+               // coverage of a package.
+               return
+       }
 
-       if isTest {
+       if !ck.isRelevant(code.file, code.Type, code.Func, EAll) {
+               return
+       }
+
+       if code.isTest() {
                ck.addTest(code)
        } else {
                ck.addTestee(code)
@@ -162,15 +168,19 @@
 }
 
 func (ck *TestNameChecker) addTestee(code code) {
+       code.order = ck.nextOrder()
        ck.testees = append(ck.testees, &testee{code})
 }
 
 func (ck *TestNameChecker) addTest(code code) {
-       if !strings.HasPrefix(code.Func, "Test_") {
+       if !strings.HasPrefix(code.Func, "Test_") &&
+               code.Func != "Test" &&
                ck.addError(
                        EName,
+                       code,
                        "Test %q must start with %q.",
-                       code.fullName(), "Test_")
+                       code.fullName(), "Test_") {
+
                return
        }
 
@@ -178,16 +188,18 @@
        testeeName := strings.TrimPrefix(strings.TrimPrefix(parts[0], "Test"), "_")
        descr := ""
        if len(parts) > 1 {
-               if parts[1] == "" {
+               if parts[1] == "" &&
                        ck.addError(
                                EName,
-                               "Test %q must not have a nonempty description.",
-                               code.fullName())
+                               code,
+                               "Test %q must have a nonempty description.",
+                               code.fullName()) {
                        return
                }
                descr = parts[1]
        }
 
+       code.order = ck.nextOrder()
        ck.tests = append(ck.tests, &test{code, testeeName, descr, nil})
 }
 
@@ -213,8 +225,8 @@
 func (ck *TestNameChecker) checkTests() {
        for _, test := range ck.tests {
                ck.checkTestFile(test)
-               ck.checkTestName(test)
                ck.checkTestTestee(test)
+               ck.checkTestDescr(test)
        }
 }



Home | Main Index | Thread Index | Old Index