[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.13

1.7       rillig      1: package pkglint
1.1       rillig      2:
                      3: import "gopkg.in/check.v1"
                      4:
1.8       rillig      5: func (s *Suite) Test_CheckLinesOptionsMk(c *check.C) {
1.1       rillig      6:        t := s.Init(c)
                      7:
1.9       rillig      8:        t.SetUpCommandLine("-Wall,no-space")
                      9:        t.SetUpVartypes()
                     10:        t.SetUpOption("mc-charset", "")
                     11:        t.SetUpOption("mysql", "")
                     12:        t.SetUpOption("ncurses", "")
                     13:        t.SetUpOption("negative", "Demonstrates negated .if/.else")
                     14:        t.SetUpOption("slang", "")
                     15:        t.SetUpOption("sqlite", "")
                     16:        t.SetUpOption("x11", "")
1.1       rillig     17:
1.5       rillig     18:        t.CreateFileLines("mk/bsd.options.mk",
1.1       rillig     19:                MkRcsID)
                     20:
1.9       rillig     21:        mklines := t.SetUpFileMkLines("category/package/options.mk",
1.1       rillig     22:                MkRcsID,
                     23:                "",
                     24:                "PKG_OPTIONS_VAR=                PKG_OPTIONS.mc",
                     25:                "PKG_OPTIONS_REQUIRED_GROUPS=    screen",
                     26:                "PKG_OPTIONS_GROUP.screen=       ncurses slang",
1.2       rillig     27:                "PKG_SUPPORTED_OPTIONS=          mc-charset x11 lang-${l} negative",
1.1       rillig     28:                "PKG_SUGGESTED_OPTIONS=          mc-charset slang",
1.2       rillig     29:                "PKG_OPTIONS_NONEMPTY_SETS+=     db",
                     30:                "PKG_OPTIONS_SET.db=             mysql sqlite",
1.1       rillig     31:                "",
                     32:                ".include \"../../mk/bsd.options.mk\"",
                     33:                "",
1.4       rillig     34:                "PKGNAME?=  default-pkgname-1.",
                     35:                "",
1.1       rillig     36:                ".if !empty(PKG_OPTIONS:Mx11)",
                     37:                ".endif",
                     38:                "",
                     39:                ".if !empty(PKG_OPTIONS:Mundeclared)",
1.2       rillig     40:                ".endif",
                     41:                "",
                     42:                ".if empty(PKG_OPTIONS:Mnegative)",
                     43:                ".else",
                     44:                ".endif",
                     45:                "",
1.7       rillig     46:                ".if empty(PKG_OPTIONS:Mnegative)",
                     47:                ".endif",
                     48:                "",
1.2       rillig     49:                ".if !empty(PKG_OPTIONS:Mncurses)",
                     50:                ".elif !empty(PKG_OPTIONS:Mslang)",
                     51:                ".endif",
                     52:                "",
                     53:                ".if !empty(PKG_OPTIONS:Mmysql)",
                     54:                ".elif !empty(PKG_OPTIONS:Msqlite)",
1.1       rillig     55:                ".endif")
                     56:
1.8       rillig     57:        CheckLinesOptionsMk(mklines)
1.1       rillig     58:
                     59:        t.CheckOutputLines(
1.6       rillig     60:                "WARN: ~/category/package/options.mk:6: l is used but not defined.",
1.4       rillig     61:                "WARN: ~/category/package/options.mk:18: Unknown option \"undeclared\".",
1.7       rillig     62:                "NOTE: ~/category/package/options.mk:21: "+
                     63:                        "The positive branch of the .if/.else should be the one where the option is set.",
                     64:                // TODO: The diagnostics should appear in the correct order.
                     65:                "WARN: ~/category/package/options.mk:6: "+
                     66:                        "Option \"mc-charset\" should be handled below in an .if block.",
                     67:                "WARN: ~/category/package/options.mk:18: "+
                     68:                        "Option \"undeclared\" is handled but not added to PKG_SUPPORTED_OPTIONS.")
1.1       rillig     69: }
                     70:
1.10      rillig     71: // This test is provided for code coverage. Similarities to existing files are purely coincidental.
                     72: func (s *Suite) Test_CheckLinesOptionsMk__edge_cases(c *check.C) {
                     73:        t := s.Init(c)
                     74:
                     75:        t.SetUpCommandLine("-Wall,no-space")
                     76:        t.SetUpVartypes()
                     77:        t.SetUpOption("option1", "Description for option1")
                     78:        t.CreateFileLines("mk/compiler.mk",
                     79:                MkRcsID)
                     80:        t.CreateFileLines("mk/bsd.options.mk",
                     81:                MkRcsID)
                     82:        t.DisableTracing()
                     83:
                     84:        mklines := t.SetUpFileMkLines("category/package/options.mk",
                     85:                MkRcsID)
                     86:
                     87:        CheckLinesOptionsMk(mklines)
                     88:
                     89:        t.CheckOutputLines(
                     90:                "WARN: ~/category/package/options.mk:EOF: Expected definition of PKG_OPTIONS_VAR.")
                     91:
                     92:        mklines = t.SetUpFileMkLines("category/package/options.mk",
                     93:                MkRcsID,
                     94:                "PKG_SUPPORTED_OPTIONS=\toption1")
                     95:
                     96:        CheckLinesOptionsMk(mklines)
                     97:
                     98:        t.CheckOutputLines(
                     99:                "WARN: ~/category/package/options.mk:2: Expected definition of PKG_OPTIONS_VAR.")
                    100:
                    101:        mklines = t.SetUpFileMkLines("category/package/options.mk",
                    102:                MkRcsID,
                    103:                "PKG_OPTIONS_VAR=\tPKG_OPTIONS.pkgbase",
                    104:                "PKG_SUPPORTED_OPTIONS=\toption1",
                    105:                ".include \"../../mk/compiler.mk\"")
                    106:
                    107:        CheckLinesOptionsMk(mklines)
                    108:
                    109:        t.CheckOutputLines(
                    110:                "WARN: ~/category/package/options.mk:3: " +
                    111:                        "Option \"option1\" should be handled below in an .if block.")
                    112:
                    113:        mklines = t.SetUpFileMkLines("category/package/options.mk",
                    114:                MkRcsID,
                    115:                "PKG_OPTIONS_VAR=\tPKG_OPTIONS.pkgbase",
                    116:                "PKG_SUPPORTED_OPTIONS=\toption1",
                    117:                ".include \"../../mk/bsd.options.mk\"",
                    118:                "",
                    119:                ".if !empty(PKG_OPTIONS:O:u:Moption1) "+
                    120:                        "|| !empty(PKG_OPTIONS:Noption1) "+
                    121:                        "|| !empty(PKG_OPTIONS:O) "+
                    122:                        "|| !empty(X11_TYPE) "+
                    123:                        "|| !empty(PKG_OPTIONS:M${X11_TYPE})",
                    124:                ".endif")
                    125:
                    126:        CheckLinesOptionsMk(mklines)
                    127:
                    128:        // Although technically this option is handled by the :Noption1 modifier,
                    129:        // this is so unusual that the warning is justified.
                    130:        t.CheckOutputLines(
                    131:                "WARN: ~/category/package/options.mk:3: Option \"option1\" should be handled below in an .if block.")
                    132: }
                    133:
1.7       rillig    134: // If there is no .include line after the declaration of the package-settable
                    135: // variables, the whole analysis stops.
                    136: //
                    137: // This case doesn't happen in practice and thus is not worth being handled in detail.
1.8       rillig    138: func (s *Suite) Test_CheckLinesOptionsMk__unexpected_line(c *check.C) {
1.1       rillig    139:        t := s.Init(c)
                    140:
1.9       rillig    141:        t.SetUpCommandLine("-Wno-space")
                    142:        t.SetUpVartypes()
1.1       rillig    143:
1.5       rillig    144:        t.CreateFileLines("mk/bsd.options.mk",
1.1       rillig    145:                MkRcsID)
                    146:
1.9       rillig    147:        mklines := t.SetUpFileMkLines("category/package/options.mk",
1.1       rillig    148:                MkRcsID,
                    149:                "",
                    150:                "PKG_OPTIONS_VAR=                PKG_OPTIONS.mc",
                    151:                "",
                    152:                "pre-configure:",
                    153:                "\techo \"In the pre-configure stage.\"")
                    154:
1.8       rillig    155:        CheckLinesOptionsMk(mklines)
1.2       rillig    156:
                    157:        t.CheckOutputLines(
1.7       rillig    158:                "WARN: ~/category/package/options.mk:5: Expected inclusion of \"../../mk/bsd.options.mk\".")
1.2       rillig    159: }
                    160:
1.8       rillig    161: func (s *Suite) Test_CheckLinesOptionsMk__malformed_condition(c *check.C) {
1.2       rillig    162:        t := s.Init(c)
                    163:
1.9       rillig    164:        t.SetUpCommandLine("-Wno-space")
                    165:        t.SetUpVartypes()
                    166:        t.SetUpOption("mc-charset", "")
                    167:        t.SetUpOption("ncurses", "")
                    168:        t.SetUpOption("slang", "")
                    169:        t.SetUpOption("x11", "")
1.2       rillig    170:
1.5       rillig    171:        t.CreateFileLines("mk/bsd.options.mk",
1.2       rillig    172:                MkRcsID)
                    173:
1.9       rillig    174:        mklines := t.SetUpFileMkLines("category/package/options.mk",
1.2       rillig    175:                MkRcsID,
                    176:                "",
                    177:                "PKG_OPTIONS_VAR=                PKG_OPTIONS.mc",
                    178:                "PKG_SUPPORTED_OPTIONS=          # none",
                    179:                "PKG_SUGGESTED_OPTIONS=          # none",
                    180:                "",
1.7       rillig    181:                "# Comments and conditionals are allowed at this point.",
1.5       rillig    182:                ".if ${OPSYS} == NetBSD",
                    183:                ".endif",
                    184:                "",
1.2       rillig    185:                ".include \"../../mk/bsd.options.mk\"",
                    186:                "",
                    187:                ".if ${OPSYS} == 'Darwin'",
                    188:                ".endif")
1.1       rillig    189:
1.8       rillig    190:        CheckLinesOptionsMk(mklines)
1.1       rillig    191:
                    192:        t.CheckOutputLines(
1.5       rillig    193:                "WARN: ~/category/package/options.mk:13: Invalid condition, unrecognized part: \"${OPSYS} == 'Darwin'\".")
1.1       rillig    194: }
1.11      rillig    195:
                    196: func (s *Suite) Test_CheckLinesOptionsMk__PLIST_VARS_based_on_PKG_SUPPORTED_OPTIONS(c *check.C) {
                    197:        t := s.Init(c)
                    198:
                    199:        t.SetUpOption("one", "")
                    200:        t.SetUpOption("two", "")
                    201:        t.SetUpOption("three", "")
                    202:        t.SetUpPackage("category/package")
                    203:        t.CreateFileLines("mk/bsd.options.mk")
                    204:        t.SetUpFileMkLines("category/package/options.mk",
                    205:                MkRcsID,
                    206:                "",
                    207:                "PKG_OPTIONS_VAR=\tPKG_OPTIONS.package",
                    208:                "PKG_SUPPORTED_OPTIONS+=\tone",
                    209:                "PKG_SUPPORTED_OPTIONS+=\ttwo",
                    210:                "PKG_SUPPORTED_OPTIONS+=\tthree",
                    211:                "",
                    212:                ".include \"../../mk/bsd.options.mk\"",
                    213:                "",
                    214:                "PLIST_VARS+=\t${PKG_SUPPORTED_OPTIONS}",
                    215:                "",
                    216:                ".if ${PKG_OPTIONS:Mone}",
                    217:                "PLIST.one=\tyes",
                    218:                ".endif",
                    219:                "",
                    220:                ".if ${PKG_OPTIONS:Mthree}",
                    221:                "PLIST.three=\tyes",
                    222:                ".endif")
                    223:        t.Chdir("category/package")
1.12      rillig    224:        t.FinishSetUp()
1.11      rillig    225:
                    226:        G.Check(".")
                    227:
                    228:        // Even though PLIST_VARS is defined indirectly by referencing
                    229:        // PKG_SUPPORTED_OPTIONS and that variable is defined in several
                    230:        // lines, pkglint gets all the facts correct and knows that
                    231:        // only PLIST.two is missing.
                    232:        t.CheckOutputLines(
                    233:                "WARN: options.mk:10: "+
                    234:                        "\"two\" is added to PLIST_VARS, but PLIST.two is not defined in this file.",
                    235:                "WARN: options.mk:5: Option \"two\" should be handled below in an .if block.")
                    236: }
1.12      rillig    237:
                    238: // Up to April 2019, pkglint logged a wrong note saying that OTHER_VARIABLE
                    239: // should have the positive branch first. That note was only ever intended
                    240: // for PKG_OPTIONS.
                    241: func (s *Suite) Test_OptionsLinesChecker_handleLowerCondition__foreign_variable(c *check.C) {
                    242:        t := s.Init(c)
                    243:
                    244:        t.SetUpOption("opt", "")
                    245:        t.CreateFileLines("mk/bsd.options.mk")
                    246:        t.SetUpPackage("category/package",
                    247:                ".include \"options.mk\"")
                    248:        t.CreateFileLines("category/package/options.mk",
                    249:                MkRcsID,
                    250:                "",
                    251:                "PKG_OPTIONS_VAR=\tPKG_OPTIONS.package",
                    252:                "PKG_SUPPORTED_OPTIONS=\topt",
                    253:                "",
                    254:                ".include \"../../mk/bsd.options.mk\"",
                    255:                "",
                    256:                ".if empty(OTHER_VARIABLE)",
                    257:                ".else",
                    258:                ".endif")
                    259:        t.FinishSetUp()
                    260:
                    261:        G.Check(t.File("category/package"))
                    262:
                    263:        t.CheckOutputLines(
                    264:                "WARN: ~/category/package/options.mk:8: OTHER_VARIABLE is used but not defined.",
                    265:                "WARN: ~/category/package/options.mk:4: Option \"opt\" should be handled below in an .if block.")
                    266: }
1.13    ! rillig    267:
        !           268: func (s *Suite) Test_CheckLinesOptionsMk__autofix(c *check.C) {
        !           269:        t := s.Init(c)
        !           270:
        !           271:        t.SetUpOption("opt", "")
        !           272:        t.CreateFileLines("mk/bsd.options.mk")
        !           273:        t.SetUpPackage("category/package",
        !           274:                ".include \"options.mk\"")
        !           275:        t.CreateFileLines("category/package/options.mk",
        !           276:                MkRcsID,
        !           277:                "",
        !           278:                "PKG_OPTIONS_VAR=\tPKG_OPTIONS.package",
        !           279:                "PKG_SUPPORTED_OPTIONS=\t# none",
        !           280:                "",
        !           281:                ".include \"../../mk/bsd.options.mk\"",
        !           282:                "",
        !           283:                ".if 0",
        !           284:                ".if 0",
        !           285:                ".endif",
        !           286:                ".endif")
        !           287:        t.FinishSetUp()
        !           288:        t.Chdir("category/package")
        !           289:
        !           290:        G.Check(".")
        !           291:
        !           292:        t.CheckOutputLines(
        !           293:                "NOTE: options.mk:9: This directive should be indented by 2 spaces.",
        !           294:                "NOTE: options.mk:10: This directive should be indented by 2 spaces.")
        !           295:
        !           296:        t.SetUpCommandLine("-Wall", "--show-autofix")
        !           297:
        !           298:        G.Check(".")
        !           299:
        !           300:        t.CheckOutputLines(
        !           301:                "NOTE: options.mk:9: This directive should be indented by 2 spaces.",
        !           302:                "AUTOFIX: options.mk:9: Replacing \".\" with \".  \".",
        !           303:                "NOTE: options.mk:10: This directive should be indented by 2 spaces.",
        !           304:                "AUTOFIX: options.mk:10: Replacing \".\" with \".  \".")
        !           305:
        !           306:        t.SetUpCommandLine("-Wall", "--autofix")
        !           307:
        !           308:        G.Check(".")
        !           309:
        !           310:        t.CheckOutputLines(
        !           311:                "AUTOFIX: options.mk:9: Replacing \".\" with \".  \".",
        !           312:                "AUTOFIX: options.mk:10: Replacing \".\" with \".  \".")
        !           313:
        !           314:        t.CheckFileLinesDetab("options.mk",
        !           315:                MkRcsID,
        !           316:                "",
        !           317:                "PKG_OPTIONS_VAR=        PKG_OPTIONS.package",
        !           318:                "PKG_SUPPORTED_OPTIONS=  # none",
        !           319:                "",
        !           320:                ".include \"../../mk/bsd.options.mk\"",
        !           321:                "",
        !           322:                ".if 0",
        !           323:                ".  if 0",
        !           324:                ".  endif",
        !           325:                ".endif")
        !           326: }

CVSweb <webmaster@jp.NetBSD.org>