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 21.2.1



details:   https://anonhg.NetBSD.org/pkgsrc/rev/3942facba28f
branches:  trunk
changeset: 455010:3942facba28f
user:      rillig <rillig%pkgsrc.org@localhost>
date:      Fri Jun 25 14:15:00 2021 +0000

description:
pkgtools/pkglint: update to 21.2.1

Changes since 21.2.0:

Files whose names ends in '~' are ignored by pkglint since they are
ignored by CVS as well.

Variables with name BUILDLINK_TRANSFORM.* may contain '-Wl,-rpath,'
directly in commands of the form 'rm:*', just like their counterpart
BUILDLINK_TRANSFORM without a package name in the variable name.

Several new tests.

diffstat:

 pkgtools/pkglint/Makefile                    |    4 +-
 pkgtools/pkglint/files/check_test.go         |    7 -
 pkgtools/pkglint/files/distinfo_test.go      |   95 +++++++++++
 pkgtools/pkglint/files/files_test.go         |   17 ++
 pkgtools/pkglint/files/intqa/qa.go           |   20 +-
 pkgtools/pkglint/files/licenses.go           |   32 +-
 pkgtools/pkglint/files/licenses_test.go      |   28 +++-
 pkgtools/pkglint/files/line_test.go          |  228 ++++++++++++++++++++++++++-
 pkgtools/pkglint/files/linechecker_test.go   |   14 +
 pkgtools/pkglint/files/lines_test.go         |   77 +++++++++
 pkgtools/pkglint/files/logging_test.go       |  174 ++++++++++++++++++++
 pkgtools/pkglint/files/makepat/pat_test.go   |    1 +
 pkgtools/pkglint/files/mklinechecker.go      |    3 +-
 pkgtools/pkglint/files/mklinechecker_test.go |   12 +-
 pkgtools/pkglint/files/mklineparser_test.go  |    3 +
 pkgtools/pkglint/files/package.go            |   26 ++-
 pkgtools/pkglint/files/pkglint_test.go       |   24 ++-
 pkgtools/pkglint/files/pkgsrc.go             |    2 +-
 pkgtools/pkglint/files/pkgver/vercmp_test.go |    2 +
 pkgtools/pkglint/files/util.go               |    4 +-
 pkgtools/pkglint/files/util_test.go          |    6 +
 pkgtools/pkglint/files/vartypecheck.go       |    2 +-
 22 files changed, 727 insertions(+), 54 deletions(-)

diffs (truncated from 1118 to 300 lines):

diff -r 66a72676ca3c -r 3942facba28f pkgtools/pkglint/Makefile
--- a/pkgtools/pkglint/Makefile Fri Jun 25 13:50:45 2021 +0000
+++ b/pkgtools/pkglint/Makefile Fri Jun 25 14:15:00 2021 +0000
@@ -1,6 +1,6 @@
-# $NetBSD: Makefile,v 1.689 2021/06/17 09:11:55 rillig Exp $
+# $NetBSD: Makefile,v 1.690 2021/06/25 14:15:00 rillig Exp $
 
-PKGNAME=       pkglint-21.2.0
+PKGNAME=       pkglint-21.2.1
 CATEGORIES=    pkgtools
 DISTNAME=      tools
 MASTER_SITES=  ${MASTER_SITE_GITHUB:=golang/}
diff -r 66a72676ca3c -r 3942facba28f pkgtools/pkglint/files/check_test.go
--- a/pkgtools/pkglint/files/check_test.go      Fri Jun 25 13:50:45 2021 +0000
+++ b/pkgtools/pkglint/files/check_test.go      Fri Jun 25 14:15:00 2021 +0000
@@ -104,13 +104,6 @@
 func Test__qa(t *testing.T) {
        ck := intqa.NewQAChecker(t.Errorf)
 
-       ck.Configure("distinfo.go", "*", "*", -intqa.EMissingTest)       // TODO
-       ck.Configure("files.go", "*", "*", -intqa.EMissingTest)          // TODO
-       ck.Configure("licenses.go", "*", "*", -intqa.EMissingTest)       // TODO
-       ck.Configure("line.go", "*", "*", -intqa.EMissingTest)           // TODO
-       ck.Configure("linechecker.go", "*", "*", -intqa.EMissingTest)    // TODO
-       ck.Configure("lines.go", "*", "*", -intqa.EMissingTest)          // TODO
-       ck.Configure("logging.go", "*", "*", -intqa.EMissingTest)        // TODO
        ck.Configure("mkline.go", "*", "*", -intqa.EMissingTest)         // TODO
        ck.Configure("mklineparser.go", "*", "*", -intqa.EMissingTest)   // TODO
        ck.Configure("mklinechecker.go", "*", "*", -intqa.EMissingTest)  // TODO
diff -r 66a72676ca3c -r 3942facba28f pkgtools/pkglint/files/distinfo_test.go
--- a/pkgtools/pkglint/files/distinfo_test.go   Fri Jun 25 13:50:45 2021 +0000
+++ b/pkgtools/pkglint/files/distinfo_test.go   Fri Jun 25 14:15:00 2021 +0000
@@ -877,6 +877,63 @@
                "ERROR: ~/category/package/distinfo:5: Patch patch-nonexistent does not exist.")
 }
 
+func (s *Suite) Test_distinfoFileInfo_filename(c *check.C) {
+       t := s.Init(c)
+
+       info := distinfoFileInfo{
+               isPatch: no,
+               hashes: []distinfoHash{{
+                       line:      t.NewLine("irrelevant", 12345, "irrelevant"),
+                       filename:  "distinfo",
+                       algorithm: "irrelevant",
+                       hash:      "irrelevant",
+               }},
+       }
+
+       t.CheckEquals(info.filename(), RelPath("distinfo"))
+}
+
+func (s *Suite) Test_distinfoFileInfo_line(c *check.C) {
+       t := s.Init(c)
+
+       line := t.NewLine("irrelevant", 12345, "irrelevant")
+       info := distinfoFileInfo{
+               isPatch: no,
+               hashes: []distinfoHash{{
+                       line:      line,
+                       filename:  "irrelevant",
+                       algorithm: "irrelevant",
+                       hash:      "irrelevant",
+               }},
+       }
+
+       t.CheckEquals(info.line(), line)
+}
+
+func (s *Suite) Test_distinfoFileInfo_algorithms(c *check.C) {
+       t := s.Init(c)
+
+       info := distinfoFileInfo{
+               isPatch: no,
+               hashes: []distinfoHash{
+                       {
+                               line:      t.NewLine("irrelevant", 12345, "irrelevant"),
+                               filename:  "irrelevant",
+                               algorithm: "SHA1",
+                               hash:      "irrelevant",
+                       },
+                       {
+                               line:      t.NewLine("irrelevant", 12346, "irrelevant"),
+                               filename:  "irrelevant",
+                               algorithm: "Size",
+                               hash:      "irrelevant",
+                       },
+               },
+       }
+
+       t.CheckEquals(info.algorithms(), "SHA1, Size")
+}
+
 // The check for versioned distfiles only makes sense if the file
 // has the usual hashes for distfiles.
 func (s *Suite) Test_distinfoFileInfo_hasDistfileAlgorithms__code_coverage(c *check.C) {
@@ -920,3 +977,41 @@
                "ERROR: distinfo:15: Expected SHA1, RMD160, SHA512, Size checksums for "+
                        "\"dist-d.tar.gz\", got SHA1, RMD160, SHA512, other.")
 }
+
+func (s *Suite) Test_computePatchSha1Hex(c *check.C) {
+       t := s.Init(c)
+
+       test := func(expectedHash string, lines ...string) {
+               fileLines := t.NewLines("irrelevant", lines...)
+
+               hash := computePatchSha1Hex(fileLines)
+
+               t.CheckEquals(hash, expectedHash)
+       }
+
+       // The well-known hash for an empty string.
+       test(
+               "da39a3ee5e6b4b0d3255bfef95601890afd80709",
+               nil...,
+       )
+
+       // Any line containing "$" + "NetBSD" is ignored for computing
+       // the hash since the CVS IDs are irrelevant.  This assumes that
+       // the patch hunks themselves do not contain CVS IDs, and this
+       // is checked in PatchChecker.checktextCvsID.
+       test(
+               "da39a3ee5e6b4b0d3255bfef95601890afd80709",
+               CvsID,
+               CvsID+"$",
+               // This is not a CVS ID since the final '$' is missing, but it is
+               // close enough. See mk/checksum/distinfo.awk, function patchsum.
+               "Some text $"+"NetBSD-2020",
+       )
+
+       test(
+               // == sha1Hex("--- old\n+++ new\n")
+               "bb5a3903635415d367f47c02990e031469ab0346",
+               "--- old",
+               "+++ new",
+       )
+}
diff -r 66a72676ca3c -r 3942facba28f pkgtools/pkglint/files/files_test.go
--- a/pkgtools/pkglint/files/files_test.go      Fri Jun 25 13:50:45 2021 +0000
+++ b/pkgtools/pkglint/files/files_test.go      Fri Jun 25 14:15:00 2021 +0000
@@ -4,6 +4,23 @@
        "gopkg.in/check.v1"
 )
 
+func (s *Suite) Test_LoadMk(c *check.C) {
+       t := s.Init(c)
+
+       t.Chdir(".")
+       t.CreateFileLines("filename.mk",
+               "# line 1 \\",
+               "# continues in line 2")
+
+       mklines := LoadMk("filename.mk", nil, 0)
+
+       t.CheckEquals(len(mklines.mklines), 1)
+       // The '#' from line 2 is discarded in nextLogicalLine, to properly
+       // parse multi-line variable assignments that are commented out.
+       // See Test_MkLineParser_MatchVarassign, 'multi-line variable'.
+       t.CheckEquals(mklines.mklines[0].Text, "# line 1  continues in line 2")
+}
+
 func (s *Suite) Test_Load(c *check.C) {
        t := s.Init(c)
 
diff -r 66a72676ca3c -r 3942facba28f pkgtools/pkglint/files/intqa/qa.go
--- a/pkgtools/pkglint/files/intqa/qa.go        Fri Jun 25 13:50:45 2021 +0000
+++ b/pkgtools/pkglint/files/intqa/qa.go        Fri Jun 25 14:15:00 2021 +0000
@@ -21,25 +21,27 @@
        ENone Error = iota + 1
        EAll
 
-       // A function or method does not have a corresponding test.
+       // EMissingTest complains if a function or method does not have a
+       // corresponding test.
        EMissingTest
 
-       // The name of a test function does not correspond to a program
-       // element to be tested.
+       // EMissingTestee complains if the name of a test function does not
+       // correspond to a program element to be tested.
        EMissingTestee
 
-       // The tests are not in the same order as their corresponding
-       // testees in the main code.
+       // EOrder complains if the tests are not in the same order as their
+       // corresponding testees in the main code.
        EOrder
 
-       // The test method does not have a valid name.
+       // EName complains if the test method does not have a valid name.
        EName
 
-       // The file of the test method does not correspond to the
-       // file of the testee.
+       // EFile complains if the file of the test method does not correspond
+       // to the file of the testee.
        EFile
 
-       // All methods of a type must be in the same file as the type definition.
+       // EMethodsSameFile complains if a method of a type is in a different
+       // file than its corresponding type definition.
        EMethodsSameFile
 )
 
diff -r 66a72676ca3c -r 3942facba28f pkgtools/pkglint/files/licenses.go
--- a/pkgtools/pkglint/files/licenses.go        Fri Jun 25 13:50:45 2021 +0000
+++ b/pkgtools/pkglint/files/licenses.go        Fri Jun 25 14:15:00 2021 +0000
@@ -23,6 +23,22 @@
        cond.Walk(lc.checkNode)
 }
 
+func (lc *LicenseChecker) checkNode(cond *licenses.Condition) {
+       if name := cond.Name; name != "" && name != "append-placeholder" {
+               lc.checkName(name)
+               return
+       }
+
+       if cond.And && cond.Or {
+               lc.MkLine.Errorf("AND and OR operators in license conditions can only be combined using parentheses.")
+               lc.MkLine.Explain(
+                       "Examples for valid license conditions are:",
+                       "",
+                       "\tlicense1 AND license2 AND (license3 OR license4)",
+                       "\t(((license1 OR license2) AND (license3 OR license4)))")
+       }
+}
+
 func (lc *LicenseChecker) checkName(license string) {
        licenseFile := NewCurrPath("")
        pkg := lc.MkLines.pkg
@@ -54,19 +70,3 @@
                                seeGuide("Handling licenses", "handling-licenses")))
        }
 }
-
-func (lc *LicenseChecker) checkNode(cond *licenses.Condition) {
-       if name := cond.Name; name != "" && name != "append-placeholder" {
-               lc.checkName(name)
-               return
-       }
-
-       if cond.And && cond.Or {
-               lc.MkLine.Errorf("AND and OR operators in license conditions can only be combined using parentheses.")
-               lc.MkLine.Explain(
-                       "Examples for valid license conditions are:",
-                       "",
-                       "\tlicense1 AND license2 AND (license3 OR license4)",
-                       "\t(((license1 OR license2) AND (license3 OR license4)))")
-       }
-}
diff -r 66a72676ca3c -r 3942facba28f pkgtools/pkglint/files/licenses_test.go
--- a/pkgtools/pkglint/files/licenses_test.go   Fri Jun 25 13:50:45 2021 +0000
+++ b/pkgtools/pkglint/files/licenses_test.go   Fri Jun 25 14:15:00 2021 +0000
@@ -15,7 +15,8 @@
                        "LICENSE=\t"+licenseValue)
 
                mklines.ForEach(func(mkline *MkLine) {
-                       (&LicenseChecker{mklines, mkline}).Check(mkline.Value(), opAssign)
+                       ck := LicenseChecker{mklines, mkline}
+                       ck.Check(mkline.Value(), mkline.Op())
                })
 
                t.CheckOutput(diagnostics)
@@ -49,6 +50,31 @@
                nil...)
 }
 
+func (s *Suite) Test_LicenseChecker_checkNode(c *check.C) {
+       t := s.Init(c)
+
+       t.CreateFileLines("licenses/gnu-gpl-v2",
+               "The licenses for most software are designed to take away ...")
+
+       test := func(assignment string, diagnostics ...string) {
+               mklines := t.SetUpFileMkLines("Makefile",
+                       assignment)
+
+               mklines.ForEach(func(mkline *MkLine) {
+                       ck := LicenseChecker{mklines, mkline}
+                       ck.Check(mkline.Value(), mkline.Op())
+               })
+
+               t.CheckOutput(diagnostics)
+       }
+
+       test("LICENSE=\tfirst second",
+               "ERROR: ~/Makefile:1: Parse error for license condition \"first second\".")
+
+       test("LICENSE+=\tadded",
+               "ERROR: ~/Makefile:1: Parse error for appended license condition \"added\".")
+}
+
 func (s *Suite) Test_LicenseChecker_checkName__LICENSE_FILE(c *check.C) {
        t := s.Init(c)
 
diff -r 66a72676ca3c -r 3942facba28f pkgtools/pkglint/files/line_test.go
--- a/pkgtools/pkglint/files/line_test.go       Fri Jun 25 13:50:45 2021 +0000
+++ b/pkgtools/pkglint/files/line_test.go       Fri Jun 25 14:15:00 2021 +0000
@@ -2,14 +2,105 @@



Home | Main Index | Thread Index | Old Index