pkgsrc-Changes-HG archive

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

[pkgsrc/trunk]: pkgsrc/pkgtools/R2pkg/files pkgtools/R2pkg: refactoring, tests



details:   https://anonhg.NetBSD.org/pkgsrc/rev/d956974d6857
branches:  trunk
changeset: 342472:d956974d6857
user:      rillig <rillig%pkgsrc.org@localhost>
date:      Sat Oct 19 14:52:40 2019 +0000

description:
pkgtools/R2pkg: refactoring, tests

diffstat:

 pkgtools/R2pkg/files/R2pkg.R      |  37 ++++++++++++++---------------
 pkgtools/R2pkg/files/R2pkg_test.R |  48 ++++++++++++++++++++++++++++++++++----
 2 files changed, 60 insertions(+), 25 deletions(-)

diffs (125 lines):

diff -r 99c514d63c29 -r d956974d6857 pkgtools/R2pkg/files/R2pkg.R
--- a/pkgtools/R2pkg/files/R2pkg.R      Sat Oct 19 14:49:29 2019 +0000
+++ b/pkgtools/R2pkg/files/R2pkg.R      Sat Oct 19 14:52:40 2019 +0000
@@ -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 @@
 
 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 -r 99c514d63c29 -r d956974d6857 pkgtools/R2pkg/files/R2pkg_test.R
--- a/pkgtools/R2pkg/files/R2pkg_test.R Sat Oct 19 14:49:29 2019 +0000
+++ b/pkgtools/R2pkg/files/R2pkg_test.R Sat Oct 19 14:52:40 2019 +0000
@@ -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('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 @@
     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,
             '',



Home | Main Index | Thread Index | Old Index