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.1
details: https://anonhg.NetBSD.org/pkgsrc/rev/b14a24c5b35c
branches: trunk
changeset: 384114:b14a24c5b35c
user: rillig <rillig%pkgsrc.org@localhost>
date: Thu Aug 16 20:41:42 2018 +0000
description:
pkgtools/pkglint: update to 5.6.1
Changes since 5.6.0:
* Fix output of relative paths in the diagnostics (thanks @wiz)
* Fix parsing of ${VAR:ts---}; it is now a syntax error
* Load more type definitions from mk/* instead of hard-coding them
* Lots of refactoring to improve test coverage, fixing several
small bugs as they were found
diffstat:
pkgtools/pkglint/Makefile | 4 +-
pkgtools/pkglint/files/alternatives.go | 4 +-
pkgtools/pkglint/files/alternatives_test.go | 15 +-
pkgtools/pkglint/files/autofix_test.go | 6 +-
pkgtools/pkglint/files/buildlink3_test.go | 2 +-
pkgtools/pkglint/files/category.go | 7 +-
pkgtools/pkglint/files/check_test.go | 112 +++++++++++++--
pkgtools/pkglint/files/distinfo.go | 10 +-
pkgtools/pkglint/files/distinfo_test.go | 52 ++++---
pkgtools/pkglint/files/files.go | 64 +++++---
pkgtools/pkglint/files/files_test.go | 20 ++
pkgtools/pkglint/files/licenses_test.go | 44 ++++-
pkgtools/pkglint/files/logging.go | 3 +-
pkgtools/pkglint/files/mkline.go | 99 ++++++-------
pkgtools/pkglint/files/mkline_test.go | 186 ++++++++++++++++++++++++--
pkgtools/pkglint/files/mklinechecker.go | 165 +++++++++++++----------
pkgtools/pkglint/files/mklinechecker_test.go | 20 +-
pkgtools/pkglint/files/mklines.go | 18 +-
pkgtools/pkglint/files/mklines_test.go | 6 +-
pkgtools/pkglint/files/mkparser.go | 3 +-
pkgtools/pkglint/files/mkparser_test.go | 13 +
pkgtools/pkglint/files/options.go | 4 +-
pkgtools/pkglint/files/options_test.go | 4 +-
pkgtools/pkglint/files/package.go | 60 ++++----
pkgtools/pkglint/files/package_test.go | 124 ++++++++---------
pkgtools/pkglint/files/parser_test.go | 10 +
pkgtools/pkglint/files/patches_test.go | 9 +-
pkgtools/pkglint/files/pkglint.go | 51 +++---
pkgtools/pkglint/files/pkglint_test.go | 55 +++++++-
pkgtools/pkglint/files/pkgsrc.go | 98 ++++++-------
pkgtools/pkglint/files/pkgsrc_test.go | 36 ++--
pkgtools/pkglint/files/plist.go | 22 +-
pkgtools/pkglint/files/plist_test.go | 27 +--
pkgtools/pkglint/files/regex/regex.go | 27 +--
pkgtools/pkglint/files/shell_test.go | 4 +-
pkgtools/pkglint/files/shtypes_test.go | 7 +
pkgtools/pkglint/files/substcontext.go | 6 +-
pkgtools/pkglint/files/substcontext_test.go | 6 +-
pkgtools/pkglint/files/tools.go | 45 +++---
pkgtools/pkglint/files/tools_test.go | 13 +
pkgtools/pkglint/files/toplevel.go | 30 ++--
pkgtools/pkglint/files/util.go | 16 +-
pkgtools/pkglint/files/util_test.go | 12 +-
pkgtools/pkglint/files/vardefs.go | 120 ++++++++++------
pkgtools/pkglint/files/vardefs_test.go | 33 ++++-
pkgtools/pkglint/files/vartype.go | 11 +-
pkgtools/pkglint/files/vartypecheck.go | 4 +-
pkgtools/pkglint/files/vartypecheck_test.go | 14 +-
48 files changed, 1073 insertions(+), 628 deletions(-)
diffs (truncated from 3717 to 300 lines):
diff -r 783e036c0356 -r b14a24c5b35c pkgtools/pkglint/Makefile
--- a/pkgtools/pkglint/Makefile Thu Aug 16 19:01:15 2018 +0000
+++ b/pkgtools/pkglint/Makefile Thu Aug 16 20:41:42 2018 +0000
@@ -1,6 +1,6 @@
-# $NetBSD: Makefile,v 1.546 2018/08/12 16:31:56 rillig Exp $
+# $NetBSD: Makefile,v 1.547 2018/08/16 20:41:42 rillig Exp $
-PKGNAME= pkglint-5.6.0
+PKGNAME= pkglint-5.6.1
DISTFILES= # none
CATEGORIES= pkgtools
diff -r 783e036c0356 -r b14a24c5b35c pkgtools/pkglint/files/alternatives.go
--- a/pkgtools/pkglint/files/alternatives.go Thu Aug 16 19:01:15 2018 +0000
+++ b/pkgtools/pkglint/files/alternatives.go Thu Aug 16 20:41:42 2018 +0000
@@ -6,8 +6,8 @@
)
func CheckfileAlternatives(filename string, plistFiles map[string]bool) {
- lines, err := readLines(filename, false)
- if err != nil {
+ lines := Load(filename, NotEmpty|LogErrors)
+ if lines == nil {
return
}
diff -r 783e036c0356 -r b14a24c5b35c pkgtools/pkglint/files/alternatives_test.go
--- a/pkgtools/pkglint/files/alternatives_test.go Thu Aug 16 19:01:15 2018 +0000
+++ b/pkgtools/pkglint/files/alternatives_test.go Thu Aug 16 20:41:42 2018 +0000
@@ -5,23 +5,24 @@
func (s *Suite) Test_Alternatives_PLIST(c *check.C) {
t := s.Init(c)
+ t.Chdir("category/package")
t.SetupFileLines("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")
- G.Pkg = NewPackage("")
+ G.Pkg = NewPackage(".")
G.Pkg.PlistFiles["bin/echo"] = true
G.Pkg.PlistFiles["bin/vim"] = true
G.Pkg.PlistFiles["sbin/sendmail.exim${EXIMVER}"] = true
- CheckfileAlternatives(t.File("ALTERNATIVES"), G.Pkg.PlistFiles)
+ CheckfileAlternatives("ALTERNATIVES", G.Pkg.PlistFiles)
t.CheckOutputLines(
- "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.",
- "ERROR: ~/ALTERNATIVES:3: Alternative wrapper \"bin/echo\" must not appear in the PLIST.",
- "ERROR: ~/ALTERNATIVES:3: Alternative implementation \"bin/gnu-echo\" must appear in the PLIST.")
+ "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.",
+ "ERROR: ALTERNATIVES:3: Alternative wrapper \"bin/echo\" must not appear in the PLIST.",
+ "ERROR: ALTERNATIVES:3: Alternative implementation \"bin/gnu-echo\" must appear in the PLIST.")
}
diff -r 783e036c0356 -r b14a24c5b35c pkgtools/pkglint/files/autofix_test.go
--- a/pkgtools/pkglint/files/autofix_test.go Thu Aug 16 19:01:15 2018 +0000
+++ b/pkgtools/pkglint/files/autofix_test.go Thu Aug 16 20:41:42 2018 +0000
@@ -117,7 +117,7 @@
"line1 := value1",
"line2 := value2",
"line3 := value3")
- pkg := NewPackage("category/basename")
+ pkg := NewPackage(t.File("category/basename"))
G.Pkg = pkg
mklines := pkg.loadPackageMakefile()
G.Pkg = nil
@@ -259,7 +259,7 @@
t.SetupCommandLine("--show-autofix", "--source")
mklines := t.SetupFileMkLines("Makefile",
MkRcsID,
- "before \\",
+ "# before \\",
"The old song \\",
"after")
line := mklines.lines[1]
@@ -274,7 +274,7 @@
t.CheckOutputLines(
"WARN: ~/Makefile:2--4: Using \"old\" is deprecated.",
"AUTOFIX: ~/Makefile:3: Replacing \"old\" with \"new\".",
- ">\tbefore \\",
+ ">\t# before \\",
"-\tThe old song \\",
"+\tThe new song \\",
">\tafter")
diff -r 783e036c0356 -r b14a24c5b35c pkgtools/pkglint/files/buildlink3_test.go
--- a/pkgtools/pkglint/files/buildlink3_test.go Thu Aug 16 19:01:15 2018 +0000
+++ b/pkgtools/pkglint/files/buildlink3_test.go Thu Aug 16 20:41:42 2018 +0000
@@ -41,7 +41,7 @@
t := s.Init(c)
t.SetupVartypes()
- G.Pkg = NewPackage("x11/hs-X11")
+ G.Pkg = NewPackage(t.File("x11/hs-X11"))
G.Pkg.EffectivePkgbase = "X11"
G.Pkg.EffectivePkgnameLine = t.NewMkLine("Makefile", 3, "DISTNAME=\tX11-1.0")
mklines := t.NewMkLines("buildlink3.mk",
diff -r 783e036c0356 -r b14a24c5b35c pkgtools/pkglint/files/category.go
--- a/pkgtools/pkglint/files/category.go Thu Aug 16 19:01:15 2018 +0000
+++ b/pkgtools/pkglint/files/category.go Thu Aug 16 20:41:42 2018 +0000
@@ -10,12 +10,11 @@
defer trace.Call1(dir)()
}
- lines := LoadNonemptyLines(dir+"/Makefile", true)
- if lines == nil {
+ mklines := LoadMk(dir+"/Makefile", NotEmpty|LogErrors)
+ if mklines == nil {
return
}
- mklines := NewMkLines(lines)
mklines.Check()
exp := NewMkExpecter(mklines)
@@ -164,7 +163,7 @@
exp.CurrentLine().Errorf("The file should end here.")
}
- SaveAutofixChanges(lines)
+ mklines.SaveAutofixChanges()
if G.opts.Recursive {
G.Todo = append(append([]string(nil), subdirs...), G.Todo...)
diff -r 783e036c0356 -r b14a24c5b35c pkgtools/pkglint/files/check_test.go
--- a/pkgtools/pkglint/files/check_test.go Thu Aug 16 19:01:15 2018 +0000
+++ b/pkgtools/pkglint/files/check_test.go Thu Aug 16 20:41:42 2018 +0000
@@ -58,12 +58,23 @@
t.checkC = nil
G.opts.LogVerbose = true // To detect duplicate work being done
+ t.EnableSilentTracing()
+
+ prevdir, err := os.Getwd()
+ if err != nil {
+ c.Fatalf("Cannot get current working directory: %s", err)
+ }
+ t.prevdir = prevdir
}
func (s *Suite) TearDownTest(c *check.C) {
t := s.Tester
t.checkC = nil // No longer usable; see https://github.com/go-check/check/issues/22
+ if err := os.Chdir(t.prevdir); err != nil {
+ fmt.Fprintf(os.Stderr, "Cannot chdir back to previous dir: %s", err)
+ }
+
G = Pkglint{} // unusable because of missing logOut and logErr
textproc.Testing = false
if out := t.Output(); out != "" {
@@ -71,6 +82,7 @@
c.TestName(), strings.Split(out, "\n"))
}
t.tmpdir = ""
+ t.DisableTracing()
}
var _ = check.Suite(new(Suite))
@@ -82,10 +94,12 @@
// all the test methods, which makes it difficult to find
// a method by auto-completion.
type Tester struct {
- stdout bytes.Buffer
- stderr bytes.Buffer
- tmpdir string
- checkC *check.C
+ stdout bytes.Buffer
+ stderr bytes.Buffer
+ tmpdir string
+ checkC *check.C // Only usable during the test method itself
+ prevdir string // The current working directory before the test started
+ relcwd string
}
func (t *Tester) c() *check.C {
@@ -98,6 +112,11 @@
// SetupCommandLine simulates a command line for the remainder of the test.
// See Pkglint.ParseCommandLine.
func (t *Tester) SetupCommandLine(args ...string) {
+
+ // Prevent tracing from being disabled; see EnableSilentTracing.
+ prevTracing := trace.Tracing
+ defer func() { trace.Tracing = prevTracing }()
+
exitcode := G.ParseCommandLine(append([]string{"pkglint"}, args...))
if exitcode != nil && *exitcode != 0 {
t.CheckOutputEmpty()
@@ -149,15 +168,14 @@
// The file is then read in, without considering line continuations.
func (t *Tester) SetupFileLines(relativeFilename string, lines ...string) []Line {
filename := t.CreateFileLines(relativeFilename, lines...)
- return LoadExistingLines(filename, false)
+ return Load(filename, MustSucceed)
}
// SetupFileLines creates a temporary file and writes the given lines to it.
// The file is then read in, handling line continuations for Makefiles.
func (t *Tester) SetupFileMkLines(relativeFilename string, lines ...string) *MkLines {
filename := t.CreateFileLines(relativeFilename, lines...)
- plainLines := LoadExistingLines(filename, true)
- return NewMkLines(plainLines)
+ return LoadMk(filename, MustSucceed)
}
// SetupPkgsrc sets up a minimal but complete pkgsrc installation in the
@@ -222,21 +240,62 @@
// File returns the absolute path to the given file in the
// temporary directory. It doesn't check whether that file exists.
+// Calls to Tester.Chdir change the base directory for the relative file name.
func (t *Tester) File(relativeFilename string) string {
if t.tmpdir == "" {
t.tmpdir = filepath.ToSlash(t.c().MkDir())
}
- return t.tmpdir + "/" + relativeFilename
+ if t.relcwd != "" {
+ return cleanpath(relativeFilename)
+ }
+ return cleanpath(t.tmpdir + "/" + relativeFilename)
}
-// ExpectFatalError, when run in a defer statement, runs the action
-// if the current function panics with a pkglintFatal
-// (typically from line.Fatalf).
-func (t *Tester) ExpectFatalError(action func()) {
+// Chdir changes the current working directory to the given subdirectory
+// of the temporary directory, creating it if necessary.
+//
+// After this call, all files loaded from the temporary directory via
+// SetupFileLines or CreateFileLines or similar methods will use path names
+// relative to this directory.
+//
+// After the test, the previous working directory is restored, so that
+// the other tests are unaffected.
+//
+// As long as this method is not called in a test, the current working
+// directory is indeterminate.
+func (t *Tester) Chdir(relativeFilename string) {
+ if t.relcwd != "" {
+ // When multiple calls of Chdir are mixed with calls to CreateFileLines,
+ // the resulting []Line and MkLines variables will use relative file names,
+ // and these will point to different areas in the file system. This is
+ // usually not indented and therefore prevented.
+ t.checkC.Fatalf("Chdir must only be called once per test; already in %q.", t.relcwd)
+ }
+
+ _ = os.MkdirAll(t.File(relativeFilename), 0700)
+ if err := os.Chdir(t.File(relativeFilename)); err != nil {
+ t.checkC.Fatalf("Cannot chdir: %s", err)
+ }
+ t.relcwd = relativeFilename
+}
+
+// ExpectFatalError promises that in the remainder of the current function
+// call, a panic with a pkglintFatal will occur (typically from Line.Fatalf).
+//
+// Usage:
+// func() {
+// defer t.ExpectFatalError()
+//
+// // The code that causes the fatal error.
+// Load(t.File("nonexistent"), MustSucceed)
+// }()
+// t.CheckOutputLines(
+// "FATAL: ~/nonexistent: Does not exist.")
+func (t *Tester) ExpectFatalError() {
r := recover()
- if _, ok := r.(pkglintFatal); ok {
- action()
- } else {
+ if r == nil {
+ panic("Expected a pkglint fatal error, but didn't get one.")
+ } else if _, ok := r.(pkglintFatal); !ok {
panic(r)
}
}
@@ -344,12 +403,28 @@
trace.Tracing = true
}
+// 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.logOut = NewSeparatorWriter(io.MultiWriter(os.Stdout, &t.stdout))
+ trace.Out = &t.stdout
+ trace.Tracing = true
+}
+
+// EnableSilentTracing enables tracing mode, but discards any tracing output.
+// This can be used to improve code coverage without any side-effects,
+// since tracing output is quite large.
+func (t *Tester) EnableSilentTracing() {
+ trace.Out = ioutil.Discard
Home |
Main Index |
Thread Index |
Old Index