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.2
details: https://anonhg.NetBSD.org/pkgsrc/rev/ae9968997840
branches: trunk
changeset: 312528:ae9968997840
user: rillig <rillig%pkgsrc.org@localhost>
date: Wed Sep 05 17:56:22 2018 +0000
description:
pkgtools/pkglint: update to 5.6.2
Changes since 5.6.1:
* Improved checks that depend on whether bsd.prefs.mk is included or
not.
* Improved checks for tools, whether they may be used at load time
or at run time.
* Improved tokenizer for shell commands. $| is not a variable but a
dollar followed by a pipe.
* Warnings about SUBST context are now shown by default.
* A warning is shown when a SUBST block is declared for *-configure
but the package has defined USE_CONFIGURE=no.
* Don't warn about USE_TOOLS:= ${USE_TOOLS:Ntool}.
* Don't warn about using the ?= operator in buildlink3.mk files before
including bsd.prefs.mk (for some more variables, but not all).
* Report an error for packages from main pkgsrc that have a TODO or
README file. Packages should be simple enough that they don't need
a README file and ready for production so that they don't need a TODO.
* Lots of small bug fixes and new tests.
diffstat:
pkgtools/pkglint/Makefile | 4 +-
pkgtools/pkglint/files/alternatives_test.go | 20 +-
pkgtools/pkglint/files/autofix.go | 8 +-
pkgtools/pkglint/files/autofix_test.go | 102 ++
pkgtools/pkglint/files/buildlink3_test.go | 44 +-
pkgtools/pkglint/files/category_test.go | 34 +-
pkgtools/pkglint/files/check_test.go | 109 +-
pkgtools/pkglint/files/distinfo_test.go | 18 +-
pkgtools/pkglint/files/expecter.go | 14 -
pkgtools/pkglint/files/files_test.go | 22 +-
pkgtools/pkglint/files/getopt/getopt_test.go | 2 +-
pkgtools/pkglint/files/licenses.go | 6 +-
pkgtools/pkglint/files/licenses_test.go | 3 +-
pkgtools/pkglint/files/line.go | 3 +-
pkgtools/pkglint/files/linechecker_test.go | 6 +
pkgtools/pkglint/files/logging.go | 9 +-
pkgtools/pkglint/files/logging_test.go | 60 +
pkgtools/pkglint/files/mkline.go | 134 +--
pkgtools/pkglint/files/mkline_test.go | 50 +-
pkgtools/pkglint/files/mklinechecker.go | 242 +++--
pkgtools/pkglint/files/mklinechecker_test.go | 201 +++-
pkgtools/pkglint/files/mklines.go | 120 +-
pkgtools/pkglint/files/mklines_test.go | 143 +++-
pkgtools/pkglint/files/mklines_varalign_test.go | 53 +-
pkgtools/pkglint/files/mkparser.go | 5 +-
pkgtools/pkglint/files/mkparser_test.go | 4 +-
pkgtools/pkglint/files/mkshparser.go | 2 +-
pkgtools/pkglint/files/mkshparser_test.go | 54 +-
pkgtools/pkglint/files/mktypes_test.go | 2 +-
pkgtools/pkglint/files/options.go | 4 +-
pkgtools/pkglint/files/options_test.go | 10 +-
pkgtools/pkglint/files/package.go | 58 +-
pkgtools/pkglint/files/package_test.go | 146 +++-
pkgtools/pkglint/files/parser_test.go | 2 +-
pkgtools/pkglint/files/patches.go | 34 +-
pkgtools/pkglint/files/patches_test.go | 182 ++++-
pkgtools/pkglint/files/pkglint.go | 158 +++-
pkgtools/pkglint/files/pkglint_test.go | 360 +++++++-
pkgtools/pkglint/files/pkgsrc.go | 236 ++++-
pkgtools/pkglint/files/pkgsrc_test.go | 125 ++-
pkgtools/pkglint/files/plist.go | 143 +-
pkgtools/pkglint/files/plist_test.go | 238 +++++
pkgtools/pkglint/files/shell.go | 128 +-
pkgtools/pkglint/files/shell_test.go | 206 ++++-
pkgtools/pkglint/files/shtokenizer.go | 83 +-
pkgtools/pkglint/files/shtokenizer_test.go | 18 +-
pkgtools/pkglint/files/shtypes.go | 2 +-
pkgtools/pkglint/files/shtypes_test.go | 2 +-
pkgtools/pkglint/files/substcontext.go | 77 +-
pkgtools/pkglint/files/substcontext_test.go | 80 ++
pkgtools/pkglint/files/textproc/prefixreplacer.go | 18 +
pkgtools/pkglint/files/tools.go | 356 ++++++-
pkgtools/pkglint/files/tools_test.go | 422 ++++++++++-
pkgtools/pkglint/files/trace/tracing.go | 79 +-
pkgtools/pkglint/files/trace/tracing_test.go | 78 +
pkgtools/pkglint/files/util.go | 82 +-
pkgtools/pkglint/files/util_test.go | 135 +++-
pkgtools/pkglint/files/vardefs.go | 63 +-
pkgtools/pkglint/files/vardefs_test.go | 5 +-
pkgtools/pkglint/files/vartype.go | 22 +-
pkgtools/pkglint/files/vartype_test.go | 13 +-
pkgtools/pkglint/files/vartypecheck.go | 104 +-
pkgtools/pkglint/files/vartypecheck_test.go | 878 +++++++++++++++++----
63 files changed, 4605 insertions(+), 1416 deletions(-)
diffs (truncated from 9321 to 300 lines):
diff -r 6ada64a1dd09 -r ae9968997840 pkgtools/pkglint/Makefile
--- a/pkgtools/pkglint/Makefile Wed Sep 05 17:01:03 2018 +0000
+++ b/pkgtools/pkglint/Makefile Wed Sep 05 17:56:22 2018 +0000
@@ -1,6 +1,6 @@
-# $NetBSD: Makefile,v 1.547 2018/08/16 20:41:42 rillig Exp $
+# $NetBSD: Makefile,v 1.548 2018/09/05 17:56:22 rillig Exp $
-PKGNAME= pkglint-5.6.1
+PKGNAME= pkglint-5.6.2
DISTFILES= # none
CATEGORIES= pkgtools
diff -r 6ada64a1dd09 -r ae9968997840 pkgtools/pkglint/files/alternatives_test.go
--- a/pkgtools/pkglint/files/alternatives_test.go Wed Sep 05 17:01:03 2018 +0000
+++ b/pkgtools/pkglint/files/alternatives_test.go Wed Sep 05 17:56:22 2018 +0000
@@ -10,7 +10,8 @@
"sbin/sendmail @PREFIX@/sbin/sendmail.postfix@POSTFIXVER@",
"sbin/sendmail @PREFIX@/sbin/sendmail.exim@EXIMVER@",
"bin/echo bin/gnu-echo",
- "bin/editor bin/vim -e")
+ "bin/editor bin/vim -e",
+ "invalid")
G.Pkg = NewPackage(".")
G.Pkg.PlistFiles["bin/echo"] = true
@@ -24,5 +25,20 @@
"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:3: Alternative implementation \"bin/gnu-echo\" must appear in the PLIST.",
+ "ERROR: ALTERNATIVES:5: Invalid ALTERNATIVES line \"invalid\".")
}
+
+func (s *Suite) Test_CheckfileAlternatives__empty(c *check.C) {
+ t := s.Init(c)
+
+ t.Chdir("category/package")
+ t.SetupFileLines("ALTERNATIVES")
+
+ G.Pkg = NewPackage(".")
+
+ CheckfileAlternatives("ALTERNATIVES", G.Pkg.PlistFiles)
+
+ t.CheckOutputLines(
+ "ERROR: ALTERNATIVES: Must not be empty.")
+}
diff -r 6ada64a1dd09 -r ae9968997840 pkgtools/pkglint/files/autofix.go
--- a/pkgtools/pkglint/files/autofix.go Wed Sep 05 17:01:03 2018 +0000
+++ b/pkgtools/pkglint/files/autofix.go Wed Sep 05 17:56:22 2018 +0000
@@ -139,7 +139,7 @@
if (oldWidth == 0 || width < oldWidth) && width >= 8 && rawLine.textnl != "\n" {
oldWidth = width
}
- if !regex.Matches(space, `^\t* {0,7}`) {
+ if !regex.Matches(space, `^\t* {0,7}$`) {
normalized = false
}
}
@@ -346,12 +346,14 @@
}
err := ioutil.WriteFile(tmpname, []byte(text), 0666)
if err != nil {
- NewLineWhole(tmpname).Errorf("Cannot write.")
+ logs(llError, tmpname, "", "Cannot write: %s", "Cannot write: "+err.Error())
continue
}
err = os.Rename(tmpname, fname)
if err != nil {
- NewLineWhole(fname).Errorf("Cannot overwrite with auto-fixed content.")
+ logs(llError, tmpname, "",
+ "Cannot overwrite with auto-fixed content: %s",
+ "Cannot overwrite with auto-fixed content: "+err.Error())
continue
}
autofixed = true
diff -r 6ada64a1dd09 -r ae9968997840 pkgtools/pkglint/files/autofix_test.go
--- a/pkgtools/pkglint/files/autofix_test.go Wed Sep 05 17:01:03 2018 +0000
+++ b/pkgtools/pkglint/files/autofix_test.go Wed Sep 05 17:56:22 2018 +0000
@@ -2,6 +2,8 @@
import (
"gopkg.in/check.v1"
+ "os"
+ "runtime"
"strings"
)
@@ -469,6 +471,8 @@
fix.InsertBefore("before")
fix.InsertAfter("after")
fix.Delete()
+ fix.Custom(func(printAutofix, autofix bool) {})
+ fix.Realign(dummyMkLine, 32)
fix.Apply()
SaveAutofixChanges(lines)
@@ -478,3 +482,101 @@
"111 222 333 444 555")
c.Check(lines[0].raw[0].textnl, equals, "111 222 333 444 555\n")
}
+
+func (s *Suite) Test_Autofix_Apply__panic(c *check.C) {
+ t := s.Init(c)
+
+ line := t.NewLine("filename", 123, "text")
+
+ c.Assert(func() {
+ fix := line.Autofix()
+ fix.Apply()
+ }, check.Panics, "Each autofix must have a diagnostic.")
+
+ c.Assert(func() {
+ fix := line.Autofix()
+ fix.Replace("from", "to")
+ fix.Apply()
+ }, check.Panics, "Autofix: The diagnostic must be given before the action.")
+
+ c.Assert(func() {
+ fix := line.Autofix()
+ fix.Warnf("Warning without period")
+ fix.Apply()
+ }, check.Panics, "Autofix: format \"Warning without period\" must end with a period.")
+}
+
+func (s *Suite) Test_Autofix_Apply__file_removed(c *check.C) {
+ t := s.Init(c)
+
+ t.SetupCommandLine("--autofix")
+ lines := t.SetupFileLines("subdir/file.txt",
+ "line 1")
+ os.RemoveAll(t.File("subdir"))
+
+ fix := lines[0].Autofix()
+ fix.Warnf("Should start with an uppercase letter.")
+ fix.Replace("line", "Line")
+ fix.Apply()
+
+ SaveAutofixChanges(lines)
+
+ c.Check(t.Output(), check.Matches, ""+
+ "AUTOFIX: ~/subdir/file.txt:1: Replacing \"line\" with \"Line\".\n"+
+ "ERROR: ~/subdir/file.txt.pkglint.tmp: Cannot write: .*\n")
+}
+
+func (s *Suite) Test_Autofix_Apply__file_busy_Windows(c *check.C) {
+ t := s.Init(c)
+
+ if runtime.GOOS != "windows" {
+ return
+ }
+
+ t.SetupCommandLine("--autofix")
+ lines := t.SetupFileLines("subdir/file.txt",
+ "line 1")
+
+ // As long as the file is kept open, it cannot be overwritten or deleted.
+ openFile, err := os.OpenFile(t.File("subdir/file.txt"), 0, 0666)
+ defer openFile.Close()
+ c.Check(err, check.IsNil)
+
+ fix := lines[0].Autofix()
+ fix.Warnf("Should start with an uppercase letter.")
+ fix.Replace("line", "Line")
+ fix.Apply()
+
+ SaveAutofixChanges(lines)
+
+ c.Check(t.Output(), check.Matches, ""+
+ "AUTOFIX: ~/subdir/file.txt:1: Replacing \"line\" with \"Line\".\n"+
+ "ERROR: ~/subdir/file.txt.pkglint.tmp: Cannot overwrite with auto-fixed content: .*\n")
+}
+
+// This test tests the highly unlikely situation in which a file is loaded
+// by pkglint, and just before writing the autofixed content back, another
+// process takes the file and replaces it with a directory of the same name.
+//
+// 100% code coverage sometimes requires creativity. :)
+func (s *Suite) Test_Autofix_Apply__file_converted_to_directory(c *check.C) {
+ t := s.Init(c)
+
+ t.SetupCommandLine("--autofix")
+ lines := t.SetupFileLines("file.txt",
+ "line 1")
+
+ c.Check(os.RemoveAll(t.File("file.txt")), check.IsNil)
+ c.Check(os.MkdirAll(t.File("file.txt"), 0777), check.IsNil)
+
+ fix := lines[0].Autofix()
+ fix.Warnf("Should start with an uppercase letter.")
+ fix.Replace("line", "Line")
+ fix.Apply()
+
+ SaveAutofixChanges(lines)
+
+ c.Check(t.Output(), check.Matches, ""+
+ "AUTOFIX: ~/file.txt:1: Replacing \"line\" with \"Line\".\n"+
+ "ERROR: ~/file.txt.pkglint.tmp: Cannot overwrite with auto-fixed content: .*\n")
+}
diff -r 6ada64a1dd09 -r ae9968997840 pkgtools/pkglint/files/buildlink3_test.go
--- a/pkgtools/pkglint/files/buildlink3_test.go Wed Sep 05 17:01:03 2018 +0000
+++ b/pkgtools/pkglint/files/buildlink3_test.go Wed Sep 05 17:56:22 2018 +0000
@@ -102,6 +102,7 @@
"",
"BUILDLINK_API_DEPENDS.hs-X11+=\ths-X11>=1.6.1",
"BUILDLINK_ABI_DEPENDS.hs-X11+=\ths-X12>=1.6.1.2nb2",
+ "BUILDLINK_ABI_DEPENDS.hs-X12+=\ths-X11>=1.6.1.2nb2",
"",
".endif\t# HS_X11_BUILDLINK3_MK",
"",
@@ -110,7 +111,8 @@
ChecklinesBuildlink3Mk(mklines)
t.CheckOutputLines(
- "WARN: buildlink3.mk:9: Package name mismatch between ABI \"hs-X12\" and API \"hs-X11\" (from line 8).")
+ "WARN: buildlink3.mk:9: Package name mismatch between ABI \"hs-X12\" and API \"hs-X11\" (from line 8).",
+ "WARN: buildlink3.mk:10: Only buildlink variables for \"hs-X11\", not \"hs-X12\" may be set in this file.")
}
func (s *Suite) Test_ChecklinesBuildlink3Mk_abi_api_versions(c *check.C) {
@@ -345,3 +347,43 @@
"ERROR: ~/buildlink3.mk:13: \"x11/libX11/buildlink3.mk\" does not exist.",
"WARN: ~/buildlink3.mk:3: Expected a BUILDLINK_TREE line.")
}
+
+func (s *Suite) Test_ChecklinesBuildlink3Mk__coverage(c *check.C) {
+ t := s.Init(c)
+
+ t.SetupVartypes()
+ t.CreateFileLines("mk/pkg-build-options.mk")
+ t.CreateFileLines("category/dependency/buildlink3.mk")
+ mklines := t.SetupFileMkLines("category/package/buildlink3.mk",
+ MkRcsID,
+ "",
+ "BUILDLINK_TREE+=\ths-X11",
+ "",
+ ".if !defined(HS_X11_BUILDLINK3_MK)",
+ "HS_X11_BUILDLINK3_MK:=",
+ "",
+ "pkgbase := dependency",
+ ".include \"../../mk/pkg-build-options.mk\"",
+ "",
+ "BUILDLINK_API_DEPENDS.hs-X11+=\ths-X11>=1.6.1",
+ "BUILDLINK_ABI_DEPENDS.hs-X11+=\ths-X11>=1.6.1.2nb2",
+ "",
+ ".include \"../../category/dependency/buildlink3.mk\"",
+ "",
+ ".if ${OPSYS} == \"NetBSD\"",
+ ".endif",
+ "",
+ ".for var in value",
+ ".endfor",
+ "",
+ ".endif\t# HS_X11_BUILDLINK3_MK",
+ "",
+ "BUILDLINK_TREE+=\t-hs-X11",
+ "",
+ "# the end")
+
+ ChecklinesBuildlink3Mk(mklines)
+
+ t.CheckOutputLines(
+ "WARN: ~/category/package/buildlink3.mk:25: The file should end here.")
+}
diff -r 6ada64a1dd09 -r ae9968997840 pkgtools/pkglint/files/category_test.go
--- a/pkgtools/pkglint/files/category_test.go Wed Sep 05 17:01:03 2018 +0000
+++ b/pkgtools/pkglint/files/category_test.go Wed Sep 05 17:56:22 2018 +0000
@@ -2,7 +2,7 @@
import "gopkg.in/check.v1"
-func (s *Suite) Test_CheckdirCategory_totally_broken(c *check.C) {
+func (s *Suite) Test_CheckdirCategory__totally_broken(c *check.C) {
t := s.Init(c)
t.SetupVartypes()
@@ -32,7 +32,7 @@
"ERROR: ~/archivers/Makefile:4: The file should end here.")
}
-func (s *Suite) Test_CheckdirCategory_invalid_comment(c *check.C) {
+func (s *Suite) Test_CheckdirCategory__invalid_comment(c *check.C) {
t := s.Init(c)
t.SetupVartypes()
@@ -53,3 +53,33 @@
t.CheckOutputLines(
"WARN: ~/archivers/Makefile:2: COMMENT contains invalid characters (U+005C U+0024 U+0024 U+0024 U+0024 U+0022).")
}
+
+func (s *Suite) Test_CheckdirCategory__wip(c *check.C) {
+ t := s.Init(c)
+
+ t.SetupPkgsrc()
+ t.SetupVartypes()
+ t.SetupFileLines("mk/misc/category.mk")
+ t.SetupFileLines("wip/package/Makefile")
+ t.SetupFileLines("wip/fs-only/Makefile")
+ t.SetupFileLines("wip/Makefile",
+ MkRcsID,
Home |
Main Index |
Thread Index |
Old Index