diff options
author | rillig <rillig> | 2015-12-02 21:46:46 +0000 |
---|---|---|
committer | rillig <rillig> | 2015-12-02 21:46:46 +0000 |
commit | b843197553ac80f7199cec720d7b554ff98cb541 (patch) | |
tree | b45de1fc9ea49a3d0acc569333eb65b8a54ee58c /pkgtools | |
parent | 7dbc6c59fe035ddf0beaa33612756c438ed6230b (diff) | |
download | pkgsrc-b843197553ac80f7199cec720d7b554ff98cb541.tar.gz |
Updated pkglint to 5.1.
Changes since 5.0:
* Fixed --autofix mode (it hadn't been enabled before)
* The --autofix mode now advertises itself when it can do something
* The --autofix mode now adds missing empty lines to patch files
(only in the leading text section, not in the actual patch content)
* Made --autofix code simpler ({prepend,append}{Before,After} was not
really needed)
* Fixed unit tests to report invalid command lines
* Added some more unit tests
Diffstat (limited to 'pkgtools')
-rw-r--r-- | pkgtools/pkglint/Makefile | 4 | ||||
-rw-r--r-- | pkgtools/pkglint/files/buildlink3_test.go | 4 | ||||
-rw-r--r-- | pkgtools/pkglint/files/check_test.go | 9 | ||||
-rw-r--r-- | pkgtools/pkglint/files/distinfo_test.go | 2 | ||||
-rw-r--r-- | pkgtools/pkglint/files/files.go | 2 | ||||
-rw-r--r-- | pkgtools/pkglint/files/files_test.go | 19 | ||||
-rw-r--r-- | pkgtools/pkglint/files/line.go | 37 | ||||
-rw-r--r-- | pkgtools/pkglint/files/mkcond_test.go | 2 | ||||
-rw-r--r-- | pkgtools/pkglint/files/mkline_test.go | 4 | ||||
-rw-r--r-- | pkgtools/pkglint/files/package_test.go | 2 | ||||
-rw-r--r-- | pkgtools/pkglint/files/patches.go | 12 | ||||
-rw-r--r-- | pkgtools/pkglint/files/patches_test.go | 22 | ||||
-rw-r--r-- | pkgtools/pkglint/files/plist_test.go | 2 | ||||
-rw-r--r-- | pkgtools/pkglint/files/shell_test.go | 4 | ||||
-rw-r--r-- | pkgtools/pkglint/files/substcontext_test.go | 2 | ||||
-rw-r--r-- | pkgtools/pkglint/files/vartypecheck.go | 2 | ||||
-rw-r--r-- | pkgtools/pkglint/files/vartypecheck_test.go | 106 |
17 files changed, 180 insertions, 55 deletions
diff --git a/pkgtools/pkglint/Makefile b/pkgtools/pkglint/Makefile index dc57be1d019..af8628fb171 100644 --- a/pkgtools/pkglint/Makefile +++ b/pkgtools/pkglint/Makefile @@ -1,6 +1,6 @@ -# $NetBSD: Makefile,v 1.468 2015/11/25 16:53:18 rillig Exp $ +# $NetBSD: Makefile,v 1.469 2015/12/02 21:46:46 rillig Exp $ -PKGNAME= pkglint-5.0 +PKGNAME= pkglint-5.1 DISTFILES= # none CATEGORIES= pkgtools diff --git a/pkgtools/pkglint/files/buildlink3_test.go b/pkgtools/pkglint/files/buildlink3_test.go index cc795a4d6e7..a643f078752 100644 --- a/pkgtools/pkglint/files/buildlink3_test.go +++ b/pkgtools/pkglint/files/buildlink3_test.go @@ -36,7 +36,7 @@ func (s *Suite) TestChecklinesBuildlink3(c *check.C) { // takes care of constructing the correct PKGNAME, but pkglint doesn’t // look at that file. func (s *Suite) TestChecklinesBuildlink3_NameMismatch(c *check.C) { - s.UseCommandLine("-Wall", "-Call") + s.UseCommandLine(c, "-Wall", "-Call") G.globalData.InitVartypes() G.pkgContext = newPkgContext("x11/hs-X11") G.pkgContext.effectivePkgbase = "X11" @@ -64,7 +64,7 @@ func (s *Suite) TestChecklinesBuildlink3_NameMismatch(c *check.C) { } func (s *Suite) TestChecklinesBuildlink3_NoBuildlinkTree(c *check.C) { - s.UseCommandLine("-Wall", "-Call") + s.UseCommandLine(c, "-Wall", "-Call") G.globalData.InitVartypes() lines := s.NewLines("buildlink3.mk", "# $"+"NetBSD$", diff --git a/pkgtools/pkglint/files/check_test.go b/pkgtools/pkglint/files/check_test.go index ba51f776860..3f0e53ce0ff 100644 --- a/pkgtools/pkglint/files/check_test.go +++ b/pkgtools/pkglint/files/check_test.go @@ -11,7 +11,6 @@ var equals = check.Equals var deepEquals = check.DeepEquals type Suite struct { - c *check.C stdout bytes.Buffer stderr bytes.Buffer } @@ -39,9 +38,10 @@ func (s *Suite) NewLines(fname string, lines ...string) []*Line { return result } -func (s *Suite) UseCommandLine(args ...string) { - if exitcode := new(Pkglint).ParseCommandLine(append([]string{"pkglint"}, args...)); exitcode != nil { - s.c.FailNow() +func (s *Suite) UseCommandLine(c *check.C, args ...string) { + exitcode := new(Pkglint).ParseCommandLine(append([]string{"pkglint"}, args...)) + if exitcode != nil && *exitcode != 0 { + c.Fatalf("Cannot parse command line: %#v", args) } } @@ -62,7 +62,6 @@ func (s *Suite) ExpectFatalError(action func()) { func (s *Suite) SetUpTest(c *check.C) { G = new(GlobalVars) G.logOut, G.logErr, G.traceOut = &s.stdout, &s.stderr, &s.stdout - s.c = c } func (s *Suite) TearDownTest(c *check.C) { diff --git a/pkgtools/pkglint/files/distinfo_test.go b/pkgtools/pkglint/files/distinfo_test.go index b520206bb61..653142c3146 100644 --- a/pkgtools/pkglint/files/distinfo_test.go +++ b/pkgtools/pkglint/files/distinfo_test.go @@ -31,7 +31,7 @@ func (s *Suite) TestChecklinesDistinfo(c *check.C) { checklinesDistinfo(lines) c.Check(s.Output(), equals, ""+ - "ERROR: distinfo:1: Expected \"$NetBSD: distinfo_test.go,v 1.1 2015/11/25 13:29:07 rillig Exp $\".\n"+ + "ERROR: distinfo:1: Expected \"$"+"NetBSD$\".\n"+ "NOTE: distinfo:2: Empty line expected.\n"+ "ERROR: distinfo:5: Expected SHA1, RMD160, SHA512, Size checksums for \"distfile.tar.gz\", got MD5, SHA1.\n") } diff --git a/pkgtools/pkglint/files/files.go b/pkgtools/pkglint/files/files.go index 7aace1785f1..1a211e3ea59 100644 --- a/pkgtools/pkglint/files/files.go +++ b/pkgtools/pkglint/files/files.go @@ -106,7 +106,7 @@ func convertToLogicalLines(fname string, rawText string, joinContinuationLines b } func saveAutofixChanges(lines []*Line) { - if !G.opts.Autofix || !G.autofixAvailable { + if !G.opts.Autofix { return } diff --git a/pkgtools/pkglint/files/files_test.go b/pkgtools/pkglint/files/files_test.go index 40e090189dc..0c3a2c4881c 100644 --- a/pkgtools/pkglint/files/files_test.go +++ b/pkgtools/pkglint/files/files_test.go @@ -3,6 +3,7 @@ package main import ( check "gopkg.in/check.v1" "io/ioutil" + "path/filepath" ) func (s *Suite) TestConvertToLogicalLines_nocont(c *check.C) { @@ -49,18 +50,19 @@ func (s *Suite) TestSplitRawLine(c *check.C) { c.Check(trailingWhitespace, equals, "") c.Check(continuation, equals, "") - leadingWhitespace, text, trailingWhitespace, continuation = splitRawLine("\tasdf \\\n") + leadingWhitespace, text, trailingWhitespace, continuation = splitRawLine("\tword \\\n") c.Check(leadingWhitespace, equals, "\t") - c.Check(text, equals, "asdf") + c.Check(text, equals, "word") c.Check(trailingWhitespace, equals, " ") c.Check(continuation, equals, "\\") } func (s *Suite) TestAutofix(c *check.C) { + s.UseCommandLine(c, "--show-autofix") tmpdir := c.MkDir() - tmpname := tmpdir + "/Makefile" - lines := s.NewLines(tmpname, + fname := filepath.ToSlash(tmpdir + "/Makefile") + lines := s.NewLines(fname, "line1", "line2", "line3") @@ -68,12 +70,15 @@ func (s *Suite) TestAutofix(c *check.C) { saveAutofixChanges(lines) - c.Assert(fileExists(tmpname), equals, false) + c.Assert(fileExists(fname), equals, false) + c.Check(s.Output(), equals, "NOTE: "+fname+":2: Autofix: replacing regular expression \".\" with \"X\".\n") + + s.UseCommandLine(c, "--autofix") - G.opts.Autofix = true saveAutofixChanges(lines) - content, err := ioutil.ReadFile(tmpdir + "/Makefile") + content, err := ioutil.ReadFile(fname) c.Assert(err, check.IsNil) c.Check(string(content), equals, "line1\nXXXXX\nline3\n") + c.Check(s.Output(), equals, "NOTE: "+fname+": Has been auto-fixed. Please re-run pkglint.\n") } diff --git a/pkgtools/pkglint/files/line.go b/pkgtools/pkglint/files/line.go index c1bc1d9eaaf..66515957241 100644 --- a/pkgtools/pkglint/files/line.go +++ b/pkgtools/pkglint/files/line.go @@ -46,6 +46,7 @@ func NewLine(fname, linenos, text string, rawLines []*RawLine) *Line { func (self *Line) rawLines() []*RawLine { return append(self.before, append(self.raw, self.after...)...) } + func (self *Line) printSource(out io.Writer) { if G.opts.PrintSource { io.WriteString(out, "\n") @@ -54,6 +55,7 @@ func (self *Line) printSource(out io.Writer) { } } } + func (self *Line) fatalf(format string, args ...interface{}) bool { self.printSource(G.logErr) return fatalf(self.fname, self.lines, format, args...) @@ -74,6 +76,7 @@ func (self *Line) debugf(format string, args ...interface{}) bool { self.printSource(G.logOut) return debugf(self.fname, self.lines, format, args...) } + func (self *Line) explain(explanation ...string) { if G.opts.Explain { complete := strings.Join(explanation, "\n") @@ -93,38 +96,32 @@ func (self *Line) explain(explanation ...string) { } G.explanationsAvailable = true } + func (self *Line) String() string { return self.fname + ":" + self.lines + ": " + self.text } func (self *Line) insertBefore(line string) { self.before = append(self.before, &RawLine{0, line + "\n"}) - self.changed = true - if G.opts.PrintAutofix { - self.notef("Autofix: inserting a line %q before this line.", line) - } + self.noteAutofix("Autofix: inserting a line %q before this line.", line) } + func (self *Line) insertAfter(line string) { self.after = append(self.after, &RawLine{0, line + "\n"}) - self.changed = true - if G.opts.PrintAutofix { - self.notef("Autofix: inserting a line %q after this line.", line) - } + self.noteAutofix("Autofix: inserting a line %q after this line.", line) } + func (self *Line) delete() { self.raw = nil self.changed = true } + func (self *Line) replace(from, to string) { for _, rawLine := range self.raw { if rawLine.lineno != 0 { if replaced := strings.Replace(rawLine.textnl, from, to, 1); replaced != rawLine.textnl { rawLine.textnl = replaced - self.changed = true - if G.opts.PrintAutofix { - self.notef("Autofix: replacing %q with %q.", from, to) - } - G.autofixAvailable = true + self.noteAutofix("Autofix: replacing %q with %q.", from, to) } } } @@ -134,12 +131,16 @@ func (self *Line) replaceRegex(from, to string) { if rawLine.lineno != 0 { if replaced := regcomp(from).ReplaceAllString(rawLine.textnl, to); replaced != rawLine.textnl { rawLine.textnl = replaced - self.changed = true - if G.opts.PrintAutofix { - self.notef("Autofix: replacing regular expression %q with %q.", from, to) - } - G.autofixAvailable = true + self.noteAutofix("Autofix: replacing regular expression %q with %q.", from, to) } } } } + +func (line *Line) noteAutofix(format string, args ...interface{}) { + line.changed = true + if G.opts.Autofix || G.opts.PrintAutofix { + line.notef(format, args...) + } + G.autofixAvailable = true +} diff --git a/pkgtools/pkglint/files/mkcond_test.go b/pkgtools/pkglint/files/mkcond_test.go index 2f6a1036fab..7741e7c6fee 100644 --- a/pkgtools/pkglint/files/mkcond_test.go +++ b/pkgtools/pkglint/files/mkcond_test.go @@ -21,7 +21,7 @@ func (s *Suite) TestParseMkCond_Compare(c *check.C) { } func (s *Suite) TestChecklineMkCondition(c *check.C) { - s.UseCommandLine("-Wtypes") + s.UseCommandLine(c, "-Wtypes") G.globalData.InitVartypes() line := NewLine("fname", "1", "", nil) diff --git a/pkgtools/pkglint/files/mkline_test.go b/pkgtools/pkglint/files/mkline_test.go index 32662de344b..5092b8fac4c 100644 --- a/pkgtools/pkglint/files/mkline_test.go +++ b/pkgtools/pkglint/files/mkline_test.go @@ -5,7 +5,7 @@ import ( ) func (s *Suite) TestChecklineMkVartype_SimpleType(c *check.C) { - s.UseCommandLine("-Wtypes", "-Dunchecked") + s.UseCommandLine(c, "-Wtypes", "-Dunchecked") G.globalData.InitVartypes() line := NewLine("fname", "1", "dummy", nil) @@ -33,7 +33,7 @@ func (s *Suite) TestChecklineMkVartype(c *check.C) { } func (s *Suite) TestChecklineMkVaralign(c *check.C) { - s.UseCommandLine("-Wspace", "-f") + s.UseCommandLine(c, "-Wspace", "-f") lines := s.NewLines("file.mk", "VAR= value", // Indentation 7, fixed to 8. "VAR= value", // Indentation 8, fixed to 8. diff --git a/pkgtools/pkglint/files/package_test.go b/pkgtools/pkglint/files/package_test.go index ae3886bf918..5d80781c5f6 100644 --- a/pkgtools/pkglint/files/package_test.go +++ b/pkgtools/pkglint/files/package_test.go @@ -17,7 +17,7 @@ func (s *Suite) TestPkgnameFromDistname(c *check.C) { } func (s *Suite) TestChecklinesPackageMakefileVarorder(c *check.C) { - s.UseCommandLine("-Worder") + s.UseCommandLine(c, "-Worder") G.pkgContext = newPkgContext("x11/9term") lines := s.NewLines("Makefile", "# $"+"NetBSD$", diff --git a/pkgtools/pkglint/files/patches.go b/pkgtools/pkglint/files/patches.go index dc08e02bc89..b081ab871fd 100644 --- a/pkgtools/pkglint/files/patches.go +++ b/pkgtools/pkglint/files/patches.go @@ -173,6 +173,7 @@ func (ctx *CheckPatchContext) checkOutside() { text := ctx.line.text if G.opts.WarnSpace && text != "" && ctx.needEmptyLineNow { ctx.line.notef("Empty line expected.") + ctx.line.insertBefore("\n") } ctx.needEmptyLineNow = false if text != "" { @@ -184,6 +185,7 @@ func (ctx *CheckPatchContext) checkOutside() { func (ctx *CheckPatchContext) checkBeginDiff() { if G.opts.WarnSpace && !ctx.prevLineWasEmpty { ctx.line.notef("Empty line expected.") + ctx.line.insertBefore("\n") } if !ctx.seenComment { ctx.line.errorf("Each patch must be documented.") @@ -369,7 +371,10 @@ var patchTransitions = map[PatchState][]transition{ {rePatchUniLineNoNewline, PST_UNI_LINE, func(ctx *CheckPatchContext) { }}, {rePatchEmpty, PST_UNI_LINE, func(ctx *CheckPatchContext) { - _ = G.opts.WarnSpace && ctx.line.notef("Leading white-space missing in hunk.") + if G.opts.WarnSpace { + ctx.line.notef("Leading white-space missing in hunk.") + ctx.line.replaceRegex(`^`, " ") + } ctx.checkHunkLine(1, 1, PST_UNI_HUNK) }}, {"", PST_UNI_HUNK, func(ctx *CheckPatchContext) { @@ -484,7 +489,10 @@ type CheckPatchContext struct { } func (ctx *CheckPatchContext) expectEmptyLine() { - _ = G.opts.WarnSpace && ctx.line.notef("Empty line expected.") + if G.opts.WarnSpace { + ctx.line.notef("Empty line expected.") + ctx.line.insertBefore("\n") + } } func (ctx *CheckPatchContext) useUnifiedDiffs() { diff --git a/pkgtools/pkglint/files/patches_test.go b/pkgtools/pkglint/files/patches_test.go index cbf83860418..cb3f6364f8f 100644 --- a/pkgtools/pkglint/files/patches_test.go +++ b/pkgtools/pkglint/files/patches_test.go @@ -2,10 +2,11 @@ package main import ( check "gopkg.in/check.v1" + "path/filepath" ) func (s *Suite) TestChecklinesPatch_WithComment(c *check.C) { - s.UseCommandLine("-Wall") + s.UseCommandLine(c, "-Wall") lines := s.NewLines("patch-WithComment", "$"+"NetBSD$", "", @@ -26,8 +27,10 @@ func (s *Suite) TestChecklinesPatch_WithComment(c *check.C) { } func (s *Suite) TestChecklinesPatch_WithoutEmptyLine(c *check.C) { - s.UseCommandLine("-Wall") - lines := s.NewLines("patch-WithoutEmptyLines", + tmpdir := c.MkDir() + fname := filepath.ToSlash(tmpdir + "/patch-WithoutEmptyLines") + s.UseCommandLine(c, "-Wall", "--autofix") + lines := s.NewLines(fname, "$"+"NetBSD$", "Text", "--- file.orig", @@ -41,12 +44,15 @@ func (s *Suite) TestChecklinesPatch_WithoutEmptyLine(c *check.C) { checklinesPatch(lines) c.Check(s.Output(), equals, ""+ - "NOTE: patch-WithoutEmptyLines:2: Empty line expected.\n"+ - "NOTE: patch-WithoutEmptyLines:3: Empty line expected.\n") + "NOTE: "+fname+":2: Empty line expected.\n"+ + "NOTE: "+fname+":2: Autofix: inserting a line \"\\n\" before this line.\n"+ + "NOTE: "+fname+":3: Empty line expected.\n"+ + "NOTE: "+fname+":3: Autofix: inserting a line \"\\n\" before this line.\n"+ + "NOTE: "+fname+": Has been auto-fixed. Please re-run pkglint.\n") } func (s *Suite) TestChecklinesPatch_WithoutComment(c *check.C) { - s.UseCommandLine("-Wall") + s.UseCommandLine(c, "-Wall") lines := s.NewLines("patch-WithoutComment", "$"+"NetBSD$", "", @@ -72,7 +78,7 @@ func (s *Suite) TestChecklineOtherAbsolutePathname(c *check.C) { } func (s *Suite) TestChecklinesPatch_ErrorCode(c *check.C) { - s.UseCommandLine("-Wall") + s.UseCommandLine(c, "-Wall") lines := s.NewLines("patch-ErrorCode", "$"+"NetBSD$", "", @@ -92,7 +98,7 @@ func (s *Suite) TestChecklinesPatch_ErrorCode(c *check.C) { } func (s *Suite) TestChecklinesPatch_WrongOrder(c *check.C) { - s.UseCommandLine("-Wall") + s.UseCommandLine(c, "-Wall") lines := s.NewLines("patch-WrongOrder", "$"+"NetBSD$", "", diff --git a/pkgtools/pkglint/files/plist_test.go b/pkgtools/pkglint/files/plist_test.go index 4fc91ac6d16..7c2bfee093e 100644 --- a/pkgtools/pkglint/files/plist_test.go +++ b/pkgtools/pkglint/files/plist_test.go @@ -15,7 +15,7 @@ func (s *Suite) TestChecklinesPlist(c *check.C) { checklinesPlist(lines) c.Check(s.Output(), equals, ""+ - "ERROR: PLIST:1: Expected \"@comment $NetBSD: plist_test.go,v 1.1 2015/11/25 13:29:07 rillig Exp $\".\n"+ + "ERROR: PLIST:1: Expected \"@comment $NetBSD: plist_test.go,v 1.2 2015/12/02 21:46:46 rillig Exp $\".\n"+ "WARN: PLIST:1: The bin/ directory should not have subdirectories.\n"+ "WARN: PLIST:5: Please remove this line. It is no longer necessary.\n") } diff --git a/pkgtools/pkglint/files/shell_test.go b/pkgtools/pkglint/files/shell_test.go index df2c57433a2..1db763e070c 100644 --- a/pkgtools/pkglint/files/shell_test.go +++ b/pkgtools/pkglint/files/shell_test.go @@ -26,7 +26,7 @@ func (s *Suite) TestChecklineMkShelltext(c *check.C) { } func (s *Suite) TestChecklineMkShellword(c *check.C) { - s.UseCommandLine("-Wall") + s.UseCommandLine(c, "-Wall") G.globalData.InitVartypes() line := NewLine("fname", "1", "dummy", nil) @@ -43,7 +43,7 @@ func (s *Suite) TestChecklineMkShellword(c *check.C) { } func (s *Suite) TestShelltextContext_CheckCommandStart(c *check.C) { - s.UseCommandLine("-Wall") + s.UseCommandLine(c, "-Wall") G.globalData.tools = map[string]bool{"echo": true} G.globalData.vartools = map[string]string{"echo": "ECHO"} G.globalData.toolsVarRequired = map[string]bool{"echo": true} diff --git a/pkgtools/pkglint/files/substcontext_test.go b/pkgtools/pkglint/files/substcontext_test.go index f9c644649ea..1ea900d0792 100644 --- a/pkgtools/pkglint/files/substcontext_test.go +++ b/pkgtools/pkglint/files/substcontext_test.go @@ -52,7 +52,7 @@ func (s *Suite) TestSubstContext_Complete(c *check.C) { } func (s *Suite) TestSubstContext_NoClass(c *check.C) { - s.UseCommandLine("-Wextra") + s.UseCommandLine(c, "-Wextra") line := NewLine("Makefile", "1", "dummy", nil) ctx := new(SubstContext) diff --git a/pkgtools/pkglint/files/vartypecheck.go b/pkgtools/pkglint/files/vartypecheck.go index 3c507d00fd3..603d130d9fb 100644 --- a/pkgtools/pkglint/files/vartypecheck.go +++ b/pkgtools/pkglint/files/vartypecheck.go @@ -302,7 +302,7 @@ func (cv *VartypeCheck) MailAddress() { if m, _, domain := match2(value, `^([+\-.0-9A-Z_a-z]+)@([-\w\d.]+)$`); m { if strings.EqualFold(domain, "NetBSD.org") && domain != "NetBSD.org" { - line.warnf("Please write NetBSD.org instead of %q.", domain) + line.warnf("Please write \"NetBSD.org\" instead of %q.", domain) } if matches(value, `(?i)^(tech-pkg|packages)@NetBSD\.org$`) { line.errorf("This mailing list address is obsolete. Use pkgsrc-users@NetBSD.org instead.") diff --git a/pkgtools/pkglint/files/vartypecheck_test.go b/pkgtools/pkglint/files/vartypecheck_test.go index 088745259a4..dee06908c27 100644 --- a/pkgtools/pkglint/files/vartypecheck_test.go +++ b/pkgtools/pkglint/files/vartypecheck_test.go @@ -2,15 +2,68 @@ package main import ( check "gopkg.in/check.v1" + "io/ioutil" + "os" ) +func (s *Suite) TestVartypeCheck_AwkCommand(c *check.C) { + newVartypeCheck("PLIST_AWK", "+=", "{print $0}").AwkCommand() +} + +func (s *Suite) TestVartypeCheck_BasicRegularExpression(c *check.C) { + newVartypeCheck("REPLACE_FILES.pl", "=", ".*\\.pl$").BasicRegularExpression() +} + +func (s *Suite) TestVartypeCheck_BuildlinkDepmethod(c *check.C) { + newVartypeCheck("BUILDLINK_DEPMETHOD.libc", "?=", "full").BuildlinkDepmethod() + newVartypeCheck("BUILDLINK_DEPMETHOD.libc", "?=", "unknown").BuildlinkDepmethod() + + c.Check(s.Output(), equals, "WARN: fname:1: Invalid dependency method \"unknown\". Valid methods are \"build\" or \"full\".\n") +} + func (s *Suite) TestVartypeCheck_Category(c *check.C) { + tmpdir := c.MkDir() + categorydir := tmpdir + "/filesyscategory" + categoryMakefile := categorydir + "/Makefile" + os.Mkdir(categorydir, 0777) + ioutil.WriteFile(categoryMakefile, []byte("# Nothing\n"), 0777) + G.currentDir = tmpdir + G.curPkgsrcdir = "." + newVartypeCheck("CATEGORIES", "=", "chinese").Category() newVartypeCheck("CATEGORIES", "=", "arabic").Category() + newVartypeCheck("CATEGORIES", "=", "filesyscategory").Category() c.Check(s.Output(), equals, "ERROR: fname:1: Invalid category \"arabic\".\n") } +func (s *Suite) TestVartypeCheck_CFlag(c *check.C) { + newVartypeCheck("CFLAGS", "+=", "-Wall").CFlag() + newVartypeCheck("CFLAGS", "+=", "/W3").CFlag() + newVartypeCheck("CFLAGS", "+=", "target:sparc64").CFlag() + newVartypeCheck("CFLAGS", "+=", "-std=c99").CFlag() + newVartypeCheck("CFLAGS", "+=", "-XX:+PrintClassHistogramAfterFullGC").CFlag() + + c.Check(s.Output(), equals, ""+ + "WARN: fname:1: Compiler flag \"/W3\" should start with a hyphen.\n"+ + "WARN: fname:1: Compiler flag \"target:sparc64\" should start with a hyphen.\n"+ + "WARN: fname:1: Unknown compiler flag \"-XX:+PrintClassHistogramAfterFullGC\".\n") +} + +func (s *Suite) TestVartypeCheck_Comment(c *check.C) { + newVartypeCheck("COMMENT", "=", "Versatile Programming Language").Comment() + newVartypeCheck("COMMENT", "=", "SHORT_DESCRIPTION_OF_THE_PACKAGE").Comment() + newVartypeCheck("COMMENT", "=", "A great package.").Comment() + newVartypeCheck("COMMENT", "=", "some packages need a very very long comment to explain their basic usefulness").Comment() + + c.Check(s.Output(), equals, ""+ + "ERROR: fname:1: COMMENT must be set.\n"+ + "WARN: fname:1: COMMENT should not begin with \"A\".\n"+ + "WARN: fname:1: COMMENT should not end with a period.\n"+ + "WARN: fname:1: COMMENT should start with a capital letter.\n"+ + "WARN: fname:1: COMMENT should not be longer than 70 characters.\n") +} + func (s *Suite) TestVartypeCheck_Dependency(c *check.C) { newVartypeCheck("CONFLICTS", "+=", "Perl").Dependency() @@ -28,6 +81,14 @@ func (s *Suite) TestVartypeCheck_Dependency(c *check.C) { c.Check(s.Output(), equals, "WARN: fname:1: Please append \"{,nb*}\" to the version number of this dependency.\n") + newVartypeCheck("CONFLICTS", "+=", "perl5-[5.10-5.22]*").Dependency() + + c.Check(s.Output(), equals, "WARN: fname:1: Only [0-9]* is allowed in the numeric part of a dependency.\n") + + newVartypeCheck("CONFLICTS", "+=", "py-docs").Dependency() + + c.Check(s.Output(), equals, "ERROR: fname:1: Unknown dependency pattern \"py-docs\".\n") + newVartypeCheck("CONFLICTS", "+=", "perl5-5.22.*{,nb*}").Dependency() c.Check(s.Output(), equals, "") @@ -52,6 +113,24 @@ func (s *Suite) TestVartypeCheck_DependencyWithPatch(c *check.C) { "WARN: fname:1: Please use USE_TOOLS+=perl:run instead of this dependency.\n") } +func (s *Suite) TestVartypeCheck_DistSuffix(c *check.C) { + newVartypeCheck("EXTRACT_SUFX", "=", ".tar.gz").DistSuffix() + newVartypeCheck("EXTRACT_SUFX", "=", ".tar.bz2").DistSuffix() + + c.Check(s.Output(), equals, "NOTE: fname:1: EXTRACT_SUFX is \".tar.gz\" by default, so this definition may be redundant.\n") +} + +func (s *Suite) TestVartypeCheck_EmulPlatform(c *check.C) { + newVartypeCheck("EMUL_PLATFORM", "=", "linux-i386").EmulPlatform() + newVartypeCheck("EMUL_PLATFORM", "=", "nextbsd-8087").EmulPlatform() + newVartypeCheck("EMUL_PLATFORM", "=", "${LINUX}").EmulPlatform() + + c.Check(s.Output(), equals, ""+ + "WARN: fname:1: Unknown operating system: nextbsd\n"+ + "WARN: fname:1: Unknown hardware architecture: 8087\n"+ + "WARN: fname:1: \"${LINUX}\" is not a valid emulation platform.\n") +} + func (s *Suite) TestVartypeCheck_FetchURL(c *check.C) { G.globalData.masterSiteUrls = map[string]string{ "https://github.com/": "MASTER_SITE_GITHUB", @@ -81,6 +160,22 @@ func (s *Suite) TestVartypeCheck_FetchURL(c *check.C) { c.Check(s.Output(), equals, "ERROR: fname:1: MASTER_SITE_INVALID does not exist.\n") } +func (s *Suite) TestVartypeCheck_Filename(c *check.C) { + newVartypeCheck("FNAME", "=", "Filename with spaces.docx").Filename() + + c.Check(s.Output(), equals, "WARN: fname:1: \"Filename with spaces.docx\" is not a valid filename.\n") + + newVartypeCheck("FNAME", "=", "OS/2-manual.txt").Filename() + + c.Check(s.Output(), equals, "WARN: fname:1: A filename should not contain a slash.\n") +} + +func (s *Suite) TestVartypeCheck_MailAddress(c *check.C) { + newVartypeCheck("MAINTAINER", "=", "pkgsrc-users@netbsd.org").MailAddress() + + c.Check(s.Output(), equals, "WARN: fname:1: Please write \"NetBSD.org\" instead of \"netbsd.org\".\n") +} + func (s *Suite) TestVartypeCheck_Message(c *check.C) { newVartypeCheck("SUBST_MESSAGE.id", "=", "\"Correct paths\"").Message() @@ -114,6 +209,17 @@ func (s *Suite) TestVartypeCheck_PkgRevision(c *check.C) { c.Check(s.Output(), equals, "") } +func (s *Suite) TestVartypeCheck_PlatformTriple(c *check.C) { + newVartypeCheck("ONLY_FOR_PLATFORM", "=", "linux-i386").PlatformTriple() + newVartypeCheck("ONLY_FOR_PLATFORM", "=", "nextbsd-5.0-8087").PlatformTriple() + newVartypeCheck("ONLY_FOR_PLATFORM", "=", "${LINUX}").PlatformTriple() + + c.Check(s.Output(), equals, ""+ + "WARN: fname:1: \"linux-i386\" is not a valid platform triple.\n"+ + "WARN: fname:1: Unknown operating system: nextbsd\n"+ + "WARN: fname:1: Unknown hardware architecture: 8087\n") +} + func (s *Suite) TestVartypeCheck_SedCommands(c *check.C) { newVartypeCheck("SUBST_SED.dummy", "=", "s,@COMPILER@,gcc,g").SedCommands() |