pkgsrc-Changes archive

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

CVS commit: pkgsrc/pkgtools/R2pkg/files



Module Name:    pkgsrc
Committed By:   rillig
Date:           Sat Oct 19 14:52:40 UTC 2019

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

Log Message:
pkgtools/R2pkg: refactoring, tests


To generate a diff of this commit:
cvs rdiff -u -r1.18 -r1.19 pkgsrc/pkgtools/R2pkg/files/R2pkg.R
cvs rdiff -u -r1.13 -r1.14 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/files/R2pkg.R
diff -u pkgsrc/pkgtools/R2pkg/files/R2pkg.R:1.18 pkgsrc/pkgtools/R2pkg/files/R2pkg.R:1.19
--- pkgsrc/pkgtools/R2pkg/files/R2pkg.R:1.18    Sat Oct 19 13:55:09 2019
+++ pkgsrc/pkgtools/R2pkg/files/R2pkg.R Sat Oct 19 14:52:40 2019
@@ -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
 
 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
 }

Index: pkgsrc/pkgtools/R2pkg/files/R2pkg_test.R
diff -u pkgsrc/pkgtools/R2pkg/files/R2pkg_test.R:1.13 pkgsrc/pkgtools/R2pkg/files/R2pkg_test.R:1.14
--- pkgsrc/pkgtools/R2pkg/files/R2pkg_test.R:1.13       Sat Oct 19 13:55:09 2019
+++ pkgsrc/pkgtools/R2pkg/files/R2pkg_test.R    Sat Oct 19 14:52:40 2019
@@ -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,
             '',



Home | Main Index | Thread Index | Old Index