pkgsrc-Changes archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

CVS commit: pkgsrc/pkgtools/R2pkg



Module Name:    pkgsrc
Committed By:   rillig
Date:           Sun Oct 13 18:13:04 UTC 2019

Modified Files:
        pkgsrc/pkgtools/R2pkg: Makefile
        pkgsrc/pkgtools/R2pkg/files: R2pkg.R
Added Files:
        pkgsrc/pkgtools/R2pkg/files: R2pkg_test.R

Log Message:
pkgtools/R2pkg: add unit tests


To generate a diff of this commit:
cvs rdiff -u -r1.7 -r1.8 pkgsrc/pkgtools/R2pkg/Makefile
cvs rdiff -u -r1.5 -r1.6 pkgsrc/pkgtools/R2pkg/files/R2pkg.R
cvs rdiff -u -r0 -r1.1 pkgsrc/pkgtools/R2pkg/files/R2pkg_test.R

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: pkgsrc/pkgtools/R2pkg/Makefile
diff -u pkgsrc/pkgtools/R2pkg/Makefile:1.7 pkgsrc/pkgtools/R2pkg/Makefile:1.8
--- pkgsrc/pkgtools/R2pkg/Makefile:1.7  Sun Oct 13 13:26:22 2019
+++ pkgsrc/pkgtools/R2pkg/Makefile      Sun Oct 13 18:13:03 2019
@@ -1,4 +1,4 @@
-# $NetBSD: Makefile,v 1.7 2019/10/13 13:26:22 rillig Exp $
+# $NetBSD: Makefile,v 1.8 2019/10/13 18:13:03 rillig Exp $
 #
 
 VERS=          0.6.2
@@ -16,6 +16,8 @@ USE_LANGUAGES=        # none
 AUTO_MKDIRS=   yes
 
 DEPENDS+=      curl>=7.52.1:../../www/curl
+TEST_DEPENDS+= R-testthat>=2.2.1:../../devel/R-testthat
+TEST_DEPENDS+= R-withr>=2.1.2:../../devel/R-withr
 
 SUBST_CLASSES+=        R
 SUBST_STAGE.R= pre-configure
@@ -24,7 +26,10 @@ SUBST_VARS.R=        VERS MAKE LIBDIR
 LIBDIR=                ${PREFIX}/lib/R2pkg
 
 do-extract:
-       cd ${FILESDIR} && ${CP} R2pkg.* ${WRKSRC}
+       cd ${FILESDIR} && ${CP} R2pkg*.* ${WRKSRC}
+
+do-test:
+       cd ${WRKSRC} && LC_ALL=C ${PREFIX}/bin/Rscript R2pkg_test.R
 
 do-install:
        ${INSTALL_SCRIPT} ${WRKSRC}/R2pkg.sh ${DESTDIR}${PREFIX}/sbin/R2pkg

Index: pkgsrc/pkgtools/R2pkg/files/R2pkg.R
diff -u pkgsrc/pkgtools/R2pkg/files/R2pkg.R:1.5 pkgsrc/pkgtools/R2pkg/files/R2pkg.R:1.6
--- pkgsrc/pkgtools/R2pkg/files/R2pkg.R:1.5     Sun Oct 13 17:23:29 2019
+++ pkgsrc/pkgtools/R2pkg/files/R2pkg.R Sun Oct 13 18:13:03 2019
@@ -1,4 +1,4 @@
-# $NetBSD: R2pkg.R,v 1.5 2019/10/13 17:23:29 rillig Exp $
+# $NetBSD: R2pkg.R,v 1.6 2019/10/13 18:13:03 rillig Exp $
 #
 # Copyright (c) 2014,2015,2016,2017,2018,2019
 #      Brook Milligan.  All rights reserved.
@@ -271,7 +271,7 @@ fix.continued.lines <- function(df,line=
   df
 }
 
-read.Makefile.as.dataframe <- function()
+read.Makefile.as.dataframe <- function(filename = 'Makefile.orig')
 {
   # message('===> read.Makefile.as.dataframe():')
 
@@ -322,7 +322,7 @@ read.Makefile.as.dataframe <- function()
     re.value,
     '$')
 
-  df <- read.file.as.dataframe('Makefile.orig')
+  df <- read.file.as.dataframe(filename)
 
   df$order <- 1:nrow(df)
   df$category <- NA
@@ -498,9 +498,9 @@ sed.license <- function(license)
 }
 sed.r_pkgver <- function(r_pkgver) make.sed.command('R_PKGVER',r_pkgver)
 
-find.Rcpp <- function(s1, s2) grepl('Rcpp', paste(s1, s2))
+find.Rcpp <- function(imps, deps) grepl('Rcpp', paste(imps, deps))
 
-buildlink3.mk <- function(s1,s2)
+buildlink3.mk <- function(imps,deps)
 {
   BUILDLINK3.MK <- data.frame()
   buildlink3.mk.list <- read.file.as.list('BUILDLINK3.MK')
@@ -511,7 +511,7 @@ buildlink3.mk <- function(s1,s2)
       value <- line
       BUILDLINK3.MK <- rbind(BUILDLINK3.MK,data.frame(key=key,value=value))
     }
-  if (find.Rcpp(s1,s2))
+  if (find.Rcpp(imps,deps))
     {
       buildlink3.line <- '.include "../../devel/R-Rcpp/buildlink3.mk"'
       key <- 'devel'
@@ -696,13 +696,13 @@ update.dependency <- function(dependency
     level.warning('error updating dependency for ',depends(dependency))
 }
 
-make.depends <- function(s1,s2)
+make.depends <- function(imps,deps)
 {
-  imports <- make.imports(s1,s2)
+  imports <- make.imports(imps,deps)
   # XXX  message('===> imports:')
   # XXX print(imports)
   DEPENDS <- data.frame()
-  BUILDLINK3.MK <- buildlink3.mk(s1,s2)
+  BUILDLINK3.MK <- buildlink3.mk(imps,deps)
   if (length(imports) > 0)
     {
       for (i in 1:length(imports))

Added files:

Index: pkgsrc/pkgtools/R2pkg/files/R2pkg_test.R
diff -u /dev/null pkgsrc/pkgtools/R2pkg/files/R2pkg_test.R:1.1
--- /dev/null   Sun Oct 13 18:13:04 2019
+++ pkgsrc/pkgtools/R2pkg/files/R2pkg_test.R    Sun Oct 13 18:13:03 2019
@@ -0,0 +1,128 @@
+# $NetBSD: R2pkg_test.R,v 1.1 2019/10/13 18:13:03 rillig Exp $
+#
+# Copyright (c) 2019
+#      Roland Illig.  All rights reserved.
+#
+# Redistribution and use in source and binary forms, with or without
+# modification, are permitted provided that the following conditions
+# are met:
+# 1. Redistributions of source code must retain the above copyright
+#    notice, this list of conditions and the following disclaimer.
+# 2. Redistributions in binary form must reproduce the above copyright
+#    notice, this list of conditions and the following disclaimer in the
+#    documentation and/or other materials provided with the distribution.
+# 3. Neither the name of the author nor the names of any contributors
+#    may be used to endorse or promote products derived from this software
+#    without specific prior written permission.
+#
+# THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
+# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+# ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
+# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+# OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+# HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+# OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+# SUCH DAMAGE.
+#
+
+source('R2pkg.R')
+library(testthat)
+library(withr)
+
+test_that('make.imports', {
+    imports <- make.imports('first (>= 1.0)', 'second')
+
+    expect_equal(imports, c('first(>=1.0)', 'second'))
+})
+
+test_that('make.dependency', {
+    imports <- make.dependency('first(>=1.0)')
+
+    expect_equal(imports, c('first', '>=1.0'))
+})
+
+test_that('buildlink3.file with matching version number', {
+    local_dir('..')
+    dependency <- make.dependency('ellipsis(>=0.1)')
+
+    bl3 <- buildlink3.file(dependency)
+
+    expect_equal(bl3, '../../math/R-ellipsis/buildlink3.mk')
+})
+
+# The version number of the dependency is not checked against
+# the resolved buildlink3 file.
+test_that('buildlink3.file with too high version number', {
+    local_dir('..')
+    dependency <- make.dependency('ellipsis(>=1000.0)')
+
+    bl3 <- buildlink3.file(dependency)
+
+    expect_equal(bl3, '../../math/R-ellipsis/buildlink3.mk')
+})
+
+test_that('level.warning', {
+    output <- ''
+    mock_message <- function(...) output <<- paste0(output, ..., '\n')
+
+    arg.level <<- 123  # XXX: should use with_environment instead
+    with_mock(message = mock_message, {
+        level.warning('mess', 'age', ' text')
+    })
+
+    expect_equal(output, '[ 123 ] WARNING: message text\n')
+})
+
+test_that('read.file.as.dataframe', {
+    content <- textConnection('VAR=value\nVAR2=value2\n')
+
+    df <- read.file.as.dataframe(content)
+
+    expect_equal(length(df$line), 3)
+    expect_equal(df$line[[1]], 'VAR=value')
+    expect_equal(df$line[[2]], 'VAR2=value2')
+    expect_equal(df$line[[3]], '')
+})
+
+test_that('read.Makefile.as.dataframe', {
+    lines <- c(
+        '# comment',
+        'VAR= value',
+        '',
+        '.include "other.mk"',
+        '.if 0',
+        '.endif'
+    )
+    content <- paste0(paste(lines, collapse = '\n'), '\n')
+    expect_equal(content, '# comment\nVAR= value\n\n.include "other.mk"\n.if 0\n.endif\n')
+
+    df <- read.Makefile.as.dataframe(textConnection(content))
+
+    out <- ''
+    with_output_sink(textConnection('out', 'w', local = TRUE), {
+        print(df)
+    })
+
+    expected.out <- c(
+        '                 line order category key_value  key depends buildlink3.mk',
+        '1           # comment     1       NA     FALSE <NA>   FALSE         FALSE',
+        '2          VAR= value     2       NA      TRUE  VAR   FALSE         FALSE',
+        '3                         3       NA     FALSE <NA>   FALSE         FALSE',
+        '4 .include "other.mk"     4       NA     FALSE <NA>   FALSE         FALSE',
+        '5               .if 0     5       NA     FALSE <NA>   FALSE         FALSE',
+        '6              .endif     6       NA     FALSE <NA>   FALSE         FALSE',
+        '7                         7       NA     FALSE <NA>   FALSE         FALSE',
+        '  operator delimiter old_value old_todo',
+        '1     <NA>      <NA>      <NA>     <NA>',
+        '2        =               value         ',
+        '3     <NA>      <NA>      <NA>     <NA>',
+        '4     <NA>      <NA>      <NA>     <NA>',
+        '5     <NA>      <NA>      <NA>     <NA>',
+        '6     <NA>      <NA>      <NA>     <NA>',
+        '7     <NA>      <NA>      <NA>     <NA>'
+    )
+    expect_equal(out, expected.out)
+})



Home | Main Index | Thread Index | Old Index