diff options
author | rillig <rillig@pkgsrc.org> | 2016-12-13 00:58:06 +0000 |
---|---|---|
committer | rillig <rillig@pkgsrc.org> | 2016-12-13 00:58:06 +0000 |
commit | 23ab914fc5aa0193db30b1653571f5bca69fc055 (patch) | |
tree | f778bb8d139fc27b6d400e00d4e50977b82803f7 | |
parent | 9609bc7d8abba8a3d39f5b097ebec93029cbf5fa (diff) | |
download | pkgsrc-23ab914fc5aa0193db30b1653571f5bca69fc055.tar.gz |
Updated pkglint to 5.4.13.
Changes since 5.4.12:
* Added check for unintended # comments, especially in HOMEPAGE
* Added check for quotes in COMMENT
* Fixed hardcoded package versions for PHP, Python, Lua, etc.
* Code cleanup in the tests
26 files changed, 461 insertions, 213 deletions
diff --git a/pkgtools/pkglint/Makefile b/pkgtools/pkglint/Makefile index 2f4c482c95d..b0301995c59 100644 --- a/pkgtools/pkglint/Makefile +++ b/pkgtools/pkglint/Makefile @@ -1,7 +1,6 @@ -# $NetBSD: Makefile,v 1.502 2016/12/04 16:30:00 bsiegert Exp $ +# $NetBSD: Makefile,v 1.503 2016/12/13 00:58:06 rillig Exp $ -PKGNAME= pkglint-5.4.12 -PKGREVISION= 1 +PKGNAME= pkglint-5.4.13 DISTFILES= # none CATEGORIES= pkgtools diff --git a/pkgtools/pkglint/files/category_test.go b/pkgtools/pkglint/files/category_test.go index 19225cb321c..42ab4d853d9 100644 --- a/pkgtools/pkglint/files/category_test.go +++ b/pkgtools/pkglint/files/category_test.go @@ -5,8 +5,9 @@ import ( ) func (s *Suite) Test_CheckdirCategory_totally_broken(c *check.C) { + s.Init(c) G.globalData.InitVartypes() - s.CreateTmpFile(c, "archivers/Makefile", ""+ + s.CreateTmpFile("archivers/Makefile", ""+ "# $\n"+ "SUBDIR+=pkg1\n"+ "SUBDIR+=\u0020aaaaa\n"+ @@ -34,16 +35,17 @@ func (s *Suite) Test_CheckdirCategory_totally_broken(c *check.C) { } func (s *Suite) Test_CheckdirCategory_invalid_comment(c *check.C) { + s.Init(c) G.globalData.InitVartypes() - s.CreateTmpFile(c, "archivers/Makefile", ""+ + s.CreateTmpFile("archivers/Makefile", ""+ "# $"+"NetBSD$\n"+ "COMMENT=\t\\Make $$$$ fast\"\n"+ "\n"+ "SUBDIR+=\tpackage\n"+ "\n"+ ".include \"../mk/misc/category.mk\"\n") - s.CreateTmpFile(c, "archivers/package/Makefile", "# dummy\n") - s.CreateTmpFile(c, "mk/misc/category.mk", "# dummy\n") + s.CreateTmpFile("archivers/package/Makefile", "# dummy\n") + s.CreateTmpFile("mk/misc/category.mk", "# dummy\n") G.CurrentDir = s.tmpdir + "/archivers" G.CurPkgsrcdir = ".." diff --git a/pkgtools/pkglint/files/check_test.go b/pkgtools/pkglint/files/check_test.go index 441dd00ec2a..291f76bc054 100644 --- a/pkgtools/pkglint/files/check_test.go +++ b/pkgtools/pkglint/files/check_test.go @@ -20,6 +20,23 @@ type Suite struct { stdout bytes.Buffer stderr bytes.Buffer tmpdir string + checkC *check.C +} + +// Init initializes the suite with the check.C instance for the actual +// test run. See https://github.com/go-check/check/issues/22 +func (s *Suite) Init(c *check.C) { + if s.checkC != nil { + panic("Suite.Init must only be called once.") + } + s.checkC = c +} + +func (s *Suite) c() *check.C { + if s.checkC == nil { + panic("Must call Suite.Init before accessing check.C.") + } + return s.checkC } func (s *Suite) Stdout() string { @@ -87,10 +104,10 @@ func (s *Suite) EndDebugToStdout() { G.opts.Debug = false } -func (s *Suite) UseCommandLine(c *check.C, args ...string) { +func (s *Suite) UseCommandLine(args ...string) { exitcode := new(Pkglint).ParseCommandLine(append([]string{"pkglint"}, args...)) if exitcode != nil && *exitcode != 0 { - c.Fatalf("Cannot parse command line: %#v", args) + s.c().Fatalf("Cannot parse command line: %#v", args) } G.opts.LogVerbose = true // See SetUpTest } @@ -123,11 +140,9 @@ func (s *Suite) RegisterTool(tool *Tool) { } } -func (s *Suite) CreateTmpFile(c *check.C, relFname, content string) (absFname string) { - if s.tmpdir == "" { - s.tmpdir = filepath.ToSlash(c.MkDir()) - } - absFname = s.tmpdir + "/" + relFname +func (s *Suite) CreateTmpFile(relFname, content string) (absFname string) { + c := s.c() + absFname = s.TmpDir() + "/" + relFname err := os.MkdirAll(path.Dir(absFname), 0777) c.Assert(err, check.IsNil) @@ -136,20 +151,28 @@ func (s *Suite) CreateTmpFile(c *check.C, relFname, content string) (absFname st return } -func (s *Suite) CreateTmpFileLines(c *check.C, relFname string, rawTexts ...string) (absFname string) { +func (s *Suite) CreateTmpFileLines(relFname string, rawTexts ...string) (absFname string) { text := "" for _, rawText := range rawTexts { text += rawText + "\n" } - return s.CreateTmpFile(c, relFname, text) + return s.CreateTmpFile(relFname, text) } -func (s *Suite) LoadTmpFile(c *check.C, relFname string) string { - bytes, err := ioutil.ReadFile(s.tmpdir + "/" + relFname) +func (s *Suite) LoadTmpFile(relFname string) (absFname string) { + c := s.c() + bytes, err := ioutil.ReadFile(s.TmpDir() + "/" + relFname) c.Assert(err, check.IsNil) return string(bytes) } +func (s *Suite) TmpDir() string { + if s.tmpdir == "" { + s.tmpdir = filepath.ToSlash(s.c().MkDir()) + } + return s.tmpdir +} + func (s *Suite) ExpectFatalError(action func()) { if r := recover(); r != nil { if _, ok := r.(pkglintFatal); ok { @@ -163,7 +186,9 @@ func (s *Suite) ExpectFatalError(action func()) { func (s *Suite) SetUpTest(c *check.C) { G = GlobalVars{Testing: true} G.logOut, G.logErr, G.debugOut = &s.stdout, &s.stderr, &s.stdout - s.UseCommandLine(c /* no arguments */) + s.checkC = c + s.UseCommandLine( /* no arguments */ ) + s.checkC = nil G.opts.LogVerbose = true // To detect duplicate work being done } diff --git a/pkgtools/pkglint/files/dir_test.go b/pkgtools/pkglint/files/dir_test.go index f721e5224f0..aa99c046f01 100644 --- a/pkgtools/pkglint/files/dir_test.go +++ b/pkgtools/pkglint/files/dir_test.go @@ -5,7 +5,8 @@ import ( ) func (s *Suite) Test_CheckDirent_outside(c *check.C) { - s.CreateTmpFile(c, "empty", "") + s.Init(c) + s.CreateTmpFile("empty", "") CheckDirent(s.tmpdir) @@ -13,10 +14,11 @@ func (s *Suite) Test_CheckDirent_outside(c *check.C) { } func (s *Suite) Test_CheckDirent(c *check.C) { - s.CreateTmpFile(c, "mk/bsd.pkg.mk", "") - s.CreateTmpFile(c, "category/package/Makefile", "") - s.CreateTmpFile(c, "category/Makefile", "") - s.CreateTmpFile(c, "Makefile", "") + s.Init(c) + s.CreateTmpFile("mk/bsd.pkg.mk", "") + s.CreateTmpFile("category/package/Makefile", "") + s.CreateTmpFile("category/Makefile", "") + s.CreateTmpFile("Makefile", "") G.globalData.Pkgsrcdir = s.tmpdir CheckDirent(s.tmpdir) diff --git a/pkgtools/pkglint/files/distinfo.go b/pkgtools/pkglint/files/distinfo.go index 18e0917ed12..2cfb4b38c62 100644 --- a/pkgtools/pkglint/files/distinfo.go +++ b/pkgtools/pkglint/files/distinfo.go @@ -14,10 +14,16 @@ func ChecklinesDistinfo(lines []*Line) { } fname := lines[0].Fname - var patchesDir = "patches" - if G.Pkg != nil && hasSuffix(fname, "/lang/php56/distinfo") { - patchesDir = G.CurPkgsrcdir + "/lang/php56/patches" - } else if G.Pkg != nil && dirExists(G.CurrentDir+"/"+G.Pkg.Patchdir) { + patchesDir := "patches" + patchesDirSet := false + if G.Pkg != nil && contains(fname, "lang/php") { + phpdir := G.globalData.Latest("lang", `^php[0-9]+$`, "/lang/$0") + if hasSuffix(fname, phpdir+"/distinfo") { + patchesDir = G.CurPkgsrcdir + phpdir + "/patches" + patchesDirSet = true + } + } + if G.Pkg != nil && !patchesDirSet && dirExists(G.CurrentDir+"/"+G.Pkg.Patchdir) { patchesDir = G.Pkg.Patchdir } if G.opts.Debug { diff --git a/pkgtools/pkglint/files/distinfo_test.go b/pkgtools/pkglint/files/distinfo_test.go index b667917b842..cfb63df2ca4 100644 --- a/pkgtools/pkglint/files/distinfo_test.go +++ b/pkgtools/pkglint/files/distinfo_test.go @@ -5,10 +5,11 @@ import ( ) func (s *Suite) Test_ChecklinesDistinfo(c *check.C) { - s.CreateTmpFile(c, "patches/patch-aa", ""+ + s.Init(c) + s.CreateTmpFile("patches/patch-aa", ""+ "$"+"NetBSD$ line is ignored\n"+ "patch contents\n") - s.CreateTmpFile(c, "patches/patch-ab", ""+ + s.CreateTmpFile("patches/patch-ab", ""+ "patch contents\n") G.CurrentDir = s.tmpdir @@ -44,7 +45,8 @@ func (s *Suite) Test_ChecklinesDistinfo_global_hash_mismatch(c *check.C) { } func (s *Suite) Test_ChecklinesDistinfo_uncommitted_patch(c *check.C) { - s.CreateTmpFile(c, "patches/patch-aa", ""+ + s.Init(c) + s.CreateTmpFile("patches/patch-aa", ""+ "$"+"NetBSD$\n"+ "\n"+ "--- oldfile\n"+ @@ -52,7 +54,7 @@ func (s *Suite) Test_ChecklinesDistinfo_uncommitted_patch(c *check.C) { "@@ -1,1 +1,1 @@\n"+ "-old\n"+ "+new\n") - s.CreateTmpFile(c, "CVS/Entries", + s.CreateTmpFile("CVS/Entries", "/distinfo/...\n") G.CurrentDir = s.tmpdir @@ -66,9 +68,10 @@ func (s *Suite) Test_ChecklinesDistinfo_uncommitted_patch(c *check.C) { } func (s *Suite) Test_ChecklinesDistinfo_unrecorded_patches(c *check.C) { - s.CreateTmpFile(c, "patches/CVS/Entries", "") - s.CreateTmpFile(c, "patches/patch-aa", "") - s.CreateTmpFile(c, "patches/patch-src-Makefile", "") + s.Init(c) + s.CreateTmpFile("patches/CVS/Entries", "") + s.CreateTmpFile("patches/patch-aa", "") + s.CreateTmpFile("patches/patch-src-Makefile", "") G.CurrentDir = s.tmpdir ChecklinesDistinfo(s.NewLines(s.tmpdir+"/distinfo", @@ -85,8 +88,8 @@ func (s *Suite) Test_ChecklinesDistinfo_unrecorded_patches(c *check.C) { } func (s *Suite) Test_ChecklinesDistinfo_manual_patches(c *check.C) { - s.CreateTmpFile(c, "patches/manual-libtool.m4", - "") + s.Init(c) + s.CreateTmpFile("patches/manual-libtool.m4", "") G.CurrentDir = s.tmpdir ChecklinesDistinfo(s.NewLines(s.tmpdir+"/distinfo", diff --git a/pkgtools/pkglint/files/files_test.go b/pkgtools/pkglint/files/files_test.go index 27eb8ca5414..556fb50fe40 100644 --- a/pkgtools/pkglint/files/files_test.go +++ b/pkgtools/pkglint/files/files_test.go @@ -57,8 +57,9 @@ func (s *Suite) Test_splitRawLine(c *check.C) { } func (s *Suite) Test_show_autofix(c *check.C) { - s.UseCommandLine(c, "--show-autofix") - fname := s.CreateTmpFile(c, "Makefile", ""+ + s.Init(c) + s.UseCommandLine("--show-autofix") + fname := s.CreateTmpFile("Makefile", ""+ "line1\n"+ "line2\n"+ "line3\n") @@ -70,15 +71,16 @@ func (s *Suite) Test_show_autofix(c *check.C) { SaveAutofixChanges(lines) c.Check(lines[1].raw[0].textnl, equals, "XXXXX\n") - c.Check(s.LoadTmpFile(c, "Makefile"), equals, "line1\nline2\nline3\n") + c.Check(s.LoadTmpFile("Makefile"), equals, "line1\nline2\nline3\n") c.Check(s.Output(), equals, ""+ "WARN: ~/Makefile:2: Something's wrong here.\n"+ "AUTOFIX: ~/Makefile:2: Replacing regular expression \".\" with \"X\".\n") } func (s *Suite) Test_autofix(c *check.C) { - s.UseCommandLine(c, "--autofix") - fname := s.CreateTmpFile(c, "Makefile", ""+ + s.Init(c) + s.UseCommandLine("--autofix") + fname := s.CreateTmpFile("Makefile", ""+ "line1\n"+ "line2\n"+ "line3\n") @@ -89,7 +91,7 @@ func (s *Suite) Test_autofix(c *check.C) { } SaveAutofixChanges(lines) - c.Check(s.LoadTmpFile(c, "Makefile"), equals, "line1\nXXXXX\nline3\n") + c.Check(s.LoadTmpFile("Makefile"), equals, "line1\nXXXXX\nline3\n") c.Check(s.Output(), equals, ""+ "AUTOFIX: ~/Makefile:2: Replacing regular expression \".\" with \"X\".\n"+ "AUTOFIX: ~/Makefile: Has been auto-fixed. Please re-run pkglint.\n") diff --git a/pkgtools/pkglint/files/globaldata.go b/pkgtools/pkglint/files/globaldata.go index b9d9b73af6f..c91076cb854 100644 --- a/pkgtools/pkglint/files/globaldata.go +++ b/pkgtools/pkglint/files/globaldata.go @@ -21,6 +21,7 @@ type GlobalData struct { UserDefinedVars map[string]*MkLine // varname => line Deprecated map[string]string // vartypes map[string]*Vartype // varcanon => type + latest map[string]string // "lang/php[0-9]*" => "lang/php70" } // Change is a change entry from the `doc/CHANGES-*` files. @@ -63,6 +64,41 @@ func (gd *GlobalData) Initialize() { gd.loadDeprecatedVars() } +func (gd *GlobalData) Latest(category string, re RegexPattern, repl string) string { + key := category + "/" + string(re) + " => " + repl + if latest, found := gd.latest[key]; found { + return latest + } + + if gd.latest == nil { + gd.latest = make(map[string]string) + } + + error := func() string { + dummyLine.Errorf("Cannot find latest version of %q in %q.", re, gd.Pkgsrcdir) + gd.latest[key] = "" + return "" + } + + all, err := ioutil.ReadDir(gd.Pkgsrcdir + "/" + category) + if err != nil { + return error() + } + + latest := "" + for _, fileInfo := range all { + if matches(fileInfo.Name(), re) { + latest = regcomp(re).ReplaceAllString(fileInfo.Name(), repl) + } + } + if latest == "" { + return error() + } + + gd.latest[key] = latest + return latest +} + func (gd *GlobalData) loadDistSites() { fname := gd.Pkgsrcdir + "/mk/fetch/sites.mk" lines := LoadExistingLines(fname, true) @@ -70,7 +106,7 @@ func (gd *GlobalData) loadDistSites() { name2url := make(map[string]string) url2name := make(map[string]string) for _, line := range lines { - if m, varname, _, _, _, urls, _ := MatchVarassign(line.Text); m { + if m, varname, _, _, _, urls, _, _ := MatchVarassign(line.Text); m { if hasPrefix(varname, "MASTER_SITE_") && varname != "MASTER_SITE_BACKUP" { for _, url := range splitOnSpace(urls) { if matches(url, `^(?:http://|https://|ftp://)`) { @@ -150,7 +186,7 @@ func (gd *GlobalData) loadTools() { for _, line := range lines { text := line.Text - if m, varname, _, _, _, value, _ := MatchVarassign(text); m { + if m, varname, _, _, _, value, _, _ := MatchVarassign(text); m { if varname == "USE_TOOLS" { if G.opts.Debug { traceStep("[condDepth=%d] %s", condDepth, value) @@ -566,7 +602,7 @@ func (tr *ToolRegistry) Trace() { } func (tr *ToolRegistry) ParseToolLine(line *Line) { - if m, varname, _, _, _, value, _ := MatchVarassign(line.Text); m { + if m, varname, _, _, _, value, _, _ := MatchVarassign(line.Text); m { if varname == "TOOLS_CREATE" && (value == "[" || matches(value, `^?[-\w.]+$`)) { tr.Register(value) diff --git a/pkgtools/pkglint/files/globaldata_test.go b/pkgtools/pkglint/files/globaldata_test.go index 3dfd757dc35..438ace98068 100644 --- a/pkgtools/pkglint/files/globaldata_test.go +++ b/pkgtools/pkglint/files/globaldata_test.go @@ -31,22 +31,23 @@ func (s *Suite) Test_parselinesSuggestedUpdates(c *check.C) { } func (s *Suite) Test_GlobalData_loadTools(c *check.C) { - s.CreateTmpFileLines(c, "mk/tools/bsd.tools.mk", + s.Init(c) + s.CreateTmpFileLines("mk/tools/bsd.tools.mk", ".include \"flex.mk\"", ".include \"gettext.mk\"") - s.CreateTmpFileLines(c, "mk/tools/defaults.mk", + s.CreateTmpFileLines("mk/tools/defaults.mk", "_TOOLS_VARNAME.chown=CHOWN", "_TOOLS_VARNAME.gawk=AWK", "_TOOLS_VARNAME.mv=MV", "_TOOLS_VARNAME.pwd=PWD") - s.CreateTmpFileLines(c, "mk/tools/flex.mk", + s.CreateTmpFileLines("mk/tools/flex.mk", "# empty") - s.CreateTmpFileLines(c, "mk/tools/gettext.mk", + s.CreateTmpFileLines("mk/tools/gettext.mk", "USE_TOOLS+=msgfmt", "TOOLS_CREATE+=msgfmt") - s.CreateTmpFileLines(c, "mk/bsd.prefs.mk", + s.CreateTmpFileLines("mk/bsd.prefs.mk", "USE_TOOLS+=\tpwd") - s.CreateTmpFileLines(c, "mk/bsd.pkg.mk", + s.CreateTmpFileLines("mk/bsd.pkg.mk", "USE_TOOLS+=\tmv") G.globalData.Pkgsrcdir = s.tmpdir G.CurrentDir = s.tmpdir @@ -75,7 +76,8 @@ func (s *Suite) Test_GlobalData_loadTools(c *check.C) { } func (s *Suite) Test_GlobalData_loadDocChangesFromFile(c *check.C) { - s.CreateTmpFile(c, "doc/CHANGES-2015", ""+ + s.Init(c) + s.CreateTmpFile("doc/CHANGES-2015", ""+ "\tAdded category/package version 1.0 [author1 2015-01-01]\n"+ "\tUpdated category/package to 1.5 [author2 2015-01-02]\n"+ "\tRenamed category/package to category/pkg [author3 2015-01-03]\n"+ diff --git a/pkgtools/pkglint/files/licenses_test.go b/pkgtools/pkglint/files/licenses_test.go index 8129dbae86d..ce1c2808322 100644 --- a/pkgtools/pkglint/files/licenses_test.go +++ b/pkgtools/pkglint/files/licenses_test.go @@ -10,7 +10,8 @@ func (s *Suite) Test_parseLicenses(c *check.C) { } func (s *Suite) Test_checklineLicense(c *check.C) { - s.CreateTmpFile(c, "licenses/gnu-gpl-v2", "Most software \u2026") + s.Init(c) + s.CreateTmpFile("licenses/gnu-gpl-v2", "Most software \u2026") mkline := NewMkLine(NewLine("Makefile", 7, "LICENSE=dummy", nil)) G.globalData.Pkgsrcdir = s.tmpdir G.CurrentDir = s.tmpdir diff --git a/pkgtools/pkglint/files/line_test.go b/pkgtools/pkglint/files/line_test.go index a855f48d7cb..8ec338757c3 100644 --- a/pkgtools/pkglint/files/line_test.go +++ b/pkgtools/pkglint/files/line_test.go @@ -5,7 +5,8 @@ import ( ) func (s *Suite) Test_Line_modifications(c *check.C) { - s.UseCommandLine(c, "--show-autofix") + s.Init(c) + s.UseCommandLine("--show-autofix") line := NewLine("fname", 1, "dummy", s.NewRawLines(1, "original\n")) @@ -63,7 +64,8 @@ func (s *Suite) Test_Line_CheckAbsolutePathname(c *check.C) { } func (s *Suite) Test_Line_show_autofix_AutofixReplace(c *check.C) { - s.UseCommandLine(c, "--show-autofix", "--source") + s.Init(c) + s.UseCommandLine("--show-autofix", "--source") line := NewLineMulti("Makefile", 27, 29, "# old", s.NewRawLines( 27, "before\n", 28, "The old song\n", @@ -84,7 +86,8 @@ func (s *Suite) Test_Line_show_autofix_AutofixReplace(c *check.C) { } func (s *Suite) Test_Line_show_autofix_AutofixInsertBefore(c *check.C) { - s.UseCommandLine(c, "--show-autofix", "--source") + s.Init(c) + s.UseCommandLine("--show-autofix", "--source") line := NewLine("Makefile", 30, "original", s.NewRawLines(30, "original\n")) if !line.AutofixInsertBefore("inserted") { @@ -100,7 +103,8 @@ func (s *Suite) Test_Line_show_autofix_AutofixInsertBefore(c *check.C) { } func (s *Suite) Test_Line_show_autofix_AutofixDelete(c *check.C) { - s.UseCommandLine(c, "--show-autofix", "--source") + s.Init(c) + s.UseCommandLine("--show-autofix", "--source") line := NewLine("Makefile", 30, "to be deleted", s.NewRawLines(30, "to be deleted\n")) if !line.AutofixDelete() { diff --git a/pkgtools/pkglint/files/mkline.go b/pkgtools/pkglint/files/mkline.go index 30a70148bb8..6e46ffcabea 100644 --- a/pkgtools/pkglint/files/mkline.go +++ b/pkgtools/pkglint/files/mkline.go @@ -58,7 +58,7 @@ func NewMkLine(line *Line) (mkline *MkLine) { "white-space.") } - if m, varname, spaceAfterVarname, op, valueAlign, value, comment := MatchVarassign(text); m { + if m, varname, spaceAfterVarname, op, valueAlign, value, spaceAfterValue, comment := MatchVarassign(text); m { if G.opts.WarnSpace && spaceAfterVarname != "" { switch { case hasSuffix(varname, "+") && op == "=": @@ -72,6 +72,13 @@ func NewMkLine(line *Line) (mkline *MkLine) { } } + if comment != "" && value != "" && spaceAfterValue == "" { + line.Warnf("The # character starts a comment.") + Explain( + "In a variable assignment, an unescaped # starts a comment that", + "continues until the end of the line. To escape the #, write \\#.") + } + value = strings.Replace(value, "\\#", "#", -1) varparam := varnameParam(varname) diff --git a/pkgtools/pkglint/files/mkline_test.go b/pkgtools/pkglint/files/mkline_test.go index 711aea53f17..40b0b11540c 100644 --- a/pkgtools/pkglint/files/mkline_test.go +++ b/pkgtools/pkglint/files/mkline_test.go @@ -5,7 +5,8 @@ import ( ) func (s *Suite) Test_MkLine_CheckVartype_simple_type(c *check.C) { - s.UseCommandLine(c, "-Wtypes") + s.Init(c) + s.UseCommandLine("-Wtypes") G.globalData.InitVartypes() mkline := NewMkLine(NewLine("fname", 1, "COMMENT=\tA nice package", nil)) @@ -33,7 +34,8 @@ func (s *Suite) Test_MkLine_CheckVartype(c *check.C) { } func (s *Suite) Test_VaralignBlock_Check_autofix(c *check.C) { - s.UseCommandLine(c, "-Wspace", "-f") + s.Init(c) + s.UseCommandLine("-Wspace", "-f") lines := s.NewLines("file.mk", "VAR= value", // Indentation 7, fixed to 8. "", // @@ -85,7 +87,8 @@ func (s *Suite) Test_VaralignBlock_Check_autofix(c *check.C) { } func (s *Suite) Test_VaralignBlock_Check_reduce_indentation(c *check.C) { - s.UseCommandLine(c, "-Wspace") + s.Init(c) + s.UseCommandLine("-Wspace") mklines := s.NewMkLines("file.mk", "VAR= \tvalue", "VAR= \tvalue", @@ -108,7 +111,8 @@ func (s *Suite) Test_VaralignBlock_Check_reduce_indentation(c *check.C) { } func (s *Suite) Test_VaralignBlock_Check_longest_line_no_space(c *check.C) { - s.UseCommandLine(c, "-Wspace") + s.Init(c) + s.UseCommandLine("-Wspace") mklines := s.NewMkLines("file.mk", "SUBST_CLASSES+= aaaaaaaa", "SUBST_STAGE.aaaaaaaa= pre-configure", @@ -129,7 +133,8 @@ func (s *Suite) Test_VaralignBlock_Check_longest_line_no_space(c *check.C) { } func (s *Suite) Test_VaralignBlock_Check_only_spaces(c *check.C) { - s.UseCommandLine(c, "-Wspace") + s.Init(c) + s.UseCommandLine("-Wspace") mklines := s.NewMkLines("file.mk", "SUBST_CLASSES+= aaaaaaaa", "SUBST_STAGE.aaaaaaaa= pre-configure", @@ -150,7 +155,8 @@ func (s *Suite) Test_VaralignBlock_Check_only_spaces(c *check.C) { } func (s *Suite) Test_NewMkLine(c *check.C) { - s.UseCommandLine(c, "-Wspace") + s.Init(c) + s.UseCommandLine("-Wspace") mklines := NewMkLines(s.NewLines("test.mk", "VARNAME.param?=value # varassign comment", "\tshell command # shell comment", @@ -207,8 +213,9 @@ func (s *Suite) Test_NewMkLine(c *check.C) { } func (s *Suite) Test_NewMkLine__autofix_space_after_varname(c *check.C) { - s.UseCommandLine(c, "-Wspace") - fname := s.CreateTmpFileLines(c, "Makefile", + s.Init(c) + s.UseCommandLine("-Wspace") + fname := s.CreateTmpFileLines("Makefile", mkrcsid, "VARNAME +=\t${VARNAME}", "VARNAME+ =\t${VARNAME+}", @@ -221,7 +228,7 @@ func (s *Suite) Test_NewMkLine__autofix_space_after_varname(c *check.C) { "WARN: ~/Makefile:2: Unnecessary space after variable name \"VARNAME\".\n"+ "WARN: ~/Makefile:4: Unnecessary space after variable name \"VARNAME+\".\n") - s.UseCommandLine(c, "-Wspace", "--autofix") + s.UseCommandLine("-Wspace", "--autofix") CheckfileMk(fname) @@ -230,7 +237,7 @@ func (s *Suite) Test_NewMkLine__autofix_space_after_varname(c *check.C) { "AUTOFIX: ~/Makefile:4: Replacing \"VARNAME+ +=\" with \"VARNAME++=\".\n"+ "AUTOFIX: ~/Makefile: Has been auto-fixed. Please re-run pkglint.\n"+ "AUTOFIX: ~/Makefile: Has been auto-fixed. Please re-run pkglint.\n") - c.Check(s.LoadTmpFile(c, "Makefile"), equals, ""+ + c.Check(s.LoadTmpFile("Makefile"), equals, ""+ mkrcsid+"\n"+ "VARNAME+=\t${VARNAME}\n"+ "VARNAME+ =\t${VARNAME+}\n"+ @@ -251,7 +258,8 @@ func (s *Suite) Test_MkLine_checkVarassign_URL_with_shell_special_characters(c * } func (s *Suite) Test_MkLine_Check_conditions(c *check.C) { - s.UseCommandLine(c, "-Wtypes") + s.Init(c) + s.UseCommandLine("-Wtypes") G.globalData.InitVartypes() NewMkLine(NewLine("fname", 1, ".if !empty(PKGSRC_COMPILER:Mmycc)", nil)).CheckCond() @@ -353,6 +361,7 @@ func (s *Suite) Test_NewMkLine_numbersign(c *check.C) { mklineVarassignUnescaped := NewMkLine(NewLine("fname", 1, "SED_CMD=\t's,#,hash,'", nil)) c.Check(mklineVarassignUnescaped.Value(), equals, "'s,") + c.Check(s.Output(), equals, "WARN: fname:1: The # character starts a comment.\n") } func (s *Suite) Test_NewMkLine_leading_space(c *check.C) { @@ -362,7 +371,8 @@ func (s *Suite) Test_NewMkLine_leading_space(c *check.C) { } func (s *Suite) Test_MkLine_checkVarassignDefPermissions(c *check.C) { - s.UseCommandLine(c, "-Wall") + s.Init(c) + s.UseCommandLine("-Wall") G.globalData.InitVartypes() mkline := NewMkLine(NewLine("options.mk", 2, "PKG_DEVELOPER?=\tyes", nil)) @@ -372,7 +382,8 @@ func (s *Suite) Test_MkLine_checkVarassignDefPermissions(c *check.C) { } func (s *Suite) Test_MkLine_CheckVarusePermissions(c *check.C) { - s.UseCommandLine(c, "-Wall") + s.Init(c) + s.UseCommandLine("-Wall") G.globalData.InitVartypes() mklines := s.NewMkLines("options.mk", mkrcsid, @@ -394,7 +405,8 @@ func (s *Suite) Test_MkLine_CheckVarusePermissions(c *check.C) { } func (s *Suite) Test_MkLine_CheckVarusePermissions__load_time(c *check.C) { - s.UseCommandLine(c, "-Wall") + s.Init(c) + s.UseCommandLine("-Wall") G.globalData.InitVartypes() mklines := s.NewMkLines("options.mk", mkrcsid, @@ -414,7 +426,8 @@ func (s *Suite) Test_MkLine_WarnVaruseLocalbase(c *check.C) { } func (s *Suite) Test_MkLines_Check__extra(c *check.C) { - s.UseCommandLine(c, "-Wextra") + s.Init(c) + s.UseCommandLine("-Wextra") G.globalData.InitVartypes() G.Pkg = NewPackage("category/pkgbase") G.Mk = s.NewMkLines("options.mk", @@ -473,7 +486,8 @@ func (s *Suite) Test_MkLine_variableNeedsQuoting__unknown_rhs(c *check.C) { } func (s *Suite) Test_MkLine_variableNeedsQuoting__append_URL_to_list_of_URLs(c *check.C) { - s.UseCommandLine(c, "-Wall") + s.Init(c) + s.UseCommandLine("-Wall") G.globalData.InitVartypes() s.RegisterMasterSite("MASTER_SITE_SOURCEFORGE", "http://downloads.sourceforge.net/sourceforge/") mkline := NewMkLine(NewLine("Makefile", 95, "MASTER_SITES=\t${HOMEPAGE}", nil)) @@ -490,7 +504,8 @@ func (s *Suite) Test_MkLine_variableNeedsQuoting__append_URL_to_list_of_URLs(c * // Assigning lists to lists is ok. func (s *Suite) Test_MkLine_variableNeedsQuoting__append_list_to_list(c *check.C) { - s.UseCommandLine(c, "-Wall") + s.Init(c) + s.UseCommandLine("-Wall") G.globalData.InitVartypes() s.RegisterMasterSite("MASTER_SITE_SOURCEFORGE", "http://downloads.sourceforge.net/sourceforge/") mkline := NewMkLine(NewLine("Makefile", 96, "MASTER_SITES=\t${MASTER_SITE_SOURCEFORGE:=squirrel-sql/}", nil)) @@ -501,7 +516,8 @@ func (s *Suite) Test_MkLine_variableNeedsQuoting__append_list_to_list(c *check.C } func (s *Suite) Test_MkLine_variableNeedsQuoting__eval_shell(c *check.C) { - s.UseCommandLine(c, "-Wall") + s.Init(c) + s.UseCommandLine("-Wall") G.globalData.InitVartypes() mkline := NewMkLine(NewLine("builtin.mk", 3, "USE_BUILTIN.Xfixes!=\t${PKG_ADMIN} pmatch 'pkg-[0-9]*' ${BUILTIN_PKG.Xfixes:Q}", nil)) @@ -513,7 +529,8 @@ func (s *Suite) Test_MkLine_variableNeedsQuoting__eval_shell(c *check.C) { } func (s *Suite) Test_MkLine_variableNeedsQuoting__command_in_single_quotes(c *check.C) { - s.UseCommandLine(c, "-Wall") + s.Init(c) + s.UseCommandLine("-Wall") G.globalData.InitVartypes() mkline := NewMkLine(NewLine("Makefile", 3, "SUBST_SED.hpath=\t-e 's|^\\(INSTALL[\t:]*=\\).*|\\1${INSTALL}|'", nil)) @@ -523,7 +540,8 @@ func (s *Suite) Test_MkLine_variableNeedsQuoting__command_in_single_quotes(c *ch } func (s *Suite) Test_MkLine_variableNeedsQuoting__command_in_command(c *check.C) { - s.UseCommandLine(c, "-Wall") + s.Init(c) + s.UseCommandLine("-Wall") G.globalData.InitVartypes() s.RegisterTool(&Tool{Name: "find", Varname: "FIND", Predefined: true}) s.RegisterTool(&Tool{Name: "sort", Varname: "SORT", Predefined: true}) @@ -540,7 +558,8 @@ func (s *Suite) Test_MkLine_variableNeedsQuoting__command_in_command(c *check.C) } func (s *Suite) Test_MkLine_variableNeedsQuoting__word_as_part_of_word(c *check.C) { - s.UseCommandLine(c, "-Wall") + s.Init(c) + s.UseCommandLine("-Wall") G.globalData.InitVartypes() G.Mk = s.NewMkLines("Makefile", mkrcsid, @@ -558,7 +577,8 @@ func (s *Suite) Test_MkLine_variableNeedsQuoting__word_as_part_of_word(c *check. // // Based on graphics/circos/Makefile. func (s *Suite) Test_MkLine_variableNeedsQuoting__command_as_command_argument(c *check.C) { - s.UseCommandLine(c, "-Wall") + s.Init(c) + s.UseCommandLine("-Wall") s.RegisterTool(&Tool{Name: "perl", Varname: "PERL5", Predefined: true}) s.RegisterTool(&Tool{Name: "bash", Varname: "BASH", Predefined: true}) G.globalData.InitVartypes() @@ -577,7 +597,8 @@ func (s *Suite) Test_MkLine_variableNeedsQuoting__command_as_command_argument(c // Based on mail/mailfront/Makefile. func (s *Suite) Test_MkLine_variableNeedsQuoting__URL_as_part_of_word_in_list(c *check.C) { - s.UseCommandLine(c, "-Wall") + s.Init(c) + s.UseCommandLine("-Wall") G.globalData.InitVartypes() G.Mk = s.NewMkLines("Makefile", mkrcsid, @@ -594,7 +615,8 @@ func (s *Suite) Test_MkLine_variableNeedsQuoting__URL_as_part_of_word_in_list(c // // Based on www/firefox31/xpi.mk. func (s *Suite) Test_MkLine_variableNeedsQuoting__command_in_subshell(c *check.C) { - s.UseCommandLine(c, "-Wall") + s.Init(c) + s.UseCommandLine("-Wall") G.globalData.InitVartypes() s.RegisterTool(&Tool{Name: "awk", Varname: "AWK", Predefined: true}) s.RegisterTool(&Tool{Name: "echo", Varname: "ECHO", Predefined: true}) @@ -613,7 +635,8 @@ func (s *Suite) Test_MkLine_variableNeedsQuoting__command_in_subshell(c *check.C // shell characters like quotes or backslashes. Therefore, quoting them // correctly is more tricky than with other variables. func (s *Suite) Test_MkLine_variableNeedsQuoting__LDFLAGS_in_single_quotes(c *check.C) { - s.UseCommandLine(c, "-Wall") + s.Init(c) + s.UseCommandLine("-Wall") G.globalData.InitVartypes() G.Mk = s.NewMkLines("x11/mlterm/Makefile", mkrcsid, @@ -627,7 +650,8 @@ func (s *Suite) Test_MkLine_variableNeedsQuoting__LDFLAGS_in_single_quotes(c *ch } func (s *Suite) Test_MkLines_Check__MASTER_SITE_in_HOMEPAGE(c *check.C) { - s.UseCommandLine(c, "-Wall") + s.Init(c) + s.UseCommandLine("-Wall") s.RegisterMasterSite("MASTER_SITE_GITHUB", "https://github.com/") G.globalData.InitVartypes() G.Mk = s.NewMkLines("devel/catch/Makefile", @@ -647,7 +671,8 @@ func (s *Suite) Test_MkLines_Check__MASTER_SITE_in_HOMEPAGE(c *check.C) { } func (s *Suite) Test_MkLine_variableNeedsQuoting__tool_in_quotes_in_subshell_in_shellwords(c *check.C) { - s.UseCommandLine(c, "-Wall") + s.Init(c) + s.UseCommandLine("-Wall") s.RegisterTool(&Tool{Name: "echo", Varname: "ECHO", Predefined: true}) s.RegisterTool(&Tool{Name: "sh", Varname: "SH", Predefined: true}) G.globalData.InitVartypes() @@ -661,7 +686,8 @@ func (s *Suite) Test_MkLine_variableNeedsQuoting__tool_in_quotes_in_subshell_in_ } func (s *Suite) Test_MkLine_variableNeedsQuoting__LDADD_in_BUILDLINK_TRANSFORM(c *check.C) { - s.UseCommandLine(c, "-Wall") + s.Init(c) + s.UseCommandLine("-Wall") G.globalData.InitVartypes() G.Mk = s.NewMkLines("x11/qt5-qtbase/Makefile.common", "BUILDLINK_TRANSFORM+=opt:-ldl:${BUILDLINK_LDADD.dl:M*}") @@ -673,7 +699,8 @@ func (s *Suite) Test_MkLine_variableNeedsQuoting__LDADD_in_BUILDLINK_TRANSFORM(c } func (s *Suite) Test_MkLine_variableNeedsQuoting_command_in_message(c *check.C) { - s.UseCommandLine(c, "-Wall") + s.Init(c) + s.UseCommandLine("-Wall") G.globalData.InitVartypes() G.Mk = s.NewMkLines("benchmarks/iozone/Makefile", "SUBST_MESSAGE.crlf=\tStripping EOL CR in ${REPLACE_PERL}") @@ -684,7 +711,8 @@ func (s *Suite) Test_MkLine_variableNeedsQuoting_command_in_message(c *check.C) } func (s *Suite) Test_MkLine_variableNeedsQuoting_guessed_list_variable_in_quotes(c *check.C) { - s.UseCommandLine(c, "-Wall") + s.Init(c) + s.UseCommandLine("-Wall") G.globalData.InitVartypes() G.Mk = s.NewMkLines("audio/jack-rack/Makefile", mkrcsid, @@ -697,7 +725,8 @@ func (s *Suite) Test_MkLine_variableNeedsQuoting_guessed_list_variable_in_quotes } func (s *Suite) Test_MkLine_variableNeedsQuoting_list_in_list(c *check.C) { - s.UseCommandLine(c, "-Wall") + s.Init(c) + s.UseCommandLine("-Wall") G.globalData.InitVartypes() G.Mk = s.NewMkLines("x11/eterm/Makefile", mkrcsid, @@ -709,7 +738,8 @@ func (s *Suite) Test_MkLine_variableNeedsQuoting_list_in_list(c *check.C) { } func (s *Suite) Test_MkLine_variableNeedsQuoting_PKGNAME_and_URL_list_in_URL_list(c *check.C) { - s.UseCommandLine(c, "-Wall") + s.Init(c) + s.UseCommandLine("-Wall") s.RegisterMasterSite("MASTER_SITE_GNOME", "http://ftp.gnome.org/") G.globalData.InitVartypes() G.Mk = s.NewMkLines("x11/gtk3/Makefile", @@ -722,7 +752,8 @@ func (s *Suite) Test_MkLine_variableNeedsQuoting_PKGNAME_and_URL_list_in_URL_lis } func (s *Suite) Test_MkLine_variableNeedsQuoting_tool_in_CONFIGURE_ENV(c *check.C) { - s.UseCommandLine(c, "-Wall") + s.Init(c) + s.UseCommandLine("-Wall") G.globalData.InitVartypes() G.globalData.Tools = NewToolRegistry() G.globalData.Tools.RegisterVarname("tar", "TAR") @@ -740,7 +771,8 @@ func (s *Suite) Test_MkLine_variableNeedsQuoting_tool_in_CONFIGURE_ENV(c *check. } func (s *Suite) Test_MkLine_Varuse_Modifier_L(c *check.C) { - s.UseCommandLine(c, "-Wall") + s.Init(c) + s.UseCommandLine("-Wall") G.globalData.InitVartypes() G.Mk = s.NewMkLines("x11/xkeyboard-config/Makefile", "FILES_SUBST+=XKBCOMP_SYMLINK=${${XKBBASE}/xkbcomp:L:Q}") @@ -751,7 +783,8 @@ func (s *Suite) Test_MkLine_Varuse_Modifier_L(c *check.C) { } func (s *Suite) Test_MkLine_CheckCond_comparison_with_shell_command(c *check.C) { - s.UseCommandLine(c, "-Wall") + s.Init(c) + s.UseCommandLine("-Wall") G.globalData.InitVartypes() G.Mk = s.NewMkLines("security/openssl/Makefile", mkrcsid, @@ -765,7 +798,8 @@ func (s *Suite) Test_MkLine_CheckCond_comparison_with_shell_command(c *check.C) } func (s *Suite) Test_MkLine_CheckCond_comparing_PKGSRC_COMPILER_with_eqeq(c *check.C) { - s.UseCommandLine(c, "-Wall") + s.Init(c) + s.UseCommandLine("-Wall") G.globalData.InitVartypes() G.Mk = s.NewMkLines("audio/pulseaudio/Makefile", mkrcsid, @@ -778,7 +812,8 @@ func (s *Suite) Test_MkLine_CheckCond_comparing_PKGSRC_COMPILER_with_eqeq(c *che } func (s *Suite) Test_MkLine_Pkgmandir(c *check.C) { - s.UseCommandLine(c, "-Wall") + s.Init(c) + s.UseCommandLine("-Wall") G.globalData.InitVartypes() G.Mk = s.NewMkLines("chat/ircII/Makefile", mkrcsid, @@ -791,7 +826,8 @@ func (s *Suite) Test_MkLine_Pkgmandir(c *check.C) { } func (s *Suite) Test_MkLine_Check_CFLAGS_with_backticks(c *check.C) { - s.UseCommandLine(c, "-Wall") + s.Init(c) + s.UseCommandLine("-Wall") G.globalData.InitVartypes() G.Mk = s.NewMkLines("chat/pidgin-icb/Makefile", mkrcsid, @@ -809,7 +845,8 @@ func (s *Suite) Test_MkLine_Check_CFLAGS_with_backticks(c *check.C) { } func (s *Suite) Test_MkLine_Check_VERSION_as_wordpart_in_MASTER_SITES(c *check.C) { - s.UseCommandLine(c, "-Wall") + s.Init(c) + s.UseCommandLine("-Wall") G.globalData.InitVartypes() mklines := s.NewMkLines("geography/viking/Makefile", mkrcsid, @@ -822,7 +859,8 @@ func (s *Suite) Test_MkLine_Check_VERSION_as_wordpart_in_MASTER_SITES(c *check.C } func (s *Suite) Test_MkLine_Check_shell_command_as_wordpart_in_ENV_list(c *check.C) { - s.UseCommandLine(c, "-Wall") + s.Init(c) + s.UseCommandLine("-Wall") G.globalData.InitVartypes() mklines := s.NewMkLines("x11/lablgtk1/Makefile", mkrcsid, @@ -836,7 +874,8 @@ func (s *Suite) Test_MkLine_Check_shell_command_as_wordpart_in_ENV_list(c *check } func (s *Suite) Test_MkLine_shell_varuse_in_backt_dquot(c *check.C) { - s.UseCommandLine(c, "-Wall") + s.Init(c) + s.UseCommandLine("-Wall") G.globalData.InitVartypes() mklines := s.NewMkLines("x11/motif/Makefile", mkrcsid, @@ -873,6 +912,18 @@ func (s *Suite) Test_MkLine_CheckVartype_CFLAGS(c *check.C) { "WARN: Makefile:2: Compiler flag \"%s\\\\\\\"\" should start with a hyphen.\n") } +// PR 51696, security/py-pbkdf2/Makefile, r1.2 +func (s *Suite) Test_MkLine__comment_in_comment(c *check.C) { + G.globalData.InitVartypes() + mklines := s.NewMkLines("Makefile", + mkrcsid, + "COMMENT=\tPKCS#5 v2.0 PBKDF2 Module") + + mklines.Check() + + c.Check(s.Output(), equals, "WARN: Makefile:2: The # character starts a comment.\n") +} + func (s *Suite) Test_Indentation(c *check.C) { ind := &Indentation{} diff --git a/pkgtools/pkglint/files/mklines_test.go b/pkgtools/pkglint/files/mklines_test.go index 330f3f88f61..24b63385a33 100644 --- a/pkgtools/pkglint/files/mklines_test.go +++ b/pkgtools/pkglint/files/mklines_test.go @@ -7,8 +7,9 @@ import ( const mkrcsid = "# $" + "NetBSD$" func (s *Suite) Test_MkLines_Check__autofix_conditional_indentation(c *check.C) { - s.UseCommandLine(c, "--autofix", "-Wspace") - tmpfile := s.CreateTmpFile(c, "fname.mk", "") + s.Init(c) + s.UseCommandLine("--autofix", "-Wspace") + tmpfile := s.CreateTmpFile("fname.mk", "") mklines := s.NewMkLines(tmpfile, mkrcsid, ".if defined(A)", @@ -26,7 +27,7 @@ func (s *Suite) Test_MkLines_Check__autofix_conditional_indentation(c *check.C) "AUTOFIX: ~/fname.mk:5: Replacing \".\" with \". \".\n"+ "AUTOFIX: ~/fname.mk:6: Replacing \".\" with \". \".\n"+ "AUTOFIX: ~/fname.mk: Has been auto-fixed. Please re-run pkglint.\n") - c.Check(s.LoadTmpFile(c, "fname.mk"), equals, ""+ + c.Check(s.LoadTmpFile("fname.mk"), equals, ""+ "# $"+"NetBSD$\n"+ ".if defined(A)\n"+ ". for a in ${A}\n"+ @@ -59,7 +60,8 @@ func (s *Suite) Test_MkLine_checklineInclude_Makefile(c *check.C) { } func (s *Suite) Test_MkLines_quoting_LDFLAGS_for_GNU_configure(c *check.C) { - s.UseCommandLine(c, "-Wall") + s.Init(c) + s.UseCommandLine("-Wall") G.globalData.InitVartypes() G.Pkg = NewPackage("category/pkgbase") mklines := s.NewMkLines("Makefile", @@ -75,8 +77,9 @@ func (s *Suite) Test_MkLines_quoting_LDFLAGS_for_GNU_configure(c *check.C) { } func (s *Suite) Test_MkLines__variable_alignment_advanced(c *check.C) { - s.UseCommandLine(c, "-Wspace") - fname := s.CreateTmpFileLines(c, "Makefile", + s.Init(c) + s.UseCommandLine("-Wspace") + fname := s.CreateTmpFileLines("Makefile", mkrcsid, "", "VAR= \\", // In continuation lines, indenting with spaces is ok @@ -111,7 +114,7 @@ func (s *Suite) Test_MkLines__variable_alignment_advanced(c *check.C) { "NOTE: ~/Makefile:17: This variable value should be aligned with tabs, not spaces, to column 17.\n"+ "NOTE: ~/Makefile:18: This variable value should be aligned with tabs, not spaces, to column 17.\n") - s.UseCommandLine(c, "-Wspace", "--autofix") + s.UseCommandLine("-Wspace", "--autofix") mklines.Check() @@ -124,7 +127,7 @@ func (s *Suite) Test_MkLines__variable_alignment_advanced(c *check.C) { "AUTOFIX: ~/Makefile:17: Replacing \"GRP_AAA= \" with \"GRP_AAA=\\t\".\n"+ "AUTOFIX: ~/Makefile:18: Replacing \"GRP_AAAA= \" with \"GRP_AAAA=\\t\".\n"+ "AUTOFIX: ~/Makefile: Has been auto-fixed. Please re-run pkglint.\n") - c.Check(s.LoadTmpFile(c, "Makefile"), equals, ""+ + c.Check(s.LoadTmpFile("Makefile"), equals, ""+ "# $"+"NetBSD$\n"+ "\n"+ "VAR= \\\n"+ @@ -149,7 +152,8 @@ func (s *Suite) Test_MkLines__variable_alignment_advanced(c *check.C) { } func (s *Suite) Test_MkLines__variable_alignment_space_and_tab(c *check.C) { - s.UseCommandLine(c, "-Wspace") + s.Init(c) + s.UseCommandLine("-Wspace") mklines := s.NewMkLines("Makefile", mkrcsid, "", @@ -162,7 +166,8 @@ func (s *Suite) Test_MkLines__variable_alignment_space_and_tab(c *check.C) { } func (s *Suite) Test_MkLines__for_loop_multiple_variables(c *check.C) { - s.UseCommandLine(c, "-Wall") + s.Init(c) + s.UseCommandLine("-Wall") s.RegisterTool(&Tool{Name: "echo", Varname: "ECHO", Predefined: true}) s.RegisterTool(&Tool{Name: "find", Varname: "FIND", Predefined: true}) s.RegisterTool(&Tool{Name: "pax", Varname: "PAX", Predefined: true}) @@ -183,7 +188,8 @@ func (s *Suite) Test_MkLines__for_loop_multiple_variables(c *check.C) { } func (s *Suite) Test_MkLines__comparing_YesNo_variable_to_string(c *check.C) { - s.UseCommandLine(c, "-Wall") + s.Init(c) + s.UseCommandLine("-Wall") G.globalData.InitVartypes() mklines := s.NewMkLines("databases/gdbm_compat/builtin.mk", mkrcsid, @@ -199,7 +205,8 @@ func (s *Suite) Test_MkLines__comparing_YesNo_variable_to_string(c *check.C) { } func (s *Suite) Test_MkLines__varuse_sh_modifier(c *check.C) { - s.UseCommandLine(c, "-Wall") + s.Init(c) + s.UseCommandLine("-Wall") G.globalData.InitVartypes() mklines := s.NewMkLines("lang/qore/module.mk", mkrcsid, @@ -220,7 +227,8 @@ func (s *Suite) Test_MkLines__varuse_sh_modifier(c *check.C) { } func (s *Suite) Test_MkLines__varuse_parameterized(c *check.C) { - s.UseCommandLine(c, "-Wall") + s.Init(c) + s.UseCommandLine("-Wall") G.globalData.InitVartypes() mklines := s.NewMkLines("converters/wv2/Makefile", mkrcsid, @@ -233,7 +241,8 @@ func (s *Suite) Test_MkLines__varuse_parameterized(c *check.C) { } func (s *Suite) Test_MkLines__loop_modifier(c *check.C) { - s.UseCommandLine(c, "-Wall") + s.Init(c) + s.UseCommandLine("-Wall") G.globalData.InitVartypes() mklines := s.NewMkLines("chat/xchat/Makefile", mkrcsid, @@ -266,7 +275,8 @@ func (s *Suite) Test_MkLines__PKG_SKIP_REASON_depending_on_OPSYS(c *check.C) { // PR 46570, item "15. net/uucp/Makefile has a make loop" func (s *Suite) Test_MkLines__indirect_variables(c *check.C) { - s.UseCommandLine(c, "-Wall") + s.Init(c) + s.UseCommandLine("-Wall") mklines := s.NewMkLines("net/uucp/Makefile", mkrcsid, "", @@ -283,7 +293,8 @@ func (s *Suite) Test_MkLines__indirect_variables(c *check.C) { } func (s *Suite) Test_MkLines_Check__list_variable_as_part_of_word(c *check.C) { - s.UseCommandLine(c, "-Wall") + s.Init(c) + s.UseCommandLine("-Wall") mklines := s.NewMkLines("converters/chef/Makefile", mkrcsid, "\tcd ${WRKSRC} && tr '\\r' '\\n' < ${DISTDIR}/${DIST_SUBDIR}/${DISTFILES} > chef.l") @@ -296,7 +307,8 @@ func (s *Suite) Test_MkLines_Check__list_variable_as_part_of_word(c *check.C) { } func (s *Suite) Test_MkLines_Check__absolute_pathname_depending_on_OPSYS(c *check.C) { - s.UseCommandLine(c, "-Wall") + s.Init(c) + s.UseCommandLine("-Wall") G.globalData.InitVartypes() mklines := s.NewMkLines("games/heretic2-demo/Makefile", mkrcsid, @@ -316,7 +328,8 @@ func (s *Suite) Test_MkLines_Check__absolute_pathname_depending_on_OPSYS(c *chec } func (s *Suite) Test_MkLines_checkForUsedComment(c *check.C) { - s.UseCommandLine(c, "--show-autofix") + s.Init(c) + s.UseCommandLine("--show-autofix") s.NewMkLines("Makefile.common", mkrcsid, "", @@ -390,8 +403,9 @@ func (s *Suite) Test_MkLines_DetermineUsedVariables__nested(c *check.C) { } func (s *Suite) Test_MkLines_PrivateTool_Undefined(c *check.C) { + s.Init(c) + s.UseCommandLine("-Wall") G.globalData.InitVartypes() - s.UseCommandLine(c, "-Wall") mklines := s.NewMkLines("fname", mkrcsid, "", @@ -403,8 +417,9 @@ func (s *Suite) Test_MkLines_PrivateTool_Undefined(c *check.C) { } func (s *Suite) Test_MkLines_PrivateTool_Defined(c *check.C) { + s.Init(c) + s.UseCommandLine("-Wall") G.globalData.InitVartypes() - s.UseCommandLine(c, "-Wall") mklines := s.NewMkLines("fname", mkrcsid, "TOOLS_CREATE+=\tmd5sum", @@ -417,7 +432,8 @@ func (s *Suite) Test_MkLines_PrivateTool_Defined(c *check.C) { } func (s *Suite) Test_MkLines_Check_indentation(c *check.C) { - s.UseCommandLine(c, "-Wall") + s.Init(c) + s.UseCommandLine("-Wall") mklines := s.NewMkLines("options.mk", mkrcsid, ". if !defined(GUARD_MK)", diff --git a/pkgtools/pkglint/files/package_test.go b/pkgtools/pkglint/files/package_test.go index a11b22463c0..1bd4e2ec232 100644 --- a/pkgtools/pkglint/files/package_test.go +++ b/pkgtools/pkglint/files/package_test.go @@ -22,7 +22,8 @@ func (s *Suite) Test_Package_pkgnameFromDistname(c *check.C) { } func (s *Suite) Test_Package_ChecklinesPackageMakefileVarorder(c *check.C) { - s.UseCommandLine(c, "-Worder") + s.Init(c) + s.UseCommandLine("-Worder") pkg := NewPackage("x11/9term") pkg.ChecklinesPackageMakefileVarorder(s.NewMkLines("Makefile", @@ -99,7 +100,8 @@ func (s *Suite) Test_Package_checkPossibleDowngrade(c *check.C) { } func (s *Suite) Test_checkdirPackage(c *check.C) { - s.CreateTmpFile(c, "Makefile", ""+ + s.Init(c) + s.CreateTmpFile("Makefile", ""+ "# $"+"NetBSD$\n") G.CurrentDir = s.tmpdir @@ -113,44 +115,46 @@ func (s *Suite) Test_checkdirPackage(c *check.C) { } func (s *Suite) Test_checkdirPackage__meta_package_without_license(c *check.C) { - s.CreateTmpFileLines(c, "Makefile", + s.Init(c) + s.CreateTmpFileLines("Makefile", mkrcsid, "", "META_PACKAGE=\tyes") - G.CurrentDir = s.tmpdir + G.CurrentDir = s.TmpDir() G.globalData.InitVartypes() - checkdirPackage(s.tmpdir) + checkdirPackage(s.TmpDir()) c.Check(s.Output(), equals, "WARN: ~/Makefile: No COMMENT given.\n") // No error about missing LICENSE. } func (s *Suite) Test_Package__varuse_at_load_time(c *check.C) { - s.CreateTmpFileLines(c, "doc/CHANGES-2016", + s.Init(c) + s.CreateTmpFileLines("doc/CHANGES-2016", "# dummy") - s.CreateTmpFileLines(c, "doc/TODO", + s.CreateTmpFileLines("doc/TODO", "# dummy") - s.CreateTmpFileLines(c, "licenses/bsd-2", + s.CreateTmpFileLines("licenses/bsd-2", "# dummy") - s.CreateTmpFileLines(c, "mk/fetch/sites.mk", + s.CreateTmpFileLines("mk/fetch/sites.mk", "# dummy") - s.CreateTmpFileLines(c, "mk/bsd.pkg.mk", + s.CreateTmpFileLines("mk/bsd.pkg.mk", "# dummy") - s.CreateTmpFileLines(c, "mk/defaults/options.description", + s.CreateTmpFileLines("mk/defaults/options.description", "option Description") - s.CreateTmpFileLines(c, "mk/defaults/mk.conf", + s.CreateTmpFileLines("mk/defaults/mk.conf", "# dummy") - s.CreateTmpFileLines(c, "mk/tools/bsd.tools.mk", + s.CreateTmpFileLines("mk/tools/bsd.tools.mk", ".include \"defaults.mk\"") - s.CreateTmpFileLines(c, "mk/tools/defaults.mk", + s.CreateTmpFileLines("mk/tools/defaults.mk", "TOOLS_CREATE+=false", "TOOLS_CREATE+=nice", "TOOLS_CREATE+=true", "_TOOLS_VARNAME.nice=NICE") - s.CreateTmpFileLines(c, "mk/bsd.prefs.mk", + s.CreateTmpFileLines("mk/bsd.prefs.mk", "# dummy") - s.CreateTmpFileLines(c, "category/pkgbase/Makefile", + s.CreateTmpFileLines("category/pkgbase/Makefile", mkrcsid, "", "COMMENT= Unit test", @@ -175,7 +179,7 @@ func (s *Suite) Test_Package__varuse_at_load_time(c *check.C) { "\t${ECHO}; ${FALSE}; ${NICE}; ${TRUE}", "", ".include \"../../mk/bsd.pkg.mk\"") - s.CreateTmpFileLines(c, "category/pkgbase/distinfo", + s.CreateTmpFileLines("category/pkgbase/distinfo", "$"+"NetBSD$") (&Pkglint{}).Main("pkglint", "-q", "-Wperm", s.tmpdir+"/category/pkgbase") @@ -188,7 +192,8 @@ func (s *Suite) Test_Package__varuse_at_load_time(c *check.C) { } func (s *Suite) Test_Package_loadPackageMakefile(c *check.C) { - makefile := s.CreateTmpFile(c, "category/package/Makefile", ""+ + s.Init(c) + makefile := s.CreateTmpFile("category/package/Makefile", ""+ "# $"+"NetBSD$\n"+ "\n"+ "PKGNAME=pkgname-1.67\n"+ @@ -205,8 +210,9 @@ func (s *Suite) Test_Package_loadPackageMakefile(c *check.C) { } func (s *Suite) Test_Package_conditionalAndUnconditionalInclude(c *check.C) { + s.Init(c) G.globalData.InitVartypes() - s.CreateTmpFileLines(c, "category/package/Makefile", + s.CreateTmpFileLines("category/package/Makefile", mkrcsid, "", "COMMENT\t=Description", @@ -216,23 +222,23 @@ func (s *Suite) Test_Package_conditionalAndUnconditionalInclude(c *check.C) { ".include \"../../sysutils/coreutils/buildlink3.mk\"", ".endif", ".include \"../../mk/bsd.pkg.mk\"") - s.CreateTmpFileLines(c, "category/package/options.mk", + s.CreateTmpFileLines("category/package/options.mk", mkrcsid, "", ".if !empty(PKG_OPTIONS:Mzlib)", ". include \"../../devel/zlib/buildlink3.mk\"", ".endif", ".include \"../../sysutils/coreutils/buildlink3.mk\"") - s.CreateTmpFileLines(c, "category/package/PLIST", + s.CreateTmpFileLines("category/package/PLIST", "@comment $"+"NetBSD$", "bin/program") - s.CreateTmpFileLines(c, "category/package/distinfo", + s.CreateTmpFileLines("category/package/distinfo", "$"+"NetBSD$") - s.CreateTmpFileLines(c, "devel/zlib/buildlink3.mk", "") - s.CreateTmpFileLines(c, "licenses/gnu-gpl-v2", "") - s.CreateTmpFileLines(c, "mk/bsd.pkg.mk", "") - s.CreateTmpFileLines(c, "sysutils/coreutils/buildlink3.mk", "") + s.CreateTmpFileLines("devel/zlib/buildlink3.mk", "") + s.CreateTmpFileLines("licenses/gnu-gpl-v2", "") + s.CreateTmpFileLines("mk/bsd.pkg.mk", "") + s.CreateTmpFileLines("sysutils/coreutils/buildlink3.mk", "") pkg := NewPackage("category/package") G.globalData.Pkgsrcdir = s.tmpdir diff --git a/pkgtools/pkglint/files/patches_test.go b/pkgtools/pkglint/files/patches_test.go index 935ab745ed4..d57fc1fa289 100644 --- a/pkgtools/pkglint/files/patches_test.go +++ b/pkgtools/pkglint/files/patches_test.go @@ -6,7 +6,8 @@ import ( ) func (s *Suite) Test_ChecklinesPatch__with_comment(c *check.C) { - s.UseCommandLine(c, "-Wall") + s.Init(c) + s.UseCommandLine("-Wall") lines := s.NewLines("patch-WithComment", "$"+"NetBSD$", "", @@ -27,8 +28,9 @@ func (s *Suite) Test_ChecklinesPatch__with_comment(c *check.C) { } func (s *Suite) Test_ChecklinesPatch__without_empty_line(c *check.C) { - fname := s.CreateTmpFile(c, "patch-WithoutEmptyLines", "dummy") - s.UseCommandLine(c, "-Wall", "--autofix") + s.Init(c) + fname := s.CreateTmpFile("patch-WithoutEmptyLines", "dummy") + s.UseCommandLine("-Wall", "--autofix") lines := s.NewLines(fname, "$"+"NetBSD$", "Text", @@ -64,7 +66,8 @@ func (s *Suite) Test_ChecklinesPatch__without_empty_line(c *check.C) { } func (s *Suite) Test_ChecklinesPatch__without_comment(c *check.C) { - s.UseCommandLine(c, "-Wall") + s.Init(c) + s.UseCommandLine("-Wall") lines := s.NewLines("patch-WithoutComment", "$"+"NetBSD$", "", @@ -82,7 +85,8 @@ func (s *Suite) Test_ChecklinesPatch__without_comment(c *check.C) { } func (s *Suite) Test_ChecklinesPatch__git_without_comment(c *check.C) { - s.UseCommandLine(c, "-Wall") + s.Init(c) + s.UseCommandLine("-Wall") lines := s.NewLines("patch-aa", "$"+"NetBSD$", "", @@ -108,7 +112,8 @@ func (s *Suite) Test_checklineOtherAbsolutePathname(c *check.C) { } func (s *Suite) Test_ChecklinesPatch__error_code(c *check.C) { - s.UseCommandLine(c, "-Wall") + s.Init(c) + s.UseCommandLine("-Wall") lines := s.NewLines("patch-ErrorCode", "$"+"NetBSD$", "", @@ -128,7 +133,8 @@ func (s *Suite) Test_ChecklinesPatch__error_code(c *check.C) { } func (s *Suite) Test_ChecklinesPatch__wrong_header_order(c *check.C) { - s.UseCommandLine(c, "-Wall") + s.Init(c) + s.UseCommandLine("-Wall") lines := s.NewLines("patch-WrongOrder", "$"+"NetBSD$", "", @@ -149,7 +155,8 @@ func (s *Suite) Test_ChecklinesPatch__wrong_header_order(c *check.C) { } func (s *Suite) Test_ChecklinesPatch__context_diff(c *check.C) { - s.UseCommandLine(c, "-Wall") + s.Init(c) + s.UseCommandLine("-Wall") lines := s.NewLines("patch-ctx", "$"+"NetBSD$", "", diff --git a/pkgtools/pkglint/files/pkglint.go b/pkgtools/pkglint/files/pkglint.go index 29919fbd6d8..0d9d94cff29 100644 --- a/pkgtools/pkglint/files/pkglint.go +++ b/pkgtools/pkglint/files/pkglint.go @@ -305,7 +305,7 @@ func ChecklinesTrailingEmptyLines(lines []*Line) { } } -func MatchVarassign(text string) (m bool, varname, spaceAfterVarname, op, valueAlign, value, comment string) { +func MatchVarassign(text string) (m bool, varname, spaceAfterVarname, op, valueAlign, value, spaceAfterValue, comment string) { i, n := 0, len(text) for i < n && text[i] == ' ' { @@ -373,6 +373,11 @@ func MatchVarassign(text string) (m bool, varname, spaceAfterVarname, op, valueA } commentStart := i + for text[i-1] == ' ' || text[i-1] == '\t' { + i-- + } + valueEnd := i + commentEnd := n m = true @@ -381,6 +386,7 @@ func MatchVarassign(text string) (m bool, varname, spaceAfterVarname, op, valueA op = text[opStart:opEnd] valueAlign = text[0:valueStart] value = strings.TrimSpace(string(valuebuf[:j])) + spaceAfterValue = text[valueEnd:commentStart] comment = text[commentStart:commentEnd] return } @@ -395,16 +401,26 @@ type DependencyPattern struct { } func resolveVarsInRelativePath(relpath string, adjustDepth bool) string { - tmp := relpath tmp = strings.Replace(tmp, "${PKGSRCDIR}", G.CurPkgsrcdir, -1) tmp = strings.Replace(tmp, "${.CURDIR}", ".", -1) tmp = strings.Replace(tmp, "${.PARSEDIR}", ".", -1) - tmp = strings.Replace(tmp, "${LUA_PKGSRCDIR}", "../../lang/lua52", -1) - tmp = strings.Replace(tmp, "${PHPPKGSRCDIR}", "../../lang/php56", -1) - tmp = strings.Replace(tmp, "${SUSE_DIR_PREFIX}", "suse100", -1) - tmp = strings.Replace(tmp, "${PYPKGSRCDIR}", "../../lang/python27", -1) - tmp = strings.Replace(tmp, "${PYPACKAGE}", "python27", -1) + if contains(tmp, "${LUA_PKGSRCDIR}") { + tmp = strings.Replace(tmp, "${LUA_PKGSRCDIR}", G.globalData.Latest("lang", `^lua[0-9]+$`, "../../lang/$0"), -1) + } + if contains(tmp, "${PHPPKGSRCDIR}") { + tmp = strings.Replace(tmp, "${PHPPKGSRCDIR}", G.globalData.Latest("lang", `^php[0-9]+$`, "../../lang/$0"), -1) + } + if contains(tmp, "${SUSE_DIR_PREFIX}") { + suseDirPrefix := G.globalData.Latest("emulators", `^(suse[0-9]+)_base`, "$1") + tmp = strings.Replace(tmp, "${SUSE_DIR_PREFIX}", suseDirPrefix, -1) + } + if contains(tmp, "${PYPKGSRCDIR}") { + tmp = strings.Replace(tmp, "${PYPKGSRCDIR}", G.globalData.Latest("lang", `^python[0-9]+$`, "../../lang/$0"), -1) + } + if contains(tmp, "${PYPACKAGE}") { + tmp = strings.Replace(tmp, "${PYPACKAGE}", G.globalData.Latest("lang", `^python[0-9]+$`, "$0"), -1) + } if G.Pkg != nil { tmp = strings.Replace(tmp, "${FILESDIR}", G.Pkg.Filesdir, -1) tmp = strings.Replace(tmp, "${PKGDIR}", G.Pkg.Pkgdir, -1) diff --git a/pkgtools/pkglint/files/pkglint_test.go b/pkgtools/pkglint/files/pkglint_test.go index 1fd91217441..486a96178f8 100644 --- a/pkgtools/pkglint/files/pkglint_test.go +++ b/pkgtools/pkglint/files/pkglint_test.go @@ -41,34 +41,35 @@ func (s *Suite) Test_resolveVariableRefs__special_chars(c *check.C) { } func (s *Suite) Test_MatchVarassign(c *check.C) { - checkVarassign := func(text string, ck check.Checker, varname, spaceAfterVarname, op, align, value, comment string) { + checkVarassign := func(text string, ck check.Checker, varname, spaceAfterVarname, op, align, value, spaceAfterValue, comment string) { type va struct { - varname, spaceAfterVarname, op, align, value, comment string + varname, spaceAfterVarname, op, align, value, spaceAfterValue, comment string } - expected := va{varname, spaceAfterVarname, op, align, value, comment} - am, avarname, aspaceAfterVarname, aop, aalign, avalue, acomment := MatchVarassign(text) + expected := va{varname, spaceAfterVarname, op, align, value, spaceAfterValue, comment} + am, avarname, aspaceAfterVarname, aop, aalign, avalue, aspaceAfterValue, acomment := MatchVarassign(text) if !am { c.Errorf("Text %q doesn’t match variable assignment", text) return } - actual := va{avarname, aspaceAfterVarname, aop, aalign, avalue, acomment} + actual := va{avarname, aspaceAfterVarname, aop, aalign, avalue, aspaceAfterValue, acomment} c.Check(actual, ck, expected) } checkNotVarassign := func(text string) { - m, _, _, _, _, _, _ := MatchVarassign(text) + m, _, _, _, _, _, _, _ := MatchVarassign(text) if m { c.Errorf("Text %q matches variable assignment, but shouldn’t.", text) } } - checkVarassign("C++=c11", equals, "C+", "", "+=", "C++=", "c11", "") - checkVarassign("V=v", equals, "V", "", "=", "V=", "v", "") - checkVarassign("VAR=#comment", equals, "VAR", "", "=", "VAR=", "", "#comment") - checkVarassign("VAR=\\#comment", equals, "VAR", "", "=", "VAR=", "#comment", "") - checkVarassign("VAR=\\\\\\##comment", equals, "VAR", "", "=", "VAR=", "\\\\#", "#comment") - checkVarassign("VAR=\\", equals, "VAR", "", "=", "VAR=", "\\", "") - checkVarassign("VAR += value", equals, "VAR", " ", "+=", "VAR += ", "value", "") - checkVarassign(" VAR=value", equals, "VAR", "", "=", " VAR=", "value", "") + checkVarassign("C++=c11", equals, "C+", "", "+=", "C++=", "c11", "", "") + checkVarassign("V=v", equals, "V", "", "=", "V=", "v", "", "") + checkVarassign("VAR=#comment", equals, "VAR", "", "=", "VAR=", "", "", "#comment") + checkVarassign("VAR=\\#comment", equals, "VAR", "", "=", "VAR=", "#comment", "", "") + checkVarassign("VAR=\\\\\\##comment", equals, "VAR", "", "=", "VAR=", "\\\\#", "", "#comment") + checkVarassign("VAR=\\", equals, "VAR", "", "=", "VAR=", "\\", "", "") + checkVarassign("VAR += value", equals, "VAR", " ", "+=", "VAR += ", "value", "", "") + checkVarassign(" VAR=value", equals, "VAR", "", "=", " VAR=", "value", "", "") + checkVarassign("VAR=value #comment", equals, "VAR", "", "=", "VAR=", "value", " ", "#comment") checkNotVarassign("\tVAR=value") checkNotVarassign("?=value") checkNotVarassign("<=value") @@ -114,3 +115,37 @@ func (s *Suite) Test_ChecklinesMessage__malformed(c *check.C) { "ERROR: MESSAGE:2: Expected \"$"+"NetBSD$\".\n"+ "WARN: MESSAGE:5: Expected a line of exactly 75 \"=\" characters.\n") } + +func (s *Suite) Test_GlobalData_Latest(c *check.C) { + s.Init(c) + G.globalData.Pkgsrcdir = s.TmpDir() + + latest1 := G.globalData.Latest("lang", `^python[0-9]+$`, "../../lang/$0") + + c.Check(latest1, equals, "") + c.Check(s.Output(), equals, "ERROR: Cannot find latest version of \"^python[0-9]+$\" in \"~\".\n") + + s.CreateTmpFile("lang/Makefile", "") + G.globalData.latest = nil + + latest2 := G.globalData.Latest("lang", `^python[0-9]+$`, "../../lang/$0") + + c.Check(latest2, equals, "") + c.Check(s.Output(), equals, "ERROR: Cannot find latest version of \"^python[0-9]+$\" in \"~\".\n") + + s.CreateTmpFile("lang/python27/Makefile", "") + G.globalData.latest = nil + + latest3 := G.globalData.Latest("lang", `^python[0-9]+$`, "../../lang/$0") + + c.Check(latest3, equals, "../../lang/python27") + c.Check(s.Output(), equals, "") + + s.CreateTmpFile("lang/python35/Makefile", "") + G.globalData.latest = nil + + latest4 := G.globalData.Latest("lang", `^python[0-9]+$`, "../../lang/$0") + + c.Check(latest4, equals, "../../lang/python35") + c.Check(s.Output(), equals, "") +} diff --git a/pkgtools/pkglint/files/plist_test.go b/pkgtools/pkglint/files/plist_test.go index 3c3767f82a9..d0267430820 100644 --- a/pkgtools/pkglint/files/plist_test.go +++ b/pkgtools/pkglint/files/plist_test.go @@ -5,7 +5,8 @@ import ( ) func (s *Suite) Test_ChecklinesPlist(c *check.C) { - s.UseCommandLine(c, "-Wall") + s.Init(c) + s.UseCommandLine("-Wall") G.Pkg = NewPackage("category/pkgbase") lines := s.NewLines("PLIST", "bin/i386/6c", @@ -56,10 +57,11 @@ func (s *Suite) Test_ChecklinesPlist__empty(c *check.C) { } func (s *Suite) Test_ChecklinesPlist__commonEnd(c *check.C) { - s.CreateTmpFile(c, "PLIST.common", ""+ + s.Init(c) + s.CreateTmpFile("PLIST.common", ""+ "@comment $"+"NetBSD$\n"+ "bin/common\n") - fname := s.CreateTmpFile(c, "PLIST.common_end", ""+ + fname := s.CreateTmpFile("PLIST.common_end", ""+ "@comment $"+"NetBSD$\n"+ "sbin/common_end\n") @@ -81,7 +83,8 @@ func (s *Suite) Test_ChecklinesPlist__conditional(c *check.C) { } func (s *Suite) Test_ChecklinesPlist__sorting(c *check.C) { - s.UseCommandLine(c, "-Wplist-sort") + s.Init(c) + s.UseCommandLine("-Wplist-sort") lines := s.NewLines("PLIST", "@comment $"+"NetBSD$", "@comment Do not remove", @@ -98,9 +101,9 @@ func (s *Suite) Test_ChecklinesPlist__sorting(c *check.C) { } func (s *Suite) Test_PlistLineSorter_Sort(c *check.C) { - s.UseCommandLine(c, "--autofix") - tmpfile := s.CreateTmpFile(c, "PLIST", "dummy\n") - ck := &PlistChecker{nil, nil, ""} + s.Init(c) + s.UseCommandLine("--autofix") + tmpfile := s.CreateTmpFile("PLIST", "dummy\n") lines := s.NewLines(tmpfile, "@comment $"+"NetBSD$", "@comment Do not remove", @@ -118,6 +121,7 @@ func (s *Suite) Test_PlistLineSorter_Sort(c *check.C) { "lib/before.la", "lib/after.la", "@exec echo \"after lib/after.la\"") + ck := &PlistChecker{nil, nil, ""} plines := ck.NewLines(lines) NewPlistLineSorter(plines).Sort() @@ -125,7 +129,7 @@ func (s *Suite) Test_PlistLineSorter_Sort(c *check.C) { c.Check(s.Output(), equals, ""+ "AUTOFIX: ~/PLIST:1: Sorting the whole file.\n"+ "AUTOFIX: ~/PLIST: Has been auto-fixed. Please re-run pkglint.\n") - c.Check(s.LoadTmpFile(c, "PLIST"), equals, ""+ + c.Check(s.LoadTmpFile("PLIST"), equals, ""+ "@comment $"+"NetBSD$\n"+ "@comment Do not remove\n"+ "A\n"+ @@ -148,7 +152,8 @@ func (s *Suite) Test_PlistChecker_checkpathShare_Desktop(c *check.C) { // Disabled due to PR 46570, item "10. It should stop". return - s.UseCommandLine(c, "-Wextra") + s.Init(c) + s.UseCommandLine("-Wextra") G.Pkg = NewPackage("category/pkgpath") ChecklinesPlist(s.NewLines("PLIST", @@ -189,9 +194,10 @@ func (s *Suite) TestPlistChecker_checkpath__python_egg(c *check.C) { } func (s *Suite) Test_PlistChecker__autofix(c *check.C) { - s.UseCommandLine(c, "-Wall") + s.Init(c) + s.UseCommandLine("-Wall") - fname := s.CreateTmpFileLines(c, "PLIST", + fname := s.CreateTmpFileLines("PLIST", "@comment $"+"NetBSD$", "lib/libvirt/connection-driver/libvirt_driver_storage.la", "${PLIST.hal}lib/libvirt/connection-driver/libvirt_driver_nodedev.la", @@ -220,7 +226,7 @@ func (s *Suite) Test_PlistChecker__autofix(c *check.C) { "WARN: ~/PLIST:4: \"lib/libvirt/connection-driver/libvirt_driver_libxl.la\" should be sorted before \"lib/libvirt/connection-driver/libvirt_driver_nodedev.la\".\n"+ "NOTE: ~/PLIST:6: PLIST files should mention \"man/\" instead of \"${PKGMANDIR}\".\n") - s.UseCommandLine(c, "-Wall", "--autofix") + s.UseCommandLine("-Wall", "--autofix") ChecklinesPlist(lines) fixedLines := LoadExistingLines(fname, false) @@ -230,7 +236,7 @@ func (s *Suite) Test_PlistChecker__autofix(c *check.C) { "AUTOFIX: ~/PLIST:1: Sorting the whole file.\n"+ "AUTOFIX: ~/PLIST: Has been auto-fixed. Please re-run pkglint.\n") c.Check(len(lines), equals, len(fixedLines)) - c.Check(s.LoadTmpFile(c, "PLIST"), equals, ""+ + c.Check(s.LoadTmpFile("PLIST"), equals, ""+ "@comment $"+"NetBSD$\n"+ "${PLIST.xen}lib/libvirt/connection-driver/libvirt_driver_libxl.la\n"+ "${PLIST.hal}lib/libvirt/connection-driver/libvirt_driver_nodedev.la\n"+ diff --git a/pkgtools/pkglint/files/shell_test.go b/pkgtools/pkglint/files/shell_test.go index 6824fbb934c..0079fab8fa4 100644 --- a/pkgtools/pkglint/files/shell_test.go +++ b/pkgtools/pkglint/files/shell_test.go @@ -102,7 +102,8 @@ func (s *Suite) Test_splitIntoShellTokens__redirect(c *check.C) { } func (s *Suite) Test_ShellLine_CheckShellCommandLine(c *check.C) { - s.UseCommandLine(c, "-Wall") + s.Init(c) + s.UseCommandLine("-Wall") G.Mk = s.NewMkLines("fname", "# dummy") shline := NewShellLine(G.Mk.mklines[0]) @@ -228,7 +229,8 @@ func (s *Suite) Test_ShellLine_CheckShellCommandLine(c *check.C) { } func (s *Suite) Test_ShellLine_CheckShellCommandLine__nofix(c *check.C) { - s.UseCommandLine(c, "-Wall") + s.Init(c) + s.UseCommandLine("-Wall") G.globalData.InitVartypes() s.RegisterTool(&Tool{Name: "echo", Predefined: true}) G.Mk = s.NewMkLines("Makefile", @@ -245,7 +247,8 @@ func (s *Suite) Test_ShellLine_CheckShellCommandLine__nofix(c *check.C) { } func (s *Suite) Test_ShellLine_CheckShellCommandLine__show_autofix(c *check.C) { - s.UseCommandLine(c, "-Wall", "--show-autofix") + s.Init(c) + s.UseCommandLine("-Wall", "--show-autofix") G.globalData.InitVartypes() s.RegisterTool(&Tool{Name: "echo", Predefined: true}) G.Mk = s.NewMkLines("Makefile", @@ -260,7 +263,8 @@ func (s *Suite) Test_ShellLine_CheckShellCommandLine__show_autofix(c *check.C) { } func (s *Suite) Test_ShellLine_CheckShellCommandLine__autofix(c *check.C) { - s.UseCommandLine(c, "-Wall", "--autofix") + s.Init(c) + s.UseCommandLine("-Wall", "--autofix") G.globalData.InitVartypes() s.RegisterTool(&Tool{Name: "echo", Predefined: true}) G.Mk = s.NewMkLines("Makefile", @@ -274,7 +278,8 @@ func (s *Suite) Test_ShellLine_CheckShellCommandLine__autofix(c *check.C) { } func (s *Suite) Test_ShellLine_CheckShellCommandLine__implementation(c *check.C) { - s.UseCommandLine(c, "-Wall") + s.Init(c) + s.UseCommandLine("-Wall") G.globalData.InitVartypes() G.Mk = s.NewMkLines("fname", "# dummy") @@ -312,7 +317,8 @@ func (s *Suite) Test_ShellLine_CheckShelltext__dollar_without_variable(c *check. } func (s *Suite) Test_ShellLine_CheckWord(c *check.C) { - s.UseCommandLine(c, "-Wall") + s.Init(c) + s.UseCommandLine("-Wall") G.globalData.InitVartypes() shline := NewShellLine(NewMkLine(NewLine("fname", 1, "# dummy", nil))) @@ -362,7 +368,8 @@ func (s *Suite) Test_ShellLine_CheckWord__dollar_without_variable(c *check.C) { } func (s *Suite) Test_ShellLine_CheckShellCommandLine__echo(c *check.C) { - s.UseCommandLine(c, "-Wall") + s.Init(c) + s.UseCommandLine("-Wall") s.RegisterTool(&Tool{Name: "echo", Varname: "ECHO", MustUseVarForm: true, Predefined: true}) G.Mk = s.NewMkLines("fname", "# dummy") @@ -486,7 +493,8 @@ func (s *Suite) Test_ShellLine_CheckShellCommandLine__install_option_d(c *check. } func (s *Suite) Test_ShellLine__shell_comment_with_line_continuation(c *check.C) { - tmpfile := s.CreateTmpFile(c, "Makefile", ""+ + s.Init(c) + tmpfile := s.CreateTmpFile("Makefile", ""+ "# $"+"NetBSD$\n"+ "pre-install:\n"+ "\t"+"# comment\\\n"+ diff --git a/pkgtools/pkglint/files/substcontext_test.go b/pkgtools/pkglint/files/substcontext_test.go index 74ddf95adb6..e4824b3b4d3 100644 --- a/pkgtools/pkglint/files/substcontext_test.go +++ b/pkgtools/pkglint/files/substcontext_test.go @@ -67,7 +67,8 @@ func (s *Suite) Test_SubstContext__OPSYSVARS(c *check.C) { } func (s *Suite) Test_SubstContext__no_class(c *check.C) { - s.UseCommandLine(c, "-Wextra") + s.Init(c) + s.UseCommandLine("-Wextra") ctx := new(SubstContext) ctx.Varassign(newSubstLine(10, "UNRELATED=anything")) diff --git a/pkgtools/pkglint/files/toplevel_test.go b/pkgtools/pkglint/files/toplevel_test.go index 74e14b64251..5f810b781dd 100644 --- a/pkgtools/pkglint/files/toplevel_test.go +++ b/pkgtools/pkglint/files/toplevel_test.go @@ -5,7 +5,8 @@ import ( ) func (s *Suite) Test_CheckdirToplevel(c *check.C) { - s.CreateTmpFile(c, "Makefile", ""+ + s.Init(c) + s.CreateTmpFile("Makefile", ""+ "# $"+"NetBSD$\n"+ "\n"+ "SUBDIR+= x11\n"+ @@ -15,10 +16,10 @@ func (s *Suite) Test_CheckdirToplevel(c *check.C) { "#SUBDIR+=\tignoreme\n"+ "SUBDIR+=\tnonexisting\n"+ // This just doesn’t happen in practice. "SUBDIR+=\tbbb\n") - s.CreateTmpFile(c, "archivers/Makefile", "") - s.CreateTmpFile(c, "bbb/Makefile", "") - s.CreateTmpFile(c, "ccc/Makefile", "") - s.CreateTmpFile(c, "x11/Makefile", "") + s.CreateTmpFile("archivers/Makefile", "") + s.CreateTmpFile("bbb/Makefile", "") + s.CreateTmpFile("ccc/Makefile", "") + s.CreateTmpFile("x11/Makefile", "") G.globalData.InitVartypes() G.CurrentDir = s.tmpdir diff --git a/pkgtools/pkglint/files/util_test.go b/pkgtools/pkglint/files/util_test.go index ea2fa730943..9f9e1c20272 100644 --- a/pkgtools/pkglint/files/util_test.go +++ b/pkgtools/pkglint/files/util_test.go @@ -61,12 +61,13 @@ func (s *Suite) Test_cleanpath(c *check.C) { } func (s *Suite) Test_isEmptyDir_and_getSubdirs(c *check.C) { - s.CreateTmpFile(c, "CVS/Entries", "dummy\n") + s.Init(c) + s.CreateTmpFile("CVS/Entries", "dummy\n") c.Check(isEmptyDir(s.tmpdir), equals, true) c.Check(getSubdirs(s.tmpdir), check.DeepEquals, []string(nil)) - s.CreateTmpFile(c, "somedir/file", "") + s.CreateTmpFile("somedir/file", "") c.Check(isEmptyDir(s.tmpdir), equals, false) c.Check(getSubdirs(s.tmpdir), check.DeepEquals, []string{"somedir"}) diff --git a/pkgtools/pkglint/files/vardefs.go b/pkgtools/pkglint/files/vardefs.go index db16e601a58..b6e60b845a7 100644 --- a/pkgtools/pkglint/files/vardefs.go +++ b/pkgtools/pkglint/files/vardefs.go @@ -544,7 +544,7 @@ func (gd *GlobalData) InitVartypes() { pkg("PERL5_REQD", lkShell, BtVersion) pkg("PERL5_USE_PACKLIST", lkNone, BtYesNo) sys("PGSQL_PREFIX", lkNone, BtPathname) - acl("PGSQL_VERSIONS_ACCEPTED", lkShell, enum("91 92 93 94"), "") + acl("PGSQL_VERSIONS_ACCEPTED", lkShell, enum("91 92 93 94 95"), "") usr("PGSQL_VERSION_DEFAULT", lkNone, BtVersion) sys("PG_LIB_EXT", lkNone, enum("dylib so")) sys("PGSQL_TYPE", lkNone, enum("postgresql81-client postgresql80-client")) diff --git a/pkgtools/pkglint/files/vartypecheck.go b/pkgtools/pkglint/files/vartypecheck.go index 9d19db68dd4..f3ffa9b0af3 100644 --- a/pkgtools/pkglint/files/vartypecheck.go +++ b/pkgtools/pkglint/files/vartypecheck.go @@ -188,6 +188,10 @@ func (cv *VartypeCheck) Comment() { if len(value) > 70 { line.Warnf("COMMENT should not be longer than 70 characters.") } + if hasPrefix(value, "\"") && hasSuffix(value, "\"") || + hasPrefix(value, "'") && hasSuffix(value, "'") { + line.Warnf("COMMENT should not be enclosed in quotes.") + } } func (cv *VartypeCheck) Dependency() { diff --git a/pkgtools/pkglint/files/vartypecheck_test.go b/pkgtools/pkglint/files/vartypecheck_test.go index e338f924341..6b37a402a00 100644 --- a/pkgtools/pkglint/files/vartypecheck_test.go +++ b/pkgtools/pkglint/files/vartypecheck_test.go @@ -31,8 +31,9 @@ func (s *Suite) Test_VartypeCheck_BuildlinkDepmethod(c *check.C) { } func (s *Suite) Test_VartypeCheck_Category(c *check.C) { - s.CreateTmpFile(c, "filesyscategory/Makefile", "# empty\n") - s.CreateTmpFile(c, "wip/Makefile", "# empty\n") + s.Init(c) + s.CreateTmpFile("filesyscategory/Makefile", "# empty\n") + s.CreateTmpFile("wip/Makefile", "# empty\n") G.CurrentDir = s.tmpdir G.CurPkgsrcdir = "." @@ -67,14 +68,18 @@ func (s *Suite) Test_VartypeCheck_Comment(c *check.C) { "Versatile Programming Language", "TODO: Short description of the package", "A great package.", - "some packages need a very very long comment to explain their basic usefulness") + "some packages need a very very long comment to explain their basic usefulness", + "\"Quoting the comment is wrong\"", + "'Quoting the comment is wrong'") c.Check(s.Output(), equals, ""+ "ERROR: fname:2: COMMENT must be set.\n"+ "WARN: fname:3: COMMENT should not begin with \"A\".\n"+ "WARN: fname:3: COMMENT should not end with a period.\n"+ "WARN: fname:4: COMMENT should start with a capital letter.\n"+ - "WARN: fname:4: COMMENT should not be longer than 70 characters.\n") + "WARN: fname:4: COMMENT should not be longer than 70 characters.\n"+ + "WARN: fname:5: COMMENT should not be enclosed in quotes.\n"+ + "WARN: fname:6: COMMENT should not be enclosed in quotes.\n") } func (s *Suite) Test_VartypeCheck_Dependency(c *check.C) { @@ -115,8 +120,9 @@ func (s *Suite) Test_VartypeCheck_Dependency(c *check.C) { } func (s *Suite) Test_VartypeCheck_DependencyWithPath(c *check.C) { - s.CreateTmpFile(c, "x11/alacarte/Makefile", "# empty\n") - s.CreateTmpFile(c, "category/package/Makefile", "# empty\n") + s.Init(c) + s.CreateTmpFile("x11/alacarte/Makefile", "# empty\n") + s.CreateTmpFile("category/package/Makefile", "# empty\n") G.globalData.Pkgsrcdir = s.tmpdir G.CurrentDir = s.tmpdir + "/category/package" G.CurPkgsrcdir = "../.." @@ -374,7 +380,8 @@ func (s *Suite) Test_VartypeCheck_SedCommands(c *check.C) { c.Check(s.Output(), equals, ""+ "NOTE: fname:1: Please always use \"-e\" in sed commands, even if there is only one substitution.\n"+ - "NOTE: fname:2: Each sed command should appear in an assignment of its own.\n") + "NOTE: fname:2: Each sed command should appear in an assignment of its own.\n"+ + "WARN: fname:3: The # character starts a comment.\n") } func (s *Suite) Test_VartypeCheck_ShellCommands(c *check.C) { |