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.7.10



details:   https://anonhg.NetBSD.org/pkgsrc/rev/efac6055835b
branches:  trunk
changeset: 334239:efac6055835b
user:      rillig <rillig%pkgsrc.org@localhost>
date:      Tue May 21 17:59:48 2019 +0000

description:
pkgtools/pkglint: update to 5.7.10

Changes since 5.7.9:

* Fixed URL checking for MASTER_SITES, especially remove the wrong error
  message about URLs of the form ${MASTER_SITE:S,^,-,:=subdir/}.

* Made warnings about invalid filenames, filename patterns, pathnames and
  pathname patterns more detailed.

diffstat:

 pkgtools/pkglint/Makefile                    |    4 +-
 pkgtools/pkglint/files/autofix.go            |   14 +-
 pkgtools/pkglint/files/autofix_test.go       |    8 +-
 pkgtools/pkglint/files/check_test.go         |  121 +++++++++++++++++++++-----
 pkgtools/pkglint/files/line.go               |   10 +-
 pkgtools/pkglint/files/logging_test.go       |   77 ++++++++++++-----
 pkgtools/pkglint/files/mklinechecker.go      |   10 +-
 pkgtools/pkglint/files/mklinechecker_test.go |   78 ++++++++++++++++-
 pkgtools/pkglint/files/mklines_test.go       |    2 +-
 pkgtools/pkglint/files/mkshparser_test.go    |    2 +-
 pkgtools/pkglint/files/package.go            |    4 +-
 pkgtools/pkglint/files/pkglint.go            |   37 ++++---
 pkgtools/pkglint/files/pkglint_test.go       |    6 +-
 pkgtools/pkglint/files/pkgsrc_test.go        |    3 +-
 pkgtools/pkglint/files/plist.go              |    2 +-
 pkgtools/pkglint/files/vardefs.go            |    2 +-
 pkgtools/pkglint/files/vartypecheck.go       |   90 ++++++++++++++-----
 pkgtools/pkglint/files/vartypecheck_test.go  |   72 +++++++++++----
 18 files changed, 398 insertions(+), 144 deletions(-)

diffs (truncated from 1222 to 300 lines):

diff -r d77a6545053c -r efac6055835b pkgtools/pkglint/Makefile
--- a/pkgtools/pkglint/Makefile Tue May 21 17:57:50 2019 +0000
+++ b/pkgtools/pkglint/Makefile Tue May 21 17:59:48 2019 +0000
@@ -1,6 +1,6 @@
-# $NetBSD: Makefile,v 1.579 2019/05/06 20:27:17 rillig Exp $
+# $NetBSD: Makefile,v 1.580 2019/05/21 17:59:48 rillig Exp $
 
-PKGNAME=       pkglint-5.7.9
+PKGNAME=       pkglint-5.7.10
 CATEGORIES=    pkgtools
 DISTNAME=      tools
 MASTER_SITES=  ${MASTER_SITE_GITHUB:=golang/}
diff -r d77a6545053c -r efac6055835b pkgtools/pkglint/files/autofix.go
--- a/pkgtools/pkglint/files/autofix.go Tue May 21 17:57:50 2019 +0000
+++ b/pkgtools/pkglint/files/autofix.go Tue May 21 17:59:48 2019 +0000
@@ -279,9 +279,9 @@
        if logDiagnostic {
                msg := sprintf(fix.diagFormat, fix.diagArgs...)
                if !logFix && G.Logger.FirstTime(line.Filename, line.Linenos(), msg) {
-                       line.showSource(G.out)
+                       line.showSource(G.Logger.out)
                }
-               G.Logf(fix.level, line.Filename, line.Linenos(), fix.diagFormat, msg)
+               G.Logger.Logf(fix.level, line.Filename, line.Linenos(), fix.diagFormat, msg)
        }
 
        if logFix {
@@ -290,20 +290,20 @@
                        if action.lineno != 0 {
                                lineno = strconv.Itoa(action.lineno)
                        }
-                       G.Logf(AutofixLogLevel, line.Filename, lineno, AutofixFormat, action.description)
+                       G.Logger.Logf(AutofixLogLevel, line.Filename, lineno, AutofixFormat, action.description)
                }
        }
 
        if logDiagnostic || logFix {
                if logFix {
-                       line.showSource(G.out)
+                       line.showSource(G.Logger.out)
                }
                if logDiagnostic && len(fix.explanation) > 0 {
                        line.Explain(fix.explanation...)
                }
                if G.Logger.Opts.ShowSource {
                        if !(G.Logger.Opts.Explain && logDiagnostic && len(fix.explanation) > 0) {
-                               G.out.Separate()
+                               G.Logger.out.Separate()
                        }
                }
        }
@@ -394,7 +394,7 @@
                fix.diagFormat != "",
                "Autofix: The diagnostic must be given before the action.")
        // This check is necessary for the --only command line option.
-       return !G.shallBeLogged(fix.diagFormat)
+       return !G.Logger.shallBeLogged(fix.diagFormat)
 }
 
 func (fix *Autofix) assertRealLine() {
@@ -414,7 +414,7 @@
        if !G.Logger.Opts.Autofix {
                for _, line := range lines.Lines {
                        if line.autofix != nil && line.autofix.modified {
-                               G.autofixAvailable = true
+                               G.Logger.autofixAvailable = true
                                if G.Logger.Opts.ShowAutofix {
                                        // Only in this case can the loaded lines be modified.
                                        G.fileCache.Evict(line.Filename)
diff -r d77a6545053c -r efac6055835b pkgtools/pkglint/files/autofix_test.go
--- a/pkgtools/pkglint/files/autofix_test.go    Tue May 21 17:57:50 2019 +0000
+++ b/pkgtools/pkglint/files/autofix_test.go    Tue May 21 17:59:48 2019 +0000
@@ -360,7 +360,7 @@
 
        t.CheckOutputLines(
                "WARN: Makefile:74: Please write row instead of line.")
-       c.Check(G.explanationsAvailable, equals, true)
+       c.Check(G.Logger.explanationsAvailable, equals, true)
 }
 
 func (s *Suite) Test_Autofix_Explain__default(c *check.C) {
@@ -380,7 +380,7 @@
                "",
                "\tExplanation",
                "")
-       c.Check(G.explanationsAvailable, equals, true)
+       c.Check(G.Logger.explanationsAvailable, equals, true)
 }
 
 func (s *Suite) Test_Autofix_Explain__show_autofix(c *check.C) {
@@ -401,7 +401,7 @@
                "",
                "\tExplanation",
                "")
-       c.Check(G.explanationsAvailable, equals, true)
+       c.Check(G.Logger.explanationsAvailable, equals, true)
 }
 
 func (s *Suite) Test_Autofix_Explain__autofix(c *check.C) {
@@ -418,7 +418,7 @@
 
        t.CheckOutputLines(
                "AUTOFIX: Makefile:74: Replacing \"line\" with \"row\".")
-       c.Check(G.explanationsAvailable, equals, false) // Not necessary.
+       c.Check(G.Logger.explanationsAvailable, equals, false) // Not necessary.
 }
 
 func (s *Suite) Test_Autofix_Explain__SilentAutofixFormat(c *check.C) {
diff -r d77a6545053c -r efac6055835b pkgtools/pkglint/files/check_test.go
--- a/pkgtools/pkglint/files/check_test.go      Tue May 21 17:57:50 2019 +0000
+++ b/pkgtools/pkglint/files/check_test.go      Tue May 21 17:59:48 2019 +0000
@@ -62,8 +62,8 @@
 
        G = NewPkglint()
        G.Testing = true
-       G.out = NewSeparatorWriter(&t.stdout)
-       G.err = NewSeparatorWriter(&t.stderr)
+       G.Logger.out = NewSeparatorWriter(&t.stdout)
+       G.Logger.err = NewSeparatorWriter(&t.stderr)
        trace.Out = &t.stdout
 
        // XXX: Maybe the tests can run a bit faster when they don't
@@ -114,7 +114,7 @@
        t.tmpdir = ""
        t.DisableTracing()
 
-       G = Pkglint{} // unusable because of missing Logger.out and Logger.err
+       G = unusablePkglint()
 }
 
 var _ = check.Suite(new(Suite))
@@ -675,9 +675,9 @@
        t.seenMain = true
 
        // Reset the logger, for tests where t.Main is called multiple times.
-       G.errors = 0
-       G.warnings = 0
-       G.logged = Once{}
+       G.Logger.errors = 0
+       G.Logger.warnings = 0
+       G.Logger.logged = Once{}
 
        argv := []string{"pkglint"}
        for _, arg := range args {
@@ -857,20 +857,16 @@
 
        t.stdout.Reset()
        t.stderr.Reset()
-       G.Logger.logged = Once{}
-       if G.Logger.out != nil { // Necessary because Main resets the G variable.
-               G.Logger.out.state = 0 // Prevent an empty line at the beginning of the next output.
-               G.Logger.err.state = 0
+       if G.Usable() {
+               G.Logger.logged = Once{}
+               if G.Logger.out != nil { // Necessary because Main resets the G variable.
+                       G.Logger.out.state = 0 // Prevent an empty line at the beginning of the next output.
+                       G.Logger.err.state = 0
+               }
        }
 
        G.Assertf(t.tmpdir != "", "Tester must be initialized before checking the output.")
-       output := stdout + stderr
-       // TODO: The explanations are wrapped. Because of this it can happen
-       //  that t.tmpdir is spread among multiple lines if that directory
-       //  name contains spaces, which is common on Windows. A temporary
-       //  workaround is to set TMP=/path/without/spaces.
-       output = strings.Replace(output, t.tmpdir, "~", -1)
-       return output
+       return strings.Replace(stdout+stderr, t.tmpdir, "~", -1)
 }
 
 // CheckOutputEmpty ensures that the output up to now is empty.
@@ -881,13 +877,88 @@
 }
 
 // CheckOutputLines checks that the output up to now equals the given lines.
+//
+// After the comparison, the output buffers are cleared so that later
+// calls only check against the newly added output.
+//
+// See CheckOutputEmpty, CheckOutputLinesIgnoreSpace.
+func (t *Tester) CheckOutputLines(expectedLines ...string) {
+       G.Assertf(len(expectedLines) > 0, "To check empty lines, use CheckLinesEmpty instead.")
+       t.CheckOutput(expectedLines)
+}
+
+// CheckOutputLinesIgnoreSpace checks that the output up to now equals the given lines.
+// During comparison, each run of whitespace (space, tab, newline) is normalized so that
+// different line breaks are ignored. This is useful for testing line-wrapped explanations.
+//
 // After the comparison, the output buffers are cleared so that later
 // calls only check against the newly added output.
 //
-// See CheckOutputEmpty.
-func (t *Tester) CheckOutputLines(expectedLines ...string) {
+// See CheckOutputEmpty, CheckOutputLines.
+func (t *Tester) CheckOutputLinesIgnoreSpace(expectedLines ...string) {
        G.Assertf(len(expectedLines) > 0, "To check empty lines, use CheckLinesEmpty instead.")
-       t.CheckOutput(expectedLines)
+       G.Assertf(t.tmpdir != "", "Tester must be initialized before checking the output.")
+
+       rawOutput := t.stdout.String() + t.stderr.String()
+       _ = t.Output() // Just to consume the output
+
+       actual, expected := t.compareOutputIgnoreSpace(rawOutput, expectedLines, t.tmpdir)
+       t.Check(actual, deepEquals, expected)
+}
+
+func (t *Tester) compareOutputIgnoreSpace(rawOutput string, expectedLines []string, tmpdir string) ([]string, []string) {
+       whitespace := regexp.MustCompile(`\s+`)
+
+       // Replace all occurrences of tmpdir in the raw output with a tilde,
+       // also covering cases where tmpdir is wrapped into multiple lines.
+       output := func() string {
+               var tmpdirPattern strings.Builder
+               for i, part := range whitespace.Split(tmpdir, -1) {
+                       if i > 0 {
+                               tmpdirPattern.WriteString("\\s+")
+                       }
+                       tmpdirPattern.WriteString(regexp.QuoteMeta(part))
+               }
+
+               return regexp.MustCompile(tmpdirPattern.String()).ReplaceAllString(rawOutput, "~")
+       }()
+
+       normSpace := func(s string) string {
+               return whitespace.ReplaceAllString(s, " ")
+       }
+       if normSpace(output) == normSpace(strings.Join(expectedLines, "\n")) {
+               return nil, nil
+       }
+
+       actualLines := strings.Split(output, "\n")
+       actualLines = actualLines[:len(actualLines)-1]
+
+       return emptyToNil(actualLines), emptyToNil(expectedLines)
+}
+
+func (s *Suite) Test_Tester_compareOutputIgnoreSpace(c *check.C) {
+       t := s.Init(c)
+
+       lines := func(lines ...string) []string { return lines }
+       test := func(rawOutput string, expectedLines []string, tmpdir string, eq bool) {
+               actual, expected := t.compareOutputIgnoreSpace(rawOutput, expectedLines, tmpdir)
+               t.Check(actual == nil && expected == nil, equals, eq)
+       }
+
+       test("", lines(), "/tmp", true)
+
+       // The expectedLines are missing a space at the end.
+       test(" \t\noutput\n\t ", lines("\toutput"), "/tmp", false)
+
+       test(" \t\noutput\n\t ", lines("\toutput\n"), "/tmp", true)
+
+       test("/tmp/\n\t \nspace", lines("~"), "/tmp/\t\t\t   \n\n\nspace", true)
+
+       // The rawOutput contains more spaces than the tmpdir.
+       test("/tmp/\n\t \nspace", lines("~"), "/tmp/space", false)
+
+       // The tmpdir contains more spaces than the rawOutput.
+       test("/tmp/space", lines("~"), "/tmp/ \t\nspace", false)
 }
 
 // CheckOutputMatches checks that the output up to now matches the given lines.
@@ -955,7 +1026,7 @@
 // This is useful when stepping through the code, especially
 // in combination with SetUpCommandLine("--debug").
 func (t *Tester) EnableTracing() {
-       G.out = NewSeparatorWriter(io.MultiWriter(os.Stdout, &t.stdout))
+       G.Logger.out = NewSeparatorWriter(io.MultiWriter(os.Stdout, &t.stdout))
        trace.Out = os.Stdout
        trace.Tracing = true
 }
@@ -963,7 +1034,7 @@
 // EnableTracingToLog enables the tracing and writes the tracing output
 // to the test log that can be examined with Tester.Output.
 func (t *Tester) EnableTracingToLog() {
-       G.out = NewSeparatorWriter(&t.stdout)
+       G.Logger.out = NewSeparatorWriter(&t.stdout)
        trace.Out = &t.stdout
        trace.Tracing = true
 }
@@ -975,7 +1046,7 @@
 // It is used to check all calls to trace.Result, since the compiler
 // cannot check them.
 func (t *Tester) EnableSilentTracing() {
-       G.out = NewSeparatorWriter(&t.stdout)
+       G.Logger.out = NewSeparatorWriter(&t.stdout)
        trace.Out = ioutil.Discard
        trace.Tracing = true
 }
@@ -984,7 +1055,9 @@
 // The diagnostics go to the in-memory buffer again,
 // ready to be checked with CheckOutputLines.
 func (t *Tester) DisableTracing() {
-       G.out = NewSeparatorWriter(&t.stdout)
+       if G.Usable() {
+               G.Logger.out = NewSeparatorWriter(&t.stdout)
+       }
        trace.Tracing = false



Home | Main Index | Thread Index | Old Index