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 5.6.3



details:   https://anonhg.NetBSD.org/pkgsrc/rev/0bf2d4ca8135
branches:  trunk
changeset: 385977:0bf2d4ca8135
user:      rillig <rillig%pkgsrc.org@localhost>
date:      Wed Oct 03 22:27:53 2018 +0000

description:
pkgtools/pkglint: Update to 5.6.3

Changes since 5.6.2:

* Add check for version patterns 1.5*, which should rather be 1.5.*

* Re-enable check for "set -e" and commands that may silently fail
  because of missing error checking

* Lots of internal clean-up and tests

diffstat:

 pkgtools/pkglint/Makefile                         |    4 +-
 pkgtools/pkglint/files/alternatives.go            |    7 +-
 pkgtools/pkglint/files/alternatives_test.go       |   23 +-
 pkgtools/pkglint/files/autofix.go                 |   15 +-
 pkgtools/pkglint/files/autofix_test.go            |   68 +-
 pkgtools/pkglint/files/buildlink3_test.go         |   37 +-
 pkgtools/pkglint/files/category_test.go           |   16 +-
 pkgtools/pkglint/files/check_test.go              |  115 +++-
 pkgtools/pkglint/files/distinfo_test.go           |   26 +-
 pkgtools/pkglint/files/expecter.go                |    2 +-
 pkgtools/pkglint/files/files.go                   |    9 +-
 pkgtools/pkglint/files/files_test.go              |    6 +-
 pkgtools/pkglint/files/fuzzer_test.go             |   90 +++
 pkgtools/pkglint/files/getopt/getopt_test.go      |   40 +
 pkgtools/pkglint/files/licenses.go                |    2 +-
 pkgtools/pkglint/files/licenses/licenses.go       |    9 +-
 pkgtools/pkglint/files/licenses/licenses_test.go  |   28 +-
 pkgtools/pkglint/files/licenses_test.go           |   29 +-
 pkgtools/pkglint/files/line.go                    |    3 +-
 pkgtools/pkglint/files/linechecker.go             |   34 +-
 pkgtools/pkglint/files/linechecker_test.go        |   24 +-
 pkgtools/pkglint/files/logging.go                 |   13 +-
 pkgtools/pkglint/files/logging_test.go            |   28 +-
 pkgtools/pkglint/files/mkline.go                  |   57 +-
 pkgtools/pkglint/files/mkline_test.go             |   68 +-
 pkgtools/pkglint/files/mklinechecker.go           |  110 +---
 pkgtools/pkglint/files/mklinechecker_test.go      |  257 ++++++++-
 pkgtools/pkglint/files/mklines.go                 |   23 +-
 pkgtools/pkglint/files/mklines_test.go            |   10 +-
 pkgtools/pkglint/files/mkparser.go                |    3 +
 pkgtools/pkglint/files/mkparser_test.go           |   17 +-
 pkgtools/pkglint/files/mkshparser_test.go         |   48 +-
 pkgtools/pkglint/files/mkshtypes.go               |   52 +-
 pkgtools/pkglint/files/mkshwalker.go              |  350 +++++++---
 pkgtools/pkglint/files/mkshwalker_test.go         |   44 +-
 pkgtools/pkglint/files/options.go                 |    9 +-
 pkgtools/pkglint/files/options_test.go            |   12 +-
 pkgtools/pkglint/files/package.go                 |  182 ++---
 pkgtools/pkglint/files/package_test.go            |  435 ++++++++++++++-
 pkgtools/pkglint/files/parser.go                  |    2 +-
 pkgtools/pkglint/files/patches_test.go            |    6 +-
 pkgtools/pkglint/files/pkglint.go                 |  107 ++-
 pkgtools/pkglint/files/pkglint_test.go            |  307 ++++++++--
 pkgtools/pkglint/files/pkgsrc.go                  |   67 +-
 pkgtools/pkglint/files/pkgsrc_test.go             |  181 ++++-
 pkgtools/pkglint/files/plist.go                   |    3 +-
 pkgtools/pkglint/files/plist_test.go              |   13 +-
 pkgtools/pkglint/files/regex/regex.go             |   96 +-
 pkgtools/pkglint/files/shell.go                   |  216 ++++--
 pkgtools/pkglint/files/shell_test.go              |  380 +++++++++++-
 pkgtools/pkglint/files/shtokenizer.go             |   40 +-
 pkgtools/pkglint/files/shtokenizer_test.go        |  657 ++++++++++++---------
 pkgtools/pkglint/files/shtypes.go                 |   40 +-
 pkgtools/pkglint/files/substcontext_test.go       |   27 +-
 pkgtools/pkglint/files/testnames_test.go          |  130 ++++
 pkgtools/pkglint/files/textproc/prefixreplacer.go |   11 +-
 pkgtools/pkglint/files/tools.go                   |   25 +-
 pkgtools/pkglint/files/tools_test.go              |    6 +-
 pkgtools/pkglint/files/toplevel_test.go           |   10 +-
 pkgtools/pkglint/files/util.go                    |  231 ++++++-
 pkgtools/pkglint/files/util_test.go               |  134 +++-
 pkgtools/pkglint/files/vardefs.go                 |  419 +++++++------
 pkgtools/pkglint/files/vardefs_test.go            |   28 +-
 pkgtools/pkglint/files/vartype.go                 |    2 +-
 pkgtools/pkglint/files/vartype_test.go            |    6 +-
 pkgtools/pkglint/files/vartypecheck.go            |   50 +-
 pkgtools/pkglint/files/vartypecheck_test.go       |   20 +-
 pkgtools/pkglint/select.mk                        |    4 +-
 68 files changed, 3931 insertions(+), 1592 deletions(-)

diffs (truncated from 9533 to 300 lines):

diff -r 0a65bded6cfd -r 0bf2d4ca8135 pkgtools/pkglint/Makefile
--- a/pkgtools/pkglint/Makefile Wed Oct 03 22:27:18 2018 +0000
+++ b/pkgtools/pkglint/Makefile Wed Oct 03 22:27:53 2018 +0000
@@ -1,6 +1,6 @@
-# $NetBSD: Makefile,v 1.548 2018/09/05 17:56:22 rillig Exp $
+# $NetBSD: Makefile,v 1.549 2018/10/03 22:27:53 rillig Exp $
 
-PKGNAME=       pkglint-5.6.2
+PKGNAME=       pkglint-5.6.3
 DISTFILES=     # none
 CATEGORIES=    pkgtools
 
diff -r 0a65bded6cfd -r 0bf2d4ca8135 pkgtools/pkglint/files/alternatives.go
--- a/pkgtools/pkglint/files/alternatives.go    Wed Oct 03 22:27:18 2018 +0000
+++ b/pkgtools/pkglint/files/alternatives.go    Wed Oct 03 22:27:53 2018 +0000
@@ -1,9 +1,6 @@
 package main
 
-import (
-       "netbsd.org/pkglint/regex"
-       "strings"
-)
+import "strings"
 
 func CheckfileAlternatives(filename string, plistFiles map[string]bool) {
        lines := Load(filename, NotEmpty|LogErrors)
@@ -19,7 +16,7 @@
                                }
 
                                relImplementation := strings.Replace(implementation, "@PREFIX@/", "", 1)
-                               plistName := regex.Compile(`@(\w+)@`).ReplaceAllString(relImplementation, "${$1}")
+                               plistName := replaceAll(relImplementation, `@(\w+)@`, "${$1}")
                                if !plistFiles[plistName] && !G.Pkg.vars.Defined("ALTERNATIVES_SRC") {
                                        if plistName != implementation {
                                                line.Errorf("Alternative implementation %q must appear in the PLIST as %q.", implementation, plistName)
diff -r 0a65bded6cfd -r 0bf2d4ca8135 pkgtools/pkglint/files/alternatives_test.go
--- a/pkgtools/pkglint/files/alternatives_test.go       Wed Oct 03 22:27:18 2018 +0000
+++ b/pkgtools/pkglint/files/alternatives_test.go       Wed Oct 03 22:27:53 2018 +0000
@@ -2,25 +2,30 @@
 
 import "gopkg.in/check.v1"
 
-func (s *Suite) Test_Alternatives_PLIST(c *check.C) {
+func (s *Suite) Test_CheckfileAlternatives__PLIST(c *check.C) {
        t := s.Init(c)
 
+       t.SetupPackage("category/package")
        t.Chdir("category/package")
-       t.SetupFileLines("ALTERNATIVES",
+       t.CreateFileLines("ALTERNATIVES",
                "sbin/sendmail @PREFIX@/sbin/sendmail.postfix@POSTFIXVER@",
                "sbin/sendmail @PREFIX@/sbin/sendmail.exim@EXIMVER@",
                "bin/echo bin/gnu-echo",
                "bin/editor bin/vim -e",
                "invalid")
+       t.CreateFileLines("PLIST",
+               PlistRcsID,
+               "bin/echo",
+               "bin/vim",
+               "sbin/sendmail.exim${EXIMVER}")
 
-       G.Pkg = NewPackage(".")
-       G.Pkg.PlistFiles["bin/echo"] = true
-       G.Pkg.PlistFiles["bin/vim"] = true
-       G.Pkg.PlistFiles["sbin/sendmail.exim${EXIMVER}"] = true
+       G.CheckDirent(".")
 
-       CheckfileAlternatives("ALTERNATIVES", G.Pkg.PlistFiles)
-
+       // TODO: Remove redundant diagnostics.
        t.CheckOutputLines(
+               "NOTE: ALTERNATIVES:1: @PREFIX@/ can be omitted from the file name.",
+               "NOTE: ALTERNATIVES:2: @PREFIX@/ can be omitted from the file name.",
+               "ERROR: ALTERNATIVES:5: Invalid ALTERNATIVES line \"invalid\".",
                "ERROR: ALTERNATIVES:1: Alternative implementation \"@PREFIX@/sbin/sendmail.postfix@POSTFIXVER@\" must appear in the PLIST as \"sbin/sendmail.postfix${POSTFIXVER}\".",
                "NOTE: ALTERNATIVES:1: @PREFIX@/ can be omitted from the file name.",
                "NOTE: ALTERNATIVES:2: @PREFIX@/ can be omitted from the file name.",
@@ -33,7 +38,7 @@
        t := s.Init(c)
 
        t.Chdir("category/package")
-       t.SetupFileLines("ALTERNATIVES")
+       t.CreateFileLines("ALTERNATIVES")
 
        G.Pkg = NewPackage(".")
 
diff -r 0a65bded6cfd -r 0bf2d4ca8135 pkgtools/pkglint/files/autofix.go
--- a/pkgtools/pkglint/files/autofix.go Wed Oct 03 22:27:18 2018 +0000
+++ b/pkgtools/pkglint/files/autofix.go Wed Oct 03 22:27:53 2018 +0000
@@ -46,8 +46,9 @@
 // If printAutofix or autofix is true, the fix should be done in
 // memory as far as possible (e.g. changes to the text of the line).
 //
-// If autofix is true, the fix should be done permanently
-// (e.g. direct changes to the file system).
+// If autofix is true, the fix should be done persistently
+// (e.g. direct changes to the file system). Except if the fix only
+// affects the current line, then SaveAutofixChanges will do that.
 func (fix *Autofix) Custom(fixer func(printAutofix, autofix bool)) {
        if fix.skip() {
                return
@@ -104,7 +105,7 @@
                                return toText
                        }
 
-                       if replaced := regex.Compile(from).ReplaceAllStringFunc(rawLine.textnl, replace); replaced != rawLine.textnl {
+                       if replaced := replaceAllFunc(rawLine.textnl, from, replace); replaced != rawLine.textnl {
                                if G.opts.PrintAutofix || G.opts.Autofix {
                                        rawLine.textnl = replaced
                                }
@@ -134,12 +135,12 @@
        }
 
        for _, rawLine := range fix.lines[1:] {
-               _, comment, space := regex.Match2(rawLine.textnl, `^(#?)([ \t]*)`)
+               _, comment, space := match2(rawLine.textnl, `^(#?)([ \t]*)`)
                width := tabWidth(comment + space)
                if (oldWidth == 0 || width < oldWidth) && width >= 8 && rawLine.textnl != "\n" {
                        oldWidth = width
                }
-               if !regex.Matches(space, `^\t* {0,7}$`) {
+               if !matches(space, `^\t* {0,7}$`) {
                        normalized = false
                }
        }
@@ -156,7 +157,7 @@
        }
 
        for _, rawLine := range fix.lines[1:] {
-               _, comment, oldSpace := regex.Match2(rawLine.textnl, `^(#?)([ \t]*)`)
+               _, comment, oldSpace := match2(rawLine.textnl, `^(#?)([ \t]*)`)
                newWidth := tabWidth(oldSpace) - oldWidth + newWidth
                newSpace := strings.Repeat("\t", newWidth/8) + strings.Repeat(" ", newWidth%8)
                replaced := strings.Replace(rawLine.textnl, comment+oldSpace, comment+newSpace, 1)
@@ -311,6 +312,7 @@
                for _, line := range lines {
                        if line.autofix != nil && line.autofix.modified {
                                G.autofixAvailable = true
+                               G.fileCache.Evict(line.Filename)
                        }
                }
                return
@@ -338,6 +340,7 @@
        }
 
        for fname := range changed {
+               G.fileCache.Evict(fname)
                changedLines := changes[fname]
                tmpname := fname + ".pkglint.tmp"
                text := ""
diff -r 0a65bded6cfd -r 0bf2d4ca8135 pkgtools/pkglint/files/autofix_test.go
--- a/pkgtools/pkglint/files/autofix_test.go    Wed Oct 03 22:27:18 2018 +0000
+++ b/pkgtools/pkglint/files/autofix_test.go    Wed Oct 03 22:27:53 2018 +0000
@@ -7,7 +7,7 @@
        "strings"
 )
 
-func (s *Suite) Test_Autofix_ReplaceRegex(c *check.C) {
+func (s *Suite) Test_Autofix_ReplaceRegex__show_autofix(c *check.C) {
        t := s.Init(c)
 
        t.SetupCommandLine("--show-autofix")
@@ -36,7 +36,7 @@
                "AUTOFIX: ~/Makefile:2: Replacing \"2\" with \"X\".")
 }
 
-func (s *Suite) Test_Autofix_ReplaceRegex_with_autofix(c *check.C) {
+func (s *Suite) Test_Autofix_ReplaceRegex__autofix(c *check.C) {
        t := s.Init(c)
 
        t.SetupCommandLine("--autofix", "--source")
@@ -75,7 +75,7 @@
                "line3")
 }
 
-func (s *Suite) Test_Autofix_ReplaceRegex_with_show_autofix(c *check.C) {
+func (s *Suite) Test_Autofix_ReplaceRegex__show_autofix_and_source(c *check.C) {
        t := s.Init(c)
 
        t.SetupCommandLine("--show-autofix", "--source")
@@ -111,11 +111,11 @@
                "+\tYXXXX")
 }
 
-func (s *Suite) Test_autofix_MkLines(c *check.C) {
+func (s *Suite) Test_SaveAutofixChanges(c *check.C) {
        t := s.Init(c)
 
        t.SetupCommandLine("--autofix")
-       t.SetupFileLines("category/basename/Makefile",
+       t.CreateFileLines("category/basename/Makefile",
                "line1 := value1",
                "line2 := value2",
                "line3 := value3")
@@ -149,6 +149,27 @@
                "XXXe3 := value3")
 }
 
+func (s *Suite) Test_SaveAutofixChanges__no_changes_necessary(c *check.C) {
+       t := s.Init(c)
+
+       t.SetupCommandLine("--autofix")
+       lines := t.SetupFileLines("DESCR",
+               "Line 1",
+               "Line 2")
+
+       fix := lines[0].Autofix()
+       fix.Warnf("Dummy warning.")
+       fix.Replace("X", "Y")
+       fix.Apply()
+
+       // Since nothing has been effectively changed,
+       // nothing needs to be saved.
+       SaveAutofixChanges(lines)
+
+       // And therefore, no AUTOFIX action must appear in the log.
+       t.CheckOutputEmpty()
+}
+
 func (s *Suite) Test_Autofix__multiple_modifications(c *check.C) {
        t := s.Init(c)
 
@@ -255,7 +276,7 @@
                "AUTOFIX: fname:1: Deleting this line.")
 }
 
-func (s *Suite) Test_Autofix_show_source_code(c *check.C) {
+func (s *Suite) Test_Autofix__show_autofix_and_source(c *check.C) {
        t := s.Init(c)
 
        t.SetupCommandLine("--show-autofix", "--source")
@@ -319,7 +340,7 @@
 
 // Demonstrates that the --show-autofix option only shows those diagnostics
 // that would be fixed.
-func (s *Suite) Test_Autofix_suppress_unfixable_warnings(c *check.C) {
+func (s *Suite) Test_Autofix__suppress_unfixable_warnings(c *check.C) {
        t := s.Init(c)
 
        t.SetupCommandLine("--show-autofix", "--source")
@@ -328,14 +349,14 @@
                "line2",
                "line3")
 
-       lines[0].Warnf("This warning is not shown since it is not automatically fixed.")
+       lines[0].Warnf("This warning is not shown since it is not part of a fix.")
 
        fix := lines[1].Autofix()
        fix.Warnf("Something's wrong here.")
        fix.ReplaceRegex(`.`, "X", -1)
        fix.Apply()
 
-       fix.Warnf("The XXX marks are usually not fixed, use TODO instead.")
+       fix.Warnf("Since XXX marks are usually not fixed, use TODO instead to draw attention.")
        fix.Replace("XXX", "TODO")
        fix.Apply()
 
@@ -351,14 +372,14 @@
                "-\tline2",
                "+\tXXXXX",
                "",
-               "WARN: Makefile:2: The XXX marks are usually not fixed, use TODO instead.",
+               "WARN: Makefile:2: Since XXX marks are usually not fixed, use TODO instead to draw attention.",
                "AUTOFIX: Makefile:2: Replacing \"XXX\" with \"TODO\".",
                "-\tline2",
                "+\tTODOXX")
 }
 
 // If an Autofix doesn't do anything it must not log any diagnostics.
-func (s *Suite) Test_Autofix_failed_replace(c *check.C) {
+func (s *Suite) Test_Autofix__noop_replace(c *check.C) {
        t := s.Init(c)
 
        line := t.NewLine("Makefile", 14, "Original text")
@@ -372,28 +393,9 @@
        t.CheckOutputEmpty()
 }
 
-func (s *Suite) Test_SaveAutofixChanges(c *check.C) {
-       t := s.Init(c)
-
-       t.SetupCommandLine("--autofix")
-       lines := t.SetupFileLines("DESCR",
-               "Line 1",
-               "Line 2")
-
-       fix := lines[0].Autofix()
-       fix.Warnf("Dummy warning.")
-       fix.Replace("X", "Y")
-       fix.Apply()
-
-       // Since nothing has been effectively changed,
-       // nothing needs to be saved.
-       SaveAutofixChanges(lines)
-
-       // And therefore, no AUTOFIX action must appear in the log.
-       t.CheckOutputEmpty()
-}
-
-func (s *Suite) Test_Autofix_CustomFix(c *check.C) {



Home | Main Index | Thread Index | Old Index