summaryrefslogtreecommitdiff
path: root/pkgtools
diff options
context:
space:
mode:
authorrillig <rillig@pkgsrc.org>2019-10-19 14:52:40 +0000
committerrillig <rillig@pkgsrc.org>2019-10-19 14:52:40 +0000
commitdb0befb71075f37beb6e1ae7a9b95a71aa6eafcb (patch)
tree2a48ea7138ccc28853ae449dadad15c010ef9942 /pkgtools
parent9b1eeb9bdc3cde41da3f1bc25a474efa897047a4 (diff)
downloadpkgsrc-db0befb71075f37beb6e1ae7a9b95a71aa6eafcb.tar.gz
pkgtools/R2pkg: refactoring, tests
Diffstat (limited to 'pkgtools')
-rw-r--r--pkgtools/R2pkg/files/R2pkg.R37
-rw-r--r--pkgtools/R2pkg/files/R2pkg_test.R48
2 files changed, 60 insertions, 25 deletions
diff --git a/pkgtools/R2pkg/files/R2pkg.R b/pkgtools/R2pkg/files/R2pkg.R
index 2536a8fc02d..f6845aadd7f 100644
--- a/pkgtools/R2pkg/files/R2pkg.R
+++ b/pkgtools/R2pkg/files/R2pkg.R
@@ -1,4 +1,4 @@
-# $NetBSD: R2pkg.R,v 1.18 2019/10/19 13:55:09 rillig Exp $
+# $NetBSD: R2pkg.R,v 1.19 2019/10/19 14:52:40 rillig Exp $
#
# Copyright (c) 2014,2015,2016,2017,2018,2019
# Brook Milligan. All rights reserved.
@@ -239,25 +239,24 @@ categorize.buildlink <- function(df,line='line')
fix.continued.lines <- function(df,line='line')
{
- if (nrow(df) > 1)
+ if (nrow(df) < 2)
+ return(df)
+
+ continued <- grepl('\\\\$', df[, line])
+ continued_key_value <- df$key_value & continued
+
+ if (FALSE %in% df[continued,'key_value'])
+ level.warning('unhandled continued line(s)')
+
+ for (i in 1 : (nrow(df) - 1))
{
- continued <- grepl('\\\\$',df[,line])
- continued_key_value <- df$key_value & continued
- if (FALSE %in% df[continued,'key_value'])
- {
- level.warning('unhandled continued line(s)')
- }
- for (i in 1:(length(continued_key_value)-1))
- {
- next_line <- i + 1
- if (continued_key_value[i])
- {
- df[i,line] <- sub('[[:blank:]]*\\\\$','',df[i,line])
- df$key_value[next_line] <- TRUE
- df$key[next_line] <- df$key[i]
- df[next_line,line] <- paste0(df$key[next_line],'+=',df[next_line,line])
- }
- }
+ if (!continued_key_value[i])
+ next
+
+ df[i, line] <- sub('[\t ]*\\\\$', '', df[i, line])
+ df$key_value[i + 1] <- TRUE
+ df$key[i + 1] <- df$key[i]
+ df[i + 1, line] <- paste0(df$key[i], '+=', df[i + 1, line])
}
df
}
diff --git a/pkgtools/R2pkg/files/R2pkg_test.R b/pkgtools/R2pkg/files/R2pkg_test.R
index b11cd437e89..baeac1ca05b 100644
--- a/pkgtools/R2pkg/files/R2pkg_test.R
+++ b/pkgtools/R2pkg/files/R2pkg_test.R
@@ -1,4 +1,4 @@
-# $NetBSD: R2pkg_test.R,v 1.13 2019/10/19 13:55:09 rillig Exp $
+# $NetBSD: R2pkg_test.R,v 1.14 2019/10/19 14:52:40 rillig Exp $
#
# Copyright (c) 2019
# Roland Illig. All rights reserved.
@@ -193,8 +193,44 @@ test_that('read.file.as.dataframe', {
# test_that('categorize.buildlink', {
# })
-# test_that('fix.continued.lines', {
-# })
+test_that('fix.continued.lines', {
+ message <- mocked_message()
+ local_mock(message = message$mock)
+
+ mklines <- make_mklines(
+ '# comment \\',
+ 'continued=comment',
+ 'VAR1= \\',
+ '\tvalue',
+ 'VAR2=\tvalue')
+
+ expect_printed(
+ data.frame(varassign = mklines$key_value, line = mklines$line),
+ ' varassign line',
+ '1 FALSE # comment \\\\',
+ '2 TRUE continued=comment', # FIXME: continuation from line 1
+ '3 TRUE VAR1=',
+ '4 TRUE VAR1+=\\tvalue', # FIXME: extra space at the beginning
+ '5 TRUE VAR2=\\tvalue')
+ message$expect_messages(
+ '[ 321 ] WARNING: unhandled continued line(s)')
+})
+
+test_that('fix.continued.lines, single continued line at EOF', {
+ mklines <- make_mklines(
+ 'VAR= \\')
+
+ expect_equal(mklines$line, 'VAR= \\')
+})
+
+test_that('fix.continued.lines, no continued lines', {
+ mklines <- make_mklines(
+ 'VAR= value',
+ 'VAR= value',
+ 'VAR= value')
+
+ expect_equal(mklines$line, rep('VAR= value',3))
+})
test_that('read.Makefile.as.dataframe', {
mklines <- make_mklines(
@@ -806,13 +842,13 @@ test_that('update.Makefile', {
expect_printed(
make.imports(metadata$Imports, metadata$Depends),
'[1] "dep1" "dep2(>=2.0)"')
- FALSE && expect_printed(
+ FALSE && expect_printed( # FIXME
make.depends(metadata$Imports, metadata$Depends),
'[1] "dep1" "dep2(>=2.0)"')
- FALSE && update.Makefile(metadata)
+ FALSE && update.Makefile(metadata) # FIXME
- FALSE && expect_equal(
+ FALSE && expect_equal( # FIXME
c(
mkcvsid,
'',