[BACK]Return to alternatives_test.go CVS log [TXT][DIR] Up to [cvs.NetBSD.org] / pkgsrc / pkgtools / pkglint / files

File: [cvs.NetBSD.org] / pkgsrc / pkgtools / pkglint / files / alternatives_test.go (download)

Revision 1.18, Sun Dec 8 00:06:38 2019 UTC (2 months, 1 week ago) by rillig
Branch: MAIN
CVS Tags: pkgsrc-2019Q4-base, pkgsrc-2019Q4
Changes since 1.17: +112 -33 lines

pkgtools/pkglint: update to 19.3.14

Changes since 19.3.13:

When pkglint suggests to replace !empty(VARNAME:Mfixed) with ${VARNAME}
== fixed, the exact suggested expression is now part of the diagnostic.
The check and the autofix have been improved. They now apply only to the
last modifier in the whole chain, everything else was a bug in pkglint.

Pkglint now knows the scope of variables better than before. It knows
the difference between variables from <sys.mk> like MACHINE_ARCH, which
are always in scope, and those from mk/defaults/mk.conf, which only come
into scope later, after bsd.prefs.mk has been included. It warns when
variables are used too early, for example in .if conditions.

The pathnames in ALTERNATIVES files are now checked for absolute
pathnames. This mistake doesn't happen in practice, but the code for
converting the different path types internally made it necessary to add
these checks. At least this prevents typos.

The special check for obsolete licenses has been removed since their
license files have been removed and that is checked as well.

Variables named *_AWK may be appended to.

The variables _PKG_SILENT and _PKG_DEBUG are no longer deprecated, they
are obsolete now. They are not used in main pkgsrc and pkgsrc-wip
anymore.

When a package sets a default value for a user-settable variable (which
is something that should not happen anyway), it should .include
bsd.prefs.mk before, in order to not accidentally overwrite the
user-specified value.

Variable modifiers of the form :from=to are now parsed like in bmake.
They are greedy and eat up any following colons as well. This means that
${VAR:.c=.o:Q} replaces source.c with source.o:Q, instead of quoting it.
Pkglint now warns about such cases.

The handling of relative paths in diagnostics is now consistent. All
paths that are part of a diagnostic are relative to the line that issues
the diagnostic.

Fatal errors are no longer suppressed in --autofix mode.

Plus lots of refactoring, to prevent accidental mixing of incompatible
relative paths.

package pkglint

import "gopkg.in/check.v1"

func (s *Suite) Test_CheckFileAlternatives__empty(c *check.C) {
	t := s.Init(c)

	t.Chdir("category/package")
	t.CreateFileLines("ALTERNATIVES")

	G.Pkg = NewPackage(".")

	CheckFileAlternatives("ALTERNATIVES")

	t.CheckOutputLines(
		"ERROR: ALTERNATIVES: Must not be empty.")
}

func (s *Suite) Test_CheckFileAlternatives__ALTERNATIVES_SRC(c *check.C) {
	t := s.Init(c)

	// It's a strange situation, having an ALTERNATIVES file defined by
	// the package but then referring to another package's file by means
	// of ALTERNATIVES_SRC. As of February 2019 I don't remember if I
	// really had this case in mind when I initially wrote the code in
	// CheckFileAlternatives.
	t.SetUpPackage("category/package",
		"ALTERNATIVES_SRC=\talts")
	t.CreateFileLines("category/package/ALTERNATIVES",
		"bin/pgm @PREFIX@/bin/gnu-program",
		"bin/pgm @PREFIX@/bin/nb-program")
	t.FinishSetUp()

	G.Check(t.File("category/package"))

	// The ALTERNATIVES file in this package is not checked at all.
	// If it were, there would be an error for the repeated bin/pgm.
	t.CheckOutputEmpty()
}

func (s *Suite) Test_AlternativesChecker_Check__PLIST(c *check.C) {
	t := s.Init(c)

	t.SetUpPackage("category/package")
	t.Chdir("category/package")
	t.CreateFileLines("ALTERNATIVES",
		"sbin/sendmail @PREFIX@/sbin/sendmail.postfix@POSTFIXVER@",
		"sbin/sendmail @PREFIX@/sbin/sendmail.exim@EXIMVER@",
		"bin/echo bin/gnu-echo",
		"bin/editor bin/vim -e",
		"invalid",
		"bin/browser\t${PREFIX}/bin/firefox",
		"highscores   @VARBASE@/game/scores",
		"sbin/init /sbin/init")
	t.CreateFileLines("PLIST",
		PlistCvsID,
		"bin/echo",
		"bin/vim",
		"sbin/sendmail.exim${EXIMVER}")
	t.FinishSetUp()

	G.Check(".")

	t.CheckOutputLines(
		"ERROR: ALTERNATIVES:1: Alternative implementation \"@PREFIX@/sbin/sendmail.postfix@POSTFIXVER@\" "+
			"must appear in the PLIST as \"sbin/sendmail.postfix${POSTFIXVER}\".",
		"ERROR: ALTERNATIVES:3: Alternative wrapper \"bin/echo\" must not appear in the PLIST.",
		"ERROR: ALTERNATIVES:3: Alternative implementation \"bin/gnu-echo\" must appear in the PLIST.",
		"ERROR: ALTERNATIVES:3: Alternative implementation \"bin/gnu-echo\" must be an absolute path.",
		"ERROR: ALTERNATIVES:4: Alternative implementation \"bin/vim\" must be an absolute path.",
		"ERROR: ALTERNATIVES:5: Invalid line \"invalid\".",
		"ERROR: ALTERNATIVES:6: Alternative implementation \"${PREFIX}/bin/firefox\" must appear in the PLIST.",
		"ERROR: ALTERNATIVES:6: Alternative implementation \"${PREFIX}/bin/firefox\" must be an absolute path.",
		"ERROR: ALTERNATIVES:7: Alternative implementation \"@VARBASE@/game/scores\" "+
			"must appear in the PLIST as \"${VARBASE}/game/scores\".")

	t.SetUpCommandLine("--autofix")

	G.Check(".")

	t.CheckOutputLines(
		"AUTOFIX: ALTERNATIVES:3: Replacing \"bin/gnu-echo\" with \"@PREFIX@/bin/gnu-echo\".",
		"AUTOFIX: ALTERNATIVES:4: Replacing \"bin/vim\" with \"@PREFIX@/bin/vim\".")
}

func (s *Suite) Test_AlternativesChecker_checkLine(c *check.C) {
	t := s.Init(c)

	t.SetUpPackage("category/package")
	t.Chdir("category/package")
	t.CreateFileLines("ALTERNATIVES",
		"bin/no-args @PREFIX@/bin/echo",
		"bin/with-args @PREFIX@/bin/echo hello,",
		"bin/with-quoted-args @PREFIX@/bin/echo \"hello, world\" \\ cowboy",
		"bin/trailing @PREFIX@/bin/echo spaces ", // TODO: warn about this
		"/abs-echo @PREFIX@/bin/echo")
	t.CreateFileLines("PLIST",
		PlistCvsID,
		"bin/echo")
	t.FinishSetUp()

	G.Check(".")

	t.CheckOutputLines(
		"ERROR: ALTERNATIVES:5: Alternative wrapper \"/abs-echo\" " +
			"must be relative to PREFIX.")
}

func (s *Suite) Test_AlternativesChecker_checkWrapperAbs(c *check.C) {
	t := s.Init(c)

	t.CreateFileLines("ALTERNATIVES",
		"relative @PREFIX@/bin/echo",
		"/absolute @PREFIX@/bin/echo")

	CheckFileAlternatives(t.File("ALTERNATIVES"))

	t.CheckOutputLines(
		"ERROR: ~/ALTERNATIVES:2: Alternative wrapper \"/absolute\" " +
			"must be relative to PREFIX.")
}

func (s *Suite) Test_AlternativesChecker_checkWrapperPlist(c *check.C) {
	t := s.Init(c)

	t.SetUpPackage("category/package")
	t.Chdir("category/package")
	t.CreateFileLines("ALTERNATIVES",
		"bin/echo @PREFIX@/bin/gnu-echo",
		"bin/editor @PREFIX@/bin/vim -e")
	t.CreateFileLines("PLIST",
		PlistCvsID,
		"bin/echo",
		"bin/gnu-echo",
		"bin/vim")
	t.FinishSetUp()

	G.Check(".")

	t.CheckOutputLines(
		"ERROR: ALTERNATIVES:1: Alternative wrapper \"bin/echo\" " +
			"must not appear in the PLIST.")
}

func (s *Suite) Test_AlternativesChecker_checkAlternativeAbs(c *check.C) {
	t := s.Init(c)

	t.SetUpPackage("category/package")
	t.Chdir("category/package")
	t.CreateFileLines("ALTERNATIVES",
		"bin/echo bin/gnu-echo",
		"bin/editor bin/vim -e")
	t.CreateFileLines("PLIST",
		PlistCvsID,
		"bin/echo",
		"bin/gnu-echo",
		"bin/vim")
	t.FinishSetUp()

	t.CheckOutputEmpty()
}

// A file that is mentioned in the ALTERNATIVES file must appear
// in the package's PLIST files. It may appear there conditionally,
// assuming that manual testing will reveal inconsistencies. Or
// that this scenario is an edge case anyway.
func (s *Suite) Test_AlternativesChecker_checkAlternativePlist__conditional(c *check.C) {
	t := s.Init(c)

	t.SetUpPackage("category/package")
	t.Chdir("category/package")
	t.CreateFileLines("ALTERNATIVES",
		"bin/wrapper1 @PREFIX@/bin/always-exists",
		"bin/wrapper2 @PREFIX@/bin/conditional",
		"bin/wrapper3 @PREFIX@/bin/not-found")
	t.CreateFileLines("PLIST",
		PlistCvsID,
		"bin/always-exists",
		"${PLIST.cond}bin/conditional")
	t.FinishSetUp()

	G.Check(".")

	t.CheckOutputLines(
		"ERROR: ALTERNATIVES:3: Alternative implementation \"@PREFIX@/bin/not-found\" " +
			"must appear in the PLIST as \"bin/not-found\".")
}

// When a man page is mentioned in the ALTERNATIVES file, it must use the
// PKGMANDIR variable. In the PLIST files though, there is some magic
// in the pkgsrc infrastructure that maps man/ to ${PKGMANDIR}, which
// leads to a bit less typing.
//
// Seen in graphics/py-blockdiag.
func (s *Suite) Test_AlternativesChecker_checkAlternativePlist__PKGMANDIR(c *check.C) {
	t := s.Init(c)

	t.SetUpPackage("category/package")
	t.CreateFileLines("category/package/ALTERNATIVES",
		"@PKGMANDIR@/man1/blockdiag @PREFIX@/@PKGMANDIR@/man1/blockdiag-@PYVERSSUFFIX@.1")
	t.CreateFileLines("category/package/PLIST",
		PlistCvsID,
		"man/man1/blockdiag-${PYVERSSUFFIX}.1")
	t.FinishSetUp()

	G.Check(t.File("category/package"))

	t.CheckOutputEmpty()
}