[BACK]Return to R2pkg_test.R CVS log [TXT][DIR] Up to [cvs.NetBSD.org] / pkgsrc / pkgtools / R2pkg / files

Annotation of pkgsrc/pkgtools/R2pkg/files/R2pkg_test.R, Revision 1.11

1.11    ! rillig      1: # $NetBSD: R2pkg_test.R,v 1.10 2019/10/19 11:04:46 rillig Exp $
1.1       rillig      2: #
                      3: # Copyright (c) 2019
                      4: #      Roland Illig.  All rights reserved.
                      5: #
                      6: # Redistribution and use in source and binary forms, with or without
                      7: # modification, are permitted provided that the following conditions
                      8: # are met:
                      9: # 1. Redistributions of source code must retain the above copyright
                     10: #    notice, this list of conditions and the following disclaimer.
                     11: # 2. Redistributions in binary form must reproduce the above copyright
                     12: #    notice, this list of conditions and the following disclaimer in the
                     13: #    documentation and/or other materials provided with the distribution.
                     14: # 3. Neither the name of the author nor the names of any contributors
                     15: #    may be used to endorse or promote products derived from this software
                     16: #    without specific prior written permission.
                     17: #
                     18: # THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
                     19: # ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
                     20: # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
                     21: # ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
                     22: # FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
                     23: # DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
                     24: # OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
                     25: # HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
                     26: # LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
                     27: # OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
                     28: # SUCH DAMAGE.
                     29: #
                     30:
                     31: source('R2pkg.R')
                     32: library(testthat)
                     33: library(withr)
                     34:
1.5       rillig     35: # TODO: use a test fixture for setting these
                     36: arg.recursive <- FALSE
                     37: arg.update <- FALSE
                     38:
1.11    ! rillig     39: package_dir <- file.path(Sys.getenv('PKGSRCDIR'), 'pkgtools', 'R2pkg')
1.2       rillig     40:
1.6       rillig     41: expect_printed <- function(obj, ...) {
1.2       rillig     42:     out <- ''
                     43:     with_output_sink(textConnection('out', 'w', local = TRUE), print(obj))
1.10      rillig     44:     exp <- c(...)
1.11    ! rillig     45:     if (! identical(out, exp)) {
1.10      rillig     46:         write(out, 'R2pkg_test.out.txt')
                     47:         write(exp, 'R2pkg_test.exp.txt')
                     48:     }
                     49:     expect_equal(length(out), length(exp))
                     50:     expect_equal(!!out, !!exp)
1.2       rillig     51: }
                     52:
1.6       rillig     53: linesConnection <- function(...)
                     54:     textConnection(paste0(c(...), collapse = '\n'))
                     55:
1.11    ! rillig     56: make_mklines <- function(...)
        !            57:     read.Makefile.as.dataframe(linesConnection(...))
        !            58:
1.6       rillig     59: test_that('linesConnection', {
                     60:     lines <- readLines(linesConnection('1', '2', '3'))
                     61:
                     62:     expect_equal(lines, c('1', '2', '3'))
                     63: })
                     64:
1.5       rillig     65: test_that('level.message', {
                     66:     output <- ''
                     67:     mock_message <- function(...) output <<- paste0(output, ..., '\n')
                     68:
                     69:     arg.level <<- 123  # XXX: should use with_environment instead
                     70:     with_mock(message = mock_message, {
                     71:         level.message('mess', 'age', ' text')
                     72:     })
                     73:
                     74:     expect_equal(output, '[ 123 ] message text\n')
                     75: })
1.3       rillig     76:
                     77: test_that('level.warning', {
                     78:     output <- ''
                     79:     mock_message <- function(...) output <<- paste0(output, ..., '\n')
                     80:
1.5       rillig     81:     arg.level <<- 321  # XXX: should use with_environment instead
1.3       rillig     82:     with_mock(message = mock_message, {
                     83:         level.warning('mess', 'age', ' text')
                     84:     })
1.1       rillig     85:
1.5       rillig     86:     expect_equal(output, '[ 321 ] WARNING: message text\n')
1.1       rillig     87: })
                     88:
1.5       rillig     89: test_that('trim.space', {
                     90:     expect_equal(trim.space(' hello, \t\nworld '), 'hello,world')
                     91: })
1.3       rillig     92:
1.5       rillig     93: test_that('trim.blank', {
                     94:     expect_equal(trim.blank(' hello, \t\nworld '), 'hello,\nworld')
                     95: })
1.3       rillig     96:
1.5       rillig     97: test_that('one.space', {
                     98:     expect_equal(
                     99:         one.space(' \t\nhello, \t\nworld \t\n'),
                    100:         ' \nhello, \nworld \n')
                    101: })
1.3       rillig    102:
1.5       rillig    103: test_that('one.line', {
                    104:     expect_equal(
                    105:         one.line(' \t\nhello, \t\nworld \t\n'),
                    106:         ' \t hello, \t world \t ')
                    107: })
1.3       rillig    108:
1.5       rillig    109: test_that('pkg.vers', {
                    110:     expect_equal(pkg.vers('1_0-2.3'), '1.0-2.3')
                    111: })
1.3       rillig    112:
1.5       rillig    113: test_that('varassign', {
                    114:     expect_equal(varassign('VAR', 'value'), 'VAR=\tvalue')
                    115: })
1.3       rillig    116:
1.4       rillig    117: test_that('adjacent.duplicates', {
                    118:     expect_equal(
                    119:     adjacent.duplicates(c(1, 2, 2, 2, 3, 3, 4)),
                    120:     c(FALSE, FALSE, TRUE, TRUE, FALSE, TRUE, FALSE)
                    121:     )
                    122: })
                    123:
                    124: test_that('paste2', {
                    125:     expect_equal(paste2(NA, NA), '')
                    126:     expect_equal(paste2('', NA), '')
                    127:     expect_equal(paste2(NA, ''), '')
                    128:     expect_equal(paste2('', ''), ' ')
                    129:     expect_equal(paste2('one', 'two'), 'one two')
                    130: })
1.3       rillig    131:
1.4       rillig    132: test_that('end.paragraph', {
                    133:     expect_equal(end.paragraph(list()), list())
                    134:     expect_equal(end.paragraph(list('line')), list('line', ''))
                    135: })
1.3       rillig    136:
1.4       rillig    137: test_that('as.sorted.list', {
                    138:     expect_equal(as.sorted.list(data.frame()), list())
1.1       rillig    139:
1.4       rillig    140:     expect_equal(
                    141:     as.sorted.list(data.frame(
                    142:     varnames = c('A', 'B', 'B', 'B', 'A'),
                    143:     values = c('1', '3', '2', '1', '1'))),
                    144:     list('1', '1', '2', '3'))
                    145: })
1.1       rillig    146:
1.3       rillig    147: test_that('read.file.as.dataframe', {
1.6       rillig    148:     content <- linesConnection(
                    149:         'VAR=value',
                    150:         'VAR2=value2')
1.1       rillig    151:
1.3       rillig    152:     df <- read.file.as.dataframe(content)
1.1       rillig    153:
1.6       rillig    154:     expect_equal(length(df$line), 2)
1.3       rillig    155:     expect_equal(df$line[[1]], 'VAR=value')
                    156:     expect_equal(df$line[[2]], 'VAR2=value2')
1.1       rillig    157: })
                    158:
1.3       rillig    159: # test_that('categorize.key_value', {
                    160: # })
                    161:
                    162: # test_that('categorize.depends', {
                    163: # })
1.1       rillig    164:
1.3       rillig    165: # test_that('categorize.buildlink', {
                    166: # })
1.1       rillig    167:
1.3       rillig    168: # test_that('fix.continued.lines', {
                    169: # })
1.1       rillig    170:
1.3       rillig    171: test_that('read.Makefile.as.dataframe', {
1.11    ! rillig    172:     mklines <- make_mklines(
1.6       rillig    173:         '# comment',
                    174:         'VAR= value',
                    175:         '',
                    176:         '.include "other.mk"',
                    177:         '.if 0',
1.11    ! rillig    178:         '.endif')
1.6       rillig    179:
1.11    ! rillig    180:     expect_printed(mklines,
1.6       rillig    181:         '                 line order category key_value  key depends buildlink3.mk',
                    182:         '1           # comment     1       NA     FALSE <NA>   FALSE         FALSE',
                    183:         '2          VAR= value     2       NA      TRUE  VAR   FALSE         FALSE',
                    184:         '3                         3       NA     FALSE <NA>   FALSE         FALSE',
                    185:         '4 .include "other.mk"     4       NA     FALSE <NA>   FALSE         FALSE',
                    186:         '5               .if 0     5       NA     FALSE <NA>   FALSE         FALSE',
                    187:         '6              .endif     6       NA     FALSE <NA>   FALSE         FALSE',
                    188:         '  operator delimiter old_value old_todo',
                    189:         '1     <NA>      <NA>      <NA>     <NA>',
                    190:         '2        =               value         ',
                    191:         '3     <NA>      <NA>      <NA>     <NA>',
                    192:         '4     <NA>      <NA>      <NA>     <NA>',
                    193:         '5     <NA>      <NA>      <NA>     <NA>',
                    194:         '6     <NA>      <NA>      <NA>     <NA>')
1.1       rillig    195: })
                    196:
1.5       rillig    197: test_that('read.file.as.list can read an empty file', {
                    198:     filename <- ''
                    199:     local_tempfile('filename')
                    200:     file.create(filename)
                    201:
                    202:     lines <- read.file.as.list(filename)
                    203:
                    204:     expect_equal(lines, list())
                    205: })
                    206:
                    207: test_that('read.file.as.list can read lines from a file', {
                    208:     filename <- ''
                    209:     local_tempfile('filename')
                    210:     writeLines(c('first', 'second \\', 'third'), filename)
                    211:
                    212:     lines <- read.file.as.list(filename)
                    213:
                    214:     expect_equal(lines, list('first', 'second \\', 'third'))
                    215: })
1.3       rillig    216:
1.2       rillig    217: test_that('read.file.as.value, exactly 1 variable assignment, no space', {
                    218:     filename <- ''
                    219:     local_tempfile('filename')
                    220:     writeLines(c('VAR=value'), filename)
                    221:
                    222:     str <- read.file.as.value(filename)
                    223:
1.5       rillig    224:     expect_equal(str, NA_character_)  # FIXME
1.2       rillig    225: })
                    226:
                    227: test_that('read.file.as.value, exactly 1 variable assignment', {
                    228:     filename <- ''
                    229:     local_tempfile('filename')
                    230:     writeLines(c('VAR=\tvalue'), filename)
                    231:
                    232:     str <- read.file.as.value(filename)
                    233:
                    234:     expect_equal(str, 'value')
                    235: })
                    236:
                    237: test_that('read.file.as.value, commented variable assignment', {
                    238:     filename <- ''
                    239:     local_tempfile('filename')
                    240:     writeLines(c('#VAR=\tvalue'), filename)
                    241:
                    242:     str <- read.file.as.value(filename)
                    243:
                    244:     # TODO: Check whether commented variables should really be considered.
                    245:     expect_equal(str, 'value')
                    246: })
                    247:
                    248: test_that('read.file.as.value, multiple variable assignments', {
                    249:     filename <- ''
                    250:     local_tempfile('filename')
                    251:     writeLines(c('VAR=\tvalue', 'VAR=\tvalue2'), filename)
                    252:
                    253:     str <- read.file.as.value(filename)
                    254:
                    255:     expect_equal(str, '')
                    256: })
                    257:
1.3       rillig    258: # test_that('read.file.as.values', {
                    259: # })
                    260:
1.7       rillig    261: test_that('simplify.whitespace', {
                    262:     expect_equal(simplify.whitespace('\t \nword \t\n\f'), ' \nword \n\f')
                    263: })
1.3       rillig    264:
1.7       rillig    265: test_that('remove.punctuation', {
                    266:     expect_equal(remove.punctuation('+,-./'), '+./')
                    267: })
1.3       rillig    268:
1.7       rillig    269: test_that('remove.quotes', {
                    270:     expect_equal(remove.quotes('"\'hello`,,'), 'hello,,')
                    271: })
1.3       rillig    272:
1.7       rillig    273: test_that('remove.articles', {
                    274:     expect_equal(remove.articles('Get a life'), 'Getlife')  # FIXME
                    275:     expect_equal(remove.articles('An apple a day'), 'appleday')  # FIXME
                    276:     expect_equal(remove.articles('Annnnnnnnnn apple'), 'apple')  # FIXME
                    277:     expect_equal(remove.articles('Grade A'), 'Grade A')
                    278:     expect_equal(remove.articles('Grade A is best'), 'Gradeis best')  # FIXME
                    279: })
1.3       rillig    280:
1.7       rillig    281: test_that('case.insensitive.equals', {
                    282:     expect_equal(case.insensitive.equals('HELLO', 'hello'), TRUE)
                    283:     expect_equal(case.insensitive.equals('HELLO', 'hellx'), FALSE)
                    284:     expect_equal(case.insensitive.equals('  "HELLO"', 'hello'), FALSE)
                    285:     expect_equal(case.insensitive.equals('  "HELLO"', '  hello'), FALSE)
                    286:     expect_equal(case.insensitive.equals('  HELLO', 'hello'), FALSE)
                    287:     expect_equal(case.insensitive.equals('  HELLO', ' hello'), TRUE)
                    288: })
1.3       rillig    289:
1.7       rillig    290: test_that('weakly.equals', {
                    291:     expect_equal(weakly.equals('HELLO', 'hello'), TRUE)
                    292:     expect_equal(weakly.equals('HELLO', 'hellx'), FALSE)
                    293:     expect_equal(weakly.equals('  "HELLO"', 'hello'), FALSE)
                    294:     expect_equal(weakly.equals('  "HELLO"', '  hello'), TRUE)
                    295:     expect_equal(weakly.equals('  HELLO', 'hello'), FALSE)
                    296:     expect_equal(weakly.equals('  HELLO', ' hello'), TRUE)
                    297: })
1.3       rillig    298:
                    299: # test_that('pkgsrc.license', {
                    300: # })
                    301:
                    302: # test_that('use.tools', {
                    303: # })
                    304:
                    305: # test_that('license', {
                    306: # })
                    307:
                    308: # test_that('maintainer', {
                    309: # })
                    310:
                    311: test_that('find.Rcpp', {
                    312:     expect_equal(find.Rcpp(list(), list()), FALSE)
                    313:     expect_equal(find.Rcpp(list('Other'), list('Other')), FALSE)
                    314:
                    315:     expect_equal(find.Rcpp(list('Rcpp'), list()), TRUE)
                    316:     expect_equal(find.Rcpp(list(), list('Rcpp')), TRUE)
                    317: })
                    318:
                    319: # test_that('buildlink3.mk', {
                    320: # })
                    321:
                    322: test_that('varassigns', {
                    323:     expect_equal(
                    324:     varassigns('VARNAME', c('value1', 'value2', '', 'value3')),
                    325:     list(
                    326:     'VARNAME=\tvalue1',
                    327:     'VARNAME=\tvalue2',  # FIXME: This doesn't make sense.
                    328:     '',
                    329:     'VARNAME=\tvalue3'))
                    330: })
                    331:
                    332: # test_that('categories', {
                    333: # })
                    334:
                    335: # test_that('description', {
                    336: # })
                    337:
                    338: # test_that('filter.imports', {
                    339: # })
                    340:
                    341: test_that('make.imports', {
1.5       rillig    342:     expect_equal(
                    343:         make.imports(NA_character_, NA_character_),
                    344:         character(0))
1.3       rillig    345:
1.5       rillig    346:     expect_equal(
                    347:         make.imports('first (>= 1.0)', 'second'),
                    348:         c('first(>=1.0)', 'second'))
                    349:
                    350:     expect_equal(
                    351:         make.imports('first(>=1)', 'second(>=1)'),
                    352:         c('first(>=1)second(>=1)'))
                    353:
                    354:     expect_equal(
                    355:         make.imports('first(>=1) second(>=1)', NA_character_),
                    356:         c('first(>=1)second(>=1)'))
1.3       rillig    357: })
                    358:
                    359: test_that('make.dependency', {
1.4       rillig    360:     expect_equal(make.dependency('pkgname'), c('pkgname'))
                    361:     expect_equal(make.dependency('pkgname(>=1.0)'), c('pkgname', '>=1.0'))
1.3       rillig    362:
1.4       rillig    363:     # undefined behavior
                    364:     expect_equal(make.dependency('pkgname (>= 1.0)'), c('pkgname ', '>= 1.0'))
1.3       rillig    365: })
                    366:
1.7       rillig    367: test_that('depends', {
                    368:     expect_equal(depends(make.dependency('pkg')), 'pkg')
                    369:     expect_equal(depends(make.dependency('pkg(>=1.0)')), 'pkg')
                    370:     expect_equal(depends(make.dependency('ellipsis(>=1.0)')), 'ellipsis')
                    371:
                    372:     # undefined behavior
                    373:     expect_equal(depends(make.dependency('pkg (>= 1.0)')), 'pkg ')
                    374:     expect_equal(depends(make.dependency('ellipsis (>= 1.0)')), 'ellipsis ')
                    375: })
                    376:
                    377: test_that('depends.pkg', {
1.8       rillig    378:     local_dir(package_dir)
1.7       rillig    379:
                    380:     expect_equal(depends.pkg('ellipsis'), '../../math/R-ellipsis')
                    381: })
1.3       rillig    382:
1.7       rillig    383: test_that('new.depends.pkg', {
1.8       rillig    384:     local_dir(package_dir)
1.3       rillig    385:
1.7       rillig    386:     if (dir.exists('../../wip'))
                    387:         expect_equal(new.depends.pkg('C50'), '../../wip/R-C50')
                    388: })
1.3       rillig    389:
                    390: # test_that('depends.pkg.fullname', {
                    391: # })
                    392:
                    393: # test_that('depends.pkg.name', {
                    394: # })
                    395:
                    396: # test_that('depends.pkg.vers', {
                    397: # })
                    398:
                    399: # test_that('depends.vers', {
                    400: # })
                    401:
                    402: # test_that('depends.vers.2', {
                    403: # })
                    404:
                    405: # test_that('depends.dir', {
                    406: # })
                    407:
                    408: # test_that('depends.line', {
                    409: # })
                    410:
                    411: # test_that('depends.line.2', {
                    412: # })
                    413:
                    414: test_that('buildlink3.file with matching version number', {
1.8       rillig    415:     local_dir(package_dir)
1.3       rillig    416:     dependency <- make.dependency('bitops(>=0.1)')
1.1       rillig    417:
1.3       rillig    418:     bl3 <- buildlink3.file(dependency)
1.1       rillig    419:
1.3       rillig    420:     expect_equal(bl3, '../../math/R-bitops/buildlink3.mk')
1.1       rillig    421: })
                    422:
1.3       rillig    423: # The version number of the dependency is not checked against
                    424: # the resolved buildlink3 file.
                    425: test_that('buildlink3.file with too high version number', {
1.8       rillig    426:     local_dir(package_dir)
1.3       rillig    427:     dependency <- make.dependency('bitops(>=1000.0)')
1.1       rillig    428:
1.3       rillig    429:     bl3 <- buildlink3.file(dependency)
1.1       rillig    430:
1.3       rillig    431:     expect_equal(bl3, '../../math/R-bitops/buildlink3.mk')
1.2       rillig    432: })
                    433:
1.7       rillig    434: test_that('buildlink3.line', {
1.8       rillig    435:     local_dir(package_dir)
1.7       rillig    436:
                    437:     expect_equal(
                    438:         buildlink3.line(make.dependency('ellipsis')),
                    439:         '.include "../../math/R-ellipsis/buildlink3.mk"')
                    440:
                    441:     # undefined behavior
                    442:     expect_equal(
                    443:         buildlink3.line(make.dependency('not-found')),
                    444:         '.include "NA/buildlink3.mk"')
                    445: })
1.3       rillig    446:
                    447: # test_that('dependency.dir', {
                    448: # })
                    449:
                    450: # test_that('message.wip.dependency', {
                    451: # })
                    452:
                    453: # test_that('message.too.many.dependencies', {
                    454: # })
                    455:
                    456: # test_that('update.dependency', {
                    457: # })
                    458:
                    459: # test_that('make.depends', {
                    460: # })
                    461:
1.4       rillig    462: test_that('use.languages', {
                    463:     languages <- use.languages(list(), list())
                    464:
                    465:     expect_equal(languages, c('# none', ''))
                    466: })
                    467:
                    468: test_that('use.languages with Rcpp as dependency', {
                    469:     languages <- use.languages(list('Rcpp(>=0)'), list())
                    470:     expected <- list('c cpp', '')
                    471:
                    472:     #expect_equal(languages, expected)
                    473: })
1.3       rillig    474:
                    475: # test_that('copy.description', {
                    476: # })
                    477:
1.8       rillig    478: test_that('write.Makefile', {
                    479:     tmpdir <- paste(tempdir(), 'category', 'pkgdir', sep = '/')
                    480:     dir.create(tmpdir, recursive = TRUE)
                    481:     local_dir(tmpdir)
                    482:     metadata <- make.metadata(linesConnection(
                    483:         'Package: pkgname',
                    484:         'Version: 1.3',
                    485:         'Depends: ellipsis'))
                    486:
                    487:     write.Makefile(metadata)
                    488:
                    489:     expect_equal(readLines('Makefile'),c(
                    490:         mkcvsid,
                    491:         '',
                    492:         'R_PKGNAME=\tpkgname',
                    493:         'R_PKGVER=\t1.3',
                    494:         'CATEGORIES=\tcategory',
                    495:         '',
                    496:         'MAINTAINER=\t',  # FIXME
                    497:         'COMMENT=\tNA',  # FIXME
                    498:         'LICENSE=\tNA',  # FIXME
                    499:         '',
                    500:         'USE_LANGUAGES=\t# none',
                    501:         '',
                    502:         '.include "../../math/R/Makefile.extension"',
                    503:         '.include "../../mk/bsd.pkg.mk"'
                    504:     ))
                    505: })
1.3       rillig    506:
                    507: # test_that('construct.line', {
                    508: # })
                    509:
1.8       rillig    510: test_that('element', {
1.11    ! rillig    511:     mklines <- make_mklines(
1.8       rillig    512:         'COMMENT=\tThe comment',
1.11    ! rillig    513:         'EMPTY=')
1.8       rillig    514:
                    515:     expect_equal(element(mklines, 'COMMENT', 'order'), 1)
                    516:     expect_equal(element(mklines, 'COMMENT', 'old_value'), 'The comment')
                    517:     expect_equal(element(mklines, 'UNKNOWN', 'order'), '???')  # FIXME: should be a number
                    518:     expect_equal(element(mklines, 'EMPTY', 'old_value'), '')
                    519: })
1.3       rillig    520:
                    521: # test_that('make.categories', {
                    522: # })
                    523:
                    524: # test_that('make.maintainer', {
                    525: # })
                    526:
1.8       rillig    527: test_that('make.comment', {
1.11    ! rillig    528:     mklines <- make_mklines(
        !           529:         'COMMENT=\tOld comment')
1.8       rillig    530:
                    531:     mklines$new_value[[1]] <- 'New comment'
                    532:     expect_equal(make.comment(mklines), 'Old comment\t# [R2pkg] updated to: New comment')
                    533:
                    534:     mklines$new_value[[1]] <- 'old Comment'
                    535:     expect_equal(make.comment(mklines), 'Old comment')
                    536: })
1.3       rillig    537:
                    538: # test_that('make.new_license', {
                    539: # })
                    540:
                    541: # test_that('license.marked.todo', {
                    542: # })
                    543:
                    544: # test_that('license.in.pkgsrc', {
                    545: # })
                    546:
                    547: # test_that('make.license', {
                    548: # })
                    549:
                    550: # test_that('make.r_pkgver', {
                    551: # })
                    552:
1.8       rillig    553: test_that('find.order', {
1.11    ! rillig    554:     mklines <- make_mklines(
1.8       rillig    555:         'CATEGORIES=',
                    556:         'HOMEPAGE=',
                    557:         'USE_TOOLS+=',
                    558:         '.include "other.mk"',
1.11    ! rillig    559:         '# comment')
1.8       rillig    560:
                    561:     vars_order <- find.order(mklines, 'key_value', 'order')
                    562:     include_order <- find.order(mklines, 'buildlink3.mk', 'order')
1.3       rillig    563:
1.8       rillig    564:     expect_equal(mklines[, 'key_value'], c(TRUE, TRUE, TRUE, FALSE, FALSE))
                    565:     expect_equal(mklines[, 'buildlink3.mk'], c(FALSE, FALSE, FALSE, FALSE, FALSE))
                    566:     expect_equal(vars_order, c(1))
                    567:     expect_equal(include_order, NA_integer_)
                    568: })
1.3       rillig    569:
1.10      rillig    570: test_that('mklines.update_with_metadata with CATEGORIES', {
1.8       rillig    571:     local_dir(package_dir)  # to get a realistic category
1.10      rillig    572:     arg.maintainer_email <<- 'with-categories@example.org'
1.11    ! rillig    573:     df <- make_mklines(
1.8       rillig    574:         'CATEGORIES=\told categories',
                    575:         'MAINTAINER=\told_maintainer@example.org',
                    576:         'COMMENT=\told comment',
1.11    ! rillig    577:         'R_PKGVER=\t1.0')
1.2       rillig    578:     metadata = list(Title = 'Package comment', Version = '19.3', License = 'license')
                    579:
1.10      rillig    580:     updated <- mklines.update_with_metadata(df, metadata)
1.2       rillig    581:
1.11    ! rillig    582:     expect_printed(data.frame(varname = updated$key, new_value = updated$new_value),
        !           583:         '     varname                   new_value',
1.10      rillig    584:         '1 CATEGORIES                    pkgtools',
                    585:         '2 MAINTAINER with-categories@example.org',  # FIXME: Should not always be reset.
                    586:         '3    COMMENT             Package comment',
                    587:         '4   R_PKGVER                        19.3')
1.2       rillig    588: })
                    589:
                    590: # If the variable has been removed from the Makefile, it is not updated.
1.10      rillig    591: test_that('mklines.update_with_metadata without CATEGORIES', {
                    592:     arg.maintainer_email <<- 'without-categories@example.org'
1.11    ! rillig    593:     df <- make_mklines(
1.6       rillig    594:         'MAINTAINER=',
                    595:         'COMMENT=',
1.11    ! rillig    596:         'R_PKGVER=')
1.2       rillig    597:     metadata = list(Title = 'Package comment', Version = '19.3', License = 'license')
                    598:
1.10      rillig    599:     updated <- mklines.update_with_metadata(df, metadata)
1.2       rillig    600:
1.11    ! rillig    601:     expect_printed(data.frame(varname = updated$key, new_value = updated$new_value),
        !           602:         '     varname                      new_value',
        !           603:         '1 MAINTAINER without-categories@example.org',
        !           604:         '2    COMMENT                Package comment',
        !           605:         '3   R_PKGVER                           19.3')
1.1       rillig    606: })
1.3       rillig    607:
1.10      rillig    608: test_that('mklines.update_value', {
                    609:     local_dir(package_dir)
                    610:
1.11    ! rillig    611:     mklines <- make_mklines(
1.10      rillig    612:         'R_PKGVER=\t1.0',
                    613:         'CATEGORIES=\told categories',
                    614:         'MAINTAINER=\told_maintainer@example.org',
                    615:         'COMMENT=\tOld comment',
1.11    ! rillig    616:         'LICENSE=\told-license')
1.10      rillig    617:     mklines$new_value <- mklines$old_value
                    618:
                    619:     updated <- mklines.update_value(mklines)
1.3       rillig    620:
1.10      rillig    621:     expect_equal(updated$value, c(
                    622:         '1.0',
                    623:         'pkgtools old categories',
                    624:         'old_maintainer@example.org',
                    625:         'Old comment',
                    626:         'old-license\t# [R2pkg] previously: old-license'))  # FIXME: no comment necessary
                    627:     expect_equal(updated$todo, c(
                    628:         '',
                    629:         '',
                    630:         '',
                    631:         '',
                    632:         '# TODO: '))
                    633: })
1.3       rillig    634:
1.10      rillig    635: test_that('mklines.update_new_line', {
1.11    ! rillig    636:     mklines <- make_mklines(
1.10      rillig    637:         'VALUE=\tvalue',
                    638:         'VALUE_WITH_COMMENT=\tvalue # comment',
                    639:         'VALUE_NA=\tvalue',
1.11    ! rillig    640:         '#COMMENTED=\tcommented value')
1.10      rillig    641:     mklines <- mklines.update_value(mklines)
                    642:     mklines$value[mklines$key == 'VALUE'] <- 'new value'
                    643:     mklines$value[mklines$key == 'VALUE_WITH_COMMENT'] <- 'new value # new comment'
                    644:     mklines$value[mklines$key == '#COMMENTED'] <- 'new commented'
1.3       rillig    645:
1.10      rillig    646:     updated <- mklines.update_new_line(mklines)
1.3       rillig    647:
1.10      rillig    648:     expect_equal(updated$new_line, c(
                    649:         'VALUE=\tnew value',
                    650:         'VALUE_WITH_COMMENT=\tnew value # new comment',
                    651:         'VALUE_NA=\tvalue',
                    652:         '#COMMENTED=\tnew commented'))
                    653: })
1.3       rillig    654:
1.10      rillig    655: test_that('mklines.annotate_distname', {
1.11    ! rillig    656:     mklines <- make_mklines(
        !           657:         'DISTNAME=\tpkg_1.0')
1.10      rillig    658:     mklines$new_line <- mklines$line
1.3       rillig    659:
1.10      rillig    660:     annotated <- mklines.annotate_distname(mklines)
1.3       rillig    661:
1.10      rillig    662:     expect_equal(
                    663:         annotated$new_line,
                    664:         'DISTNAME=\tpkg_1.0\t# [R2pkg] replace this line with R_PKGNAME=pkg and R_PKGVER=1.0 as first stanza')
                    665: })
1.3       rillig    666:
1.10      rillig    667: test_that('mklines.remove_lines_before_update', {
1.11    ! rillig    668:     mklines <- make_mklines(
1.10      rillig    669:         'MASTER_SITES=',
                    670:         'HOMEPAGE=',
                    671:         'BUILDLINK_API_DEPENDS.dependency+=',
                    672:         'BUILDLINK_ABI_DEPENDS.dependency+=',
1.11    ! rillig    673:         'COMMENT=')
1.10      rillig    674:     mklines$new_line <- mklines$line
                    675:
                    676:     cleaned <- mklines.remove_lines_before_update(mklines)
                    677:
1.11    ! rillig    678:     expect_equal(cleaned$key, c(
        !           679:         'COMMENT'))
        !           680: })
        !           681:
        !           682: test_that('mklines.reassign_order, no change necessary', {
        !           683:     mklines <- make_mklines(
        !           684:         'R_PKGNAME= ellipsis',
        !           685:         'R_PKGVER= 0.1',
        !           686:         'CATEGORIES= pkgtools')
        !           687:
        !           688:     updated <- mklines.reassign_order(mklines)
        !           689:
        !           690:     expect_equal(updated, mklines)
1.10      rillig    691: })
1.3       rillig    692:
1.11    ! rillig    693: test_that('mklines.reassign_order, reordered', {
        !           694:     mklines <- make_mklines(
        !           695:         'CATEGORIES= pkgtools',
        !           696:         'R_PKGNAME= ellipsis',
        !           697:         'R_PKGVER= 0.1')
        !           698:
        !           699:     expect_printed(data.frame(varname = mklines$key, order = mklines$order),
        !           700:         '     varname order',
        !           701:         '1 CATEGORIES     1',
        !           702:         '2  R_PKGNAME     2',
        !           703:         '3   R_PKGVER     3')
        !           704:
        !           705:     updated <- mklines.reassign_order(mklines)
        !           706:
        !           707:     expect_printed(data.frame(varname = updated$key, order = updated$order),
        !           708:         '     varname order',
        !           709:         '1 CATEGORIES   1.0',
        !           710:         '2  R_PKGNAME   0.8',
        !           711:         '3   R_PKGVER   0.9')
        !           712: })
1.3       rillig    713:
                    714: test_that('conflicts', {
                    715:     expect_equal(conflicts('UnknownPackage'), list())
                    716:
                    717:     expect_equal(
                    718:         conflicts('lattice'),
                    719:         list('CONFLICTS=\tR>=3.6.1', ''))
                    720:
                    721:     expect_equal(
                    722:         conflicts(c('lattice', 'methods', 'general', 'UnknownPackage')),
                    723:         list('CONFLICTS=\tR>=3.6.1', ''))
                    724: })
                    725:
                    726: # test_that('conflicts.order', {
                    727: # })
                    728:
                    729: # test_that('make.df.conflicts', {
                    730: # })
                    731:
                    732: # test_that('make.df.depends', {
                    733: # })
                    734:
                    735: # test_that('make.df.buildlink3', {
                    736: # })
                    737:
                    738: # test_that('make.df.makefile', {
                    739: # })
                    740:
1.5       rillig    741: test_that('update.Makefile', {
                    742:     local_dir(tempdir())
                    743:     local_mock('system', function(...) {
1.6       rillig    744:         expect_printed(list(...), 'asdf')
1.5       rillig    745:         ''
                    746:     })
                    747:     writeLines(
                    748:         c(
                    749:             mkcvsid,
                    750:             '',
                    751:             '.include "../../mk/bsd.pkg.mk"'),
                    752:         'Makefile.orig')
1.8       rillig    753:     metadata <- make.metadata(linesConnection(
                    754:         'Package: pkgname',
                    755:         'Version: 1.0',
                    756:         'Depends: dep1 dep2(>=2.0)'))
1.5       rillig    757:     expect_printed(
                    758:         as.data.frame(metadata),
1.6       rillig    759:         '  Package Version Title Description License Imports          Depends',
                    760:         '1 pkgname     1.0  <NA>        <NA>    <NA>    <NA> dep1 dep2(>=2.0)')
                    761:     expect_printed(metadata$Imports, '[1] NA')
                    762:     expect_printed(metadata$Depends, '[1] "dep1 dep2(>=2.0)"')
1.5       rillig    763:     expect_printed(
                    764:         paste2(metadata$Imports, metadata$Depends),
1.6       rillig    765:         '[1] "dep1 dep2(>=2.0)"')
1.5       rillig    766:     expect_printed(
                    767:         make.imports(metadata$Imports, metadata$Depends),
1.6       rillig    768:         '[1] "dep1"        "dep2(>=2.0)"')
1.5       rillig    769:     FALSE && expect_printed(
                    770:         make.depends(metadata$Imports, metadata$Depends),
1.6       rillig    771:         '[1] "dep1"        "dep2(>=2.0)"')
1.5       rillig    772:
                    773:     FALSE && update.Makefile(metadata)
                    774:
                    775:     FALSE && expect_equal(
                    776:         c(
                    777:             mkcvsid,
                    778:             '',
                    779:             'asdf'),
                    780:         readLines('Makefile'))
                    781: })
1.3       rillig    782:
                    783: # test_that('create.Makefile', {
                    784: # })
                    785:
1.5       rillig    786: test_that('create.DESCR', {
                    787:     local_dir(tempdir())
1.6       rillig    788:     metadata <- make.metadata(linesConnection(
                    789:         'Description: First line',
                    790:         ' .',
                    791:         ' Second paragraph',
                    792:         ' has 2 lines'))
1.5       rillig    793:
                    794:     create.DESCR(metadata)
                    795:
                    796:     lines <- readLines('DESCR', encoding = 'UTF-8')
                    797:     expect_equal(lines, c(
                    798:         'First line',
                    799:         '',
                    800:         'Second paragraph has 2 lines'
                    801:     ))
                    802: })
1.3       rillig    803:
1.6       rillig    804: test_that('create.DESCR for a package without Description', {
                    805:     local_dir(tempdir())
                    806:     metadata <- make.metadata(linesConnection('Package: pkgname'))
                    807:
                    808:     create.DESCR(metadata)
                    809:
                    810:     lines <- readLines('DESCR', encoding = 'UTF-8')
                    811:     expect_equal(lines, c('NA'))  # FIXME
                    812: })
                    813:
1.5       rillig    814: test_that('make.metadata', {
                    815:     description <- paste(
                    816:         c(
                    817:             'Package: pkgname',
                    818:             'Version: 1.0',
                    819:             'Imports: dep1 other'
                    820:         ),
                    821:         collapse = '\n')
                    822:
                    823:     metadata <- make.metadata(textConnection(description))
                    824:
                    825:     expect_equal(metadata$Package, 'pkgname')
                    826:     expect_equal(metadata$Version, '1.0')
                    827:     expect_equal(metadata$Imports, 'dep1 other')
                    828:     expect_equal(metadata$Depends, NA_character_)
                    829: })
1.3       rillig    830:
                    831: # test_that('main', {
                    832: # })

CVSweb <webmaster@jp.NetBSD.org>