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

Annotation of pkgsrc/pkgtools/pkglint/files/package_test.go, Revision 1.74

1.35      rillig      1: package pkglint
1.1       rillig      2:
1.35      rillig      3: import (
                      4:        "gopkg.in/check.v1"
1.48      rillig      5:        "os"
1.50      rillig      6:        "sort"
1.35      rillig      7:        "strings"
                      8: )
1.1       rillig      9:
1.58      rillig     10: func (s *Suite) Test_Package__varuse_at_load_time(c *check.C) {
1.30      rillig     11:        t := s.Init(c)
                     12:
1.58      rillig     13:        t.SetUpPkgsrc()
                     14:        t.SetUpTool("printf", "", AtRunTime)
                     15:        t.CreateFileLines("licenses/2-clause-bsd",
                     16:                "# dummy")
                     17:        t.CreateFileLines("category/Makefile")
                     18:        t.CreateFileLines("mk/tools/defaults.mk",
                     19:                "TOOLS_CREATE+=false",
                     20:                "TOOLS_CREATE+=nice",
                     21:                "TOOLS_CREATE+=true",
                     22:                "_TOOLS_VARNAME.nice=NICE")
1.72      rillig     23:        t.CreateFileLines("category/pkgbase/DESCR",
                     24:                "Description")
1.58      rillig     25:
                     26:        t.CreateFileLines("category/pkgbase/Makefile",
1.48      rillig     27:                MkCvsID,
1.30      rillig     28:                "",
1.61      rillig     29:                "PKGNAME=\tloadtime-vartest-1.0",
                     30:                "CATEGORIES=\tcategory",
                     31:                "",
                     32:                "COMMENT=\tDemonstrate variable values during parsing",
                     33:                "LICENSE=\t2-clause-bsd",
1.58      rillig     34:                "",
1.61      rillig     35:                "PLIST_SRC=\t# none",
                     36:                "NO_CHECKSUM=\tyes",
                     37:                "NO_CONFIGURE=\tyes",
1.58      rillig     38:                "",
1.61      rillig     39:                "USE_TOOLS+=\techo false",
                     40:                "FALSE_BEFORE!=\techo false=${FALSE:Q}", // false=
                     41:                "NICE_BEFORE!=\techo nice=${NICE:Q}",    // nice=
                     42:                "TRUE_BEFORE!=\techo true=${TRUE:Q}",    // true=
1.58      rillig     43:                //
                     44:                // All three variables above are empty since the tool
                     45:                // variables are initialized by bsd.prefs.mk. The variables
                     46:                // from share/mk/sys.mk are available, though.
                     47:                //
                     48:                "",
                     49:                ".include \"../../mk/bsd.prefs.mk\"",
                     50:                //
                     51:                // At this point, all tools from USE_TOOLS are defined with their variables.
                     52:                // ${FALSE} works, but a plain "false" might call the wrong tool.
                     53:                // That's because the tool wrappers are not set up yet. This
                     54:                // happens between the post-depends and pre-fetch stages. Even
                     55:                // then, the plain tool names may only be used in the
                     56:                // {pre,do,post}-* targets, since a recursive make(1) needs to be
                     57:                // run to set up the correct PATH.
                     58:                //
                     59:                "",
1.61      rillig     60:                "USE_TOOLS+=\tnice",
1.58      rillig     61:                //
                     62:                // The "nice" tool will only be available as ${NICE} after bsd.pkg.mk
                     63:                // has been included. Even including bsd.prefs.mk another time does
                     64:                // not have any effect since it is guarded against multiple inclusion.
                     65:                //
                     66:                "",
                     67:                ".include \"../../mk/bsd.prefs.mk\"", // Has no effect.
                     68:                "",
1.61      rillig     69:                "FALSE_AFTER!=\techo false=${FALSE:Q}", // false=false
                     70:                "NICE_AFTER!=\techo nice=${NICE:Q}",    // nice=
                     71:                "TRUE_AFTER!=\techo true=${TRUE:Q}",    // true=true
1.58      rillig     72:                "",
                     73:                "do-build:",
                     74:                "\t${RUN} printf 'before:  %-20s  %-20s  %-20s\\n' ${FALSE_BEFORE} ${NICE_BEFORE} ${TRUE_BEFORE}",
                     75:                "\t${RUN} printf 'after:   %-20s  %-20s  %-20s\\n' ${FALSE_AFTER} ${NICE_AFTER} ${TRUE_AFTER}",
                     76:                "\t${RUN} printf 'runtime: %-20s  %-20s  %-20s\\n' false=${FALSE:Q} nice=${NICE:Q} true=${TRUE:Q}",
                     77:                "",
                     78:                ".include \"../../mk/bsd.pkg.mk\"")
                     79:
1.61      rillig     80:        t.SetUpCommandLine("-q", "-Wall")
1.58      rillig     81:        t.FinishSetUp()
1.30      rillig     82:
1.58      rillig     83:        G.Check(t.File("category/pkgbase"))
1.30      rillig     84:
                     85:        t.CheckOutputLines(
1.58      rillig     86:                "NOTE: ~/category/pkgbase/Makefile:14: Consider the :sh modifier instead of != for \"echo false=${FALSE:Q}\".",
                     87:                "WARN: ~/category/pkgbase/Makefile:14: To use the tool ${FALSE} at load time, bsd.prefs.mk has to be included before.",
                     88:                "NOTE: ~/category/pkgbase/Makefile:15: Consider the :sh modifier instead of != for \"echo nice=${NICE:Q}\".",
1.30      rillig     89:
1.58      rillig     90:                // TODO: replace "at load time" with "before including bsd.prefs.mk in line ###".
                     91:                // TODO: ${NICE} could be used at load time if it were added to USE_TOOLS earlier.
                     92:                "WARN: ~/category/pkgbase/Makefile:15: The tool ${NICE} cannot be used at load time.",
1.52      rillig     93:
1.58      rillig     94:                "NOTE: ~/category/pkgbase/Makefile:16: Consider the :sh modifier instead of != for \"echo true=${TRUE:Q}\".",
                     95:                "WARN: ~/category/pkgbase/Makefile:16: To use the tool ${TRUE} at load time, bsd.prefs.mk has to be included before.",
                     96:                "NOTE: ~/category/pkgbase/Makefile:24: Consider the :sh modifier instead of != for \"echo false=${FALSE:Q}\".",
                     97:                "NOTE: ~/category/pkgbase/Makefile:25: Consider the :sh modifier instead of != for \"echo nice=${NICE:Q}\".",
                     98:                "WARN: ~/category/pkgbase/Makefile:25: The tool ${NICE} cannot be used at load time.",
                     99:                "NOTE: ~/category/pkgbase/Makefile:26: Consider the :sh modifier instead of != for \"echo true=${TRUE:Q}\".")
1.52      rillig    100: }
                    101:
1.58      rillig    102: func (s *Suite) Test_Package__relative_included_filenames_in_same_directory(c *check.C) {
1.30      rillig    103:        t := s.Init(c)
                    104:
1.58      rillig    105:        t.SetUpPackage("category/package",
                    106:                "PKGNAME=\tpkgname-1.67",
                    107:                "DISTNAME=\tdistfile_1_67",
                    108:                ".include \"../../category/package/other.mk\"")
                    109:        t.CreateFileLines("category/package/other.mk",
                    110:                MkCvsID,
                    111:                "PKGNAME=\tpkgname-1.67",
                    112:                "DISTNAME=\tdistfile_1_67",
                    113:                ".include \"../../category/package/other.mk\"")
                    114:        t.FinishSetUp()
1.30      rillig    115:
1.58      rillig    116:        G.Check(t.File("category/package"))
1.30      rillig    117:
1.58      rillig    118:        // TODO: Since other.mk is referenced via "../../category/package",
                    119:        //  it would be nice if this relative path would be reflected in the output
                    120:        //  instead of referring just to "other.mk".
1.60      rillig    121:        //  This needs to be fixed somewhere near Relpath.
1.58      rillig    122:        //
                    123:        // The notes are in reverse order because they are produced when checking
                    124:        // other.mk, and there the relative order is correct (line 2 before line 3).
1.30      rillig    125:        t.CheckOutputLines(
1.58      rillig    126:                "NOTE: ~/category/package/Makefile:4: "+
                    127:                        "Definition of PKGNAME is redundant because of other.mk:2.",
                    128:                "NOTE: ~/category/package/Makefile:3: "+
                    129:                        "Definition of DISTNAME is redundant because of other.mk:3.")
1.30      rillig    130: }
                    131:
1.58      rillig    132: func (s *Suite) Test_Package__using_common_Makefile_overriding_DISTINFO_FILE(c *check.C) {
1.47      rillig    133:        t := s.Init(c)
                    134:
1.58      rillig    135:        t.SetUpPackage("security/pinentry")
                    136:        t.CreateFileLines("security/pinentry/Makefile.common",
                    137:                MkCvsID,
                    138:                "DISTINFO_FILE=\t${.CURDIR}/../../security/pinentry/distinfo")
                    139:        t.SetUpPackage("security/pinentry-fltk",
                    140:                ".include \"../../security/pinentry/Makefile.common\"",
                    141:                "DISTINFO_FILE=\t${.CURDIR}/distinfo")
                    142:        t.CreateFileDummyPatch("security/pinentry-fltk/patches/patch-aa")
                    143:        t.CreateFileLines("security/pinentry-fltk/distinfo",
                    144:                CvsID,
                    145:                "",
                    146:                "SHA1 (patch-aa) = ebbf34b0641bcb508f17d5a27f2bf2a536d810ac")
1.47      rillig    147:        t.FinishSetUp()
                    148:
1.58      rillig    149:        G.Check(t.File("security/pinentry"))
                    150:
                    151:        t.CheckOutputEmpty()
                    152:
                    153:        G.Check(t.File("security/pinentry-fltk"))
1.47      rillig    154:
1.58      rillig    155:        // The DISTINFO_FILE definition from pinentry-fltk overrides
                    156:        // the one from pinentry since it appears later.
                    157:        // Therefore the patch is searched for at the right location.
1.47      rillig    158:        t.CheckOutputEmpty()
                    159: }
                    160:
1.58      rillig    161: func (s *Suite) Test_Package__redundant_variable_in_unrelated_files(c *check.C) {
1.17      rillig    162:        t := s.Init(c)
                    163:
1.58      rillig    164:        t.SetUpPackage("databases/py-trytond-ldap-authentication",
                    165:                ".include \"../../devel/py-trytond/Makefile.common\"",
                    166:                ".include \"../../lang/python/egg.mk\"")
                    167:        t.CreateFileLines("devel/py-trytond/Makefile.common",
                    168:                MkCvsID,
                    169:                "PY_PATCHPLIST=\tyes")
                    170:        t.CreateFileLines("lang/python/egg.mk",
                    171:                MkCvsID,
                    172:                "PY_PATCHPLIST=\tyes")
                    173:        t.FinishSetUp()
1.1       rillig    174:
1.58      rillig    175:        G.Check(t.File("databases/py-trytond-ldap-authentication"))
1.35      rillig    176:
1.58      rillig    177:        // Since egg.mk and Makefile.common are unrelated, the definition of
                    178:        // PY_PATCHPLIST is not redundant in these files.
                    179:        t.CheckOutputEmpty()
1.1       rillig    180: }
                    181:
1.58      rillig    182: // As of April 2019, there are only a few files in the whole pkgsrc tree
                    183: // that are called Makefile.*, except Makefile.common, which occurs more
                    184: // often.
                    185: //
                    186: // Using the file extension for variants of that Makefile is confusing,
                    187: // therefore they should be renamed to *.mk.
                    188: func (s *Suite) Test_Package__Makefile_files(c *check.C) {
1.17      rillig    189:        t := s.Init(c)
                    190:
1.58      rillig    191:        t.SetUpPackage("category/package")
                    192:        t.CreateFileLines("category/package/Makefile.common",
                    193:                MkCvsID)
                    194:        t.CreateFileLines("category/package/Makefile.orig",
                    195:                MkCvsID)
                    196:        t.CreateFileLines("category/package/Makefile.php",
                    197:                MkCvsID)
                    198:        t.CreateFileLines("category/package/ext.mk",
                    199:                MkCvsID)
                    200:        t.FinishSetUp()
1.47      rillig    201:
1.58      rillig    202:        G.Check(t.File("category/package"))
1.3       rillig    203:
1.58      rillig    204:        // No warning for the Makefile.orig since the package is not
                    205:        // being imported at the moment; see Pkglint.checkReg.
1.47      rillig    206:        t.CheckOutputLines(
1.58      rillig    207:                "NOTE: ~/category/package/Makefile.php: " +
                    208:                        "Consider renaming \"Makefile.php\" to \"php.mk\".")
1.47      rillig    209: }
                    210:
1.58      rillig    211: func (s *Suite) Test_Package__patch_in_FILESDIR(c *check.C) {
1.47      rillig    212:        t := s.Init(c)
                    213:
1.58      rillig    214:        t.SetUpCommandLine("-Wall", "-Call")
                    215:        t.SetUpPackage("category/package")
                    216:        t.CreateFileLines("category/package/files/patch-aa",
                    217:                "This file can contain anything, no matter what the filename says.")
                    218:        t.FinishSetUp()
1.47      rillig    219:
1.58      rillig    220:        G.Check(t.File("category/package"))
1.1       rillig    221:
1.58      rillig    222:        // No warnings. The files in FILESDIR are independent of pkgsrc
                    223:        // and may contain anything. There are no naming conventions or
                    224:        // anything else.
                    225:        t.CheckOutputEmpty()
1.47      rillig    226: }
1.3       rillig    227:
1.58      rillig    228: // See https://mail-index.netbsd.org/tech-pkg/2018/07/22/msg020092.html
                    229: func (s *Suite) Test_Package__redundant_master_sites(c *check.C) {
1.47      rillig    230:        t := s.Init(c)
                    231:
1.58      rillig    232:        t.SetUpPkgsrc()
                    233:        t.SetUpMasterSite("MASTER_SITE_R_CRAN", "http://cran.r-project.org/src/")
                    234:        t.CreateFileLines("math/R/Makefile.extension",
                    235:                MkCvsID,
                    236:                "",
                    237:                "PKGNAME?=\tR-${R_PKGNAME}-${R_PKGVER}",
                    238:                "MASTER_SITES?=\t${MASTER_SITE_R_CRAN:=contrib/}",
                    239:                "GENERATE_PLIST+=\techo \"bin/r-package\";",
                    240:                "NO_CHECKSUM=\tyes",
                    241:                "LICENSE?=\tgnu-gpl-v2")
                    242:        t.CreateFileLines("math/R-date/Makefile",
1.48      rillig    243:                MkCvsID,
1.3       rillig    244:                "",
1.58      rillig    245:                "R_PKGNAME=\tdate",
                    246:                "R_PKGVER=\t1.2.3",
                    247:                "COMMENT=\tR package for handling date arithmetic",
                    248:                "MASTER_SITES=\t${MASTER_SITE_R_CRAN:=contrib/}", // Redundant; see math/R/Makefile.extension.
1.3       rillig    249:                "",
1.58      rillig    250:                ".include \"../../math/R/Makefile.extension\"",
1.47      rillig    251:                ".include \"../../mk/bsd.pkg.mk\"")
1.72      rillig    252:        t.CreateFileLines("math/R-date/DESCR",
                    253:                "Description")
1.58      rillig    254:        t.FinishSetUp()
1.47      rillig    255:
1.58      rillig    256:        // See Package.checkfilePackageMakefile
                    257:        G.checkdirPackage(t.File("math/R-date"))
1.1       rillig    258:
1.58      rillig    259:        // The definition in Makefile:6 is redundant because the same definition
                    260:        // occurs later in Makefile.extension:4.
                    261:        //
                    262:        // When a file includes another file, it's always the including file that
                    263:        // is marked as redundant since the included file typically provides the
                    264:        // generally useful value for several packages;
                    265:        // see RedundantScope.handleVarassign, keyword includePath.
1.17      rillig    266:        t.CheckOutputLines(
1.58      rillig    267:                "NOTE: ~/math/R-date/Makefile:6: " +
                    268:                        "Definition of MASTER_SITES is redundant " +
                    269:                        "because of ../../math/R/Makefile.extension:4.")
1.18      rillig    270: }
                    271:
1.58      rillig    272: // Before 2018-09-09, the .CURDIR variable did not have a fallback value.
                    273: // When resolving the relative path x11/gst-x11/${.CURDIR}/../../multimedia/gst-base/distinfo,
                    274: // "gst-x11/${.CURDIR}" was interpreted as "category/package", and the whole
                    275: // path was resolved to "x11/multimedia/gst-base/distinfo, which of course
                    276: // could not be found.
                    277: func (s *Suite) Test_Package__distinfo_from_other_package(c *check.C) {
1.18      rillig    278:        t := s.Init(c)
                    279:
1.58      rillig    280:        t.SetUpPkgsrc()
                    281:        t.Chdir(".")
                    282:        t.CreateFileLines("x11/gst-x11/Makefile",
                    283:                MkCvsID,
                    284:                ".include \"../../multimedia/gst-base/Makefile.common\"",
                    285:                ".include \"../../mk/bsd.pkg.mk\"")
                    286:        t.CreateFileLines("multimedia/gst-base/Makefile.common",
                    287:                MkCvsID,
                    288:                ".include \"plugins.mk\"")
                    289:        t.CreateFileLines("multimedia/gst-base/plugins.mk",
1.48      rillig    290:                MkCvsID,
1.58      rillig    291:                "DISTINFO_FILE=\t${.CURDIR}/../../multimedia/gst-base/distinfo")
                    292:        t.CreateFileLines("multimedia/gst-base/distinfo",
                    293:                CvsID,
1.18      rillig    294:                "",
1.58      rillig    295:                "SHA1 (patch-aa) = 1234")
                    296:        t.FinishSetUp()
1.48      rillig    297:
1.58      rillig    298:        G.Check("x11/gst-x11")
1.18      rillig    299:
                    300:        t.CheckOutputLines(
1.58      rillig    301:                "WARN: x11/gst-x11/Makefile: This package should have a PLIST file.",
                    302:                "ERROR: x11/gst-x11/Makefile: Each package must define its LICENSE.",
                    303:                "WARN: x11/gst-x11/Makefile: Each package should define a COMMENT.",
1.72      rillig    304:                "WARN: x11/gst-x11/../../multimedia/gst-base/distinfo:3: "+
                    305:                        "Patch file \"patch-aa\" does not exist in directory \"../../x11/gst-x11/patches\".",
                    306:                "ERROR: x11/gst-x11/Makefile: Each package must have a DESCR file.")
1.18      rillig    307: }
                    308:
1.58      rillig    309: func (s *Suite) Test_Package__case_insensitive(c *check.C) {
1.18      rillig    310:        t := s.Init(c)
                    311:
1.58      rillig    312:        t.SetUpPkgsrc()
                    313:        t.SetUpPackage("net/p5-Net-DNS")
                    314:        t.SetUpPackage("category/package",
                    315:                "DEPENDS+=\tp5-Net-DNS>=0:../../net/p5-net-dns")
                    316:        t.FinishSetUp()
                    317:
                    318:        // this test is only interesting on a case-insensitive filesystem
1.59      rillig    319:        if !t.File("mk/BSD.PKG.MK").IsFile() {
1.58      rillig    320:                return
                    321:        }
1.48      rillig    322:
1.58      rillig    323:        G.Check(t.File("category/package"))
1.48      rillig    324:
1.63      rillig    325:        // TODO: On a case-sensitive filesystem, p5-net-dns would not be found.
1.48      rillig    326:        t.CheckOutputEmpty()
                    327: }
                    328:
1.70      rillig    329: // This package has several identifiers that all differ:
                    330: //  - it lives in the directory "package"
                    331: //  - the package name is "pkgname"
                    332: //  - it downloads "distname-1.0.tar.gz"
                    333: //    (in some places the distname is used as the package name)
                    334: //  - in options.mk its name is "optid"
                    335: //  - in buildlink3.mk its name is "bl3id"
                    336: // All these identifiers should ideally be the same.
                    337: // For historic reasons, the package directory and the package name
                    338: // may differ.
                    339: func (s *Suite) Test_Package__different_package_identifiers(c *check.C) {
                    340:        t := s.Init(c)
                    341:
                    342:        t.SetUpPackage("category/package",
                    343:                "DISTNAME=\tdistname-1.0",
                    344:                "PKGNAME=\tpkgname-1.0")
                    345:        t.CreateFileLines("mk/bsd.options.mk")
                    346:        t.CreateFileLines("category/package/options.mk",
                    347:                MkCvsID,
                    348:                "",
                    349:                "PKG_OPTIONS_VAR=\tPKG_OPTIONS.optid",
                    350:                "PKG_SUPPORTED_OPTIONS=\t# none",
                    351:                "",
                    352:                ".include \"../../mk/bsd.options.mk\"",
                    353:                "",
                    354:                "# Nothing to do here")
                    355:        t.CreateFileBuildlink3Id("category/package/buildlink3.mk", "bl3id")
                    356:        t.Chdir("category/package")
                    357:        t.FinishSetUp()
                    358:
                    359:        G.checkdirPackage(".")
                    360:
                    361:        t.CheckOutputLines(
                    362:                "ERROR: buildlink3.mk:3: Package name mismatch "+
                    363:                        "between \"bl3id\" in this file and \"pkgname\" from Makefile:4.",
                    364:                "WARN: options.mk:3: The buildlink3 identifier \"bl3id\" "+
                    365:                        "should be the same as the options identifier \"optid\".")
                    366:
                    367: }
                    368:
1.58      rillig    369: func (s *Suite) Test_NewPackage(c *check.C) {
1.48      rillig    370:        t := s.Init(c)
1.18      rillig    371:
1.58      rillig    372:        t.SetUpPkgsrc()
                    373:        t.CreateFileLines("category/Makefile",
                    374:                MkCvsID)
                    375:        t.FinishSetUp()
1.18      rillig    376:
1.58      rillig    377:        t.ExpectAssert(func() { NewPackage("category") })
1.18      rillig    378: }
                    379:
1.59      rillig    380: func (s *Suite) Test_Package_load__variable_from_Makefile_used_in_builtin_mk(c *check.C) {
                    381:        t := s.Init(c)
                    382:
                    383:        t.SetUpPackage("devel/binutils",
                    384:                "BINUTILS_PREFIX=\t${PREFIX}/${MACHINE_GNU_PLATFORM}")
                    385:        t.CreateFileLines("devel/binutils/builtin.mk",
                    386:                MkCvsID,
                    387:                ".include \"../../mk/bsd.prefs.mk\"",
                    388:                "BINUTILS_PREFIX?=\t/usr",
                    389:                "",
                    390:                "BUILTIN_FIND_FILES.BINUTILS_FILES:=\t${BINUTILS_PREFIX}/include/bfd.h")
                    391:        t.FinishSetUp()
                    392:
                    393:        G.Check(t.File("devel/binutils"))
                    394:
                    395:        // The BINUTILS_PREFIX from the Makefile is not used since the
                    396:        // builtin.mk file is only parsed inside of buildlink3.mk, and
                    397:        // that doesn't happen for the package itself, but only for those
                    398:        // packages that depend on this package.
                    399:        t.CheckOutputLines(
                    400:                "WARN: ~/devel/binutils/Makefile:20: " +
                    401:                        "BINUTILS_PREFIX is defined but not used.")
                    402: }
                    403:
                    404: func (s *Suite) Test_Package_load__buildlink3_mk_includes_other_mk(c *check.C) {
                    405:        t := s.Init(c)
                    406:
                    407:        t.SetUpCommandLine("-Wall", "--explain")
                    408:        t.SetUpPackage("multimedia/libav")
1.62      rillig    409:        t.CreateFileBuildlink3("multimedia/libav/buildlink3.mk",
1.59      rillig    410:                ".include \"available.mk\"")
                    411:        t.CreateFileLines("multimedia/libav/available.mk",
                    412:                MkCvsID,
                    413:                "",
                    414:                "LIBAV_AVAILABLE=\tno")
                    415:        t.FinishSetUp()
                    416:
                    417:        G.Check(t.File("multimedia/libav"))
                    418:
                    419:        // From looking at the file available.mk alone, this variable looks
                    420:        // unused indeed, but its intention is to be used by other packages.
                    421:        // The explanation has a large paragraph covering exactly this case,
                    422:        // therefore the warning is ok.
                    423:        t.CheckOutputLines(
                    424:                "WARN: ~/multimedia/libav/available.mk:3: "+
                    425:                        "LIBAV_AVAILABLE is defined but not used.",
                    426:                "",
                    427:                "\tThis might be a simple typo.",
                    428:                "",
                    429:                "\tIf a package provides a file containing several related variables",
                    430:                "\t(such as module.mk, app.mk, extension.mk), that file may define",
                    431:                "\tvariables that look unused since they are only used by other",
                    432:                "\tpackages. These variables should be documented at the head of the",
                    433:                "\tfile; see mk/subst.mk for an example of such a documentation",
                    434:                "\tcomment.",
                    435:                "")
                    436: }
                    437:
1.58      rillig    438: // Demonstrates that Makefile fragments are handled differently,
                    439: // depending on the directory they are in.
                    440: func (s *Suite) Test_Package_load__extra_files(c *check.C) {
1.48      rillig    441:        t := s.Init(c)
                    442:
1.58      rillig    443:        t.SetUpPackage("category/package",
                    444:                "PKGDIR=\t../../category/other")
                    445:        t.SetUpPackage("category/other")
                    446:        t.Chdir("category/package")
                    447:        t.CreateFileLines("gnu-style.mk",
                    448:                "ifeq ($(CC),gcc)",
                    449:                "IS_GCC=\tyes",
                    450:                "else",
                    451:                "IS_GCC=\tno",
                    452:                "endif")
                    453:        t.CreateFileLines("patches/patch-Makefile.mk",
                    454:                CvsID,
1.48      rillig    455:                "",
1.58      rillig    456:                "Documentation",
1.48      rillig    457:                "",
1.58      rillig    458:                "--- Makefile.mk.orig",
                    459:                "--- Makefile.mk",
                    460:                "@@ -1,1 +1,1 @@",
                    461:                "- old",
                    462:                "+ new")
1.59      rillig    463:        t.CreateFileLines("patches/readme.mk", // Is ignored
1.58      rillig    464:                "This is not a BSD-style Makefile.")
                    465:        t.Copy("gnu-style.mk", "files/gnu-style.mk")
                    466:        t.Copy("gnu-style.mk", "../../category/other/gnu-style.mk")
                    467:
                    468:        t.FinishSetUp()
                    469:
                    470:        G.Check(".")
1.48      rillig    471:
1.58      rillig    472:        t.CheckOutputLines(
                    473:                // All *.mk files in the package directory are assumed
                    474:                // to be BSD-style Makefiles, therefore the many warnings.
                    475:                "WARN: gnu-style.mk:1: Please use curly braces {} instead of round parentheses () for CC.",
                    476:                "ERROR: gnu-style.mk:1: Unknown Makefile line format: \"ifeq ($(CC),gcc)\".",
                    477:                "ERROR: gnu-style.mk:3: Unknown Makefile line format: \"else\".",
                    478:                "ERROR: gnu-style.mk:5: Unknown Makefile line format: \"endif\".",
1.48      rillig    479:
1.58      rillig    480:                "ERROR: distinfo: Patch \"patches/patch-Makefile.mk\" is not recorded. Run \""+confMake+" makepatchsum\".",
1.48      rillig    481:
1.58      rillig    482:                // The following diagnostics are duplicated because the files from
                    483:                // the package directory are loaded once during Package.load, just
                    484:                // for collecting the used variables. And then a second time in
                    485:                // Package.check to perform the actual checks.
                    486:                //
                    487:                // The above diagnostics are only those from parsing the file, to
                    488:                // correctly classify the lines. This is because the main purpose
                    489:                // of Package.load above is to load the files and collect some
                    490:                // data, not to perform the actual checks.
                    491:                //
                    492:                // Therefore, the below lines contain two more diagnostics.
                    493:                "WARN: gnu-style.mk:1: Please use curly braces {} instead of round parentheses () for CC.",
                    494:                "ERROR: gnu-style.mk:1: Unknown Makefile line format: \"ifeq ($(CC),gcc)\".",
                    495:                "ERROR: gnu-style.mk:3: Unknown Makefile line format: \"else\".",
                    496:                "ERROR: gnu-style.mk:5: Unknown Makefile line format: \"endif\".",
                    497:                "ERROR: gnu-style.mk:1: Expected \""+MkCvsID+"\".",
                    498:                "WARN: gnu-style.mk:2: IS_GCC is defined but not used.",
1.18      rillig    499:
1.58      rillig    500:                // There is no warning about files/gnu-style.mk since pkglint
                    501:                // doesn't even attempt at guessing the file type. Files placed
                    502:                // in this directory can have an arbitrary format.
1.47      rillig    503:
1.58      rillig    504:                "ERROR: ../../category/other/distinfo: Patch \"../../category/package/patches/"+
                    505:                        "patch-Makefile.mk\" is not recorded. Run \""+confMake+" makepatchsum\".",
1.18      rillig    506:
1.58      rillig    507:                // All *.mk files from PKGDIR are loaded to see which variables
                    508:                // they define, in order to make the check for unused variables
                    509:                // more reliable.
                    510:                //
                    511:                // All files that belong to the package itself, and not to pkgsrc
                    512:                // should therefore be placed in the files/ directory.
                    513:                "WARN: ../../category/other/gnu-style.mk:1: "+
                    514:                        "Please use curly braces {} instead of round parentheses () for CC.",
                    515:                "ERROR: ../../category/other/gnu-style.mk:1: Unknown Makefile line format: \"ifeq ($(CC),gcc)\".",
                    516:                "ERROR: ../../category/other/gnu-style.mk:3: Unknown Makefile line format: \"else\".",
                    517:                "ERROR: ../../category/other/gnu-style.mk:5: Unknown Makefile line format: \"endif\".",
                    518:                "ERROR: ../../category/other/gnu-style.mk:1: Expected \""+MkCvsID+"\".",
                    519:                "WARN: ../../category/other/gnu-style.mk:2: IS_GCC is defined but not used.",
1.47      rillig    520:
1.58      rillig    521:                "ERROR: patches/patch-Makefile.mk: Contains no patch.",
                    522:                "WARN: patches/readme.mk: Patch files should be named \"patch-\", followed by letters, '-', '_', '.', and digits only.")
1.18      rillig    523: }
                    524:
1.71      rillig    525: func (s *Suite) Test_Package_loadBuildlink3Pkgbase(c *check.C) {
                    526:        t := s.Init(c)
                    527:
                    528:        t.SetUpPackage("category/package",
                    529:                ".include \"../../category/lib/buildlink3.mk\"")
                    530:        t.CreateFileBuildlink3("category/package/buildlink3.mk",
                    531:                "pkgbase := package",
                    532:                ".include \"../../mk/pkg-build-options.mk\"",
                    533:                ".include \"../../category/lib/buildlink3.mk\"")
                    534:        t.SetUpPackage("category/lib")
                    535:        t.CreateFileBuildlink3("category/lib/buildlink3.mk",
                    536:                "pkgbase := lib",
                    537:                ".include \"../../mk/pkg-build-options.mk\"")
                    538:        t.CreateFileLines("mk/pkg-build-options.mk")
                    539:        t.Chdir("category/package")
                    540:        t.FinishSetUp()
                    541:        pkg := NewPackage(".")
                    542:
                    543:        pkg.Check()
                    544:
                    545:        t.CheckOutputEmpty()
                    546:        seenPkgbase := pkg.seenPkgbase
                    547:        t.Check(seenPkgbase.seen, check.HasLen, 2)
                    548:        t.CheckEquals(seenPkgbase.Seen("lib"), true)
                    549:        t.CheckEquals(seenPkgbase.Seen("package"), true)
                    550: }
                    551:
1.58      rillig    552: func (s *Suite) Test_Package_loadPackageMakefile__dump(c *check.C) {
1.35      rillig    553:        t := s.Init(c)
                    554:
1.58      rillig    555:        t.SetUpCommandLine("--dumpmakefile")
                    556:        t.SetUpPkgsrc()
                    557:        t.CreateFileLines("category/Makefile")
1.72      rillig    558:        t.CreateFileLines("category/package/DESCR",
                    559:                "Description")
1.58      rillig    560:        t.CreateFileLines("category/package/PLIST",
                    561:                PlistCvsID,
                    562:                "bin/program")
                    563:        t.CreateFileLines("category/package/distinfo",
                    564:                CvsID,
                    565:                "",
                    566:                "SHA1 (distfile-1.0.tar.gz) = 12341234...",
                    567:                "RMD160 (distfile-1.0.tar.gz) = 12341234...",
                    568:                "SHA512 (distfile-1.0.tar.gz) = 12341234...",
                    569:                "Size (distfile-1.0.tar.gz) = 12341234...")
                    570:        t.CreateFileLines("category/package/Makefile",
1.48      rillig    571:                MkCvsID,
1.35      rillig    572:                "",
1.61      rillig    573:                "CATEGORIES=\tcategory",
1.35      rillig    574:                "",
                    575:                "COMMENT=\tComment",
1.58      rillig    576:                "LICENSE=\t2-clause-bsd")
                    577:        // TODO: There is no .include line at the end of the Makefile.
                    578:        //  This should always be checked though.
                    579:        t.FinishSetUp()
1.48      rillig    580:
1.58      rillig    581:        G.checkdirPackage(t.File("category/package"))
1.35      rillig    582:
1.58      rillig    583:        t.CheckOutputLines(
                    584:                "Whole Makefile (with all included files) follows:",
                    585:                "~/category/package/Makefile:1: "+MkCvsID,
                    586:                "~/category/package/Makefile:2: ",
1.61      rillig    587:                "~/category/package/Makefile:3: CATEGORIES=\tcategory",
1.58      rillig    588:                "~/category/package/Makefile:4: ",
                    589:                "~/category/package/Makefile:5: COMMENT=\tComment",
                    590:                "~/category/package/Makefile:6: LICENSE=\t2-clause-bsd")
1.35      rillig    591: }
                    592:
1.58      rillig    593: func (s *Suite) Test_Package_loadPackageMakefile(c *check.C) {
1.18      rillig    594:        t := s.Init(c)
                    595:
1.58      rillig    596:        t.CreateFileLines("category/package/Makefile",
1.48      rillig    597:                MkCvsID,
1.18      rillig    598:                "",
1.58      rillig    599:                "PKGNAME=pkgname-1.67",
                    600:                "DISTNAME=distfile_1_67",
                    601:                ".include \"../../category/package/Makefile\"")
1.67      rillig    602:        pkg := NewPackage(t.File("category/package"))
1.48      rillig    603:
1.67      rillig    604:        pkg.loadPackageMakefile()
1.18      rillig    605:
1.58      rillig    606:        // Including a package Makefile directly is an error (in the last line),
                    607:        // but that is checked later.
                    608:        // This test demonstrates that a file including itself does not lead to an
                    609:        // endless loop while parsing. It might trigger an error in the future.
1.18      rillig    610:        t.CheckOutputEmpty()
1.1       rillig    611: }
                    612:
1.58      rillig    613: func (s *Suite) Test_Package_loadPackageMakefile__PECL_VERSION(c *check.C) {
1.17      rillig    614:        t := s.Init(c)
1.15      rillig    615:
1.58      rillig    616:        t.CreateFileLines("lang/php/ext.mk",
1.48      rillig    617:                MkCvsID,
1.15      rillig    618:                "",
1.58      rillig    619:                "PHPEXT_MK=      # defined",
                    620:                "PHPPKGSRCDIR=   ../../lang/php72",
                    621:                "LICENSE?=        unknown-license",
                    622:                "COMMENT?=       Some PHP package",
                    623:                "GENERATE_PLIST+=# none",
1.15      rillig    624:                "",
1.58      rillig    625:                ".if !defined(PECL_VERSION)",
                    626:                "DISTINFO_FILE=  ${.CURDIR}/${PHPPKGSRCDIR}/distinfo",
                    627:                ".endif",
                    628:                ".if defined(USE_PHP_EXT_PATCHES)",
                    629:                "PATCHDIR=       ${.CURDIR}/${PHPPKGSRCDIR}/patches",
                    630:                ".endif")
                    631:        pkg := t.SetUpPackage("category/package",
                    632:                "PECL_VERSION=\t1.1.2",
                    633:                ".include \"../../lang/php/ext.mk\"")
                    634:        t.FinishSetUp()
1.15      rillig    635:
1.58      rillig    636:        G.Check(pkg)
1.15      rillig    637: }
                    638:
1.58      rillig    639: // Pkglint loads some files from the pkgsrc infrastructure and skips others.
                    640: //
                    641: // When a buildlink3.mk file from the infrastructure is included, it should
                    642: // be allowed to include its corresponding builtin.mk file in turn.
                    643: //
                    644: // This is necessary to load the correct variable assignments for the
                    645: // redundancy check, in particular variable assignments that serve as
                    646: // arguments to "procedure calls", such as mk/find-files.mk.
                    647: func (s *Suite) Test_Package_parse__include_infrastructure(c *check.C) {
1.17      rillig    648:        t := s.Init(c)
                    649:
1.58      rillig    650:        t.SetUpCommandLine("--dumpmakefile")
                    651:        t.SetUpPackage("category/package",
                    652:                ".include \"../../mk/dlopen.buildlink3.mk\"",
                    653:                ".include \"../../mk/pthread.buildlink3.mk\"")
                    654:        t.CreateFileLines("mk/dlopen.buildlink3.mk",
                    655:                ".include \"dlopen.builtin.mk\"")
                    656:        t.CreateFileLines("mk/dlopen.builtin.mk",
                    657:                ".include \"pthread.builtin.mk\"")
                    658:        t.CreateFileLines("mk/pthread.buildlink3.mk",
                    659:                ".include \"pthread.builtin.mk\"")
                    660:        t.CreateFileLines("mk/pthread.builtin.mk",
                    661:                "# This should be included by pthread.buildlink3.mk")
                    662:        t.FinishSetUp()
1.48      rillig    663:
1.58      rillig    664:        G.Check(t.File("category/package"))
1.13      rillig    665:
1.58      rillig    666:        t.CheckOutputLines(
                    667:                "Whole Makefile (with all included files) follows:",
                    668:                "~/category/package/Makefile:1: "+MkCvsID,
                    669:                "~/category/package/Makefile:2: ",
                    670:                "~/category/package/Makefile:3: DISTNAME=\tpackage-1.0",
                    671:                "~/category/package/Makefile:4: #PKGNAME=\tpackage-1.0",
                    672:                "~/category/package/Makefile:5: CATEGORIES=\tcategory",
                    673:                "~/category/package/Makefile:6: MASTER_SITES=\t# none",
                    674:                "~/category/package/Makefile:7: ",
                    675:                "~/category/package/Makefile:8: MAINTAINER=\tpkgsrc-users@NetBSD.org",
                    676:                "~/category/package/Makefile:9: HOMEPAGE=\t# none",
                    677:                "~/category/package/Makefile:10: COMMENT=\tDummy package",
                    678:                "~/category/package/Makefile:11: LICENSE=\t2-clause-bsd",
                    679:                "~/category/package/Makefile:12: ",
                    680:                "~/category/package/Makefile:13: .include \"suppress-varorder.mk\"",
                    681:                "~/category/package/suppress-varorder.mk:1: "+MkCvsID,
                    682:                "~/category/package/Makefile:14: ",
                    683:                "~/category/package/Makefile:15: # filler",
                    684:                "~/category/package/Makefile:16: # filler",
                    685:                "~/category/package/Makefile:17: # filler",
                    686:                "~/category/package/Makefile:18: # filler",
                    687:                "~/category/package/Makefile:19: ",
                    688:                "~/category/package/Makefile:20: .include \"../../mk/dlopen.buildlink3.mk\"",
                    689:                "~/category/package/../../mk/dlopen.buildlink3.mk:1: .include \"dlopen.builtin.mk\"",
                    690:                "~/mk/dlopen.builtin.mk:1: .include \"pthread.builtin.mk\"",
                    691:                "~/category/package/Makefile:21: .include \"../../mk/pthread.buildlink3.mk\"",
                    692:                "~/category/package/../../mk/pthread.buildlink3.mk:1: .include \"pthread.builtin.mk\"",
                    693:                "~/mk/pthread.builtin.mk:1: # This should be included by pthread.buildlink3.mk",
                    694:                "~/category/package/Makefile:22: ",
                    695:                "~/category/package/Makefile:23: .include \"../../mk/bsd.pkg.mk\"")
1.13      rillig    696: }
                    697:
1.58      rillig    698: // See https://github.com/rillig/pkglint/issues/1
                    699: func (s *Suite) Test_Package_parse__include_without_exists(c *check.C) {
1.18      rillig    700:        t := s.Init(c)
                    701:
1.58      rillig    702:        t.SetUpPackage("category/package",
                    703:                ".include \"options.mk\"")
                    704:        t.FinishSetUp()
1.48      rillig    705:
1.58      rillig    706:        G.checkdirPackage(t.File("category/package"))
1.18      rillig    707:
                    708:        t.CheckOutputLines(
1.58      rillig    709:                "ERROR: ~/category/package/Makefile:20: Cannot read \"options.mk\".")
1.48      rillig    710: }
                    711:
1.58      rillig    712: // See https://github.com/rillig/pkglint/issues/1
                    713: func (s *Suite) Test_Package_parse__include_after_exists(c *check.C) {
1.48      rillig    714:        t := s.Init(c)
                    715:
1.58      rillig    716:        t.SetUpPackage("category/package",
                    717:                ".if exists(options.mk)",
                    718:                ".  include \"options.mk\"",
                    719:                ".endif")
                    720:        t.FinishSetUp()
1.48      rillig    721:
1.58      rillig    722:        G.checkdirPackage(t.File("category/package"))
1.48      rillig    723:
1.58      rillig    724:        // No error message at all because of the .if exists before.
                    725:        t.CheckOutputEmpty()
1.48      rillig    726: }
                    727:
1.58      rillig    728: // See https://github.com/rillig/pkglint/issues/1
                    729: func (s *Suite) Test_Package_parse__include_other_after_exists(c *check.C) {
1.48      rillig    730:        t := s.Init(c)
                    731:
1.58      rillig    732:        t.SetUpPackage("category/package",
                    733:                ".if exists(options.mk)",
                    734:                ".  include \"another.mk\"",
                    735:                ".endif")
                    736:        t.FinishSetUp()
1.48      rillig    737:
1.58      rillig    738:        G.checkdirPackage(t.File("category/package"))
1.18      rillig    739:
1.58      rillig    740:        t.CheckOutputLines(
                    741:                "ERROR: ~/category/package/Makefile:21: Cannot read \"another.mk\".")
1.18      rillig    742: }
                    743:
1.58      rillig    744: func (s *Suite) Test_Package_parse__simple(c *check.C) {
1.48      rillig    745:        t := s.Init(c)
                    746:
1.58      rillig    747:        t.SetUpPackage("category/package")
                    748:        t.Chdir("category/package")
                    749:        t.FinishSetUp()
1.48      rillig    750:
1.67      rillig    751:        pkg := NewPackage(".")
                    752:        pkg.included.Trace = true
                    753:        pkg.load()
1.48      rillig    754:
                    755:        t.CheckOutputLines(
1.58      rillig    756:                "FirstTime: suppress-varorder.mk")
1.48      rillig    757: }
                    758:
1.58      rillig    759: func (s *Suite) Test_Package_parse__nonexistent_Makefile(c *check.C) {
1.48      rillig    760:        t := s.Init(c)
                    761:
1.58      rillig    762:        t.SetUpPackage("category/package")
                    763:        t.Chdir("category/package")
                    764:        t.Remove("Makefile")
                    765:        t.FinishSetUp()
1.48      rillig    766:
1.67      rillig    767:        pkg := NewPackage(".")
                    768:        pkg.included.Trace = true
                    769:        pkg.load()
1.48      rillig    770:
                    771:        t.CheckOutputLines(
1.58      rillig    772:                "ERROR: Makefile: Cannot be read.")
1.48      rillig    773: }
                    774:
1.58      rillig    775: func (s *Suite) Test_Package_parse__include_in_same_directory(c *check.C) {
1.17      rillig    776:        t := s.Init(c)
                    777:
1.58      rillig    778:        t.SetUpPackage("category/package",
                    779:                ".include \"version.mk\"")
                    780:        t.Chdir("category/package")
                    781:        t.CreateFileLines("version.mk",
                    782:                MkCvsID)
                    783:        t.FinishSetUp()
1.3       rillig    784:
1.67      rillig    785:        pkg := NewPackage(".")
                    786:        pkg.included.Trace = true
                    787:        pkg.load()
1.3       rillig    788:
1.58      rillig    789:        t.CheckOutputLines(
                    790:                "FirstTime: suppress-varorder.mk",
                    791:                "FirstTime: version.mk")
1.3       rillig    792: }
                    793:
1.58      rillig    794: func (s *Suite) Test_Package_parse__nonexistent_include(c *check.C) {
1.17      rillig    795:        t := s.Init(c)
                    796:
1.58      rillig    797:        t.SetUpPackage("category/package",
                    798:                ".include \"version.mk\"")
                    799:        t.Chdir("category/package")
                    800:        t.FinishSetUp()
1.3       rillig    801:
1.67      rillig    802:        pkg := NewPackage(".")
                    803:        pkg.included.Trace = true
                    804:        pkg.load()
1.3       rillig    805:
1.58      rillig    806:        t.CheckOutputLines(
                    807:                "FirstTime: suppress-varorder.mk",
                    808:                "FirstTime: version.mk",
                    809:                "ERROR: Makefile:20: Cannot read \"version.mk\".")
1.1       rillig    810: }
1.4       rillig    811:
1.58      rillig    812: // When reading the package Makefile, pkglint loads and interprets each
                    813: // file only once. This is especially important for packages with a large
                    814: // dependency graph containing many common subdependencies.
                    815: func (s *Suite) Test_Package_parse__include_twice(c *check.C) {
1.30      rillig    816:        t := s.Init(c)
                    817:
1.58      rillig    818:        t.SetUpPackage("category/package",
                    819:                ".include \"version.mk\"",
                    820:                ".include \"version.mk\"")
                    821:        t.Chdir("category/package")
                    822:        t.CreateFileLines("version.mk",
                    823:                MkCvsID)
1.43      rillig    824:        t.FinishSetUp()
1.30      rillig    825:
1.67      rillig    826:        pkg := NewPackage(".")
                    827:        pkg.included.Trace = true
                    828:        pkg.load()
1.30      rillig    829:
                    830:        t.CheckOutputLines(
1.58      rillig    831:                "FirstTime: suppress-varorder.mk",
                    832:                "FirstTime: version.mk")
1.30      rillig    833: }
                    834:
1.58      rillig    835: func (s *Suite) Test_Package_parse__include_in_other_directory(c *check.C) {
1.41      rillig    836:        t := s.Init(c)
                    837:
1.58      rillig    838:        t.SetUpPackage("category/package",
                    839:                ".include \"../../category/other/version.mk\"")
                    840:        t.Chdir("category/package")
                    841:        t.CreateFileLines("../../category/other/version.mk",
                    842:                MkCvsID)
1.43      rillig    843:        t.FinishSetUp()
1.41      rillig    844:
1.67      rillig    845:        pkg := NewPackage(".")
                    846:        pkg.included.Trace = true
                    847:        pkg.load()
1.41      rillig    848:
                    849:        t.CheckOutputLines(
1.58      rillig    850:                "FirstTime: suppress-varorder.mk",
                    851:                "FirstTime: ../../category/other/version.mk")
1.41      rillig    852: }
                    853:
1.58      rillig    854: // Demonstrates that Package.included contains the file paths of the
                    855: // included files, relative to the package directory.
                    856: func (s *Suite) Test_Package_parse__includes_in_other_directory(c *check.C) {
1.48      rillig    857:        t := s.Init(c)
                    858:
1.58      rillig    859:        t.SetUpPackage("category/package",
                    860:                ".include \"../../category/other/module.mk\"")
                    861:        t.Chdir("category/package")
                    862:        t.CreateFileLines("../../category/other/module.mk",
                    863:                MkCvsID,
                    864:                ".include \"version.mk\"")
                    865:        t.CreateFileLines("../../category/other/version.mk",
                    866:                MkCvsID)
1.48      rillig    867:        t.FinishSetUp()
                    868:
1.67      rillig    869:        pkg := NewPackage(".")
                    870:        pkg.included.Trace = true
                    871:        pkg.load()
1.48      rillig    872:
1.58      rillig    873:        t.CheckOutputLines(
                    874:                "FirstTime: suppress-varorder.mk",
                    875:                "FirstTime: ../../category/other/module.mk",
                    876:                "FirstTime: ../../category/other/version.mk")
1.48      rillig    877: }
                    878:
1.58      rillig    879: func (s *Suite) Test_Package_parse__nonexistent_in_other_directory(c *check.C) {
1.30      rillig    880:        t := s.Init(c)
                    881:
1.58      rillig    882:        t.SetUpPackage("category/package",
                    883:                ".include \"../../category/other/module.mk\"")
                    884:        t.Chdir("category/package")
                    885:        t.CreateFileLines("../../category/other/module.mk",
                    886:                MkCvsID,
                    887:                ".include \"version.mk\"")
1.43      rillig    888:        t.FinishSetUp()
1.30      rillig    889:
1.67      rillig    890:        pkg := NewPackage(".")
                    891:        pkg.included.Trace = true
                    892:        pkg.load()
1.30      rillig    893:
                    894:        t.CheckOutputLines(
1.58      rillig    895:                "FirstTime: suppress-varorder.mk",
                    896:                "FirstTime: ../../category/other/module.mk",
                    897:                "FirstTime: ../../category/other/version.mk",
                    898:                "ERROR: ../../category/other/module.mk:2: Cannot read \"version.mk\".")
1.30      rillig    899: }
                    900:
1.58      rillig    901: func (s *Suite) Test_Package_parse__skipping(c *check.C) {
1.48      rillig    902:        t := s.Init(c)
                    903:
                    904:        pkg := t.SetUpPackage("category/package",
1.58      rillig    905:                ".include \"${MYSQL_PKGSRCDIR:S/-client$/-server/}/buildlink3.mk\"")
1.48      rillig    906:        t.FinishSetUp()
                    907:
1.58      rillig    908:        t.EnableTracingToLog()
1.48      rillig    909:        G.Check(pkg)
1.58      rillig    910:        t.EnableSilentTracing()
1.48      rillig    911:
1.58      rillig    912:        // Since 2018-12-16 there is no warning or note anymore for the
                    913:        // buildlink3.mk file being skipped since it didn't help the average
                    914:        // pkglint user.
1.48      rillig    915:
1.58      rillig    916:        // The information is still available in the trace log though.
1.41      rillig    917:
1.58      rillig    918:        output := t.Output()
                    919:        var relevant []string
                    920:        for _, line := range strings.Split(output, "\n") {
1.61      rillig    921:                if contains(line, "Skipping unresolvable") {
1.58      rillig    922:                        relevant = append(relevant, line)
                    923:                }
                    924:        }
1.41      rillig    925:
1.58      rillig    926:        t.CheckDeepEquals(relevant, []string{
                    927:                "TRACE: 1 2 3 4   ~/category/package/Makefile:20: " +
                    928:                        "Skipping unresolvable include file \"${MYSQL_PKGSRCDIR:S/-client$/-server/}/buildlink3.mk\"."})
1.41      rillig    929: }
                    930:
1.58      rillig    931: func (s *Suite) Test_Package_parse__not_found(c *check.C) {
1.41      rillig    932:        t := s.Init(c)
                    933:
1.58      rillig    934:        pkg := t.SetUpPackage("category/package",
                    935:                ".include \"../../devel/zlib/buildlink3.mk\"")
                    936:        t.CreateFileLines("devel/zlib/buildlink3.mk",
                    937:                ".include \"../../enoent/enoent/buildlink3.mk\"")
1.43      rillig    938:        t.FinishSetUp()
1.41      rillig    939:
1.58      rillig    940:        G.checkdirPackage(pkg)
1.41      rillig    941:
1.58      rillig    942:        t.CheckOutputLines(
                    943:                "ERROR: ~/devel/zlib/buildlink3.mk:1: Cannot read \"../../enoent/enoent/buildlink3.mk\".")
1.41      rillig    944: }
                    945:
1.58      rillig    946: func (s *Suite) Test_Package_parse__relative(c *check.C) {
1.52      rillig    947:        t := s.Init(c)
                    948:
1.58      rillig    949:        t.CreateFileLines("category/package/extra.mk",
1.52      rillig    950:                MkCvsID)
1.58      rillig    951:        pkg := t.SetUpPackage("category/package",
                    952:                ".include \"../package/extra.mk\"")
                    953:        t.FinishSetUp()
1.52      rillig    954:
1.58      rillig    955:        G.Check(pkg)
1.52      rillig    956:
                    957:        t.CheckOutputLines(
1.58      rillig    958:                "WARN: ~/category/package/Makefile:20: " +
                    959:                        "References to other packages should look " +
                    960:                        "like \"../../category/package\", not \"../package\".")
1.52      rillig    961: }
                    962:
1.58      rillig    963: // When a buildlink3.mk file is included, the corresponding builtin.mk
                    964: // file is included by the pkgsrc infrastructure. Therefore all variables
                    965: // declared in the builtin.mk file become known in the package.
                    966: func (s *Suite) Test_Package_parse__builtin_mk(c *check.C) {
1.52      rillig    967:        t := s.Init(c)
                    968:
1.58      rillig    969:        t.SetUpTool("echo", "ECHO", AtRunTime)
1.52      rillig    970:        t.SetUpPackage("category/package",
1.58      rillig    971:                ".include \"../../category/lib1/buildlink3.mk\"",
                    972:                "",
                    973:                "show-var-from-builtin: .PHONY",
                    974:                "\techo ${VAR_FROM_BUILTIN} ${OTHER_VAR}")
1.62      rillig    975:        t.CreateFileBuildlink3("category/lib1/buildlink3.mk")
1.58      rillig    976:        t.CreateFileLines("category/lib1/builtin.mk",
1.52      rillig    977:                MkCvsID,
1.58      rillig    978:                "VAR_FROM_BUILTIN=\t# defined")
                    979:        t.FinishSetUp()
1.52      rillig    980:
1.58      rillig    981:        G.Check(t.File("category/package"))
1.52      rillig    982:
                    983:        t.CheckOutputLines(
1.58      rillig    984:                "WARN: ~/category/package/Makefile:23: Please use \"${ECHO}\" instead of \"echo\".",
                    985:                "WARN: ~/category/package/Makefile:23: OTHER_VAR is used but not defined.")
1.52      rillig    986: }
                    987:
1.58      rillig    988: // Ensures that the paths in Package.included are indeed relative to the
                    989: // package directory. This hadn't been the case until March 2019.
                    990: func (s *Suite) Test_Package_parse__included(c *check.C) {
1.52      rillig    991:        t := s.Init(c)
                    992:
                    993:        t.SetUpPackage("category/package",
1.58      rillig    994:                ".include \"../../devel/library/buildlink3.mk\"",
                    995:                ".include \"../../lang/language/module.mk\"")
                    996:        t.SetUpPackage("devel/library")
1.62      rillig    997:        t.CreateFileBuildlink3("devel/library/buildlink3.mk")
1.58      rillig    998:        t.CreateFileLines("devel/library/builtin.mk",
                    999:                MkCvsID)
                   1000:        t.CreateFileLines("lang/language/module.mk",
1.52      rillig   1001:                MkCvsID,
1.58      rillig   1002:                ".include \"version.mk\"")
                   1003:        t.CreateFileLines("lang/language/version.mk",
1.52      rillig   1004:                MkCvsID)
1.58      rillig   1005:        t.FinishSetUp()
                   1006:        t.Chdir("category/package")
                   1007:        pkg := NewPackage(".")
1.52      rillig   1008:
1.58      rillig   1009:        pkg.included.Trace = true
                   1010:        pkg.loadPackageMakefile()
1.52      rillig   1011:
                   1012:        t.CheckOutputLines(
1.58      rillig   1013:                "FirstTime: suppress-varorder.mk",
                   1014:                "FirstTime: ../../devel/library/buildlink3.mk",
                   1015:                "FirstTime: ../../devel/library/builtin.mk",
                   1016:                "FirstTime: ../../lang/language/module.mk",
                   1017:                "FirstTime: ../../lang/language/version.mk")
1.52      rillig   1018: }
                   1019:
1.58      rillig   1020: func (s *Suite) Test_Package_parse__include_Makefile_common_same_directory(c *check.C) {
1.17      rillig   1021:        t := s.Init(c)
                   1022:
1.58      rillig   1023:        t.SetUpPackage("category/dependency")
                   1024:        t.CreateFileLines("category/dependency/Makefile.common",
                   1025:                MkCvsID,
                   1026:                "#",
                   1027:                "#")
                   1028:        t.SetUpPackage("category/package",
                   1029:                ".include \"../../category/dependency/Makefile.common\"",
                   1030:                ".include \"Makefile.common\"")
                   1031:        t.CreateFileLines("category/package/Makefile.common",
                   1032:                MkCvsID,
                   1033:                "#",
                   1034:                "#")
                   1035:        t.FinishSetUp()
1.4       rillig   1036:
1.58      rillig   1037:        G.Check(t.File("category/package"))
1.4       rillig   1038:
1.17      rillig   1039:        t.CheckOutputLines(
1.58      rillig   1040:                "WARN: ~/category/dependency/Makefile.common:1: " +
                   1041:                        "Please add a line \"# used by category/package/Makefile\" here.")
1.4       rillig   1042: }
1.7       rillig   1043:
1.58      rillig   1044: func (s *Suite) Test_Package_parse__include_Makefile_common_explicit(c *check.C) {
1.48      rillig   1045:        t := s.Init(c)
                   1046:
1.58      rillig   1047:        t.SetUpPackage("category/dependency")
                   1048:        t.CreateFileLines("category/dependency/Makefile.common",
                   1049:                MkCvsID,
                   1050:                "#",
                   1051:                "#")
                   1052:        t.SetUpPackage("category/package",
                   1053:                ".include \"../../category/dependency/Makefile.common\"",
                   1054:                ".include \"../../category/package/Makefile.common\"")
                   1055:        t.CreateFileLines("category/package/Makefile.common",
                   1056:                MkCvsID,
                   1057:                "#",
                   1058:                "#")
1.48      rillig   1059:        t.FinishSetUp()
                   1060:
1.58      rillig   1061:        G.Check(t.File("category/package"))
1.48      rillig   1062:
1.58      rillig   1063:        t.CheckOutputLines(
                   1064:                "WARN: ~/category/dependency/Makefile.common:1: " +
                   1065:                        "Please add a line \"# used by category/package/Makefile\" here.")
1.48      rillig   1066: }
                   1067:
1.58      rillig   1068: func (s *Suite) Test_Package_parse__fallback_lookup_in_package_directory(c *check.C) {
1.48      rillig   1069:        t := s.Init(c)
                   1070:
1.58      rillig   1071:        t.CreateFileLines("mk/pthread.buildlink3.mk",
                   1072:                MkCvsID,
                   1073:                ".include \"../../mk/pthread.builtin.mk\"")
                   1074:        t.CreateFileLines("mk/pthread.builtin.mk",
                   1075:                MkCvsID)
1.48      rillig   1076:        t.SetUpPackage("category/package",
1.58      rillig   1077:                ".include \"../../mk/pthread.buildlink3.mk\"")
1.48      rillig   1078:        t.FinishSetUp()
                   1079:
                   1080:        G.Check(t.File("category/package"))
                   1081:
                   1082:        t.CheckOutputLines(
1.63      rillig   1083:                "WARN: ~/mk/pthread.buildlink3.mk:2: " +
1.58      rillig   1084:                        "The path to the included file should be \"pthread.builtin.mk\".")
1.48      rillig   1085: }
                   1086:
1.61      rillig   1087: func (s *Suite) Test_Package_loadIncluded__nested_inclusion(c *check.C) {
                   1088:        t := s.Init(c)
                   1089:
                   1090:        t.SetUpPackage("x11/kde-runtime4",
                   1091:                ".include \"../../x11/kde-libs4/buildlink3.mk\"")
                   1092:        t.SetUpPackage("x11/kde-libs4")
1.62      rillig   1093:        t.CreateFileBuildlink3("x11/kde-libs4/buildlink3.mk",
1.61      rillig   1094:                ".include \"../../databases/openldap/buildlink3.mk\"")
                   1095:        t.SetUpPackage("databases/openldap")
1.62      rillig   1096:        t.CreateFileBuildlink3("databases/openldap/buildlink3.mk",
1.61      rillig   1097:                "VAR=\tvalue",
                   1098:                "VAR=\tvalue") // Provoke a warning in this file.
                   1099:        t.FinishSetUp()
                   1100:        // Without this line, the current directory is an absolute directory,
                   1101:        // and the pkgsrc top directory is as well. One of them prevents the
                   1102:        // verbose paths from being generated.
                   1103:        t.Chdir(".")
                   1104:
                   1105:        G.Check("x11/kde-runtime4")
                   1106:
                   1107:        // The first part of the path must be "x11/kde-runtime4" to easily
                   1108:        // identify the package by which all other files are included.
                   1109:        t.CheckOutputLines(
                   1110:                "NOTE: x11/kde-runtime4/../../databases/openldap/buildlink3.mk:13: " +
                   1111:                        "Definition of VAR is redundant because of line 12.")
                   1112: }
                   1113:
1.58      rillig   1114: // Just for code coverage.
                   1115: func (s *Suite) Test_Package_resolveIncludedFile__no_tracing(c *check.C) {
1.30      rillig   1116:        t := s.Init(c)
                   1117:
1.58      rillig   1118:        t.SetUpPackage("category/package",
                   1119:                ".include \"../../mk/${UNKNOWN_PKGPATH}.mk\"",
                   1120:                ".include \"../../${UNKNOWN_PKGPATH}/buildlink3.mk\"",
                   1121:                ".include \"../../lang/language/buildlink3.mk\"")
                   1122:        t.CreateFileLines("lang/language/buildlink3.mk",
                   1123:                MkCvsID)
1.43      rillig   1124:        t.FinishSetUp()
1.58      rillig   1125:        pkg := NewPackage(t.File("category/package"))
                   1126:        t.DisableTracing()
1.30      rillig   1127:
1.58      rillig   1128:        pkg.included.Trace = true
                   1129:        pkg.loadPackageMakefile()
1.30      rillig   1130:
                   1131:        t.CheckOutputLines(
1.58      rillig   1132:                "FirstTime: suppress-varorder.mk",
                   1133:                "FirstTime: ../../lang/language/buildlink3.mk",
                   1134:                "FirstTime: ../../lang/language/builtin.mk")
1.30      rillig   1135: }
                   1136:
1.58      rillig   1137: func (s *Suite) Test_Package_resolveIncludedFile__skipping(c *check.C) {
1.17      rillig   1138:        t := s.Init(c)
                   1139:
1.58      rillig   1140:        t.SetUpPackage("category/package",
                   1141:                ".include \"../../mk/known.mk\"",
                   1142:                ".include \"../../${UNKNOWN_PKGPATH}/buildlink3.mk\"",
                   1143:                ".include \"../../lang/language/buildlink3.mk\"")
                   1144:        t.CreateFileLines("mk/known.mk",
1.48      rillig   1145:                MkCvsID,
1.58      rillig   1146:                ".include \"${UNKNOWN}.mk\"")
                   1147:        t.CreateFileLines("lang/language/buildlink3.mk",
                   1148:                MkCvsID)
1.43      rillig   1149:        t.FinishSetUp()
1.58      rillig   1150:        pkg := NewPackage(t.File("category/package"))
1.43      rillig   1151:
1.58      rillig   1152:        t.EnableTracingToLog()
                   1153:        pkg.loadPackageMakefile()
1.7       rillig   1154:
1.58      rillig   1155:        // The trace log does not contain the message that mk/known.mk includes
                   1156:        // a file that is skipped. This is because most package authors are not
                   1157:        // involved in the pkgsrc infrastructure, therefore there's no point in
                   1158:        // logging anything about these files.
                   1159:        t.CheckOutputLinesMatching(`.*Skipping.*`,
                   1160:                "TRACE: 1 2   ~/category/package/Makefile:21: "+
                   1161:                        "Skipping unresolvable include file \"../../${UNKNOWN_PKGPATH}/buildlink3.mk\".")
                   1162: }
1.42      rillig   1163:
1.58      rillig   1164: func (s *Suite) Test_Package_shouldDiveInto(c *check.C) {
                   1165:        t := s.Init(c)
1.60      rillig   1166:        t.Chdir("category/package")
1.42      rillig   1167:
1.62      rillig   1168:        test := func(including CurrPath, included RelPath, expected bool) {
                   1169:                pkg := NewPackage(".")
                   1170:                actual := pkg.shouldDiveInto(including, included)
1.58      rillig   1171:                t.CheckEquals(actual, expected)
                   1172:        }
1.9       rillig   1173:
1.58      rillig   1174:        // The variables that appear in these files are largely modeled by
                   1175:        // pkglint in the file vardefs.go. Therefore parsing these files again
                   1176:        // doesn't make much sense.
                   1177:        test("Makefile", "../../mk/bsd.pkg.mk", false)
                   1178:        test("Makefile", "../../mk/bsd.prefs.mk", false)
                   1179:        test("Makefile", "../../mk/bsd.fast.prefs.mk", false)
1.48      rillig   1180:
1.58      rillig   1181:        // All files that are included from outside of the pkgsrc infrastructure
                   1182:        // are relevant. This is typically mk/compiler.mk or the various
                   1183:        // mk/*.buildlink3.mk files.
                   1184:        test("Makefile", "Makefile.common", true)
                   1185:        test("Makefile", "../../mk/compiler.mk", true)
1.48      rillig   1186:
1.58      rillig   1187:        // The mk/*.buildlink3.mk files often come with a companion file called
                   1188:        // mk/*.builtin.mk, which also defines variables that are visible from
                   1189:        // the package.
                   1190:        //
                   1191:        // This case is needed for getting the redundancy check right. Without it
                   1192:        // there will be warnings about redundant assignments to the
                   1193:        // BUILTIN_CHECK.pthread variable.
                   1194:        test("pthread.buildlink3.mk", "pthread.builtin.mk", true)
                   1195:        test("../../mk/pthread.buildlink3.mk", "pthread.builtin.mk", true)
                   1196:        test("../../mk/pthread.buildlink3.mk", "../../mk/pthread.builtin.mk", true)
1.48      rillig   1197:
1.58      rillig   1198:        // Files other than the companion builtin.mk are ignored.
                   1199:        test("../../mk/pthread.buildlink3.mk", "pthread.internals.mk", false)
1.48      rillig   1200:
1.58      rillig   1201:        // Files that are included from within the pkgsrc infrastructure are not
                   1202:        // interesting since their content is largely modeled by pkglint in the
                   1203:        // file vardefs.go.
                   1204:        test("../../mk/one.mk", "two.mk", false)
                   1205:        test("../../mk/one.mk", "../../mk/two.mk", false)
                   1206:        test("../../mk/one.mk", "../lang/go/version.mk", false)
1.48      rillig   1207:
1.58      rillig   1208:        // wip/mk doesn't count as infrastructure since it is often used as a
                   1209:        // second layer, using the API of the main mk/ infrastructure.
                   1210:        test("wip/mk/cargo-binary.mk", "../../lang/rust/cargo.mk", true)
                   1211: }
1.48      rillig   1212:
1.58      rillig   1213: func (s *Suite) Test_Package_collectSeenInclude__builtin_mk(c *check.C) {
                   1214:        t := s.Init(c)
1.48      rillig   1215:
1.58      rillig   1216:        t.SetUpPackage("category/package",
                   1217:                ".include \"builtin.mk\"")
                   1218:        t.CreateFileLines("category/package/builtin.mk",
                   1219:                MkCvsID)
                   1220:        t.FinishSetUp()
1.48      rillig   1221:
1.58      rillig   1222:        pkg := NewPackage(t.File("category/package"))
                   1223:        pkg.load()
1.48      rillig   1224:
1.58      rillig   1225:        t.CheckEquals(pkg.seenInclude, true)
1.48      rillig   1226: }
                   1227:
1.58      rillig   1228: func (s *Suite) Test_Package_collectSeenInclude__multiple(c *check.C) {
1.17      rillig   1229:        t := s.Init(c)
                   1230:
1.58      rillig   1231:        t.SetUpPackage("category/package",
                   1232:                ".include \"001.mk\"",
                   1233:                ".include \"002.mk\"")
                   1234:        t.CreateFileLines("category/package/001.mk",
                   1235:                MkCvsID)
                   1236:        t.CreateFileLines("category/package/002.mk",
                   1237:                MkCvsID)
                   1238:        t.FinishSetUp()
1.9       rillig   1239:
1.58      rillig   1240:        t.EnableTracingToLog()
                   1241:        G.Check(t.File("category/package"))
                   1242:        t.EnableSilentTracing()
1.9       rillig   1243:
1.58      rillig   1244:        // TODO: It's not necessary to trace this message three times.
                   1245:        t.CheckOutputLinesMatching(`^TRACE: .*seenInclude`,
                   1246:                "TRACE: 1 2 3 4   Including \"suppress-varorder.mk\" sets seenInclude.",
                   1247:                "TRACE: 1 2 3 4   Including \"001.mk\" sets seenInclude.",
                   1248:                "TRACE: 1 2 3 4   Including \"002.mk\" sets seenInclude.")
1.40      rillig   1249: }
                   1250:
1.58      rillig   1251: // Just ensure that pkglint doesn't crash.
                   1252: func (s *Suite) Test_Package_loadPlistDirs__empty(c *check.C) {
1.40      rillig   1253:        t := s.Init(c)
                   1254:
1.58      rillig   1255:        t.SetUpPackage("category/package")
                   1256:        t.CreateFileLines("category/package/PLIST.common",
                   1257:                nil...)
1.43      rillig   1258:        t.FinishSetUp()
1.40      rillig   1259:
1.58      rillig   1260:        pkg := NewPackage(t.File("category/package"))
                   1261:        pkg.load()
                   1262:
1.62      rillig   1263:        var dirs []RelPath
1.58      rillig   1264:        for dir := range pkg.Plist.Dirs {
                   1265:                dirs = append(dirs, dir)
                   1266:        }
1.59      rillig   1267:        sort.Slice(dirs, func(i, j int) bool { return dirs[i] < dirs[j] })
1.40      rillig   1268:
1.62      rillig   1269:        t.CheckDeepEquals(dirs, []RelPath{"bin"})
1.9       rillig   1270: }
1.10      rillig   1271:
1.58      rillig   1272: func (s *Suite) Test_Package_loadPlistDirs(c *check.C) {
1.30      rillig   1273:        t := s.Init(c)
                   1274:
1.58      rillig   1275:        t.SetUpPackage("category/package")
                   1276:        t.CreateFileLines("category/package/PLIST.common",
                   1277:                PlistCvsID,
                   1278:                "@exec echo hello",
                   1279:                "${PLIST.condition}dir/subdir/file",
                   1280:                "@unexec echo bye")
1.43      rillig   1281:        t.FinishSetUp()
1.30      rillig   1282:
1.58      rillig   1283:        pkg := NewPackage(t.File("category/package"))
                   1284:        pkg.load()
                   1285:
1.62      rillig   1286:        var dirs []RelPath
1.58      rillig   1287:        for dir := range pkg.Plist.Dirs {
                   1288:                dirs = append(dirs, dir)
                   1289:        }
1.59      rillig   1290:        sort.Slice(dirs, func(i, j int) bool { return dirs[i] < dirs[j] })
1.58      rillig   1291:
1.62      rillig   1292:        t.CheckDeepEquals(dirs, []RelPath{"bin", "dir", "dir/subdir"})
1.30      rillig   1293: }
                   1294:
1.48      rillig   1295: func (s *Suite) Test_Package_check__files_Makefile(c *check.C) {
1.17      rillig   1296:        t := s.Init(c)
                   1297:
1.48      rillig   1298:        t.SetUpPackage("category/package")
                   1299:        t.CreateFileLines("category/package/files/Makefile",
                   1300:                "This file may contain anything.")
                   1301:
                   1302:        t.Main("category/package/files/Makefile")
1.28      rillig   1303:
1.48      rillig   1304:        // Since there is nothing to check in files/*, pkglint could
                   1305:        // as well report this as a usage error.
                   1306:        //
                   1307:        // Until June 2019, checking individual files in FILESDIR had
                   1308:        // been enabled by the -Call command line option.
                   1309:        t.CheckOutputLines(
                   1310:                "Looks fine.")
1.10      rillig   1311:
1.48      rillig   1312:        t.Main("category/package")
1.10      rillig   1313:
1.17      rillig   1314:        t.CheckOutputLines(
1.48      rillig   1315:                "Looks fine.")
1.10      rillig   1316: }
1.22      rillig   1317:
1.48      rillig   1318: func (s *Suite) Test_Package_check__patches_Makefile(c *check.C) {
1.22      rillig   1319:        t := s.Init(c)
                   1320:
1.58      rillig   1321:        t.SetUpPackage("category/package")
                   1322:        t.CreateFileLines("category/package/patches/Makefile",
                   1323:                "This file may contain anything.")
                   1324:
                   1325:        t.Main("category/package")
                   1326:
                   1327:        t.CheckOutputLines(
                   1328:                "WARN: ~/category/package/patches/Makefile: Patch files should be "+
                   1329:                        "named \"patch-\", followed by letters, '-', '_', '.', and digits only.",
                   1330:                "1 warning found.")
                   1331: }
                   1332:
1.72      rillig   1333: func (s *Suite) Test_Package_checkDescr__DESCR_SRC(c *check.C) {
                   1334:        t := s.Init(c)
                   1335:
                   1336:        t.SetUpPackage("other/package")
                   1337:        t.SetUpPackage("category/package",
                   1338:                "DESCR_SRC=\t../../other/package/DESCR")
                   1339:        t.Remove("category/package/DESCR")
                   1340:        t.FinishSetUp()
                   1341:
                   1342:        G.Check(t.File("category/package"))
                   1343:
                   1344:        t.CheckOutputEmpty()
                   1345: }
                   1346:
1.73      rillig   1347: // All files that can possibly be added to DISTFILES need a corresponding
                   1348: // entry in the distinfo file.
                   1349: //
                   1350: // https://mail-index.netbsd.org/pkgsrc-changes/2020/02/05/msg206172.html
                   1351: // https://mail-index.netbsd.org/pkgsrc-changes/2020/03/25/msg209445.html
                   1352: func (s *Suite) Test_Package_checkDistfilesInDistinfo__indirect_conditional_DISTFILES(c *check.C) {
                   1353:        G.Experimental = true
                   1354:
                   1355:        t := s.Init(c)
                   1356:
                   1357:        t.SetUpPackage("category/package",
                   1358:                ".include \"../../mk/bsd.prefs.mk\"",
                   1359:                "",
                   1360:                "DISTFILES.i386=\t\tdistfile-i386.tar.gz",
                   1361:                "DISTFILES.other=\tdistfile-other.tar.gz",
                   1362:                "",
                   1363:                ".if ${MACHINE_ARCH} == i386",
                   1364:                "DISTFILES+=\t${DISTFILES.i386}",
                   1365:                ".else",
                   1366:                "DISTFILES+=\t${DISTFILES.other}",
                   1367:                ".endif",
                   1368:                "",
                   1369:                "DISTFILES+=\tok-3.tar.gz")
                   1370:        t.CreateFileLines("category/package/distinfo",
                   1371:                CvsID,
                   1372:                "",
                   1373:                "SHA1 (ok-3.tar.gz) = 1234",
                   1374:                "RMD160 (ok-3.tar.gz) = 1234",
                   1375:                "SHA512 (ok-3.tar.gz) = 1234",
                   1376:                "Size (ok-3.tar.gz) = 1234",
                   1377:                "SHA1 (package-1.0.tar.gz) = 1234",
                   1378:                "RMD160 (package-1.0.tar.gz) = 1234",
                   1379:                "SHA512 (package-1.0.tar.gz) = 1234",
                   1380:                "Size (package-1.0.tar.gz) = 1234")
                   1381:        t.Chdir("category/package")
                   1382:        t.FinishSetUp()
                   1383:
                   1384:        G.Check(".")
                   1385:
                   1386:        t.CheckOutputLines(
                   1387:                "WARN: Makefile:26: Distfile \"distfile-i386.tar.gz\" is not mentioned in distinfo.",
                   1388:                "WARN: Makefile:28: Distfile \"distfile-other.tar.gz\" is not mentioned in distinfo.")
                   1389: }
                   1390:
                   1391: func (s *Suite) Test_Package_checkDistfilesInDistinfo__indirect_DIST_SUBDIR(c *check.C) {
                   1392:        G.Experimental = true
                   1393:
                   1394:        t := s.Init(c)
                   1395:
                   1396:        t.SetUpPackage("category/package",
                   1397:                ".include \"../../mk/bsd.prefs.mk\"",
                   1398:                "",
                   1399:                // As of 2020-03-26, pkglint doesn't know how to resolve PKGNAME_NOREV.
                   1400:                "DIST_SUBDIR=\t${PKGNAME_NOREV}",
                   1401:                // Strictly speaking, this is redundant, but as of 2020-03-26,
                   1402:                // pkglint doesn't infer the default DISTFILES, so it needs a bit of help here.
                   1403:                "DISTFILES+=\tdistfile-1.0.tar.gz",
                   1404:                "DISTFILES+=\tdistfile-other.tar.gz")
                   1405:        t.CreateFileLines("distinfo",
                   1406:                CvsID,
                   1407:                "",
                   1408:                "SHA1 (package-1.0/distfile-other.tar.gz) = 1234",
                   1409:                "RMD160 (package-1.0/distfile-other.tar.gz) = 1234",
                   1410:                "SHA512 (package-1.0/distfile-other.tar.gz) = 1234",
                   1411:                "Size (package-1.0/distfile-other.tar.gz) = 1234",
                   1412:                "SHA1 (package-1.0/package-1.0.tar.gz) = 1234",
                   1413:                "RMD160 (package-1.0/package-1.0.tar.gz) = 1234",
                   1414:                "SHA512 (package-1.0/package-1.0.tar.gz) = 1234",
                   1415:                "Size (package-1.0/package-1.0.tar.gz) = 1234")
                   1416:        t.Chdir("category/package")
                   1417:        t.FinishSetUp()
                   1418:
                   1419:        G.Check(".")
                   1420:
                   1421:        t.CheckOutputLines(
                   1422:                "WARN: Makefile:24: Distfile \"distfile-other.tar.gz\" is not mentioned in distinfo.")
                   1423: }
                   1424:
                   1425: func (s *Suite) Test_Package_checkDistfilesInDistinfo__depending_on_package_settable(c *check.C) {
                   1426:        G.Experimental = true
                   1427:
                   1428:        t := s.Init(c)
                   1429:
                   1430:        t.SetUpPackage("print/tex-varisize",
                   1431:                "DISTNAME=\tvarisize",
                   1432:                "PKGNAME=\ttex-${DISTNAME}-2014",
                   1433:                "TEXLIVE_REV=\t15878",
                   1434:                "",
                   1435:                "TEXLIVE_UNVERSIONED=\tyes",
                   1436:                "",
                   1437:                ".include \"../../print/texlive/package.mk\"")
                   1438:        t.CreateFileLines("print/tex-varisize/distinfo",
                   1439:                CvsID,
                   1440:                "",
                   1441:                "SHA1 (tex-varisize-15878/varisize.tar.xz) = 1234",
                   1442:                "RMD160 (tex-varisize-15878/varisize.tar.xz) = 1234",
                   1443:                "SHA512 (tex-varisize-15878/varisize.tar.xz) = 1234",
                   1444:                "Size (tex-varisize-15878/varisize.tar.xz) = 3176 bytes")
                   1445:        t.CreateFileLines("print/texlive/package.mk",
                   1446:                MkCvsID,
                   1447:                "",
                   1448:                ".if empty(TEXLIVE_UNVERSIONED)",
                   1449:                "DISTFILES?=\t${DISTNAME}.r${TEXLIVE_REV}${EXTRACT_SUFX}",
                   1450:                ".endif")
                   1451:        t.Chdir("print/tex-varisize")
                   1452:        t.FinishSetUp()
                   1453:
                   1454:        G.Check(".")
                   1455:
                   1456:        // The package-settable TEXLIVE_UNVERSIONED is definitely not empty,
                   1457:        // therefore the line in package.mk doesn't apply.
                   1458:        // FIXME: This warning is wrong because the line in package.mk is unreachable.
                   1459:        //  See MkLines.IsUnreachable.
                   1460:        t.CheckOutputLines(
                   1461:                "WARN: ../../print/texlive/package.mk:4: Distfile \"varisize.r15878.tar.gz\" " +
                   1462:                        "is not mentioned in ../../print/tex-varisize/distinfo.")
                   1463: }
                   1464:
1.58      rillig   1465: func (s *Suite) Test_Package_checkfilePackageMakefile__GNU_CONFIGURE(c *check.C) {
                   1466:        t := s.Init(c)
                   1467:
1.61      rillig   1468:        t.SetUpCommandLine("-Wall")
1.58      rillig   1469:        pkg := t.SetUpPackage("category/package",
                   1470:                "GNU_CONFIGURE=\tyes",
                   1471:                "USE_LANGUAGES=\t#")
                   1472:        t.FinishSetUp()
                   1473:
                   1474:        G.Check(pkg)
                   1475:
                   1476:        t.CheckOutputLines(
                   1477:                "WARN: ~/category/package/Makefile:20: GNU_CONFIGURE almost always needs a C compiler, but \"c\" is not added to USE_LANGUAGES in line 21.")
                   1478: }
                   1479:
                   1480: // Packages that define GNU_CONFIGURE should also set at least USE_LANGUAGES=c.
                   1481: // Except if they know what they are doing, as documented in the comment "none, really".
                   1482: func (s *Suite) Test_Package_checkfilePackageMakefile__GNU_CONFIGURE_ok(c *check.C) {
                   1483:        t := s.Init(c)
                   1484:
                   1485:        pkg := t.SetUpPackage("category/package",
                   1486:                "GNU_CONFIGURE=\tyes",
                   1487:                "USE_LANGUAGES=\t# none, really")
                   1488:        t.FinishSetUp()
                   1489:
                   1490:        G.Check(pkg)
                   1491:
                   1492:        t.CheckOutputEmpty()
                   1493: }
                   1494:
                   1495: func (s *Suite) Test_Package_checkfilePackageMakefile__REPLACE_PERL(c *check.C) {
                   1496:        t := s.Init(c)
                   1497:
                   1498:        pkg := t.SetUpPackage("category/package",
                   1499:                "REPLACE_PERL=\t*.pl",
                   1500:                "NO_CONFIGURE=\tyes")
                   1501:        t.FinishSetUp()
                   1502:
                   1503:        G.Check(pkg)
                   1504:
                   1505:        t.CheckOutputLines(
                   1506:                "WARN: ~/category/package/Makefile:20: REPLACE_PERL is ignored when NO_CONFIGURE is set (in line 21).")
                   1507: }
                   1508:
                   1509: func (s *Suite) Test_Package_checkfilePackageMakefile__META_PACKAGE_with_distinfo(c *check.C) {
                   1510:        t := s.Init(c)
                   1511:
                   1512:        pkg := t.SetUpPackage("category/package",
                   1513:                "META_PACKAGE=\tyes")
                   1514:        t.FinishSetUp()
1.22      rillig   1515:
1.58      rillig   1516:        G.Check(pkg)
1.22      rillig   1517:
                   1518:        t.CheckOutputLines(
1.58      rillig   1519:                "WARN: ~/category/package/Makefile:20: This package should not have a PLIST file.",
                   1520:                "WARN: ~/category/package/distinfo: "+
                   1521:                        "This file should not exist since NO_CHECKSUM or META_PACKAGE is set.")
1.22      rillig   1522: }
                   1523:
1.58      rillig   1524: func (s *Suite) Test_Package_checkfilePackageMakefile__META_PACKAGE_with_patch(c *check.C) {
1.48      rillig   1525:        t := s.Init(c)
                   1526:
1.58      rillig   1527:        pkg := t.SetUpPackage("category/package",
                   1528:                "META_PACKAGE=\tyes")
                   1529:        t.Remove("category/package/PLIST")
                   1530:        t.CreateFileDummyPatch("category/package/patches/patch-aa")
                   1531:        t.CreateFileLines("category/package/distinfo",
                   1532:                CvsID,
                   1533:                "",
                   1534:                "SHA1 (patch-aa) = ebbf34b0641bcb508f17d5a27f2bf2a536d810ac")
                   1535:
1.48      rillig   1536:        t.FinishSetUp()
                   1537:
1.58      rillig   1538:        G.Check(pkg)
1.48      rillig   1539:
1.58      rillig   1540:        // At first it may sound strange to have a META_PACKAGE with patches.
                   1541:        // As of June 2019, there are 21 meta packages having a patches
                   1542:        // directory, being referred to by PATCHDIR.
                   1543:        t.CheckOutputEmpty()
1.48      rillig   1544: }
                   1545:
1.58      rillig   1546: func (s *Suite) Test_Package_checkfilePackageMakefile__USE_IMAKE_and_USE_X11(c *check.C) {
1.48      rillig   1547:        t := s.Init(c)
                   1548:
1.58      rillig   1549:        pkg := t.SetUpPackage("category/package",
                   1550:                "USE_X11=\tyes",
                   1551:                "USE_IMAKE=\tyes")
1.48      rillig   1552:        t.FinishSetUp()
                   1553:
1.58      rillig   1554:        G.Check(pkg)
1.48      rillig   1555:
                   1556:        t.CheckOutputLines(
1.58      rillig   1557:                "NOTE: ~/category/package/Makefile:21: USE_IMAKE makes USE_X11 in line 20 redundant.")
1.48      rillig   1558: }
                   1559:
1.58      rillig   1560: func (s *Suite) Test_Package_checkfilePackageMakefile__USE_IMAKE_without_USE_X11(c *check.C) {
1.48      rillig   1561:        t := s.Init(c)
                   1562:
1.58      rillig   1563:        pkg := t.SetUpPackage("category/package",
                   1564:                "USE_IMAKE=\tyes")
1.48      rillig   1565:        t.FinishSetUp()
                   1566:
1.58      rillig   1567:        G.Check(pkg)
1.48      rillig   1568:
1.58      rillig   1569:        t.CheckOutputEmpty()
1.48      rillig   1570: }
                   1571:
1.58      rillig   1572: func (s *Suite) Test_Package_checkfilePackageMakefile__USE_IMAKE_and_USE_X11_in_infra(c *check.C) {
1.48      rillig   1573:        t := s.Init(c)
                   1574:
1.58      rillig   1575:        t.CreateFileLines("mk/x11.buildlink3.mk",
1.48      rillig   1576:                MkCvsID,
1.58      rillig   1577:                "USE_X11=\tyes")
                   1578:        pkg := t.SetUpPackage("category/package",
                   1579:                ".include \"../../mk/x11.buildlink3.mk\"",
                   1580:                "USE_IMAKE=\tyes")
1.48      rillig   1581:        t.FinishSetUp()
                   1582:
1.58      rillig   1583:        G.Check(pkg)
1.48      rillig   1584:
1.58      rillig   1585:        t.CheckOutputEmpty()
1.48      rillig   1586: }
                   1587:
1.58      rillig   1588: func (s *Suite) Test_Package_checkfilePackageMakefile__PLIST_common(c *check.C) {
1.56      rillig   1589:        t := s.Init(c)
                   1590:
1.58      rillig   1591:        t.SetUpPackage("category/package")
                   1592:        t.Copy("category/package/PLIST", "category/package/PLIST.common")
                   1593:        t.Remove("category/package/PLIST")
1.56      rillig   1594:        t.FinishSetUp()
                   1595:
1.58      rillig   1596:        G.Check(t.File("category/package"))
1.56      rillig   1597:
1.58      rillig   1598:        // No warning about missing PLIST file.
                   1599:        t.CheckOutputEmpty()
1.56      rillig   1600: }
                   1601:
1.58      rillig   1602: func (s *Suite) Test_Package_checkfilePackageMakefile__files_Makefile(c *check.C) {
1.56      rillig   1603:        t := s.Init(c)
                   1604:
1.58      rillig   1605:        t.SetUpCommandLine("-Wall", "-Call")
1.56      rillig   1606:        t.SetUpPackage("category/package",
1.58      rillig   1607:                "#LICENSE=\t# none")
                   1608:        t.CreateFileLines("category/package/files/Makefile",
                   1609:                "#")
1.56      rillig   1610:        t.FinishSetUp()
                   1611:
1.58      rillig   1612:        G.Check(t.File("category/package"))
1.56      rillig   1613:
                   1614:        t.CheckOutputLines(
1.58      rillig   1615:                "ERROR: ~/category/package/Makefile: Each package must define its LICENSE.")
1.56      rillig   1616: }
                   1617:
1.58      rillig   1618: // Until version 19.3.5, pkglint warned that this package would need a
                   1619: // distinfo file.
                   1620: func (s *Suite) Test_Package_checkfilePackageMakefile__no_distfiles(c *check.C) {
1.56      rillig   1621:        t := s.Init(c)
                   1622:
                   1623:        t.SetUpPackage("category/package",
1.58      rillig   1624:                "DISTFILES=\t# none")
1.56      rillig   1625:        t.FinishSetUp()
                   1626:
1.58      rillig   1627:        G.Check(t.File("category/package"))
1.56      rillig   1628:
                   1629:        t.CheckOutputLines(
1.58      rillig   1630:                "WARN: ~/category/package/distinfo: " +
                   1631:                        "This file should not exist since NO_CHECKSUM or META_PACKAGE is set.")
1.56      rillig   1632: }
                   1633:
1.58      rillig   1634: func (s *Suite) Test_Package_checkfilePackageMakefile__distfiles(c *check.C) {
1.52      rillig   1635:        t := s.Init(c)
                   1636:
1.58      rillig   1637:        t.SetUpPackage("category/package",
                   1638:                "DISTFILES=\tpackage-1.0.tar.gz")
                   1639:        t.Remove("category/package/distinfo")
1.52      rillig   1640:        t.FinishSetUp()
                   1641:
1.58      rillig   1642:        G.Check(t.File("category/package"))
1.52      rillig   1643:
                   1644:        t.CheckOutputLines(
1.58      rillig   1645:                "WARN: ~/category/package/distinfo: " +
                   1646:                        "A package that downloads files should have a distinfo file.")
1.52      rillig   1647: }
                   1648:
1.62      rillig   1649: // The fonts/t1lib package has split the options handling between the
                   1650: // package Makefile and options.mk. Make sure that this situation is
                   1651: // handled correctly by pkglint.
                   1652: //
                   1653: // See "tr.SeenPrefs = true".
                   1654: func (s *Suite) Test_Package_checkfilePackageMakefile__options_mk(c *check.C) {
                   1655:        t := s.Init(c)
                   1656:
                   1657:        t.SetUpOption("option", "An example option")
                   1658:        t.SetUpPackage("category/package",
                   1659:                ".include \"options.mk\"",
                   1660:                "",
                   1661:                ".if ${PKG_OPTIONS:Moption}",
                   1662:                ".endif")
                   1663:        t.CreateFileLines("mk/bsd.options.mk")
                   1664:        t.CreateFileLines("category/package/options.mk",
                   1665:                MkCvsID,
                   1666:                "",
                   1667:                "PKG_OPTIONS_VAR=\tPKG_OPTIONS.package",
                   1668:                "PKG_SUPPORTED_OPTIONS=\toption",
                   1669:                "",
                   1670:                ".include \"../../mk/bsd.options.mk\"",
                   1671:                "",
                   1672:                ".if ${PKG_OPTIONS:Moption}",
                   1673:                ".endif")
                   1674:        t.FinishSetUp()
                   1675:
                   1676:        G.Check(t.File("category/package"))
                   1677:
                   1678:        t.CheckOutputEmpty()
                   1679: }
                   1680:
1.64      rillig   1681: // When the lines of the package Makefile are checked, it is necessary
                   1682: // to know whether bsd.prefs.mk has already been included.
                   1683: //
                   1684: // When the files are loaded recursively, Package.seenPrefs is set to
                   1685: // true as soon as some file includes bsd.prefs.mk. After that, when
                   1686: // loading reaches the main package Makefile again, Package.prefsLine
                   1687: // is set to the line that had just been included.
                   1688: //
                   1689: // In this test case, the preferences are loaded indirectly by line 22,
                   1690: // which includes common.mk, and that in turn includes bsd.prefs.mk.
1.62      rillig   1691: func (s *Suite) Test_Package_checkfilePackageMakefile__prefs_indirect(c *check.C) {
                   1692:        t := s.Init(c)
                   1693:
                   1694:        t.SetUpPackage("category/package",
1.64      rillig   1695:                ".if ${OPSYS} == NetBSD", // 20: OPSYS is not yet defined here.
                   1696:                ".endif",                 // 21
                   1697:                ".include \"common.mk\"", // 22: OPSYS gets defined.
                   1698:                ".if ${OPSYS} == NetBSD", // 23: Now OPSYS is defined.
1.62      rillig   1699:                ".endif")
                   1700:        t.CreateFileLines("category/package/common.mk",
                   1701:                MkCvsID,
                   1702:                "",
                   1703:                ".include \"../../mk/bsd.prefs.mk\"")
                   1704:        t.FinishSetUp()
                   1705:        pkg := NewPackage(t.File("category/package"))
                   1706:
1.67      rillig   1707:        files, mklines, allLines := pkg.load()
1.62      rillig   1708:
1.67      rillig   1709:        t.CheckEquals(pkg.seenPrefs, false)
                   1710:        t.CheckEquals(pkg.prefsLine, mklines.mklines[21])
1.62      rillig   1711:
1.67      rillig   1712:        pkg.check(files, mklines, allLines)
1.62      rillig   1713:
1.67      rillig   1714:        t.CheckEquals(pkg.seenPrefs, true)
                   1715:        t.CheckEquals(pkg.prefsLine, mklines.mklines[21])
1.62      rillig   1716:
                   1717:        // Since bsd.prefs.mk is included indirectly by common.mk,
1.64      rillig   1718:        // OPSYS may be used at load time in line 23, but not in line 20.
                   1719:        t.CheckOutputLines(
                   1720:                "WARN: ~/category/package/Makefile:20: " +
                   1721:                        "To use OPSYS at load time, " +
                   1722:                        ".include \"../../mk/bsd.prefs.mk\" first.")
1.62      rillig   1723: }
                   1724:
1.63      rillig   1725: func (s *Suite) Test_Package_checkfilePackageMakefile__redundancy_in_infra(c *check.C) {
                   1726:        t := s.Init(c)
                   1727:
                   1728:        t.SetUpPackage("category/package",
                   1729:                ".include \"../../mk/redundant.mk\"",
                   1730:                ".include \"redundant.mk\"")
                   1731:        t.CreateFileLines("mk/redundant.mk",
                   1732:                MkCvsID,
                   1733:                "INFRA_REDUNDANT:=\t# empty",
                   1734:                "INFRA_REDUNDANT=\t# empty")
                   1735:        t.CreateFileLines("category/package/redundant.mk",
                   1736:                MkCvsID,
                   1737:                "PKG_REDUNDANT:=\t# empty",
                   1738:                "PKG_REDUNDANT=\t# empty")
                   1739:        t.Chdir(".")
                   1740:        t.FinishSetUp()
                   1741:
                   1742:        G.checkdirPackage("category/package")
                   1743:
                   1744:        t.CheckOutputLines(
                   1745:                "NOTE: category/package/redundant.mk:3: "+
                   1746:                        "Definition of PKG_REDUNDANT is redundant because of line 2.",
                   1747:                "WARN: category/package/redundant.mk:2: "+
                   1748:                        "PKG_REDUNDANT is defined but not used.")
                   1749:
                   1750:        G.Check("mk/redundant.mk")
                   1751:
                   1752:        // The redundancy check is only performed when a whole package
                   1753:        // is checked. Therefore nothing is reported here.
                   1754:        t.CheckOutputEmpty()
1.66      rillig   1755:
                   1756:        // If the global checks are enabled, redundancy warnings from the
                   1757:        // pkgsrc infrastructure are reported as well.
                   1758:        //
                   1759:        // This prevents the redundant PKG_OPTIONS definition from
                   1760:        // mk/bsd.options.mk to be shown when checking a normal package.
                   1761:        t.SetUpCommandLine("-Wall", "-Cglobal")
                   1762:
                   1763:        G.checkdirPackage("category/package")
                   1764:
                   1765:        t.CheckOutputLines(
                   1766:                "NOTE: category/package/../../mk/redundant.mk:3: "+
                   1767:                        "Definition of INFRA_REDUNDANT is redundant because of line 2.",
                   1768:                "NOTE: category/package/redundant.mk:3: "+
                   1769:                        "Definition of PKG_REDUNDANT is redundant because of line 2.",
                   1770:                "WARN: category/package/redundant.mk:2: "+
                   1771:                        "PKG_REDUNDANT is defined but not used.")
1.63      rillig   1772: }
                   1773:
1.58      rillig   1774: // When a package defines PLIST_SRC, it may or may not use the
                   1775: // PLIST file from the package directory. Therefore the check
                   1776: // is skipped completely.
                   1777: func (s *Suite) Test_Package_checkPlist__PLIST_SRC(c *check.C) {
1.52      rillig   1778:        t := s.Init(c)
                   1779:
                   1780:        t.SetUpPackage("category/package",
1.58      rillig   1781:                "PLIST_SRC=\t${WRKDIR}/PLIST")
1.52      rillig   1782:        t.FinishSetUp()
                   1783:
1.58      rillig   1784:        G.Check(t.File("category/package"))
1.52      rillig   1785:
                   1786:        t.CheckOutputEmpty()
                   1787: }
                   1788:
1.58      rillig   1789: func (s *Suite) Test_Package_checkPlist__META_PACKAGE(c *check.C) {
1.52      rillig   1790:        t := s.Init(c)
                   1791:
1.58      rillig   1792:        t.SetUpPackage("category/package",
                   1793:                "META_PACKAGE=\tyes")
1.52      rillig   1794:        t.FinishSetUp()
                   1795:
1.58      rillig   1796:        G.Check(t.File("category/package"))
1.52      rillig   1797:
                   1798:        t.CheckOutputLines(
1.58      rillig   1799:                "WARN: ~/category/package/Makefile:20: This package should not have a PLIST file.",
                   1800:                "WARN: ~/category/package/distinfo: This file should not exist "+
                   1801:                        "since NO_CHECKSUM or META_PACKAGE is set.")
1.52      rillig   1802: }
                   1803:
1.58      rillig   1804: func (s *Suite) Test_Package_checkPlist__Perl5_packlist(c *check.C) {
1.48      rillig   1805:        t := s.Init(c)
                   1806:
1.58      rillig   1807:        t.SetUpPackage("category/p5-Packlist",
                   1808:                "PERL5_PACKLIST=\tauto/Packlist/.packlist")
1.48      rillig   1809:        t.FinishSetUp()
                   1810:
1.58      rillig   1811:        G.Check(t.File("category/p5-Packlist"))
1.48      rillig   1812:
                   1813:        t.CheckOutputLines(
1.58      rillig   1814:                "WARN: ~/category/p5-Packlist/Makefile:20: This package should not have a PLIST file.")
1.52      rillig   1815: }
                   1816:
1.58      rillig   1817: func (s *Suite) Test_Package_checkPlist__PERL5_USE_PACKLIST_no(c *check.C) {
1.52      rillig   1818:        t := s.Init(c)
                   1819:
1.58      rillig   1820:        t.SetUpPackage("category/p5-NoPacklist",
                   1821:                "PERL5_USE_PACKLIST=\tno")
1.52      rillig   1822:        t.FinishSetUp()
                   1823:
1.58      rillig   1824:        G.Check(t.File("category/p5-NoPacklist"))
1.52      rillig   1825:
                   1826:        t.CheckOutputEmpty()
1.48      rillig   1827: }
                   1828:
1.58      rillig   1829: func (s *Suite) Test_Package_checkPlist__PERL5_USE_PACKLIST_yes(c *check.C) {
                   1830:        t := s.Init(c)
                   1831:
                   1832:        t.SetUpPackage("category/p5-Packlist",
                   1833:                "PERL5_USE_PACKLIST=\tyes")
                   1834:        t.FinishSetUp()
                   1835:
                   1836:        G.Check(t.File("category/p5-Packlist"))
                   1837:
                   1838:        t.CheckOutputLines(
                   1839:                "WARN: ~/category/p5-Packlist/Makefile:20: This package should not have a PLIST file.")
                   1840: }
                   1841:
                   1842: func (s *Suite) Test_Package_CheckVarorder__only_required_variables(c *check.C) {
1.48      rillig   1843:        t := s.Init(c)
                   1844:
1.58      rillig   1845:        pkg := NewPackage(t.File("x11/9term"))
                   1846:        mklines := t.NewMkLines("Makefile",
1.48      rillig   1847:                MkCvsID,
                   1848:                "",
1.58      rillig   1849:                "DISTNAME=9term",
                   1850:                "CATEGORIES=x11",
1.48      rillig   1851:                "",
1.58      rillig   1852:                ".include \"../../mk/bsd.pkg.mk\"")
1.48      rillig   1853:
1.58      rillig   1854:        pkg.CheckVarorder(mklines)
1.48      rillig   1855:
                   1856:        t.CheckOutputLines(
1.58      rillig   1857:                "WARN: Makefile:3: The canonical order of the variables is " +
                   1858:                        "DISTNAME, CATEGORIES, empty line, COMMENT, LICENSE.")
1.48      rillig   1859: }
                   1860:
1.58      rillig   1861: func (s *Suite) Test_Package_CheckVarorder__with_optional_variables(c *check.C) {
1.48      rillig   1862:        t := s.Init(c)
                   1863:
1.58      rillig   1864:        pkg := NewPackage(t.File("x11/9term"))
                   1865:        mklines := t.NewMkLines("Makefile",
                   1866:                MkCvsID,
                   1867:                "",
                   1868:                "GITHUB_PROJECT=project",
                   1869:                "DISTNAME=9term",
                   1870:                "CATEGORIES=x11")
1.48      rillig   1871:
1.58      rillig   1872:        pkg.CheckVarorder(mklines)
1.48      rillig   1873:
1.58      rillig   1874:        // TODO: Make this warning more specific to the actual situation.
1.48      rillig   1875:        t.CheckOutputLines(
1.58      rillig   1876:                "WARN: Makefile:3: The canonical order of the variables is " +
                   1877:                        "GITHUB_PROJECT, DISTNAME, CATEGORIES, GITHUB_PROJECT, empty line, " +
                   1878:                        "COMMENT, LICENSE.")
1.48      rillig   1879: }
                   1880:
1.58      rillig   1881: // Just for code coverage.
                   1882: func (s *Suite) Test_Package_CheckVarorder__no_tracing(c *check.C) {
1.22      rillig   1883:        t := s.Init(c)
                   1884:
1.58      rillig   1885:        pkg := NewPackage(t.File("x11/9term"))
                   1886:        mklines := t.NewMkLines("Makefile",
                   1887:                MkCvsID,
                   1888:                "",
                   1889:                "DISTNAME=9term",
                   1890:                "CATEGORIES=x11",
                   1891:                "",
                   1892:                ".include \"../../mk/bsd.pkg.mk\"")
                   1893:        t.DisableTracing()
1.22      rillig   1894:
1.58      rillig   1895:        pkg.CheckVarorder(mklines)
1.22      rillig   1896:
1.58      rillig   1897:        t.CheckOutputLines(
                   1898:                "WARN: Makefile:3: The canonical order of the variables is " +
                   1899:                        "DISTNAME, CATEGORIES, empty line, COMMENT, LICENSE.")
1.22      rillig   1900: }
                   1901:
1.58      rillig   1902: // Ensure that comments and empty lines do not lead to panics.
                   1903: // This would be when accessing fields from the MkLine without checking the line type before.
                   1904: func (s *Suite) Test_Package_CheckVarorder__comments_do_not_crash(c *check.C) {
1.22      rillig   1905:        t := s.Init(c)
                   1906:
1.58      rillig   1907:        pkg := NewPackage(t.File("x11/9term"))
                   1908:        mklines := t.NewMkLines("Makefile",
                   1909:                MkCvsID,
                   1910:                "",
                   1911:                "GITHUB_PROJECT=project",
                   1912:                "",
                   1913:                "# comment",
                   1914:                "",
                   1915:                "DISTNAME=9term",
                   1916:                "# comment",
                   1917:                "CATEGORIES=x11")
1.22      rillig   1918:
1.58      rillig   1919:        pkg.CheckVarorder(mklines)
1.22      rillig   1920:
                   1921:        t.CheckOutputLines(
1.58      rillig   1922:                "WARN: Makefile:3: The canonical order of the variables is " +
                   1923:                        "GITHUB_PROJECT, DISTNAME, CATEGORIES, GITHUB_PROJECT, empty line, " +
                   1924:                        "COMMENT, LICENSE.")
1.22      rillig   1925: }
1.24      rillig   1926:
1.58      rillig   1927: func (s *Suite) Test_Package_CheckVarorder__comments_are_ignored(c *check.C) {
1.24      rillig   1928:        t := s.Init(c)
                   1929:
1.58      rillig   1930:        pkg := NewPackage(t.File("x11/9term"))
                   1931:        mklines := t.NewMkLines("Makefile",
1.48      rillig   1932:                MkCvsID,
1.24      rillig   1933:                "",
1.58      rillig   1934:                "DISTNAME=\tdistname-1.0",
                   1935:                "CATEGORIES=\tsysutils",
1.24      rillig   1936:                "",
1.58      rillig   1937:                "MAINTAINER=\tpkgsrc-users@NetBSD.org",
                   1938:                "# comment",
                   1939:                "COMMENT=\tComment",
                   1940:                "LICENSE=\tgnu-gpl-v2")
1.24      rillig   1941:
1.58      rillig   1942:        pkg.CheckVarorder(mklines)
1.24      rillig   1943:
1.58      rillig   1944:        t.CheckOutputEmpty()
1.24      rillig   1945: }
1.29      rillig   1946:
1.58      rillig   1947: func (s *Suite) Test_Package_CheckVarorder__commented_variable_assignment(c *check.C) {
1.29      rillig   1948:        t := s.Init(c)
                   1949:
1.58      rillig   1950:        pkg := NewPackage(t.File("x11/9term"))
                   1951:        mklines := t.NewMkLines("Makefile",
                   1952:                MkCvsID,
1.29      rillig   1953:                "",
1.58      rillig   1954:                "DISTNAME=\tdistname-1.0",
                   1955:                "CATEGORIES=\tsysutils",
1.29      rillig   1956:                "",
1.58      rillig   1957:                "MAINTAINER=\tpkgsrc-users@NetBSD.org",
                   1958:                "#HOMEPAGE=\thttps://example.org/",
                   1959:                "COMMENT=\tComment",
                   1960:                "LICENSE=\tgnu-gpl-v2")
1.29      rillig   1961:
1.58      rillig   1962:        pkg.CheckVarorder(mklines)
1.29      rillig   1963:
1.58      rillig   1964:        t.CheckOutputEmpty()
1.29      rillig   1965: }
                   1966:
1.58      rillig   1967: func (s *Suite) Test_Package_CheckVarorder__skip_because_of_foreign_variable(c *check.C) {
1.29      rillig   1968:        t := s.Init(c)
                   1969:
1.58      rillig   1970:        pkg := NewPackage(t.File("x11/9term"))
                   1971:        mklines := t.NewMkLines("Makefile",
                   1972:                MkCvsID,
                   1973:                "",
                   1974:                "DISTNAME=\tdistname-1.0",
                   1975:                "USE_TOOLS+=gmake",
                   1976:                "CATEGORIES=\tsysutils",
                   1977:                "",
                   1978:                "MAINTAINER=\tpkgsrc-users@NetBSD.org",
                   1979:                "#HOMEPAGE=\thttps://example.org/",
                   1980:                "COMMENT=\tComment",
                   1981:                "LICENSE=\tgnu-gpl-v2")
                   1982:
                   1983:        t.EnableTracingToLog()
                   1984:        pkg.CheckVarorder(mklines)
1.29      rillig   1985:
1.58      rillig   1986:        t.CheckOutputLinesMatching(`.*varorder.*`,
                   1987:                "TRACE: 1   Skipping varorder because of line 4.")
1.29      rillig   1988: }
1.30      rillig   1989:
1.58      rillig   1990: func (s *Suite) Test_Package_CheckVarorder__skip_if_there_are_directives(c *check.C) {
1.30      rillig   1991:        t := s.Init(c)
                   1992:
1.58      rillig   1993:        pkg := NewPackage(t.File("category/package"))
                   1994:        mklines := t.NewMkLines("Makefile",
1.48      rillig   1995:                MkCvsID,
1.30      rillig   1996:                "",
1.58      rillig   1997:                "DISTNAME=\tdistname-1.0",
                   1998:                "CATEGORIES=\tsysutils",
                   1999:                "",
                   2000:                ".if ${DISTNAME:Mdistname-*}",
                   2001:                "MAINTAINER=\tpkgsrc-users@NetBSD.org",
                   2002:                ".endif",
                   2003:                "LICENSE=\tgnu-gpl-v2")
                   2004:
                   2005:        pkg.CheckVarorder(mklines)
1.30      rillig   2006:
1.58      rillig   2007:        // No warning about the missing COMMENT since the .if directive
                   2008:        // causes the whole check to be skipped.
                   2009:        t.CheckOutputEmpty()
1.30      rillig   2010:
1.58      rillig   2011:        // Just for code coverage.
                   2012:        t.DisableTracing()
                   2013:        pkg.CheckVarorder(mklines)
                   2014:        t.CheckOutputEmpty()
1.30      rillig   2015: }
                   2016:
1.58      rillig   2017: // TODO: Add more tests like skip_if_there_are_directives for other line types.
                   2018:
                   2019: func (s *Suite) Test_Package_CheckVarorder__GITHUB_PROJECT_at_the_top(c *check.C) {
1.30      rillig   2020:        t := s.Init(c)
                   2021:
1.58      rillig   2022:        pkg := NewPackage(t.File("x11/9term"))
                   2023:        mklines := t.NewMkLines("Makefile",
                   2024:                MkCvsID,
                   2025:                "",
                   2026:                "GITHUB_PROJECT=\t\tautocutsel",
                   2027:                "DISTNAME=\t\tautocutsel-0.10.0",
                   2028:                "CATEGORIES=\t\tx11",
                   2029:                "MASTER_SITES=\t\t${MASTER_SITE_GITHUB:=sigmike/}",
                   2030:                "GITHUB_TAG=\t\t${PKGVERSION_NOREV}",
                   2031:                "",
                   2032:                "COMMENT=\tComment",
                   2033:                "LICENSE=\tgnu-gpl-v2")
1.30      rillig   2034:
1.58      rillig   2035:        pkg.CheckVarorder(mklines)
1.30      rillig   2036:
1.58      rillig   2037:        t.CheckOutputEmpty()
1.30      rillig   2038: }
                   2039:
1.58      rillig   2040: func (s *Suite) Test_Package_CheckVarorder__GITHUB_PROJECT_at_the_bottom(c *check.C) {
1.30      rillig   2041:        t := s.Init(c)
                   2042:
1.58      rillig   2043:        pkg := NewPackage(t.File("x11/9term"))
                   2044:        mklines := t.NewMkLines("Makefile",
                   2045:                MkCvsID,
                   2046:                "",
                   2047:                "DISTNAME=\t\tautocutsel-0.10.0",
                   2048:                "CATEGORIES=\t\tx11",
                   2049:                "MASTER_SITES=\t\t${MASTER_SITE_GITHUB:=sigmike/}",
                   2050:                "GITHUB_PROJECT=\t\tautocutsel",
                   2051:                "GITHUB_TAG=\t\t${PKGVERSION_NOREV}",
                   2052:                "",
                   2053:                "COMMENT=\tComment",
                   2054:                "LICENSE=\tgnu-gpl-v2")
1.30      rillig   2055:
1.58      rillig   2056:        pkg.CheckVarorder(mklines)
1.30      rillig   2057:
                   2058:        t.CheckOutputEmpty()
                   2059: }
                   2060:
1.58      rillig   2061: func (s *Suite) Test_Package_CheckVarorder__license(c *check.C) {
1.30      rillig   2062:        t := s.Init(c)
                   2063:
1.58      rillig   2064:        t.CreateFileLines("mk/bsd.pkg.mk", "# dummy")
                   2065:        t.CreateFileLines("x11/Makefile", MkCvsID)
1.72      rillig   2066:        t.CreateFileLines("x11/9term/DESCR", "Terminal")
1.58      rillig   2067:        t.CreateFileLines("x11/9term/PLIST", PlistCvsID, "bin/9term")
                   2068:        t.CreateFileLines("x11/9term/Makefile",
                   2069:                MkCvsID,
                   2070:                "",
                   2071:                "DISTNAME=\t9term-1.0",
                   2072:                "CATEGORIES=\tx11",
                   2073:                "",
                   2074:                "COMMENT=\tTerminal",
                   2075:                "",
                   2076:                "NO_CHECKSUM=\tyes",
                   2077:                "",
                   2078:                ".include \"../../mk/bsd.pkg.mk\"")
                   2079:
                   2080:        t.SetUpVartypes()
1.30      rillig   2081:
1.58      rillig   2082:        G.Check(t.File("x11/9term"))
1.30      rillig   2083:
1.58      rillig   2084:        // Since the error is grave enough, the warning about the correct position is suppressed.
                   2085:        // TODO: Knowing the correct position helps, though.
1.30      rillig   2086:        t.CheckOutputLines(
1.58      rillig   2087:                "ERROR: ~/x11/9term/Makefile: Each package must define its LICENSE.")
1.30      rillig   2088: }
                   2089:
1.58      rillig   2090: // https://mail-index.netbsd.org/tech-pkg/2017/01/18/msg017698.html
                   2091: func (s *Suite) Test_Package_CheckVarorder__MASTER_SITES(c *check.C) {
1.30      rillig   2092:        t := s.Init(c)
                   2093:
1.58      rillig   2094:        pkg := NewPackage(t.File("category/package"))
                   2095:        mklines := t.NewMkLines("Makefile",
                   2096:                MkCvsID,
                   2097:                "",
                   2098:                "PKGNAME=\tpackage-1.0",
                   2099:                "CATEGORIES=\tcategory",
                   2100:                "MASTER_SITES=\thttp://example.org/",
                   2101:                "MASTER_SITES+=\thttp://mirror.example.org/",
                   2102:                "",
                   2103:                "COMMENT=\tComment",
                   2104:                "LICENSE=\tgnu-gpl-v2")
1.30      rillig   2105:
1.58      rillig   2106:        pkg.CheckVarorder(mklines)
1.30      rillig   2107:
1.58      rillig   2108:        // No warning that "MASTER_SITES appears too late"
                   2109:        t.CheckOutputEmpty()
1.30      rillig   2110: }
                   2111:
1.58      rillig   2112: func (s *Suite) Test_Package_CheckVarorder__diagnostics(c *check.C) {
1.48      rillig   2113:        t := s.Init(c)
                   2114:
1.58      rillig   2115:        t.SetUpVartypes()
                   2116:        pkg := NewPackage(t.File("category/package"))
                   2117:        mklines := t.NewMkLines("Makefile",
                   2118:                MkCvsID,
                   2119:                "",
                   2120:                "CATEGORIES=     net",
                   2121:                "",
                   2122:                "COMMENT=        Comment",
                   2123:                "LICENSE=        gnu-gpl-v3",
                   2124:                "",
                   2125:                "GITHUB_PROJECT= pkgbase",
                   2126:                "DISTNAME=       v1.0",
                   2127:                "PKGNAME=        ${GITHUB_PROJECT}-${DISTNAME}",
                   2128:                "MASTER_SITES=   ${MASTER_SITE_GITHUB:=project/}",
                   2129:                "DIST_SUBDIR=    ${GITHUB_PROJECT}",
                   2130:                "",
                   2131:                "MAINTAINER=     maintainer@example.org",
                   2132:                "HOMEPAGE=       https://github.com/project/pkgbase/",
1.48      rillig   2133:                "",
1.58      rillig   2134:                ".include \"../../mk/bsd.pkg.mk\"")
                   2135:
                   2136:        pkg.CheckVarorder(mklines)
                   2137:
                   2138:        t.CheckOutputLines(
                   2139:                "WARN: Makefile:3: The canonical order of the variables is " +
                   2140:                        "GITHUB_PROJECT, DISTNAME, PKGNAME, CATEGORIES, " +
                   2141:                        "MASTER_SITES, GITHUB_PROJECT, DIST_SUBDIR, empty line, " +
                   2142:                        "MAINTAINER, HOMEPAGE, COMMENT, LICENSE.")
1.48      rillig   2143:
1.58      rillig   2144:        // After moving the variables according to the warning:
                   2145:        mklines = t.NewMkLines("Makefile",
                   2146:                MkCvsID,
                   2147:                "",
                   2148:                "GITHUB_PROJECT= pkgbase",
                   2149:                "DISTNAME=       v1.0",
                   2150:                "PKGNAME=        ${GITHUB_PROJECT}-${DISTNAME}",
                   2151:                "CATEGORIES=     net",
                   2152:                "MASTER_SITES=   ${MASTER_SITE_GITHUB:=project/}",
                   2153:                "DIST_SUBDIR=    ${GITHUB_PROJECT}",
                   2154:                "",
                   2155:                "MAINTAINER=     maintainer@example.org",
                   2156:                "HOMEPAGE=       https://github.com/project/pkgbase/",
                   2157:                "COMMENT=        Comment",
                   2158:                "LICENSE=        gnu-gpl-v3",
                   2159:                "",
                   2160:                ".include \"../../mk/bsd.pkg.mk\"")
1.48      rillig   2161:
1.58      rillig   2162:        pkg.CheckVarorder(mklines)
1.48      rillig   2163:
                   2164:        t.CheckOutputEmpty()
                   2165: }
                   2166:
1.58      rillig   2167: func (s *Suite) Test_Package_CheckVarorder__comment_at_end_of_section(c *check.C) {
1.30      rillig   2168:        t := s.Init(c)
                   2169:
1.58      rillig   2170:        t.SetUpVartypes()
                   2171:        pkg := NewPackage(t.File("category/package"))
                   2172:        mklines := t.NewMkLines("Makefile",
                   2173:                MkCvsID,
                   2174:                "",
                   2175:                "CATEGORIES=     net",
                   2176:                "SITES.*=        # none",
                   2177:                "# comment after the last variable of a section",
                   2178:                "",
                   2179:                "MAINTAINER=     maintainer@example.org",
                   2180:                "HOMEPAGE=       https://github.com/project/pkgbase/",
                   2181:                "COMMENT=        Comment",
                   2182:                "LICENSE=        gnu-gpl-v3",
                   2183:                "",
                   2184:                ".include \"../../mk/bsd.pkg.mk\"")
1.30      rillig   2185:
1.58      rillig   2186:        t.EnableTracingToLog()
                   2187:        pkg.CheckVarorder(mklines)
1.30      rillig   2188:
1.58      rillig   2189:        // The varorder code is not skipped, not even because of the comment
                   2190:        // after SITES.*.
                   2191:        t.CheckOutputLinesMatching(`.*varorder.*`,
                   2192:                nil...)
1.30      rillig   2193: }
                   2194:
1.58      rillig   2195: func (s *Suite) Test_Package_CheckVarorder__comments_between_sections(c *check.C) {
1.48      rillig   2196:        t := s.Init(c)
                   2197:
1.58      rillig   2198:        t.SetUpVartypes()
                   2199:        pkg := NewPackage(t.File("category/package"))
                   2200:        mklines := t.NewMkLines("Makefile",
                   2201:                MkCvsID,
                   2202:                "",
                   2203:                "CATEGORIES=     net",
                   2204:                "",
                   2205:                "# comment 1",
                   2206:                "",
                   2207:                "# comment 2",
                   2208:                "",
                   2209:                "MAINTAINER=     maintainer@example.org",
                   2210:                "HOMEPAGE=       https://github.com/project/pkgbase/",
                   2211:                "COMMENT=        Comment",
                   2212:                "LICENSE=        gnu-gpl-v3",
                   2213:                "",
                   2214:                ".include \"../../mk/bsd.pkg.mk\"")
1.48      rillig   2215:
1.58      rillig   2216:        pkg.CheckVarorder(mklines)
1.48      rillig   2217:
1.58      rillig   2218:        // The empty line between the comments is not treated as a section separator.
1.48      rillig   2219:        t.CheckOutputEmpty()
                   2220: }
                   2221:
1.58      rillig   2222: func (s *Suite) Test_Package_CheckVarorder__commented_varassign(c *check.C) {
1.48      rillig   2223:        t := s.Init(c)
                   2224:
1.58      rillig   2225:        t.SetUpVartypes()
                   2226:        pkg := NewPackage(t.File("category/package"))
                   2227:        mklines := t.NewMkLines("Makefile",
1.48      rillig   2228:                MkCvsID,
1.58      rillig   2229:                "",
                   2230:                "CATEGORIES=     net",
                   2231:                "#MASTER_SITES=  # none",
                   2232:                "",
                   2233:                "HOMEPAGE=       https://github.com/project/pkgbase/",
                   2234:                "#HOMEPAGE=      https://github.com/project/pkgbase/",
                   2235:                "#HOMEPAGE=      https://github.com/project/pkgbase/",
                   2236:                "#HOMEPAGE=      https://github.com/project/pkgbase/",
                   2237:                "#HOMEPAGE=      https://github.com/project/pkgbase/",
                   2238:                "LICENSE=        gnu-gpl-v3",
                   2239:                "COMMENT=        Comment",
                   2240:                "",
                   2241:                ".include \"../../mk/bsd.pkg.mk\"")
1.48      rillig   2242:
1.58      rillig   2243:        pkg.CheckVarorder(mklines)
1.48      rillig   2244:
1.58      rillig   2245:        // The order of the variables LICENSE and COMMENT is intentionally
                   2246:        // wrong to force the warning.
                   2247:        //
                   2248:        // Up to June 2019 (308099138a62) pkglint mentioned in the warning
                   2249:        // each commented variable assignment, even repeatedly for the same
                   2250:        // variable name.
                   2251:        //
                   2252:        // These variable assignments should be in the correct order, even
                   2253:        // if they are commented out. It's not necessary though to list a
                   2254:        // variable more than once.
                   2255:        t.CheckOutputLines(
                   2256:                "WARN: Makefile:3: The canonical order of the variables is " +
                   2257:                        "CATEGORIES, MASTER_SITES, empty line, HOMEPAGE, COMMENT, LICENSE.")
1.48      rillig   2258: }
                   2259:
1.58      rillig   2260: func (s *Suite) Test_Package_CheckVarorder__DEPENDS(c *check.C) {
1.48      rillig   2261:        t := s.Init(c)
                   2262:
1.58      rillig   2263:        t.SetUpVartypes()
                   2264:        pkg := NewPackage(t.File("category/package"))
                   2265:        mklines := t.NewMkLines("Makefile",
                   2266:                MkCvsID,
                   2267:                "",
                   2268:                "CATEGORIES=     net",
                   2269:                "",
                   2270:                "COMMENT=        Comment",
                   2271:                "LICENSE=        license",
                   2272:                "MAINTAINER=     maintainer@example.org", // In wrong order
                   2273:                "",
                   2274:                "DEPENDS+=       dependency>=1.0:../../category/dependency",
                   2275:                "",
                   2276:                ".include \"../../mk/bsd.pkg.mk\"")
1.48      rillig   2277:
1.58      rillig   2278:        pkg.CheckVarorder(mklines)
1.48      rillig   2279:
                   2280:        t.CheckOutputLines(
1.58      rillig   2281:                "WARN: Makefile:3: The canonical order of the variables is " +
                   2282:                        "CATEGORIES, empty line, MAINTAINER, COMMENT, LICENSE, empty line, DEPENDS.")
1.48      rillig   2283: }
                   2284:
1.40      rillig   2285: func (s *Suite) Test_Package_checkGnuConfigureUseLanguages__no_C(c *check.C) {
                   2286:        t := s.Init(c)
                   2287:
                   2288:        t.SetUpPackage("category/package",
                   2289:                "USE_LANGUAGES=\tfortran77",
                   2290:                "USE_LANGUAGES+=\tc++14",
                   2291:                "USE_LANGUAGES+=\tada",
                   2292:                "GNU_CONFIGURE=\tyes")
1.43      rillig   2293:        t.FinishSetUp()
1.40      rillig   2294:
                   2295:        G.Check(t.File("category/package"))
                   2296:
                   2297:        t.CheckOutputLines(
                   2298:                "WARN: ~/category/package/Makefile:23: "+
                   2299:                        "GNU_CONFIGURE almost always needs a C compiler, "+
                   2300:                        "but \"c\" is not added to USE_LANGUAGES in line 20.",
                   2301:                "WARN: ~/category/package/Makefile:23: "+
                   2302:                        "GNU_CONFIGURE almost always needs a C compiler, "+
                   2303:                        "but \"c\" is not added to USE_LANGUAGES in line 21.",
                   2304:                "WARN: ~/category/package/Makefile:23: "+
                   2305:                        "GNU_CONFIGURE almost always needs a C compiler, "+
                   2306:                        "but \"c\" is not added to USE_LANGUAGES in line 22.")
                   2307: }
                   2308:
                   2309: func (s *Suite) Test_Package_checkGnuConfigureUseLanguages__C_in_the_middle(c *check.C) {
                   2310:        t := s.Init(c)
                   2311:
                   2312:        t.SetUpPackage("category/package",
                   2313:                "USE_LANGUAGES=\tfortran77",
                   2314:                "USE_LANGUAGES+=\tc99",
                   2315:                "USE_LANGUAGES+=\tada",
                   2316:                "GNU_CONFIGURE=\tyes")
1.43      rillig   2317:        t.FinishSetUp()
1.40      rillig   2318:
                   2319:        G.Check(t.File("category/package"))
                   2320:
                   2321:        // Until March 2019 pkglint wrongly warned that USE_LANGUAGES would not
                   2322:        // include c or c99, although c99 was added.
                   2323:        t.CheckOutputEmpty()
                   2324: }
                   2325:
                   2326: func (s *Suite) Test_Package_checkGnuConfigureUseLanguages__realistic_compiler_mk(c *check.C) {
                   2327:        t := s.Init(c)
                   2328:
                   2329:        t.SetUpPackage("category/package",
                   2330:                "USE_LANGUAGES=\tfortran77",
                   2331:                "USE_LANGUAGES+=\tc++",
                   2332:                "USE_LANGUAGES+=\tada",
                   2333:                "GNU_CONFIGURE=\tyes",
                   2334:                "",
                   2335:                ".include \"../../mk/compiler.mk\"")
                   2336:        t.CreateFileLines("mk/compiler.mk",
1.51      rillig   2337:                "_CXX_STD_VERSIONS=\tc++ c++14",
                   2338:                ".if ${USE_LANGUAGES:Mada} \\",
                   2339:                " || ${USE_LANGUAGES:Mc} \\",
                   2340:                " || ${USE_LANGUAGES:Mfortran77}",
                   2341:                ".endif",
1.40      rillig   2342:                "",
1.51      rillig   2343:                // This line is ignored since it comes from the pkgsrc infrastructure.
                   2344:                "USE_LANGUAGES?=\t\tc")
                   2345:
1.43      rillig   2346:        t.FinishSetUp()
1.40      rillig   2347:
                   2348:        G.Check(t.File("category/package"))
                   2349:
                   2350:        // The package defines several languages it needs, but C is not one of them.
                   2351:        // When the package is loaded, the included files are read in recursively, even
                   2352:        // when they come from the pkgsrc infrastructure.
                   2353:        //
                   2354:        // Up to March 2019, the USE_LANGUAGES definitions from mk/compiler.mk were
                   2355:        // loaded as if they were defined by the package, without taking the conditionals
                   2356:        // into account. Thereby "c" was added unconditionally to USE_LANGUAGES.
                   2357:        //
                   2358:        // Since March 2019 the infrastructure files are ignored when determining the value
                   2359:        // of USE_LANGUAGES.
                   2360:        t.CheckOutputLines(
                   2361:                "WARN: ~/category/package/Makefile:23: "+
                   2362:                        "GNU_CONFIGURE almost always needs a C compiler, "+
                   2363:                        "but \"c\" is not added to USE_LANGUAGES in line 20.",
                   2364:                "WARN: ~/category/package/Makefile:23: "+
                   2365:                        "GNU_CONFIGURE almost always needs a C compiler, "+
                   2366:                        "but \"c\" is not added to USE_LANGUAGES in line 21.",
                   2367:                "WARN: ~/category/package/Makefile:23: "+
                   2368:                        "GNU_CONFIGURE almost always needs a C compiler, "+
                   2369:                        "but \"c\" is not added to USE_LANGUAGES in line 22.")
                   2370: }
                   2371:
                   2372: func (s *Suite) Test_Package_checkGnuConfigureUseLanguages__only_GNU_CONFIGURE(c *check.C) {
                   2373:        t := s.Init(c)
                   2374:
                   2375:        t.SetUpPackage("category/package",
                   2376:                "GNU_CONFIGURE=\tyes")
1.43      rillig   2377:        t.FinishSetUp()
1.40      rillig   2378:
                   2379:        G.Check(t.File("category/package"))
                   2380:
                   2381:        t.CheckOutputEmpty()
                   2382: }
                   2383:
                   2384: func (s *Suite) Test_Package_checkGnuConfigureUseLanguages__ok(c *check.C) {
                   2385:        t := s.Init(c)
                   2386:
                   2387:        t.SetUpPackage("category/package",
                   2388:                "GNU_CONFIGURE=\tyes",
                   2389:                "USE_LANGUAGES=\tc++ objc")
1.43      rillig   2390:        t.FinishSetUp()
1.40      rillig   2391:
                   2392:        G.Check(t.File("category/package"))
                   2393:
                   2394:        t.CheckOutputEmpty()
                   2395: }
                   2396:
1.48      rillig   2397: func (s *Suite) Test_Package_checkGnuConfigureUseLanguages__not_constant_1(c *check.C) {
                   2398:        t := s.Init(c)
                   2399:
                   2400:        t.SetUpPackage("category/package",
                   2401:                ".if 0",
                   2402:                "GNU_CONFIGURE=\tyes",
                   2403:                ".endif",
                   2404:                "USE_LANGUAGES=\tc++ objc")
                   2405:        t.FinishSetUp()
                   2406:
                   2407:        G.Check(t.File("category/package"))
                   2408:
                   2409:        t.CheckOutputEmpty()
                   2410: }
                   2411:
                   2412: func (s *Suite) Test_Package_checkGnuConfigureUseLanguages__not_constant_2(c *check.C) {
                   2413:        t := s.Init(c)
                   2414:
                   2415:        t.SetUpPackage("category/package",
                   2416:                "GNU_CONFIGURE=\tyes",
                   2417:                ".if 0",
                   2418:                "USE_LANGUAGES=\tc++ objc",
                   2419:                ".endif")
                   2420:        t.FinishSetUp()
                   2421:
                   2422:        G.Check(t.File("category/package"))
                   2423:
                   2424:        t.CheckOutputEmpty()
                   2425: }
                   2426:
1.43      rillig   2427: func (s *Suite) Test_Package_checkUseLanguagesCompilerMk__too_late(c *check.C) {
1.40      rillig   2428:        t := s.Init(c)
                   2429:
                   2430:        t.SetUpPackage("category/package",
                   2431:                ".include \"../../mk/compiler.mk\"",
                   2432:                "USE_LANGUAGES=\tc c99 fortran ada c++14")
1.43      rillig   2433:        t.FinishSetUp()
1.40      rillig   2434:
                   2435:        G.Check(t.File("category/package"))
                   2436:
1.43      rillig   2437:        t.CheckOutputLines(
                   2438:                "WARN: ~/category/package/Makefile:21: " +
                   2439:                        "Modifying USE_LANGUAGES after including ../../mk/compiler.mk has no effect.")
                   2440: }
                   2441:
                   2442: func (s *Suite) Test_Package_checkUseLanguagesCompilerMk__compiler_mk(c *check.C) {
                   2443:        t := s.Init(c)
                   2444:
                   2445:        t.SetUpPackage("category/package",
                   2446:                "USE_LANGUAGES=\tc c99 fortran ada c++14",
                   2447:                ".include \"../../mk/compiler.mk\"",
1.48      rillig   2448:                ".include \"compiler.mk\"",
1.43      rillig   2449:                "USE_LANGUAGES=\tc c99 fortran ada c++14")
                   2450:        t.CreateFileLines("category/package/compiler.mk",
1.48      rillig   2451:                MkCvsID,
                   2452:                "USE_LANGUAGES=\tc++")
1.43      rillig   2453:        t.FinishSetUp()
                   2454:
                   2455:        G.Check(t.File("category/package"))
                   2456:
                   2457:        t.CheckOutputLines(
1.48      rillig   2458:                "WARN: ~/category/package/Makefile:20: "+
                   2459:                        "Variable USE_LANGUAGES is overwritten in compiler.mk:2.",
                   2460:                "WARN: ~/category/package/compiler.mk:2: "+
                   2461:                        "Modifying USE_LANGUAGES after including ../../mk/compiler.mk has no effect.",
1.43      rillig   2462:                "WARN: ~/category/package/Makefile:23: "+
                   2463:                        "Modifying USE_LANGUAGES after including ../../mk/compiler.mk has no effect.")
1.40      rillig   2464: }
                   2465:
1.48      rillig   2466: func (s *Suite) Test_Package_checkUseLanguagesCompilerMk__endian_mk(c *check.C) {
1.30      rillig   2467:        t := s.Init(c)
                   2468:
1.48      rillig   2469:        t.SetUpPackage("category/package",
                   2470:                ".include \"endian.mk\"",
                   2471:                "USE_LANGUAGES=\tc c99 fortran ada c++14",
                   2472:                ".include \"../../mk/endian.mk\"",
                   2473:                "USE_LANGUAGES=\tc c99 fortran ada c++14")
                   2474:        t.CreateFileLines("category/package/endian.mk",
1.58      rillig   2475:                MkCvsID)
                   2476:        t.CreateFileLines("mk/endian.mk",
                   2477:                MkCvsID)
                   2478:        t.FinishSetUp()
                   2479:
                   2480:        G.Check(t.File("category/package"))
                   2481:
                   2482:        t.CheckOutputLines(
                   2483:                "NOTE: ~/category/package/Makefile:23: "+
                   2484:                        "Definition of USE_LANGUAGES is redundant because of line 21.",
                   2485:                "WARN: ~/category/package/Makefile:23: "+
                   2486:                        "Modifying USE_LANGUAGES after including ../../mk/compiler.mk has no effect.")
                   2487: }
                   2488:
                   2489: // PKGNAME is stronger than DISTNAME.
                   2490: func (s *Suite) Test_Package_determineEffectivePkgVars__precedence(c *check.C) {
                   2491:        t := s.Init(c)
                   2492:
                   2493:        pkg := NewPackage(t.File("category/pkgbase"))
                   2494:        pkgnameLine := t.NewMkLine("Makefile", 3, "PKGNAME=pkgname-1.0")
                   2495:        distnameLine := t.NewMkLine("Makefile", 4, "DISTNAME=distname-1.0")
                   2496:        pkgrevisionLine := t.NewMkLine("Makefile", 5, "PKGREVISION=13")
                   2497:
                   2498:        pkg.vars.Define(pkgnameLine.Varname(), pkgnameLine)
                   2499:        pkg.vars.Define(distnameLine.Varname(), distnameLine)
                   2500:        pkg.vars.Define(pkgrevisionLine.Varname(), pkgrevisionLine)
                   2501:
                   2502:        pkg.determineEffectivePkgVars()
                   2503:
                   2504:        t.CheckEquals(pkg.EffectivePkgbase, "pkgname")
                   2505:        t.CheckEquals(pkg.EffectivePkgname, "pkgname-1.0nb13")
                   2506:        t.CheckEquals(pkg.EffectivePkgversion, "1.0")
                   2507: }
                   2508:
                   2509: func (s *Suite) Test_Package_determineEffectivePkgVars__same(c *check.C) {
                   2510:        t := s.Init(c)
                   2511:
                   2512:        pkg := t.SetUpPackage("category/package",
                   2513:                "DISTNAME=\tdistname-1.0",
                   2514:                "PKGNAME=\tdistname-1.0")
                   2515:        t.FinishSetUp()
                   2516:
                   2517:        G.Check(pkg)
                   2518:
                   2519:        t.CheckOutputLines(
                   2520:                "NOTE: ~/category/package/Makefile:4: " +
                   2521:                        "This assignment is probably redundant since PKGNAME is ${DISTNAME} by default.")
                   2522: }
                   2523:
                   2524: func (s *Suite) Test_Package_determineEffectivePkgVars__simple_reference(c *check.C) {
                   2525:        t := s.Init(c)
                   2526:
                   2527:        pkg := t.SetUpPackage("category/package",
                   2528:                "DISTNAME=\tdistname-1.0",
                   2529:                "PKGNAME=\t${DISTNAME}")
                   2530:        t.FinishSetUp()
                   2531:
                   2532:        G.Check(pkg)
                   2533:
                   2534:        t.CheckOutputLines(
                   2535:                "NOTE: ~/category/package/Makefile:4: " +
                   2536:                        "This assignment is probably redundant since PKGNAME is ${DISTNAME} by default.")
                   2537: }
                   2538:
                   2539: func (s *Suite) Test_Package_determineEffectivePkgVars__commented(c *check.C) {
                   2540:        t := s.Init(c)
                   2541:
                   2542:        pkg := t.SetUpPackage("category/package",
                   2543:                "DISTNAME=\tdistname-1.0",
                   2544:                "PKGNAME=\t${DISTNAME} # intentionally")
1.43      rillig   2545:        t.FinishSetUp()
1.30      rillig   2546:
1.58      rillig   2547:        G.Check(pkg)
1.35      rillig   2548:
1.58      rillig   2549:        t.CheckOutputEmpty()
1.30      rillig   2550: }
                   2551:
1.58      rillig   2552: func (s *Suite) Test_Package_determineEffectivePkgVars__invalid_DISTNAME(c *check.C) {
1.30      rillig   2553:        t := s.Init(c)
                   2554:
1.58      rillig   2555:        pkg := t.SetUpPackage("category/package",
                   2556:                "DISTNAME=\tpkgname-version")
1.43      rillig   2557:        t.FinishSetUp()
1.30      rillig   2558:
1.58      rillig   2559:        G.Check(pkg)
1.30      rillig   2560:
                   2561:        t.CheckOutputLines(
1.58      rillig   2562:                "WARN: ~/category/package/Makefile:3: " +
                   2563:                        "As DISTNAME is not a valid package name, please define the PKGNAME explicitly.")
1.30      rillig   2564: }
                   2565:
1.58      rillig   2566: func (s *Suite) Test_Package_determineEffectivePkgVars__indirect_DISTNAME(c *check.C) {
1.30      rillig   2567:        t := s.Init(c)
                   2568:
1.58      rillig   2569:        pkg := t.SetUpPackage("category/package",
                   2570:                "DISTNAME=\t${DISTFILES:[1]:C,\\..*,,}")
1.43      rillig   2571:        t.FinishSetUp()
1.30      rillig   2572:
1.58      rillig   2573:        G.Check(pkg)
1.48      rillig   2574:
1.58      rillig   2575:        // No warning since the case of DISTNAME being dependent on another
                   2576:        // variable is too difficult to analyze.
                   2577:        t.CheckOutputEmpty()
1.48      rillig   2578: }
                   2579:
1.58      rillig   2580: func (s *Suite) Test_Package_determineEffectivePkgVars__C_modifier(c *check.C) {
1.48      rillig   2581:        t := s.Init(c)
                   2582:
1.58      rillig   2583:        t.SetUpPackage("x11/p5-gtk2",
                   2584:                "DISTNAME=\tGtk2-1.0",
                   2585:                "PKGNAME=\t${DISTNAME:C:Gtk2:p5-gtk2:}")
1.48      rillig   2586:        t.FinishSetUp()
1.58      rillig   2587:        pkg := NewPackage(t.File("x11/p5-gtk2"))
                   2588:        files, mklines, allLines := pkg.load()
1.48      rillig   2589:
1.58      rillig   2590:        pkg.check(files, mklines, allLines)
1.48      rillig   2591:
1.58      rillig   2592:        t.CheckEquals(pkg.EffectivePkgname, "p5-gtk2-1.0")
1.48      rillig   2593: }
                   2594:
1.58      rillig   2595: // In some cases the PKGNAME is derived from DISTNAME, and it seems as
                   2596: // if the :C modifier would not affect anything. This may nevertheless
                   2597: // be on purpose since the modifier may apply to future versions and
                   2598: // do things like replacing a "-1" with a ".1".
                   2599: func (s *Suite) Test_Package_determineEffectivePkgVars__ineffective_C_modifier(c *check.C) {
1.48      rillig   2600:        t := s.Init(c)
                   2601:
                   2602:        t.SetUpPackage("category/package",
1.58      rillig   2603:                "DISTNAME=\tdistname-1.0",
                   2604:                "PKGNAME=\t${DISTNAME:C:does_not_match:replacement:}")
1.48      rillig   2605:        t.FinishSetUp()
1.58      rillig   2606:        pkg := NewPackage(t.File("category/package"))
                   2607:        files, mklines, allLines := pkg.load()
1.48      rillig   2608:
1.58      rillig   2609:        pkg.check(files, mklines, allLines)
1.48      rillig   2610:
1.58      rillig   2611:        t.CheckEquals(pkg.EffectivePkgname, "distname-1.0")
                   2612:        t.CheckOutputEmpty()
1.48      rillig   2613: }
                   2614:
1.58      rillig   2615: func (s *Suite) Test_Package_determineEffectivePkgVars__Python_prefix(c *check.C) {
1.48      rillig   2616:        t := s.Init(c)
                   2617:
1.58      rillig   2618:        G.Experimental = true
1.48      rillig   2619:        t.SetUpPackage("category/package",
1.58      rillig   2620:                "PKGNAME=\tpackage-2.0",
                   2621:                ".include \"../../lang/python/extension.mk\"")
                   2622:        t.CreateFileLines("lang/python/extension.mk",
1.48      rillig   2623:                MkCvsID)
                   2624:
1.58      rillig   2625:        t.Main("-Wall", "category/package")
1.48      rillig   2626:
                   2627:        t.CheckOutputLines(
1.58      rillig   2628:                "WARN: ~/category/package/Makefile:4: The PKGNAME of Python extensions should start with ${PYPKGPREFIX}.",
                   2629:                "1 warning found.")
1.48      rillig   2630: }
                   2631:
1.58      rillig   2632: func (s *Suite) Test_Package_determineEffectivePkgVars__Python_prefix_PKGNAME_variable(c *check.C) {
1.48      rillig   2633:        t := s.Init(c)
                   2634:
1.58      rillig   2635:        G.Experimental = true
1.48      rillig   2636:        t.SetUpPackage("category/package",
1.58      rillig   2637:                "PKGNAME=\t${VAR}-package-2.0",
                   2638:                ".include \"../../lang/python/extension.mk\"")
                   2639:        t.CreateFileLines("lang/python/extension.mk",
                   2640:                MkCvsID,
                   2641:                "VAR=\tvalue")
1.48      rillig   2642:
1.58      rillig   2643:        t.Main("-Wall", "category/package")
1.48      rillig   2644:
1.58      rillig   2645:        // Since PKGNAME starts with a variable, pkglint doesn't investigate
                   2646:        // further what the possible value of this variable could be. If it
                   2647:        // did, it would see that the prefix is not PYPKGPREFIX and would
                   2648:        // complain.
1.48      rillig   2649:        t.CheckOutputLines(
1.58      rillig   2650:                "Looks fine.")
1.48      rillig   2651: }
                   2652:
1.58      rillig   2653: // As of August 2019, pkglint loads the package files in alphabetical order.
                   2654: // This means that the package Makefile is loaded early, and includes by
                   2655: // other files may be invisible yet. This applies to both Makefile.* and to
                   2656: // *.mk since both of these appear later.
                   2657: //
                   2658: // The effects of these files are nevertheless visible at the right time
                   2659: // because the package Makefile is loaded including all its included files.
                   2660: func (s *Suite) Test_Package_determineEffectivePkgVars__Python_prefix_late(c *check.C) {
1.48      rillig   2661:        t := s.Init(c)
                   2662:
1.58      rillig   2663:        G.Experimental = true
1.48      rillig   2664:        t.SetUpPackage("category/package",
1.58      rillig   2665:                "PKGNAME=\tpackage-2.0",
                   2666:                ".include \"common.mk\"")
                   2667:        t.CreateFileLines("category/package/common.mk",
1.48      rillig   2668:                MkCvsID,
1.58      rillig   2669:                ".include \"../../lang/python/extension.mk\"")
                   2670:        t.CreateFileLines("lang/python/extension.mk",
1.48      rillig   2671:                MkCvsID)
                   2672:
1.58      rillig   2673:        t.Main("-Wall", "category/package")
1.48      rillig   2674:
                   2675:        t.CheckOutputLines(
1.58      rillig   2676:                "WARN: ~/category/package/Makefile:4: "+
                   2677:                        "The PKGNAME of Python extensions should start with ${PYPKGPREFIX}.",
                   2678:                "1 warning found.")
1.48      rillig   2679: }
                   2680:
1.58      rillig   2681: func (s *Suite) Test_Package_nbPart(c *check.C) {
1.48      rillig   2682:        t := s.Init(c)
                   2683:
1.58      rillig   2684:        pkg := NewPackage(t.File("category/pkgbase"))
                   2685:        pkg.vars.Define("PKGREVISION", t.NewMkLine("Makefile", 1, "PKGREVISION=14"))
                   2686:
                   2687:        t.CheckEquals(pkg.nbPart(), "nb14")
1.48      rillig   2688:
1.58      rillig   2689:        pkg.vars = NewScope()
                   2690:        pkg.vars.Define("PKGREVISION", t.NewMkLine("Makefile", 1, "PKGREVISION=asdf"))
1.48      rillig   2691:
1.58      rillig   2692:        t.CheckEquals(pkg.nbPart(), "")
1.48      rillig   2693: }
                   2694:
1.58      rillig   2695: func (s *Suite) Test_Package_pkgnameFromDistname(c *check.C) {
1.48      rillig   2696:        t := s.Init(c)
                   2697:
1.58      rillig   2698:        var once Once
                   2699:        test := func(pkgname, distname, expectedPkgname string, diagnostics ...string) {
                   2700:                t.SetUpPackage("category/package",
                   2701:                        "PKGNAME=\t"+pkgname,
                   2702:                        "DISTNAME=\t"+distname)
                   2703:                if once.FirstTime("called") {
                   2704:                        t.FinishSetUp()
                   2705:                }
                   2706:
                   2707:                pkg := NewPackage(t.File("category/package"))
                   2708:                pkg.loadPackageMakefile()
                   2709:                pkg.determineEffectivePkgVars()
                   2710:                t.CheckEquals(pkg.EffectivePkgname, expectedPkgname)
                   2711:                t.CheckOutput(diagnostics)
                   2712:        }
1.48      rillig   2713:
1.58      rillig   2714:        test("pkgname-1.0", "whatever", "pkgname-1.0")
1.48      rillig   2715:
1.58      rillig   2716:        test("${DISTNAME}", "distname-1.0", "distname-1.0",
                   2717:                "NOTE: ~/category/package/Makefile:4: This assignment is probably redundant since PKGNAME is ${DISTNAME} by default.")
1.48      rillig   2718:
1.58      rillig   2719:        test("${DISTNAME:S/dist/pkg/}", "distname-1.0", "pkgname-1.0")
1.48      rillig   2720:
1.58      rillig   2721:        test("${DISTNAME:S|a|b|g}", "panama-0.13", "pbnbmb-0.13")
1.48      rillig   2722:
1.58      rillig   2723:        // The substitution succeeds, but the substituted value is missing
                   2724:        // the package version. Therefore it is discarded completely.
                   2725:        test("${DISTNAME:S|^lib||}", "libncurses", "")
1.48      rillig   2726:
1.58      rillig   2727:        // The substitution succeeds, but the substituted value is missing
                   2728:        // the package version. Therefore it is discarded completely.
                   2729:        test("${DISTNAME:S|^lib||}", "mylib", "")
1.48      rillig   2730:
1.58      rillig   2731:        test("${DISTNAME:tl:S/-/./g:S/he/-/1}", "SaxonHE9-5-0-1J", "saxon-9.5.0.1j")
1.48      rillig   2732:
1.58      rillig   2733:        test("${DISTNAME:C/beta/.0./}", "fspanel-0.8beta1", "fspanel-0.8.0.1")
1.48      rillig   2734:
1.58      rillig   2735:        test("${DISTNAME:C/Gtk2/p5-gtk2/}", "Gtk2-1.0", "p5-gtk2-1.0")
1.48      rillig   2736:
1.58      rillig   2737:        test("${DISTNAME:S/-0$/.0/1}", "aspell-af-0.50-0", "aspell-af-0.50.0")
1.48      rillig   2738:
1.58      rillig   2739:        test("${DISTNAME:M*.tar.gz:C,\\..*,,}", "aspell-af-0.50-0", "")
1.48      rillig   2740:
1.58      rillig   2741:        test("${DISTNAME:S,a,b,c,d}", "aspell-af-0.50-0", "bspell-af-0.50-0",
                   2742:                "WARN: ~/category/package/Makefile:4: Invalid variable modifier \"c,d\" for \"DISTNAME\".")
1.30      rillig   2743:
1.58      rillig   2744:        test("${DISTFILE:C,\\..*,,}", "aspell-af-0.50-0", "")
1.60      rillig   2745:
                   2746:        // Parse error because of missing closing brace, parsing succeeds.
                   2747:        test("${DISTNAME:M", "package-1.0", "",
                   2748:                "WARN: ~/category/package/Makefile:4: "+
                   2749:                        "Missing closing \"}\" for \"DISTNAME\".")
                   2750:
                   2751:        // Parse error with an unparseable rest.
                   2752:        test("$", "package-1.0", "",
                   2753:                nil...)
1.30      rillig   2754: }
                   2755:
1.58      rillig   2756: func (s *Suite) Test_Package_checkPossibleDowngrade(c *check.C) {
1.38      rillig   2757:        t := s.Init(c)
                   2758:
1.58      rillig   2759:        t.CreateFileLines("doc/CHANGES-2018",
                   2760:                "\tUpdated category/pkgbase to 1.8 [committer 2018-01-05]")
                   2761:        G.Pkgsrc.loadDocChanges()
                   2762:
                   2763:        t.Chdir("category/pkgbase")
1.67      rillig   2764:        pkg := NewPackage(".")
                   2765:        pkg.EffectivePkgname = "package-1.0nb15"
                   2766:        pkg.EffectivePkgnameLine = t.NewMkLine("Makefile", 5, "PKGNAME=dummy")
1.38      rillig   2767:
1.67      rillig   2768:        pkg.checkPossibleDowngrade()
1.38      rillig   2769:
                   2770:        t.CheckOutputLines(
1.58      rillig   2771:                "WARN: Makefile:5: The package is being downgraded from 1.8 (see ../../doc/CHANGES-2018:1) to 1.0nb15.")
1.38      rillig   2772:
1.58      rillig   2773:        G.Pkgsrc.LastChange["category/pkgbase"].target = "1.0nb22"
1.40      rillig   2774:
1.67      rillig   2775:        pkg.checkPossibleDowngrade()
1.48      rillig   2776:
1.58      rillig   2777:        t.CheckOutputEmpty()
1.48      rillig   2778: }
                   2779:
1.58      rillig   2780: func (s *Suite) Test_Package_checkPossibleDowngrade__moved(c *check.C) {
1.48      rillig   2781:        t := s.Init(c)
                   2782:
1.58      rillig   2783:        t.SetUpPackage("category/pkgbase",
                   2784:                "PKGNAME=\tpackage-1.0")
                   2785:        t.CreateFileLines("doc/CHANGES-2018",
                   2786:                "\tUpdated category/old-package to 1.8 [committer 2018-01-05]",
                   2787:                "\tMoved category/old-package to category/pkgbase [committer 2018-01-05]")
1.48      rillig   2788:        t.FinishSetUp()
                   2789:
1.58      rillig   2790:        pkg := NewPackage(t.File("category/pkgbase"))
                   2791:        pkg.load()
                   2792:        pkg.determineEffectivePkgVars()
                   2793:        pkg.checkPossibleDowngrade()
1.48      rillig   2794:
1.58      rillig   2795:        t.CheckEquals(G.Pkgsrc.LastChange["category/pkgbase"].Action, Moved)
                   2796:        // No warning because the latest action is not Updated.
                   2797:        t.CheckOutputEmpty()
1.48      rillig   2798: }
                   2799:
1.58      rillig   2800: func (s *Suite) Test_Package_checkPossibleDowngrade__locally_modified_update(c *check.C) {
1.48      rillig   2801:        t := s.Init(c)
                   2802:
                   2803:        t.SetUpPackage("category/package",
1.58      rillig   2804:                "PKGNAME=\tpackage-1.8")
                   2805:        t.CreateFileLines("doc/CHANGES-2018",
                   2806:                "\tUpdated category/package to 1.0 [committer 2018-01-05]")
                   2807:        t.CreateFileLines("category/package/CVS/Entries",
                   2808:                "/Makefile//modified//")
1.48      rillig   2809:        t.FinishSetUp()
                   2810:
                   2811:        G.Check(t.File("category/package"))
                   2812:
1.58      rillig   2813:        // Since the Makefile is locally modified, pkglint doesn't issue
                   2814:        // any warning since it assumes the package is being upgraded.
                   2815:        t.CheckOutputEmpty()
1.48      rillig   2816:
1.58      rillig   2817:        // When the Makefile is no longer locally modified, the warning
                   2818:        // is activated again.
                   2819:        t.Remove("category/package/CVS/Entries")
                   2820:        G.cvsEntriesDir = ""
1.48      rillig   2821:
                   2822:        G.Check(t.File("category/package"))
                   2823:
                   2824:        t.CheckOutputLines(
1.58      rillig   2825:                "NOTE: ~/category/package/Makefile:4: Package version \"1.8\" " +
                   2826:                        "is greater than the latest \"1.0\" from ../../doc/CHANGES-2018:1.")
1.48      rillig   2827: }
                   2828:
1.58      rillig   2829: func (s *Suite) Test_Package_checkUpdate(c *check.C) {
1.48      rillig   2830:        t := s.Init(c)
                   2831:
1.59      rillig   2832:        // The package names intentionally differ from the package directories
                   2833:        // to ensure that the check uses the package name.
1.58      rillig   2834:        t.SetUpPackage("category/pkg1",
1.61      rillig   2835:                "PKGNAME=\tpackage1-1.0")
1.58      rillig   2836:        t.SetUpPackage("category/pkg2",
1.61      rillig   2837:                "PKGNAME=\tpackage2-1.0")
1.58      rillig   2838:        t.SetUpPackage("category/pkg3",
1.61      rillig   2839:                "PKGNAME=\tpackage3-5.0")
1.58      rillig   2840:        t.CreateFileLines("doc/TODO",
1.59      rillig   2841:                CvsID,
1.58      rillig   2842:                "Suggested package updates",
1.59      rillig   2843:                "=========================",
                   2844:                "For possible Perl packages updates, see http://www.NetBSD.org/~wiz/perl.html.",
1.58      rillig   2845:                "",
                   2846:                "\t"+"o package1-1.0",
1.59      rillig   2847:                "\t"+"o package1-1.0 [with comment]",
                   2848:                "\t"+"o package2-2.0",
1.58      rillig   2849:                "\t"+"o package2-2.0 [nice new features]",
1.59      rillig   2850:                "\t"+"o package3-3.0",
1.58      rillig   2851:                "\t"+"o package3-3.0 [security update]")
1.52      rillig   2852:        t.Chdir(".")
1.40      rillig   2853:
1.61      rillig   2854:        t.Main("-Wall", "category/pkg1", "category/pkg2", "category/pkg3")
1.48      rillig   2855:
1.58      rillig   2856:        t.CheckOutputLines(
1.59      rillig   2857:                "NOTE: category/pkg1/Makefile:4: The update request to 1.0 from ../../doc/TODO:6 has been done.",
                   2858:                "NOTE: category/pkg1/Makefile:4: The update request to 1.0 (with comment) from ../../doc/TODO:7 has been done.",
                   2859:                "WARN: category/pkg2/Makefile:4: This package should be updated to 2.0 (see ../../doc/TODO:8).",
                   2860:                "WARN: category/pkg2/Makefile:4: This package should be updated to 2.0 (nice new features; see ../../doc/TODO:9).",
                   2861:                "NOTE: category/pkg3/Makefile:4: This package is newer than the update request to 3.0 from ../../doc/TODO:10.",
                   2862:                "NOTE: category/pkg3/Makefile:4: This package is newer than the update request to 3.0 (security update) from ../../doc/TODO:11.",
                   2863:                "2 warnings and 4 notes found.")
1.48      rillig   2864: }
                   2865:
1.58      rillig   2866: func (s *Suite) Test_Package_checkDirent__errors(c *check.C) {
1.48      rillig   2867:        t := s.Init(c)
                   2868:
1.61      rillig   2869:        t.SetUpCommandLine("-Call", "-Wall")
1.58      rillig   2870:        t.SetUpPkgsrc()
                   2871:        t.CreateFileLines("category/package/files/subdir/file")
                   2872:        t.CreateFileLines("category/package/files/subdir/subsub/file")
1.48      rillig   2873:        t.FinishSetUp()
                   2874:
1.58      rillig   2875:        pkg := NewPackage(t.File("category/package"))
                   2876:        pkg.checkDirent(t.File("category/package/options.mk"), 0444)
                   2877:        pkg.checkDirent(t.File("category/package/files/subdir"), 0555|os.ModeDir)
                   2878:        pkg.checkDirent(t.File("category/package/files/subdir/subsub"), 0555|os.ModeDir)
                   2879:        pkg.checkDirent(t.File("category/package/files"), 0555|os.ModeDir)
1.48      rillig   2880:
1.58      rillig   2881:        t.CheckOutputLines(
                   2882:                "ERROR: ~/category/package/options.mk: Cannot be read.",
                   2883:                "WARN: ~/category/package/files/subdir/subsub: Unknown directory name.")
1.40      rillig   2884: }
                   2885:
1.58      rillig   2886: func (s *Suite) Test_Package_checkDirent__file_selection(c *check.C) {
1.47      rillig   2887:        t := s.Init(c)
                   2888:
1.61      rillig   2889:        t.SetUpCommandLine("-Call", "-Wall")
1.58      rillig   2890:        t.SetUpPkgsrc()
                   2891:        t.CreateFileLines("doc/CHANGES-2018",
                   2892:                CvsID)
                   2893:        t.CreateFileLines("category/package/buildlink3.mk",
1.61      rillig   2894:                MkCvsID,
                   2895:                "")
1.58      rillig   2896:        t.CreateFileLines("category/package/unexpected.txt",
                   2897:                CvsID)
1.47      rillig   2898:        t.FinishSetUp()
1.58      rillig   2899:
1.47      rillig   2900:        pkg := NewPackage(t.File("category/package"))
1.58      rillig   2901:        pkg.checkDirent(t.File("doc/CHANGES-2018"), 0444)
                   2902:        pkg.checkDirent(t.File("category/package/buildlink3.mk"), 0444)
                   2903:        pkg.checkDirent(t.File("category/package/unexpected.txt"), 0444)
1.47      rillig   2904:
1.48      rillig   2905:        t.CheckOutputLines(
1.61      rillig   2906:                "NOTE: ~/category/package/buildlink3.mk:2: Trailing empty lines.",
1.58      rillig   2907:                "WARN: ~/category/package/buildlink3.mk:EOF: Expected a BUILDLINK_TREE line.",
                   2908:                "WARN: ~/category/package/unexpected.txt: Unexpected file found.")
1.48      rillig   2909: }
                   2910:
1.58      rillig   2911: // Since all required information is passed to G.checkDirent via parameters,
                   2912: // this test produces the expected results even though none of these files actually exists.
                   2913: func (s *Suite) Test_Package_checkDirent__skipped(c *check.C) {
1.48      rillig   2914:        t := s.Init(c)
                   2915:
1.58      rillig   2916:        t.SetUpPackage("category/package")
1.48      rillig   2917:        t.FinishSetUp()
1.58      rillig   2918:        t.Chdir("category/package")
                   2919:        pkg := NewPackage(".")
                   2920:
                   2921:        pkg.checkDirent("work", os.ModeSymlink)
                   2922:        pkg.checkDirent("work.i386", os.ModeSymlink)
                   2923:        pkg.checkDirent("work.hostname", os.ModeSymlink)
                   2924:        pkg.checkDirent("other", os.ModeSymlink)
1.48      rillig   2925:
1.58      rillig   2926:        pkg.checkDirent("device", os.ModeDevice)
1.48      rillig   2927:
1.58      rillig   2928:        t.CheckOutputLines(
                   2929:                "WARN: other: Invalid symlink name.",
                   2930:                "ERROR: device: Only files and directories are allowed in pkgsrc.")
1.47      rillig   2931: }
                   2932:
1.48      rillig   2933: // In packages without specific MAINTAINER, everyone may commit changes.
                   2934: func (s *Suite) Test_Package_checkOwnerMaintainer__no_maintainer(c *check.C) {
1.30      rillig   2935:        t := s.Init(c)
                   2936:
1.35      rillig   2937:        G.Username = "example-user"
1.30      rillig   2938:        t.CreateFileLines("category/package/CVS/Entries",
                   2939:                "/Makefile//modified//")
1.48      rillig   2940:        t.SetUpPackage("category/package",
                   2941:                "MAINTAINER=\tpkgsrc-users@NetBSD.org")
                   2942:        t.FinishSetUp()
1.30      rillig   2943:
1.48      rillig   2944:        G.Check(t.File("category/package"))
1.30      rillig   2945:
1.48      rillig   2946:        t.CheckOutputEmpty()
                   2947: }
                   2948:
                   2949: // A package with a MAINTAINER may be edited by the maintainer itself.
                   2950: func (s *Suite) Test_Package_checkOwnerMaintainer__maintainer_equal(c *check.C) {
                   2951:        t := s.Init(c)
                   2952:
                   2953:        G.Username = "maintainer"
                   2954:        t.CreateFileLines("category/package/CVS/Entries",
                   2955:                "/Makefile//modified//")
                   2956:        t.SetUpPackage("category/package",
                   2957:                "MAINTAINER=\tmaintainer@example.org")
1.43      rillig   2958:        t.FinishSetUp()
1.30      rillig   2959:
1.48      rillig   2960:        G.Check(t.File("category/package"))
1.30      rillig   2961:
                   2962:        t.CheckOutputEmpty()
1.48      rillig   2963: }
1.30      rillig   2964:
1.48      rillig   2965: // A package with a MAINTAINER may be edited by everyone, with care.
                   2966: func (s *Suite) Test_Package_checkOwnerMaintainer__maintainer_unequal(c *check.C) {
                   2967:        t := s.Init(c)
1.30      rillig   2968:
1.48      rillig   2969:        G.Username = "example-user"
                   2970:        t.CreateFileLines("category/package/CVS/Entries",
                   2971:                "/Makefile//modified//")
1.37      rillig   2972:        t.SetUpPackage("category/package",
1.35      rillig   2973:                "MAINTAINER=\tmaintainer@example.org")
1.48      rillig   2974:        t.FinishSetUp()
1.30      rillig   2975:
1.48      rillig   2976:        G.Check(t.File("category/package"))
1.30      rillig   2977:
                   2978:        t.CheckOutputLines(
                   2979:                "NOTE: ~/category/package/Makefile: " +
                   2980:                        "Please only commit changes that maintainer@example.org would approve.")
1.48      rillig   2981: }
                   2982:
                   2983: // A package with an OWNER may be edited by the owner itself.
                   2984: func (s *Suite) Test_Package_checkOwnerMaintainer__owner_equal(c *check.C) {
                   2985:        t := s.Init(c)
1.30      rillig   2986:
1.48      rillig   2987:        G.Username = "owner"
                   2988:        t.CreateFileLines("category/package/CVS/Entries",
                   2989:                "/Makefile//modified//")
                   2990:        t.SetUpPackage("category/package",
                   2991:                "OWNER=\towner@example.org")
                   2992:        t.FinishSetUp()
                   2993:
                   2994:        G.Check(t.File("category/package"))
1.30      rillig   2995:
1.48      rillig   2996:        t.CheckOutputEmpty()
                   2997: }
                   2998:
                   2999: func (s *Suite) Test_Package_checkOwnerMaintainer__owner_unequal(c *check.C) {
                   3000:        t := s.Init(c)
                   3001:
                   3002:        G.Username = "example-user"
                   3003:        t.CreateFileLines("category/package/CVS/Entries",
                   3004:                "/Makefile//modified//")
                   3005:        t.SetUpPackage("category/package",
1.30      rillig   3006:                "OWNER=\towner@example.org")
1.48      rillig   3007:        t.FinishSetUp()
1.30      rillig   3008:
1.48      rillig   3009:        G.Check(t.File("category/package"))
1.30      rillig   3010:
                   3011:        t.CheckOutputLines(
                   3012:                "WARN: ~/category/package/Makefile: " +
                   3013:                        "Don't commit changes to this file without asking the OWNER, owner@example.org.")
1.48      rillig   3014: }
1.30      rillig   3015:
1.48      rillig   3016: // In a package with both OWNER and MAINTAINER, OWNER wins.
                   3017: func (s *Suite) Test_Package_checkOwnerMaintainer__both(c *check.C) {
                   3018:        t := s.Init(c)
1.35      rillig   3019:
1.48      rillig   3020:        G.Username = "example-user"
                   3021:        t.CreateFileLines("category/package/CVS/Entries",
                   3022:                "/Makefile//modified//")
                   3023:        t.SetUpPackage("category/package",
1.35      rillig   3024:                "MAINTAINER=\tmaintainer@example.org",
                   3025:                "OWNER=\towner@example.org")
1.48      rillig   3026:        t.FinishSetUp()
1.35      rillig   3027:
1.48      rillig   3028:        G.Check(t.File("category/package"))
1.35      rillig   3029:
                   3030:        t.CheckOutputLines(
1.50      rillig   3031:                "WARN: ~/category/package/Makefile: " +
                   3032:                        "Don't commit changes to this file without asking the OWNER, owner@example.org.")
1.30      rillig   3033: }
1.39      rillig   3034:
1.47      rillig   3035: // Just for code coverage.
1.48      rillig   3036: func (s *Suite) Test_Package_checkOwnerMaintainer__no_tracing(c *check.C) {
1.47      rillig   3037:        t := s.Init(c)
                   3038:
                   3039:        G.Username = "example-user"
                   3040:        t.CreateFileLines("category/package/CVS/Entries",
                   3041:                "/Makefile//modified//")
                   3042:
                   3043:        pkg := t.SetUpPackage("category/package",
                   3044:                "MAINTAINER=\tmaintainer@example.org")
                   3045:        t.FinishSetUp()
                   3046:        t.DisableTracing()
                   3047:
                   3048:        G.Check(pkg)
                   3049:
                   3050:        t.CheckOutputLines(
                   3051:                "NOTE: ~/category/package/Makefile: Please only commit changes " +
                   3052:                        "that maintainer@example.org would approve.")
                   3053: }
                   3054:
1.48      rillig   3055: func (s *Suite) Test_Package_checkOwnerMaintainer__directory(c *check.C) {
1.41      rillig   3056:        t := s.Init(c)
                   3057:
                   3058:        G.Username = "example-user"
                   3059:        t.CreateFileLines("category/package/CVS/Entries",
                   3060:                "/Makefile//modified//",
                   3061:                "D/patches////")
                   3062:        t.CreateFileDummyPatch("category/package/patches/patch-aa")
                   3063:
                   3064:        pkg := t.SetUpPackage("category/package",
                   3065:                "MAINTAINER=\tmaintainer@example.org")
                   3066:        t.CreateFileLines("category/package/distinfo",
1.48      rillig   3067:                CvsID,
1.41      rillig   3068:                "",
                   3069:                "SHA1 (patch-aa) = ebbf34b0641bcb508f17d5a27f2bf2a536d810ac")
1.43      rillig   3070:        t.FinishSetUp()
1.41      rillig   3071:
                   3072:        G.Check(pkg)
                   3073:
1.54      rillig   3074:        // No warning for the patches directory, only for regular files.
1.41      rillig   3075:        t.CheckOutputLines(
1.43      rillig   3076:                "NOTE: ~/category/package/Makefile: " +
                   3077:                        "Please only commit changes that " +
1.41      rillig   3078:                        "maintainer@example.org would approve.")
                   3079: }
                   3080:
1.54      rillig   3081: func (s *Suite) Test_Package_checkOwnerMaintainer__url2pkg(c *check.C) {
                   3082:        t := s.Init(c)
                   3083:
                   3084:        G.Username = "example-user"
                   3085:        pkg := t.SetUpPackage("category/package",
                   3086:                "MAINTAINER=\tINSERT_YOUR_MAIL_ADDRESS_HERE")
                   3087:        t.CreateFileLines("category/package/CVS/Entries",
                   3088:                "/Makefile//modified//")
                   3089:        t.FinishSetUp()
                   3090:
                   3091:        G.Check(pkg)
                   3092:
                   3093:        t.CheckOutputLines(
                   3094:                "WARN: ~/category/package/Makefile:8: " +
                   3095:                        "\"INSERT_YOUR_MAIL_ADDRESS_HERE\" is not a valid mail address.")
                   3096: }
                   3097:
1.48      rillig   3098: func (s *Suite) Test_Package_checkFreeze(c *check.C) {
                   3099:        t := s.Init(c)
                   3100:
                   3101:        t.SetUpCommandLine("-Wall", "--explain")
                   3102:        pkg := t.SetUpPackage("category/package")
                   3103:        t.CreateFileLines("category/package/CVS/Entries",
                   3104:                "/Makefile//modified//")
                   3105:        t.CreateFileLines("doc/CHANGES-2018",
                   3106:                "\tmk/bsd.pkg.mk: started freeze for 2018Q2 [freezer 2018-03-20]")
                   3107:        t.FinishSetUp()
                   3108:
                   3109:        G.Check(pkg)
                   3110:
                   3111:        t.CheckOutputLines(
                   3112:                "NOTE: ~/category/package/Makefile: Pkgsrc is frozen since 2018-03-20.",
                   3113:                "",
                   3114:                "\tDuring a pkgsrc freeze, changes to pkgsrc should only be made very",
1.54      rillig   3115:                "\tcarefully. See https://www.NetBSD.org/developers/pkgsrc/ for the",
1.48      rillig   3116:                "\texact rules.",
                   3117:                "")
                   3118: }
                   3119:
1.50      rillig   3120: func (s *Suite) Test_Package_checkFreeze__freeze_ended(c *check.C) {
                   3121:        t := s.Init(c)
                   3122:
                   3123:        t.SetUpCommandLine("-Wall", "--explain")
                   3124:        pkg := t.SetUpPackage("category/package")
                   3125:        t.CreateFileLines("category/package/CVS/Entries",
                   3126:                "/Makefile//modified//")
                   3127:        t.CreateFileLines("doc/CHANGES-2018",
                   3128:                "\tmk/bsd.pkg.mk: started freeze for 2018Q2 [freezer 2018-03-20]",
                   3129:                "\tmk/bsd.pkg.mk: freeze ended for 2018Q2 [freezer 2018-03-27]")
                   3130:        t.FinishSetUp()
                   3131:
                   3132:        G.Check(pkg)
                   3133:
                   3134:        t.CheckOutputEmpty()
                   3135: }
                   3136:
1.58      rillig   3137: func (s *Suite) Test_Package_checkLinesBuildlink3Inclusion__file_but_not_package(c *check.C) {
1.39      rillig   3138:        t := s.Init(c)
                   3139:
1.58      rillig   3140:        t.CreateFileLines("category/dependency/buildlink3.mk")
                   3141:        t.CreateFileLines("category/dependency/module.mk")
1.67      rillig   3142:        pkg := NewPackage(t.File("category/package"))
1.58      rillig   3143:        mklines := t.NewMkLines("category/package/buildlink3.mk",
                   3144:                MkCvsID,
                   3145:                "",
                   3146:                ".include \"../../category/dependency/buildlink3.mk\"",
                   3147:                ".include \"../../category/dependency/module.mk\"")
1.39      rillig   3148:
1.67      rillig   3149:        pkg.checkLinesBuildlink3Inclusion(mklines)
1.39      rillig   3150:
                   3151:        t.CheckOutputLines(
1.58      rillig   3152:                "WARN: category/package/buildlink3.mk:3: " +
                   3153:                        "../../category/dependency/buildlink3.mk is included by this file " +
                   3154:                        "but not by the package.")
1.39      rillig   3155: }
                   3156:
1.58      rillig   3157: // Several files from the pkgsrc infrastructure are named *.buildlink3.mk,
                   3158: // even though they don't follow the typical file format for buildlink3.mk
                   3159: // files. Therefore they are ignored by this check.
                   3160: func (s *Suite) Test_Package_checkLinesBuildlink3Inclusion__infra_buildlink_file(c *check.C) {
1.39      rillig   3161:        t := s.Init(c)
                   3162:
1.58      rillig   3163:        t.SetUpPackage("category/package",
                   3164:                ".include \"../../mk/motif.buildlink3.mk\"")
1.62      rillig   3165:        t.CreateFileBuildlink3("category/package/buildlink3.mk",
1.58      rillig   3166:                ".include \"../../mk/motif.buildlink3.mk\"")
                   3167:        t.CreateFileLines("mk/motif.buildlink3.mk",
                   3168:                MkCvsID)
1.39      rillig   3169:
1.58      rillig   3170:        t.Main("--quiet", "-Wall", "category/package")
1.39      rillig   3171:
                   3172:        t.CheckOutputEmpty()
1.58      rillig   3173: }
                   3174:
                   3175: func (s *Suite) Test_Package_checkLinesBuildlink3Inclusion__package_but_not_file(c *check.C) {
                   3176:        t := s.Init(c)
                   3177:
                   3178:        t.CreateFileLines("category/dependency/buildlink3.mk")
1.67      rillig   3179:        pkg := NewPackage(t.File("category/package"))
                   3180:        pkg.bl3["../../category/dependency/buildlink3.mk"] =
1.58      rillig   3181:                t.NewMkLine("../../category/dependency/buildlink3.mk", 1, "")
                   3182:        mklines := t.NewMkLines("category/package/buildlink3.mk",
                   3183:                MkCvsID)
                   3184:
                   3185:        t.EnableTracingToLog()
1.67      rillig   3186:        pkg.checkLinesBuildlink3Inclusion(mklines)
1.58      rillig   3187:
                   3188:        // This is only traced but not logged as a regular warning since
                   3189:        // several packages have build dependencies that are not needed
                   3190:        // for building other packages. These cannot be flagged as warnings.
                   3191:        t.CheckOutputLines(
                   3192:                "TRACE: + (*Package).checkLinesBuildlink3Inclusion()",
                   3193:                "TRACE: 1   ../../category/dependency/buildlink3.mk "+
                   3194:                        "is included by the package but not by the buildlink3.mk file.",
                   3195:                "TRACE: - (*Package).checkLinesBuildlink3Inclusion()")
                   3196: }
                   3197:
1.62      rillig   3198: // The file mk/ocaml.mk uses ../.. to reach PKGSRCDIR.
                   3199: // The canonical path is .. since ocaml.mk is only one directory away
                   3200: // from PKGSRCDIR.
                   3201: // Before 2019-12-07, pkglint didn't resolve the resulting path correctly.
                   3202: func (s *Suite) Test_Package_checkLinesBuildlink3Inclusion__mk_dotdot_dotdot(c *check.C) {
                   3203:        t := s.Init(c)
                   3204:
                   3205:        t.SetUpPackage("x11/ocaml-graphics",
                   3206:                ".include \"../../mk/ocaml.mk\"")
                   3207:        t.CreateFileLines("mk/ocaml.mk",
                   3208:                MkCvsID,
                   3209:                ".include \"../../lang/ocaml/buildlink3.mk\"")
                   3210:        t.CreateFileLines("lang/ocaml/buildlink3.mk",
                   3211:                MkCvsID)
                   3212:        t.Chdir(".")
                   3213:        t.FinishSetUp()
                   3214:        pkg := NewPackage("x11/ocaml-graphics")
                   3215:
                   3216:        files, mklines, allLines := pkg.load()
                   3217:        pkg.check(files, mklines, allLines)
                   3218:
                   3219:        t.CheckDeepEquals(
                   3220:                keys(pkg.bl3),
                   3221:                []string{"../../lang/ocaml/buildlink3.mk"})
                   3222:        t.CheckOutputEmpty()
                   3223: }
                   3224:
                   3225: // Ocaml packages include ../../mk/ocaml.mk.
                   3226: // That file uses the canonical .. to reach PKGSRCDIR,
                   3227: // not the ../.. that is typically used in packages.
                   3228: func (s *Suite) Test_Package_checkLinesBuildlink3Inclusion__mk_dotdot(c *check.C) {
                   3229:        t := s.Init(c)
                   3230:
                   3231:        t.SetUpPackage("x11/ocaml-graphics",
                   3232:                ".include \"../../mk/ocaml.mk\"")
                   3233:        t.CreateFileLines("mk/ocaml.mk",
                   3234:                MkCvsID,
                   3235:                ".include \"../lang/ocaml/buildlink3.mk\"")
                   3236:        t.CreateFileLines("lang/ocaml/buildlink3.mk",
                   3237:                MkCvsID)
                   3238:        t.Chdir(".")
                   3239:        t.FinishSetUp()
                   3240:        pkg := NewPackage("x11/ocaml-graphics")
                   3241:
                   3242:        files, mklines, allLines := pkg.load()
                   3243:        pkg.check(files, mklines, allLines)
                   3244:
                   3245:        t.CheckDeepEquals(
                   3246:                keys(pkg.bl3),
                   3247:                []string{"../../lang/ocaml/buildlink3.mk"})
                   3248:        t.CheckOutputEmpty()
                   3249: }
                   3250:
                   3251: func (s *Suite) Test_Package_checkLinesBuildlink3Inclusion__ocaml(c *check.C) {
                   3252:        t := s.Init(c)
                   3253:
                   3254:        t.SetUpPackage("x11/ocaml-graphics",
                   3255:                ".include \"../../mk/ocaml.mk\"")
                   3256:        t.CreateFileBuildlink3("x11/ocaml-graphics/buildlink3.mk",
                   3257:                ".include \"../../lang/ocaml/buildlink3.mk\"")
                   3258:        t.CreateFileLines("mk/ocaml.mk",
                   3259:                MkCvsID,
                   3260:                // Note: this is ../.. even though .. is enough.
                   3261:                ".include \"../../lang/ocaml/buildlink3.mk\"")
                   3262:        t.CreateFileLines("lang/ocaml/buildlink3.mk",
                   3263:                MkCvsID)
                   3264:        t.Chdir(".")
                   3265:        t.FinishSetUp()
                   3266:
                   3267:        G.Check("mk/ocaml.mk")
                   3268:        G.checkdirPackage("x11/ocaml-graphics")
                   3269:
1.68      rillig   3270:        // Up to 2020-02-15, pkglint reported a missing relative path in
                   3271:        // mk/ocaml.mk:2 since resolving relative paths had not used the
                   3272:        // correct base directory.
                   3273:        t.CheckOutputEmpty()
1.62      rillig   3274: }
                   3275:
1.58      rillig   3276: // Just for code coverage.
                   3277: func (s *Suite) Test_Package_checkLinesBuildlink3Inclusion__no_tracing(c *check.C) {
                   3278:        t := s.Init(c)
                   3279:
                   3280:        t.SetUpPackage("category/package")
1.62      rillig   3281:        t.CreateFileBuildlink3("category/package/buildlink3.mk")
1.58      rillig   3282:        t.FinishSetUp()
1.39      rillig   3283:
1.58      rillig   3284:        t.DisableTracing()
                   3285:        G.Check(t.File("category/package"))
1.39      rillig   3286:
                   3287:        t.CheckOutputEmpty()
                   3288: }
                   3289:
1.58      rillig   3290: func (s *Suite) Test_Package_checkIncludeConditionally__conditional_and_unconditional_include(c *check.C) {
1.39      rillig   3291:        t := s.Init(c)
                   3292:
1.58      rillig   3293:        t.SetUpOption("zlib", "")
                   3294:        t.SetUpPackage("category/package",
1.62      rillig   3295:                ".include \"../../mk/bsd.prefs.mk\"",
1.58      rillig   3296:                ".include \"../../devel/zlib/buildlink3.mk\"",
                   3297:                ".if ${OPSYS} == \"Linux\"",
                   3298:                ".include \"../../sysutils/coreutils/buildlink3.mk\"",
                   3299:                ".endif")
                   3300:        t.CreateFileLines("mk/bsd.options.mk", "")
                   3301:        t.CreateFileLines("devel/zlib/buildlink3.mk", "")
                   3302:        t.CreateFileLines("sysutils/coreutils/buildlink3.mk", "")
                   3303:
                   3304:        t.CreateFileLines("category/package/options.mk",
1.48      rillig   3305:                MkCvsID,
1.58      rillig   3306:                "",
                   3307:                "PKG_OPTIONS_VAR=\tPKG_OPTIONS.package",
                   3308:                "PKG_SUPPORTED_OPTIONS=\tzlib",
                   3309:                "",
                   3310:                ".include \"../../mk/bsd.options.mk\"",
                   3311:                "",
                   3312:                ".if !empty(PKG_OPTIONS:Mzlib)",
                   3313:                ".  include \"../../devel/zlib/buildlink3.mk\"",
                   3314:                ".endif",
                   3315:                ".include \"../../sysutils/coreutils/buildlink3.mk\"")
                   3316:        t.Chdir("category/package")
                   3317:        t.FinishSetUp()
                   3318:
                   3319:        G.checkdirPackage(".")
                   3320:
                   3321:        t.CheckOutputLines(
1.62      rillig   3322:                "WARN: Makefile:21: \"../../devel/zlib/buildlink3.mk\" is included "+
1.58      rillig   3323:                        "unconditionally here "+
                   3324:                        "and conditionally in options.mk:9 (depending on PKG_OPTIONS).",
1.62      rillig   3325:                "WARN: Makefile:23: \"../../sysutils/coreutils/buildlink3.mk\" is included "+
1.58      rillig   3326:                        "conditionally here (depending on OPSYS) and "+
                   3327:                        "unconditionally in options.mk:11.")
                   3328: }
                   3329:
                   3330: func (s *Suite) Test_Package_checkIncludeConditionally__explain_PKG_OPTIONS_in_Makefile(c *check.C) {
                   3331:        t := s.Init(c)
                   3332:
                   3333:        t.SetUpCommandLine("-Wall", "--explain")
                   3334:        t.SetUpOption("zlib", "use zlib compression")
                   3335:
                   3336:        t.CreateFileLines("mk/bsd.options.mk",
                   3337:                MkCvsID)
                   3338:        t.CreateFileLines("devel/zlib/buildlink3.mk",
                   3339:                MkCvsID)
                   3340:        t.SetUpPackage("category/package",
                   3341:                "PKG_OPTIONS_VAR=\tPKG_OPTIONS.package",
                   3342:                "PKG_SUPPORTED_OPTIONS=\tzlib",
                   3343:                "",
                   3344:                ".include \"../../mk/bsd.options.mk\"",
                   3345:                "",
                   3346:                ".if ${PKG_OPTIONS:Mzlib}",
                   3347:                ".include \"../../devel/zlib/buildlink3.mk\"",
                   3348:                ".endif")
1.62      rillig   3349:        t.CreateFileBuildlink3("category/package/buildlink3.mk",
1.58      rillig   3350:                ".include \"../../devel/zlib/buildlink3.mk\"")
                   3351:        t.Chdir("category/package")
1.43      rillig   3352:        t.FinishSetUp()
1.39      rillig   3353:
1.58      rillig   3354:        G.checkdirPackage(".")
1.39      rillig   3355:
1.58      rillig   3356:        t.CheckOutputLines(
                   3357:                "WARN: Makefile:26: "+
                   3358:                        "\"../../devel/zlib/buildlink3.mk\" is included conditionally here "+
                   3359:                        "(depending on PKG_OPTIONS) and unconditionally in buildlink3.mk:12.",
                   3360:                "",
                   3361:                "\tWhen including a dependent file, the conditions in the buildlink3.mk",
                   3362:                "\tfile should be the same as in options.mk or the Makefile.",
                   3363:                "",
                   3364:                "\tTo find out the PKG_OPTIONS of this package at build time, have a",
                   3365:                "\tlook at mk/pkg-build-options.mk.",
                   3366:                "")
1.39      rillig   3367: }
1.40      rillig   3368:
1.58      rillig   3369: func (s *Suite) Test_Package_checkIncludeConditionally__no_explanation(c *check.C) {
1.40      rillig   3370:        t := s.Init(c)
                   3371:
1.58      rillig   3372:        t.SetUpCommandLine("-Wall", "--explain")
                   3373:        t.CreateFileLines("devel/zlib/buildlink3.mk",
                   3374:                MkCvsID)
1.40      rillig   3375:        t.SetUpPackage("category/package",
1.62      rillig   3376:                ".include \"../../mk/bsd.prefs.mk\"",
                   3377:                "",
1.58      rillig   3378:                ".if ${OPSYS} == Linux",
                   3379:                ".include \"../../devel/zlib/buildlink3.mk\"",
                   3380:                ".endif")
1.62      rillig   3381:        t.CreateFileBuildlink3("category/package/buildlink3.mk",
1.58      rillig   3382:                ".include \"../../devel/zlib/buildlink3.mk\"")
                   3383:        t.Chdir("category/package")
1.43      rillig   3384:        t.FinishSetUp()
1.40      rillig   3385:
1.58      rillig   3386:        G.checkdirPackage(".")
1.40      rillig   3387:
                   3388:        t.CheckOutputLines(
1.62      rillig   3389:                "WARN: Makefile:23: " +
1.58      rillig   3390:                        "\"../../devel/zlib/buildlink3.mk\" is included conditionally here " +
                   3391:                        "(depending on OPSYS) and unconditionally in buildlink3.mk:12.")
1.40      rillig   3392: }
1.46      rillig   3393:
1.60      rillig   3394: func (s *Suite) Test_Package_checkIncludeConditionally__conditionally_no_variable(c *check.C) {
                   3395:        t := s.Init(c)
                   3396:
                   3397:        t.SetUpOption("zlib", "")
                   3398:        t.SetUpPackage("category/package",
                   3399:                ".include \"../../devel/zlib/buildlink3.mk\"",
                   3400:                ".if exists(/usr/include)",
                   3401:                ".include \"../../sysutils/coreutils/buildlink3.mk\"",
                   3402:                ".endif")
                   3403:        t.CreateFileLines("mk/bsd.options.mk", "")
                   3404:        t.CreateFileLines("devel/zlib/buildlink3.mk", "")
                   3405:        t.CreateFileLines("sysutils/coreutils/buildlink3.mk", "")
                   3406:
                   3407:        t.CreateFileLines("category/package/options.mk",
                   3408:                MkCvsID,
                   3409:                "",
                   3410:                "PKG_OPTIONS_VAR=\tPKG_OPTIONS.package",
                   3411:                "PKG_SUPPORTED_OPTIONS=\t# none",
                   3412:                "",
                   3413:                ".include \"../../mk/bsd.options.mk\"",
                   3414:                "",
                   3415:                ".if exists(/usr/include)",
                   3416:                ".  include \"../../devel/zlib/buildlink3.mk\"",
                   3417:                ".endif",
                   3418:                ".include \"../../sysutils/coreutils/buildlink3.mk\"")
                   3419:        t.Chdir("category/package")
                   3420:        t.FinishSetUp()
                   3421:
                   3422:        G.checkdirPackage(".")
                   3423:
                   3424:        t.CheckOutputLines(
                   3425:                "WARN: Makefile:20: \"../../devel/zlib/buildlink3.mk\" "+
                   3426:                        "is included unconditionally here "+
                   3427:                        "and conditionally in options.mk:9.",
                   3428:                "WARN: Makefile:22: \"../../sysutils/coreutils/buildlink3.mk\" "+
                   3429:                        "is included conditionally here "+
                   3430:                        "and unconditionally in options.mk:11.")
                   3431: }
                   3432:
1.58      rillig   3433: func (s *Suite) Test_Package_checkIncludeConditionally__explain_PKG_OPTIONS_in_options_mk(c *check.C) {
1.46      rillig   3434:        t := s.Init(c)
                   3435:
1.58      rillig   3436:        t.SetUpCommandLine("-Wall", "--explain")
                   3437:        t.SetUpOption("zlib", "use zlib compression")
                   3438:
                   3439:        t.CreateFileLines("mk/bsd.options.mk",
1.48      rillig   3440:                MkCvsID)
1.58      rillig   3441:        t.CreateFileLines("devel/zlib/buildlink3.mk",
1.48      rillig   3442:                MkCvsID)
1.58      rillig   3443:        t.SetUpPackage("category/package",
                   3444:                ".include \"options.mk\"")
                   3445:        t.CreateFileLines("category/package/options.mk",
                   3446:                MkCvsID,
                   3447:                "",
                   3448:                "PKG_OPTIONS_VAR=\tPKG_OPTIONS.package",
                   3449:                "PKG_SUPPORTED_OPTIONS=\tzlib",
                   3450:                "",
                   3451:                ".include \"../../mk/bsd.options.mk\"",
                   3452:                "",
                   3453:                ".if ${PKG_OPTIONS:Mzlib}",
                   3454:                ".include \"../../devel/zlib/buildlink3.mk\"",
                   3455:                ".endif")
1.62      rillig   3456:        t.CreateFileBuildlink3("category/package/buildlink3.mk",
1.58      rillig   3457:                ".include \"../../devel/zlib/buildlink3.mk\"")
                   3458:        t.Chdir("category/package")
1.46      rillig   3459:        t.FinishSetUp()
                   3460:
1.58      rillig   3461:        G.checkdirPackage(".")
1.46      rillig   3462:
                   3463:        t.CheckOutputLines(
1.58      rillig   3464:                "WARN: buildlink3.mk:12: "+
                   3465:                        "\"../../devel/zlib/buildlink3.mk\" is included unconditionally here "+
                   3466:                        "and conditionally in options.mk:9 (depending on PKG_OPTIONS).",
                   3467:                "",
                   3468:                "\tWhen including a dependent file, the conditions in the buildlink3.mk",
                   3469:                "\tfile should be the same as in options.mk or the Makefile.",
                   3470:                "",
                   3471:                "\tTo find out the PKG_OPTIONS of this package at build time, have a",
                   3472:                "\tlook at mk/pkg-build-options.mk.",
                   3473:                "")
1.46      rillig   3474: }
1.48      rillig   3475:
1.58      rillig   3476: func (s *Suite) Test_Package_checkIncludeConditionally__unconditionally_first(c *check.C) {
1.48      rillig   3477:        t := s.Init(c)
                   3478:
                   3479:        t.SetUpPackage("category/package")
1.58      rillig   3480:        t.Chdir("category/package")
                   3481:        t.CreateFileLines("including.mk",
                   3482:                MkCvsID,
                   3483:                "",
1.62      rillig   3484:                ".include \"../../mk/bsd.prefs.mk\"",
                   3485:                "",
1.58      rillig   3486:                ".include \"included.mk\"",
                   3487:                ".if ${OPSYS} == \"Linux\"",
                   3488:                ".include \"included.mk\"",
                   3489:                ".endif")
                   3490:        t.CreateFileLines("included.mk",
                   3491:                MkCvsID)
1.48      rillig   3492:        t.FinishSetUp()
                   3493:
1.58      rillig   3494:        G.Check(".")
1.48      rillig   3495:
1.58      rillig   3496:        t.CheckOutputLines(
1.62      rillig   3497:                "WARN: including.mk:5: \"included.mk\" is included " +
                   3498:                        "unconditionally here and conditionally in line 7 (depending on OPSYS).")
1.48      rillig   3499: }
                   3500:
1.58      rillig   3501: func (s *Suite) Test_Package_checkIncludeConditionally__only_conditionally(c *check.C) {
1.48      rillig   3502:        t := s.Init(c)
                   3503:
                   3504:        t.SetUpPackage("category/package",
1.62      rillig   3505:                ".include \"../../mk/bsd.prefs.mk\"",
                   3506:                "",
1.58      rillig   3507:                ".if ${OPSYS} == \"Linux\"",
                   3508:                ".include \"included.mk\"",
                   3509:                ".endif")
                   3510:        t.Chdir("category/package")
                   3511:        t.CreateFileLines("included.mk",
                   3512:                MkCvsID)
1.48      rillig   3513:        t.FinishSetUp()
                   3514:
1.58      rillig   3515:        G.Check(".")
1.48      rillig   3516:
                   3517:        t.CheckOutputEmpty()
                   3518: }
                   3519:
1.58      rillig   3520: func (s *Suite) Test_Package_checkIncludeConditionally__conditionally_first(c *check.C) {
1.48      rillig   3521:        t := s.Init(c)
                   3522:
1.58      rillig   3523:        t.SetUpPackage("category/package")
                   3524:        t.Chdir("category/package")
                   3525:        t.CreateFileLines("including.mk",
                   3526:                MkCvsID,
                   3527:                "",
1.62      rillig   3528:                ".include \"../../mk/bsd.prefs.mk\"",
                   3529:                "",
1.58      rillig   3530:                ".if ${OPSYS} == \"Linux\"",
                   3531:                ".include \"included.mk\"",
                   3532:                ".endif",
                   3533:                ".include \"included.mk\"")
                   3534:        t.CreateFileLines("included.mk",
                   3535:                MkCvsID)
1.48      rillig   3536:        t.FinishSetUp()
                   3537:
1.58      rillig   3538:        G.Check(".")
1.48      rillig   3539:
                   3540:        t.CheckOutputLines(
1.62      rillig   3541:                "WARN: including.mk:6: \"included.mk\" is included " +
                   3542:                        "conditionally here (depending on OPSYS) and unconditionally in line 8.")
1.48      rillig   3543: }
                   3544:
1.58      rillig   3545: func (s *Suite) Test_Package_checkIncludeConditionally__included_multiple_times(c *check.C) {
1.48      rillig   3546:        t := s.Init(c)
                   3547:
1.58      rillig   3548:        t.SetUpPackage("category/package")
                   3549:        t.Chdir("category/package")
                   3550:        t.CreateFileLines("including.mk",
                   3551:                MkCvsID,
                   3552:                "",
1.62      rillig   3553:                ".include \"../../mk/bsd.prefs.mk\"",
                   3554:                "",
1.58      rillig   3555:                ".include \"included.mk\"",
                   3556:                ".if ${OPSYS} == \"Linux\"",
                   3557:                ".include \"included.mk\"",
                   3558:                ".endif",
                   3559:                "",
                   3560:                ".include \"included.mk\"",
                   3561:                ".if ${OPSYS} == \"Linux\"",
                   3562:                ".include \"included.mk\"",
                   3563:                ".endif")
                   3564:        t.CreateFileLines("included.mk",
                   3565:                MkCvsID)
1.48      rillig   3566:        t.FinishSetUp()
                   3567:
1.58      rillig   3568:        G.Check(".")
1.48      rillig   3569:
                   3570:        t.CheckOutputLines(
1.58      rillig   3571:                "WARN: including.mk:5: \"included.mk\" is included "+
1.62      rillig   3572:                        "unconditionally here and conditionally in line 12 (depending on OPSYS).",
                   3573:                "WARN: including.mk:7: \"included.mk\" is included "+
                   3574:                        "conditionally here (depending on OPSYS) and unconditionally in line 10.",
                   3575:                "WARN: including.mk:10: \"included.mk\" is included "+
                   3576:                        "unconditionally here and conditionally in line 12 (depending on OPSYS).")
1.48      rillig   3577: }
                   3578:
1.58      rillig   3579: // For preferences files, it doesn't matter whether they are included
                   3580: // conditionally or unconditionally since at the end they are included
                   3581: // anyway by the infrastructure.
                   3582: func (s *Suite) Test_Package_checkIncludeConditionally__prefs(c *check.C) {
1.48      rillig   3583:        t := s.Init(c)
                   3584:
1.58      rillig   3585:        t.SetUpPackage("category/package")
                   3586:        t.Chdir("category/package")
                   3587:        t.CreateFileLines("including.mk",
                   3588:                MkCvsID,
                   3589:                "",
                   3590:                ".include \"../../mk/bsd.prefs.mk\"",
                   3591:                ".if ${OPSYS} == \"Linux\"",
                   3592:                ".include \"../../mk/bsd.prefs.mk\"",
                   3593:                ".endif")
1.48      rillig   3594:        t.FinishSetUp()
                   3595:
1.58      rillig   3596:        G.Check(".")
1.48      rillig   3597:
                   3598:        t.CheckOutputEmpty()
                   3599: }
                   3600:
1.58      rillig   3601: func (s *Suite) Test_Package_checkIncludeConditionally__other_directory(c *check.C) {
                   3602:        t := s.Init(c)
                   3603:
                   3604:        t.SetUpPackage("category/package",
                   3605:                ".include \"../../category/package-base/including.mk\"")
                   3606:        t.CreateFileLines("category/package-base/including.mk",
                   3607:                MkCvsID,
                   3608:                "",
                   3609:                ".include \"included.mk\"",
                   3610:                ".if ${OPSYS} == \"Linux\"",
                   3611:                ".include \"included.mk\"",
                   3612:                ".endif",
                   3613:                "",
                   3614:                ".include \"included.mk\"",
                   3615:                ".if ${OPSYS} == \"Linux\"",
                   3616:                ".include \"included.mk\"",
                   3617:                ".endif")
                   3618:        t.CreateFileLines("category/package-base/included.mk",
                   3619:                MkCvsID)
                   3620:
                   3621:        t.Main("-Wall", "-Call", "category/package")
                   3622:
                   3623:        // TODO: Understand why ../../category/package-base/including.mk is
                   3624:        //  not checked for (un)conditional includes.
                   3625:        t.CheckOutputLines(
                   3626:                "Looks fine.")
                   3627: }
                   3628:
                   3629: // In practice the distinfo file can always be autofixed since it has
                   3630: // just been read successfully and the corresponding patch file could
                   3631: // also be autofixed right before.
                   3632: func (s *Suite) Test_Package_AutofixDistinfo__missing_file(c *check.C) {
1.48      rillig   3633:        t := s.Init(c)
                   3634:
1.58      rillig   3635:        t.SetUpPkgsrc()
1.67      rillig   3636:        pkg := NewPackage(t.File("category/package"))
1.48      rillig   3637:        t.FinishSetUp()
                   3638:
1.67      rillig   3639:        pkg.AutofixDistinfo("old", "new")
1.48      rillig   3640:
                   3641:        t.CheckOutputLines(
1.58      rillig   3642:                "ERROR: ~/category/package/distinfo: Cannot be read.")
1.48      rillig   3643: }
1.52      rillig   3644:
                   3645: func (s *Suite) Test_Package_Includes(c *check.C) {
                   3646:        t := s.Init(c)
                   3647:
                   3648:        t.SetUpPackage("category/package",
                   3649:                ".include \"unconditionally.mk\"",
                   3650:                ".if 0",
                   3651:                ".include \"never.mk\"",
                   3652:                ".endif",
                   3653:                ".if ${OPSYS} == Linux",
                   3654:                ".include \"conditionally.mk\"",
                   3655:                ".endif")
                   3656:        t.CreateFileLines("category/package/unconditionally.mk",
                   3657:                MkCvsID)
                   3658:        t.CreateFileLines("category/package/conditionally.mk",
                   3659:                MkCvsID)
                   3660:        t.CreateFileLines("category/package/never.mk",
                   3661:                MkCvsID)
                   3662:        t.FinishSetUp()
                   3663:
                   3664:        pkg := NewPackage(t.File("category/package"))
                   3665:
                   3666:        pkg.load()
                   3667:
1.69      rillig   3668:        t.CheckEquals(pkg.Includes("unconditionally.mk") != nil, true)
                   3669:        t.CheckEquals(pkg.Includes("conditionally.mk") != nil, true)
                   3670:        t.CheckEquals(pkg.Includes("other.mk") != nil, false)
1.52      rillig   3671:
1.59      rillig   3672:        // The file never.mk is in conditionalIncludes since pkglint only
                   3673:        // analyzes on the syntactical level. It doesn't evaluate the
                   3674:        // condition from the .if to see whether it is satisfiable.
                   3675:        //
                   3676:        // See Package.collectConditionalIncludes and Indentation.IsConditional.
                   3677:        t.CheckEquals(
                   3678:                pkg.conditionalIncludes["never.mk"].Location,
1.68      rillig   3679:                NewLocation(t.File("category/package/Makefile"), 22))
1.52      rillig   3680: }

CVSweb <webmaster@jp.NetBSD.org>