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

Annotation of pkgsrc/pkgtools/pkglint/files/options_test.go, Revision 1.17

1.7       rillig      1: package pkglint
1.1       rillig      2:
                      3: import "gopkg.in/check.v1"
                      4:
1.17    ! rillig      5: func (s *Suite) Test_CheckLinesOptionsMk__literal(c *check.C) {
        !             6:        t := s.Init(c)
        !             7:
        !             8:        t.SetUpOption("declared", "")
        !             9:        t.SetUpOption("both", "")
        !            10:        t.SetUpOption("handled", "")
        !            11:        t.SetUpPackage("category/package",
        !            12:                ".include \"../../mk/bsd.options.mk\"")
        !            13:        t.CreateFileLines("mk/bsd.options.mk",
        !            14:                MkCvsID)
        !            15:        mklines := t.SetUpFileMkLines("category/package/options.mk",
        !            16:                MkCvsID,
        !            17:                "",
        !            18:                "PKG_OPTIONS_VAR=\tPKG_OPTIONS.package",
        !            19:                "PKG_SUPPORTED_OPTIONS=\tdeclared both",
        !            20:                "",
        !            21:                ".include \"../../mk/bsd.options.mk\"",
        !            22:                "",
        !            23:                ".if ${PKG_OPTIONS:Mboth}",
        !            24:                ".endif",
        !            25:                "",
        !            26:                ".if ${PKG_OPTIONS:Mhandled}",
        !            27:                ".endif")
        !            28:        t.Chdir("category/package")
        !            29:        t.FinishSetUp()
        !            30:
        !            31:        CheckLinesOptionsMk(mklines)
        !            32:
        !            33:        t.CheckOutputLines(
        !            34:                "WARN: ~/category/package/options.mk:4: "+
        !            35:                        "Option \"declared\" should be handled below in an .if block.",
        !            36:                "WARN: ~/category/package/options.mk:11: "+
        !            37:                        "Option \"handled\" is handled but not added to PKG_SUPPORTED_OPTIONS.")
        !            38: }
        !            39:
        !            40: func (s *Suite) Test_CheckLinesOptionsMk__literal_in_for_loop(c *check.C) {
        !            41:        t := s.Init(c)
        !            42:
        !            43:        t.SetUpOption("declared", "")
        !            44:        t.SetUpOption("both", "")
        !            45:        t.SetUpOption("handled", "")
        !            46:        t.SetUpPackage("category/package",
        !            47:                ".include \"../../mk/bsd.options.mk\"")
        !            48:        t.CreateFileLines("mk/bsd.options.mk",
        !            49:                MkCvsID)
        !            50:        mklines := t.SetUpFileMkLines("category/package/options.mk",
        !            51:                MkCvsID,
        !            52:                "",
        !            53:                "PKG_OPTIONS_VAR=\tPKG_OPTIONS.package",
        !            54:                ".for declared_option in declared both",
        !            55:                "PKG_SUPPORTED_OPTIONS=\t${declared_option}",
        !            56:                ".endfor",
        !            57:                "",
        !            58:                ".include \"../../mk/bsd.options.mk\"",
        !            59:                "",
        !            60:                ".for handled_option in both handled",
        !            61:                ".  if ${PKG_OPTIONS:M${handled_option}}",
        !            62:                ".  endif",
        !            63:                ".endfor")
        !            64:        t.Chdir("category/package")
        !            65:        t.FinishSetUp()
        !            66:
        !            67:        CheckLinesOptionsMk(mklines)
        !            68:
        !            69:        t.CheckOutputLines(
        !            70:                "WARN: ~/category/package/options.mk:5: "+
        !            71:                        "Option \"declared\" should be handled below in an .if block.",
        !            72:                "WARN: ~/category/package/options.mk:11: "+
        !            73:                        "Option \"handled\" is handled but not added to PKG_SUPPORTED_OPTIONS.")
        !            74: }
        !            75:
        !            76: // Before version 19.3.5, pkglint warned when bsd.prefs.mk was
        !            77: // included in the top half of the file.
        !            78: func (s *Suite) Test_CheckLinesOptionsMk__prefs(c *check.C) {
        !            79:        t := s.Init(c)
        !            80:
        !            81:        t.SetUpOption("option", "")
        !            82:        t.SetUpPackage("category/package",
        !            83:                ".include \"../../mk/bsd.options.mk\"")
        !            84:        t.CreateFileLines("mk/bsd.options.mk",
        !            85:                MkCvsID)
        !            86:        mklines := t.SetUpFileMkLines("category/package/options.mk",
        !            87:                MkCvsID,
        !            88:                "",
        !            89:                ".include \"../../mk/bsd.prefs.mk\"",
        !            90:                "",
        !            91:                "PKG_OPTIONS_VAR=\tPKG_OPTIONS.package",
        !            92:                "PKG_SUPPORTED_OPTIONS=\toption",
        !            93:                "",
        !            94:                ".include \"../../mk/bsd.options.mk\"",
        !            95:                "",
        !            96:                ".if ${PKG_OPTIONS:Moption}",
        !            97:                ".endif")
        !            98:        t.Chdir("category/package")
        !            99:        t.FinishSetUp()
        !           100:
        !           101:        CheckLinesOptionsMk(mklines)
        !           102:
        !           103:        t.CheckOutputEmpty()
        !           104: }
        !           105:
1.8       rillig    106: func (s *Suite) Test_CheckLinesOptionsMk(c *check.C) {
1.1       rillig    107:        t := s.Init(c)
                    108:
1.9       rillig    109:        t.SetUpCommandLine("-Wall,no-space")
                    110:        t.SetUpVartypes()
                    111:        t.SetUpOption("mc-charset", "")
                    112:        t.SetUpOption("mysql", "")
                    113:        t.SetUpOption("ncurses", "")
                    114:        t.SetUpOption("negative", "Demonstrates negated .if/.else")
                    115:        t.SetUpOption("slang", "")
                    116:        t.SetUpOption("sqlite", "")
                    117:        t.SetUpOption("x11", "")
1.1       rillig    118:
1.5       rillig    119:        t.CreateFileLines("mk/bsd.options.mk",
1.14      rillig    120:                MkCvsID)
1.1       rillig    121:
1.9       rillig    122:        mklines := t.SetUpFileMkLines("category/package/options.mk",
1.14      rillig    123:                MkCvsID,
1.1       rillig    124:                "",
                    125:                "PKG_OPTIONS_VAR=                PKG_OPTIONS.mc",
                    126:                "PKG_OPTIONS_REQUIRED_GROUPS=    screen",
                    127:                "PKG_OPTIONS_GROUP.screen=       ncurses slang",
1.2       rillig    128:                "PKG_SUPPORTED_OPTIONS=          mc-charset x11 lang-${l} negative",
1.1       rillig    129:                "PKG_SUGGESTED_OPTIONS=          mc-charset slang",
1.2       rillig    130:                "PKG_OPTIONS_NONEMPTY_SETS+=     db",
                    131:                "PKG_OPTIONS_SET.db=             mysql sqlite",
1.1       rillig    132:                "",
                    133:                ".include \"../../mk/bsd.options.mk\"",
                    134:                "",
1.4       rillig    135:                "PKGNAME?=  default-pkgname-1.",
                    136:                "",
1.1       rillig    137:                ".if !empty(PKG_OPTIONS:Mx11)",
                    138:                ".endif",
                    139:                "",
                    140:                ".if !empty(PKG_OPTIONS:Mundeclared)",
1.2       rillig    141:                ".endif",
                    142:                "",
                    143:                ".if empty(PKG_OPTIONS:Mnegative)",
                    144:                ".else",
                    145:                ".endif",
                    146:                "",
1.7       rillig    147:                ".if empty(PKG_OPTIONS:Mnegative)",
                    148:                ".endif",
                    149:                "",
1.2       rillig    150:                ".if !empty(PKG_OPTIONS:Mncurses)",
                    151:                ".elif !empty(PKG_OPTIONS:Mslang)",
                    152:                ".endif",
                    153:                "",
                    154:                ".if !empty(PKG_OPTIONS:Mmysql)",
                    155:                ".elif !empty(PKG_OPTIONS:Msqlite)",
1.1       rillig    156:                ".endif")
                    157:
1.8       rillig    158:        CheckLinesOptionsMk(mklines)
1.1       rillig    159:
                    160:        t.CheckOutputLines(
1.6       rillig    161:                "WARN: ~/category/package/options.mk:6: l is used but not defined.",
1.4       rillig    162:                "WARN: ~/category/package/options.mk:18: Unknown option \"undeclared\".",
1.7       rillig    163:                "NOTE: ~/category/package/options.mk:21: "+
                    164:                        "The positive branch of the .if/.else should be the one where the option is set.",
                    165:                // TODO: The diagnostics should appear in the correct order.
                    166:                "WARN: ~/category/package/options.mk:6: "+
1.17    ! rillig    167:                        "Option \"mc-charset\" should be handled below in an .if block.")
        !           168:        // TODO: There is no warning for the option "undeclared" since
        !           169:        //  the option lang-${l} sets declaredArbitrary. This in turn
        !           170:        //  disables possible wrong warnings, but a few too many.
1.1       rillig    171: }
                    172:
1.10      rillig    173: // This test is provided for code coverage. Similarities to existing files are purely coincidental.
                    174: func (s *Suite) Test_CheckLinesOptionsMk__edge_cases(c *check.C) {
                    175:        t := s.Init(c)
                    176:
                    177:        t.SetUpCommandLine("-Wall,no-space")
                    178:        t.SetUpVartypes()
                    179:        t.SetUpOption("option1", "Description for option1")
                    180:        t.CreateFileLines("mk/compiler.mk",
1.14      rillig    181:                MkCvsID)
1.10      rillig    182:        t.CreateFileLines("mk/bsd.options.mk",
1.14      rillig    183:                MkCvsID)
1.10      rillig    184:        t.DisableTracing()
                    185:
                    186:        mklines := t.SetUpFileMkLines("category/package/options.mk",
1.14      rillig    187:                MkCvsID)
1.10      rillig    188:
                    189:        CheckLinesOptionsMk(mklines)
                    190:
                    191:        t.CheckOutputLines(
1.17    ! rillig    192:                "ERROR: ~/category/package/options.mk: Each options.mk file must define PKG_OPTIONS_VAR.",
        !           193:                "ERROR: ~/category/package/options.mk: Each options.mk file must .include \"../../mk/bsd.options.mk\".")
1.10      rillig    194:
                    195:        mklines = t.SetUpFileMkLines("category/package/options.mk",
1.14      rillig    196:                MkCvsID,
1.10      rillig    197:                "PKG_SUPPORTED_OPTIONS=\toption1")
                    198:
                    199:        CheckLinesOptionsMk(mklines)
                    200:
                    201:        t.CheckOutputLines(
1.17    ! rillig    202:                "WARN: ~/category/package/options.mk:2: "+
        !           203:                        "Expected definition of PKG_OPTIONS_VAR.",
        !           204:                "ERROR: ~/category/package/options.mk: "+
        !           205:                        "Each options.mk file must define PKG_OPTIONS_VAR.",
        !           206:                "ERROR: ~/category/package/options.mk: "+
        !           207:                        "Each options.mk file must .include \"../../mk/bsd.options.mk\".",
        !           208:                "WARN: ~/category/package/options.mk:2: "+
        !           209:                        "Option \"option1\" should be handled below in an .if block.")
1.10      rillig    210:
                    211:        mklines = t.SetUpFileMkLines("category/package/options.mk",
1.14      rillig    212:                MkCvsID,
1.10      rillig    213:                "PKG_OPTIONS_VAR=\tPKG_OPTIONS.pkgbase",
                    214:                "PKG_SUPPORTED_OPTIONS=\toption1",
                    215:                ".include \"../../mk/compiler.mk\"")
                    216:
                    217:        CheckLinesOptionsMk(mklines)
                    218:
                    219:        t.CheckOutputLines(
1.17    ! rillig    220:                "ERROR: ~/category/package/options.mk: "+
        !           221:                        "Each options.mk file must .include \"../../mk/bsd.options.mk\".",
        !           222:                "WARN: ~/category/package/options.mk:3: "+
1.10      rillig    223:                        "Option \"option1\" should be handled below in an .if block.")
                    224:
                    225:        mklines = t.SetUpFileMkLines("category/package/options.mk",
1.14      rillig    226:                MkCvsID,
1.10      rillig    227:                "PKG_OPTIONS_VAR=\tPKG_OPTIONS.pkgbase",
                    228:                "PKG_SUPPORTED_OPTIONS=\toption1",
                    229:                ".include \"../../mk/bsd.options.mk\"",
                    230:                "",
                    231:                ".if !empty(PKG_OPTIONS:O:u:Moption1) "+
                    232:                        "|| !empty(PKG_OPTIONS:Noption1) "+
                    233:                        "|| !empty(PKG_OPTIONS:O) "+
                    234:                        "|| !empty(X11_TYPE) "+
                    235:                        "|| !empty(PKG_OPTIONS:M${X11_TYPE})",
                    236:                ".endif")
                    237:
                    238:        CheckLinesOptionsMk(mklines)
                    239:
                    240:        // Although technically this option is handled by the :Noption1 modifier,
                    241:        // this is so unusual that the warning is justified.
                    242:        t.CheckOutputLines(
                    243:                "WARN: ~/category/package/options.mk:3: Option \"option1\" should be handled below in an .if block.")
                    244: }
                    245:
1.7       rillig    246: // If there is no .include line after the declaration of the package-settable
                    247: // variables, the whole analysis stops.
                    248: //
                    249: // This case doesn't happen in practice and thus is not worth being handled in detail.
1.8       rillig    250: func (s *Suite) Test_CheckLinesOptionsMk__unexpected_line(c *check.C) {
1.1       rillig    251:        t := s.Init(c)
                    252:
1.9       rillig    253:        t.SetUpCommandLine("-Wno-space")
                    254:        t.SetUpVartypes()
1.1       rillig    255:
1.5       rillig    256:        t.CreateFileLines("mk/bsd.options.mk",
1.14      rillig    257:                MkCvsID)
1.1       rillig    258:
1.9       rillig    259:        mklines := t.SetUpFileMkLines("category/package/options.mk",
1.14      rillig    260:                MkCvsID,
1.1       rillig    261:                "",
                    262:                "PKG_OPTIONS_VAR=                PKG_OPTIONS.mc",
                    263:                "",
                    264:                "pre-configure:",
                    265:                "\techo \"In the pre-configure stage.\"")
                    266:
1.8       rillig    267:        CheckLinesOptionsMk(mklines)
1.2       rillig    268:
                    269:        t.CheckOutputLines(
1.17    ! rillig    270:                "ERROR: ~/category/package/options.mk: " +
        !           271:                        "Each options.mk file must .include \"../../mk/bsd.options.mk\".")
1.2       rillig    272: }
                    273:
1.8       rillig    274: func (s *Suite) Test_CheckLinesOptionsMk__malformed_condition(c *check.C) {
1.2       rillig    275:        t := s.Init(c)
                    276:
1.9       rillig    277:        t.SetUpCommandLine("-Wno-space")
                    278:        t.SetUpVartypes()
                    279:        t.SetUpOption("mc-charset", "")
                    280:        t.SetUpOption("ncurses", "")
                    281:        t.SetUpOption("slang", "")
                    282:        t.SetUpOption("x11", "")
1.2       rillig    283:
1.5       rillig    284:        t.CreateFileLines("mk/bsd.options.mk",
1.14      rillig    285:                MkCvsID)
1.2       rillig    286:
1.9       rillig    287:        mklines := t.SetUpFileMkLines("category/package/options.mk",
1.14      rillig    288:                MkCvsID,
1.2       rillig    289:                "",
                    290:                "PKG_OPTIONS_VAR=                PKG_OPTIONS.mc",
                    291:                "PKG_SUPPORTED_OPTIONS=          # none",
                    292:                "PKG_SUGGESTED_OPTIONS=          # none",
                    293:                "",
1.7       rillig    294:                "# Comments and conditionals are allowed at this point.",
1.5       rillig    295:                ".if ${OPSYS} == NetBSD",
                    296:                ".endif",
                    297:                "",
1.2       rillig    298:                ".include \"../../mk/bsd.options.mk\"",
                    299:                "",
                    300:                ".if ${OPSYS} == 'Darwin'",
                    301:                ".endif")
1.1       rillig    302:
1.8       rillig    303:        CheckLinesOptionsMk(mklines)
1.1       rillig    304:
                    305:        t.CheckOutputLines(
1.5       rillig    306:                "WARN: ~/category/package/options.mk:13: Invalid condition, unrecognized part: \"${OPSYS} == 'Darwin'\".")
1.1       rillig    307: }
1.11      rillig    308:
                    309: func (s *Suite) Test_CheckLinesOptionsMk__PLIST_VARS_based_on_PKG_SUPPORTED_OPTIONS(c *check.C) {
                    310:        t := s.Init(c)
                    311:
                    312:        t.SetUpOption("one", "")
                    313:        t.SetUpOption("two", "")
                    314:        t.SetUpOption("three", "")
                    315:        t.SetUpPackage("category/package")
                    316:        t.CreateFileLines("mk/bsd.options.mk")
                    317:        t.SetUpFileMkLines("category/package/options.mk",
1.14      rillig    318:                MkCvsID,
1.11      rillig    319:                "",
                    320:                "PKG_OPTIONS_VAR=\tPKG_OPTIONS.package",
                    321:                "PKG_SUPPORTED_OPTIONS+=\tone",
                    322:                "PKG_SUPPORTED_OPTIONS+=\ttwo",
                    323:                "PKG_SUPPORTED_OPTIONS+=\tthree",
                    324:                "",
                    325:                ".include \"../../mk/bsd.options.mk\"",
                    326:                "",
                    327:                "PLIST_VARS+=\t${PKG_SUPPORTED_OPTIONS}",
                    328:                "",
                    329:                ".if ${PKG_OPTIONS:Mone}",
                    330:                "PLIST.one=\tyes",
                    331:                ".endif",
                    332:                "",
                    333:                ".if ${PKG_OPTIONS:Mthree}",
                    334:                "PLIST.three=\tyes",
                    335:                ".endif")
                    336:        t.Chdir("category/package")
1.12      rillig    337:        t.FinishSetUp()
1.11      rillig    338:
                    339:        G.Check(".")
                    340:
                    341:        // Even though PLIST_VARS is defined indirectly by referencing
                    342:        // PKG_SUPPORTED_OPTIONS and that variable is defined in several
                    343:        // lines, pkglint gets all the facts correct and knows that
                    344:        // only PLIST.two is missing.
                    345:        t.CheckOutputLines(
                    346:                "WARN: options.mk:10: "+
                    347:                        "\"two\" is added to PLIST_VARS, but PLIST.two is not defined in this file.",
                    348:                "WARN: options.mk:5: Option \"two\" should be handled below in an .if block.")
                    349: }
1.12      rillig    350:
                    351: // Up to April 2019, pkglint logged a wrong note saying that OTHER_VARIABLE
                    352: // should have the positive branch first. That note was only ever intended
                    353: // for PKG_OPTIONS.
                    354: func (s *Suite) Test_OptionsLinesChecker_handleLowerCondition__foreign_variable(c *check.C) {
                    355:        t := s.Init(c)
                    356:
                    357:        t.SetUpOption("opt", "")
                    358:        t.CreateFileLines("mk/bsd.options.mk")
                    359:        t.SetUpPackage("category/package",
                    360:                ".include \"options.mk\"")
                    361:        t.CreateFileLines("category/package/options.mk",
1.14      rillig    362:                MkCvsID,
1.12      rillig    363:                "",
                    364:                "PKG_OPTIONS_VAR=\tPKG_OPTIONS.package",
                    365:                "PKG_SUPPORTED_OPTIONS=\topt",
                    366:                "",
                    367:                ".include \"../../mk/bsd.options.mk\"",
                    368:                "",
                    369:                ".if empty(OTHER_VARIABLE)",
                    370:                ".else",
                    371:                ".endif")
                    372:        t.FinishSetUp()
                    373:
                    374:        G.Check(t.File("category/package"))
                    375:
                    376:        t.CheckOutputLines(
                    377:                "WARN: ~/category/package/options.mk:8: OTHER_VARIABLE is used but not defined.",
                    378:                "WARN: ~/category/package/options.mk:4: Option \"opt\" should be handled below in an .if block.")
                    379: }
1.13      rillig    380:
                    381: func (s *Suite) Test_CheckLinesOptionsMk__autofix(c *check.C) {
                    382:        t := s.Init(c)
                    383:
                    384:        t.SetUpOption("opt", "")
                    385:        t.CreateFileLines("mk/bsd.options.mk")
                    386:        t.SetUpPackage("category/package",
                    387:                ".include \"options.mk\"")
                    388:        t.CreateFileLines("category/package/options.mk",
1.14      rillig    389:                MkCvsID,
1.13      rillig    390:                "",
                    391:                "PKG_OPTIONS_VAR=\tPKG_OPTIONS.package",
                    392:                "PKG_SUPPORTED_OPTIONS=\t# none",
                    393:                "",
                    394:                ".include \"../../mk/bsd.options.mk\"",
                    395:                "",
                    396:                ".if 0",
                    397:                ".if 0",
                    398:                ".endif",
                    399:                ".endif")
                    400:        t.FinishSetUp()
                    401:        t.Chdir("category/package")
                    402:
                    403:        G.Check(".")
                    404:
                    405:        t.CheckOutputLines(
                    406:                "NOTE: options.mk:9: This directive should be indented by 2 spaces.",
                    407:                "NOTE: options.mk:10: This directive should be indented by 2 spaces.")
                    408:
                    409:        t.SetUpCommandLine("-Wall", "--show-autofix")
                    410:
                    411:        G.Check(".")
                    412:
                    413:        t.CheckOutputLines(
                    414:                "NOTE: options.mk:9: This directive should be indented by 2 spaces.",
                    415:                "AUTOFIX: options.mk:9: Replacing \".\" with \".  \".",
                    416:                "NOTE: options.mk:10: This directive should be indented by 2 spaces.",
                    417:                "AUTOFIX: options.mk:10: Replacing \".\" with \".  \".")
                    418:
                    419:        t.SetUpCommandLine("-Wall", "--autofix")
                    420:
                    421:        G.Check(".")
                    422:
                    423:        t.CheckOutputLines(
                    424:                "AUTOFIX: options.mk:9: Replacing \".\" with \".  \".",
                    425:                "AUTOFIX: options.mk:10: Replacing \".\" with \".  \".")
                    426:
                    427:        t.CheckFileLinesDetab("options.mk",
1.14      rillig    428:                MkCvsID,
1.13      rillig    429:                "",
                    430:                "PKG_OPTIONS_VAR=        PKG_OPTIONS.package",
                    431:                "PKG_SUPPORTED_OPTIONS=  # none",
                    432:                "",
                    433:                ".include \"../../mk/bsd.options.mk\"",
                    434:                "",
                    435:                ".if 0",
                    436:                ".  if 0",
                    437:                ".  endif",
                    438:                ".endif")
                    439: }
1.15      rillig    440:
                    441: // A few packages (such as www/w3m) define several options that are
                    442: // handled by a single .if block in the lower part.
                    443: func (s *Suite) Test_CheckLinesOptionsMk__combined_option_handling(c *check.C) {
                    444:        t := s.Init(c)
                    445:
                    446:        t.SetUpOption("opt-variant1", "")
                    447:        t.SetUpOption("opt-variant2", "")
                    448:        t.SetUpOption("other", "")
                    449:        t.CreateFileLines("mk/bsd.options.mk")
                    450:        t.SetUpPackage("category/package",
                    451:                ".include \"options.mk\"")
                    452:        t.CreateFileLines("category/package/options.mk",
                    453:                MkCvsID,
                    454:                "",
                    455:                "PKG_OPTIONS_VAR=\tPKG_OPTIONS.package",
                    456:                "PKG_SUPPORTED_OPTIONS=\topt-variant1 opt-variant2",
                    457:                "",
                    458:                ".include \"../../mk/bsd.options.mk\"",
                    459:                "",
                    460:                ".if ${PKG_OPTIONS:Mopt-variant*}",
                    461:                ".endif")
                    462:        t.FinishSetUp()
                    463:        t.Chdir("category/package")
                    464:
                    465:        G.Check(".")
                    466:
                    467:        // Before 5.7.21 on 2019-08-17, pkglint issued an error about the
                    468:        // "invalid option name opt-variant*" and warnings about the
                    469:        // unhandled options "opt-variant1" and "opt-variant2".
                    470:        t.CheckOutputEmpty()
                    471: }
                    472:
                    473: func (s *Suite) Test_CheckLinesOptionsMk__combined_option_handling_coverage(c *check.C) {
                    474:        t := s.Init(c)
                    475:
                    476:        t.SetUpOption("opt-variant", "")
                    477:        t.CreateFileLines("mk/bsd.options.mk")
                    478:        t.SetUpPackage("category/package",
                    479:                ".include \"options.mk\"")
                    480:        t.CreateFileLines("category/package/options.mk",
                    481:                MkCvsID,
                    482:                "",
                    483:                "PKG_OPTIONS_VAR=\tPKG_OPTIONS.package",
                    484:                "PKG_SUPPORTED_OPTIONS=\topt-variant",
                    485:                "",
                    486:                ".include \"../../mk/bsd.options.mk\"",
                    487:                "",
                    488:                ".if ${PKG_OPTIONS:Mopt-[}", // intentional syntax error
                    489:                ".endif",
                    490:                "",
                    491:                ".if ${PKG_OPTIONS:Mother-*}",
                    492:                ".endif")
                    493:        t.FinishSetUp()
                    494:        t.Chdir("category/package")
                    495:
                    496:        G.Check(".")
                    497:
1.17    ! rillig    498:        // The pattern "opt-[" does not match any of the declared options
        !           499:        // since the pattern is malformed and pkglint does not distinguish
        !           500:        // between invalid and non-matching patterns.
        !           501:        //
        !           502:        // The pattern "other-*" also doesn't match.
        !           503:        //
        !           504:        // Since the patterns don't match any of the variables from
        !           505:        // PKG_SUPPORTED_OPTIONS, pkglint cannot analyze all possible cases
        !           506:        // and therefore suppresses all warnings about options that are
        !           507:        // declared but not handled.
        !           508:        t.CheckOutputEmpty()
1.15      rillig    509: }
1.16      rillig    510:
                    511: func (s *Suite) Test_CheckLinesOptionsMk__options_in_for_loop(c *check.C) {
                    512:        t := s.Init(c)
                    513:
                    514:        t.SetUpOption("idea", "")
                    515:        t.SetUpOption("md2", "")
                    516:        t.SetUpOption("md5", "")
                    517:        t.SetUpOption("other", "")
                    518:        t.CreateFileLines("mk/bsd.options.mk")
                    519:        t.SetUpPackage("category/package",
                    520:                ".include \"options.mk\"")
                    521:        t.CreateFileLines("category/package/options.mk",
                    522:                MkCvsID,
                    523:                "",
                    524:                "PKG_OPTIONS_VAR=\tPKG_OPTIONS.package",
                    525:                "PKG_SUPPORTED_OPTIONS=\tidea md2 md5 other",
                    526:                "",
                    527:                ".include \"../../mk/bsd.options.mk\"",
                    528:                "",
                    529:                ".for alg in idea md2 md5",
                    530:                ".  if ${PKG_OPTIONS:M${alg}}",
                    531:                ".  endif",
                    532:                ".endfor")
                    533:        t.FinishSetUp()
                    534:        t.Chdir("category/package")
                    535:
                    536:        G.Check(".")
                    537:
                    538:        t.CheckOutputLines(
                    539:                "WARN: options.mk:4: Option \"other\" should be handled below in an .if block.")
                    540: }
                    541:
                    542: func (s *Suite) Test_CheckLinesOptionsMk__indirect(c *check.C) {
                    543:        t := s.Init(c)
                    544:
                    545:        t.SetUpOption("generic", "")
                    546:        t.SetUpOption("netbsd", "")
                    547:        t.SetUpOption("os", "")
                    548:        t.CreateFileLines("mk/bsd.options.mk")
                    549:        t.SetUpPackage("category/package",
                    550:                ".include \"options.mk\"")
                    551:        t.CreateFileLines("category/package/options.mk",
                    552:                MkCvsID,
                    553:                "",
                    554:                "PKG_OPTIONS_VAR=\tPKG_OPTIONS.package",
                    555:                "PKG_SUPPORTED_OPTIONS=\tgeneric",
                    556:                "PKG_SUGGESTED_OPTIONS=\tgeneric",
                    557:                "",
                    558:                "PKG_SUPPORTED_OPTIONS.FreeBSD=\tos",
                    559:                "PKG_SUGGESTED_OPTIONS.FreeBSD=\tos",
                    560:                "",
                    561:                "PKG_SUPPORTED_OPTIONS.NetBSD+=\tnetbsd os",
                    562:                "PKG_SUGGESTED_OPTIONS.NetBSD+=\tnetbsd os",
                    563:                "",
                    564:                ".include \"../../mk/bsd.options.mk\"",
                    565:                "",
                    566:                "PLIST_VARS+=\tgeneric netbsd os",
                    567:                "",
                    568:                ".for option in ${PLIST_VARS}",
                    569:                ".  if ${PKG_OPTIONS:M${option}}",
                    570:                "CONFIGURE_ARGS+=\t--enable-${option:S/-/_/}",
                    571:                "PLIST.${option}=\tyes",
                    572:                ".  endif",
                    573:                ".endfor")
                    574:        t.FinishSetUp()
                    575:        t.Chdir("category/package")
                    576:
                    577:        G.Check(".")
                    578:
                    579:        t.CheckOutputEmpty()
                    580: }
                    581:
                    582: // An unrealistic scenario, but necessary for code coverage.
                    583: func (s *Suite) Test_CheckLinesOptionsMk__partly_indirect(c *check.C) {
                    584:        t := s.Init(c)
                    585:
                    586:        t.CreateFileLines("mk/bsd.options.mk")
                    587:        t.SetUpPackage("category/package",
                    588:                ".include \"options.mk\"")
                    589:        t.CreateFileLines("category/package/options.mk",
                    590:                MkCvsID,
                    591:                "",
                    592:                "PKG_OPTIONS_VAR=\tPKG_OPTIONS.package",
                    593:                "PKG_SUPPORTED_OPTIONS=\tgeneric-${OPSYS}",
                    594:                "",
                    595:                ".include \"../../mk/bsd.options.mk\"",
                    596:                "",
                    597:                ".for option in generic-${OPSYS}",
                    598:                ".  if ${PKG_OPTIONS:M${option}}",
                    599:                ".  endif",
                    600:                ".endfor")
                    601:        t.FinishSetUp()
                    602:        t.Chdir("category/package")
                    603:
                    604:        G.Check(".")
                    605:
                    606:        t.CheckOutputEmpty()
                    607: }
1.17    ! rillig    608:
        !           609: func (s *Suite) Test_CheckLinesOptionsMk__indirect_supported_options_parentheses(c *check.C) {
        !           610:        t := s.Init(c)
        !           611:
        !           612:        t.SetUpOption("indirect", "")
        !           613:        t.SetUpOption("direct", "")
        !           614:        t.SetUpVartypes()
        !           615:        t.CreateFileLines("mk/bsd.options.mk",
        !           616:                MkCvsID)
        !           617:        mklines := t.SetUpFileMkLines("category/package/options.mk",
        !           618:                MkCvsID,
        !           619:                "",
        !           620:                "PKG_OPTIONS_VAR=\tPKG_OPTIONS.package",
        !           621:                "OPTIONS=\t\tindirect",
        !           622:                "PKG_SUPPORTED_OPTIONS=\t$(OPTIONS) direct",
        !           623:                "",
        !           624:                ".include \"../../mk/bsd.options.mk\"",
        !           625:                "",
        !           626:                ".for option in ${OPTIONS}",
        !           627:                ".  if ${PKG_OPTIONS:M${option}}",
        !           628:                ".  endif",
        !           629:                ".endfor")
        !           630:
        !           631:        CheckLinesOptionsMk(mklines)
        !           632:
        !           633:        t.CheckOutputLines(
        !           634:                "WARN: ~/category/package/options.mk:5: "+
        !           635:                        "Please use curly braces {} instead of round parentheses () for OPTIONS.",
        !           636:                "WARN: ~/category/package/options.mk:5: "+
        !           637:                        "Option \"direct\" should be handled below in an .if block.")
        !           638: }
        !           639:
        !           640: func (s *Suite) Test_CheckLinesOptionsMk__handled_but_not_supported(c *check.C) {
        !           641:        t := s.Init(c)
        !           642:
        !           643:        t.SetUpOption("option", "")
        !           644:        t.SetUpVartypes()
        !           645:        t.CreateFileLines("mk/bsd.options.mk",
        !           646:                MkCvsID)
        !           647:        mklines := t.SetUpFileMkLines("category/package/options.mk",
        !           648:                MkCvsID,
        !           649:                "",
        !           650:                "PKG_OPTIONS_VAR=\tPKG_OPTIONS.package",
        !           651:                "PKG_SUPPORTED_OPTIONS=\t# none",
        !           652:                "",
        !           653:                ".include \"../../mk/bsd.options.mk\"",
        !           654:                "",
        !           655:                ".if ${PKG_OPTIONS:Moption}",
        !           656:                ".endif")
        !           657:
        !           658:        CheckLinesOptionsMk(mklines)
        !           659:
        !           660:        t.CheckOutputLines(
        !           661:                "WARN: ~/category/package/options.mk:8: " +
        !           662:                        "Option \"option\" is handled but not added to PKG_SUPPORTED_OPTIONS.")
        !           663: }
        !           664:
        !           665: func (s *Suite) Test_CheckLinesOptionsMk__supported_but_not_checked(c *check.C) {
        !           666:        t := s.Init(c)
        !           667:
        !           668:        t.SetUpOption("option", "")
        !           669:        t.SetUpVartypes()
        !           670:        t.CreateFileLines("mk/bsd.options.mk",
        !           671:                MkCvsID)
        !           672:        mklines := t.SetUpFileMkLines("category/package/options.mk",
        !           673:                MkCvsID,
        !           674:                "",
        !           675:                "PKG_OPTIONS_VAR=\tPKG_OPTIONS.package",
        !           676:                "PKG_SUPPORTED_OPTIONS=\toption",
        !           677:                "",
        !           678:                ".include \"../../mk/bsd.options.mk\"",
        !           679:                "",
        !           680:                ".if ${PKG_OPTIONS:Mopt${:Uion}}",
        !           681:                ".endif")
        !           682:
        !           683:        CheckLinesOptionsMk(mklines)
        !           684:
        !           685:        // Pkglint does not expand the ${:Uion}, therefore it doesn't know that
        !           686:        // the option is indeed handled. Because of this uncertainty, pkglint
        !           687:        // does not issue any warnings about possibly unhandled options at all.
        !           688:        t.CheckOutputEmpty()
        !           689: }

CVSweb <webmaster@jp.NetBSD.org>