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 19:10:31 UTC 2019

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

Log Message:
pkgtools/R2pkg: make license handling code simpler


To generate a diff of this commit:
cvs rdiff -u -r1.22 -r1.23 pkgsrc/pkgtools/R2pkg/files/R2pkg.R
cvs rdiff -u -r1.17 -r1.18 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.22 pkgsrc/pkgtools/R2pkg/files/R2pkg.R:1.23
--- pkgsrc/pkgtools/R2pkg/files/R2pkg.R:1.22    Sat Oct 19 18:43:51 2019
+++ pkgsrc/pkgtools/R2pkg/files/R2pkg.R Sat Oct 19 19:10:31 2019
@@ -1,4 +1,4 @@
-# $NetBSD: R2pkg.R,v 1.22 2019/10/19 18:43:51 rillig Exp $
+# $NetBSD: R2pkg.R,v 1.23 2019/10/19 19:10:31 rillig Exp $
 #
 # Copyright (c) 2014,2015,2016,2017,2018,2019
 #      Brook Milligan.  All rights reserved.
@@ -608,16 +608,6 @@ write.Makefile <- function(orig_mklines,
   writeLines(lines, 'Makefile')
 }
 
-construct.line <- function(df,key,value)
-{
-  key <- df[df$key==key,'key']
-  operator <- df[df$key==key,'operator']
-  delimiter <- df[df$key==key,'delimiter']
-  value <- df[df$key==key,value]
-  df$new_line[df$key==key] <- paste0(key,operator,delimiter,value)
-  df
-}
-
 element <- function(mklines, varname, field, quiet=FALSE)
 {
   i <- match(varname, mklines$key, 0)
@@ -685,37 +675,17 @@ make.license <- function(df)
   old_known <- license.in.pkgsrc(old_license)
   new_known <- license.in.pkgsrc(new_license)
 
-  if (old_known && new_known)
-    {
-      if (case.insensitive.equals(old_license,new_license))
-        {
-          license <- old_license
-          todo <- old_todo
-        }
-      else
-        {
-          license <- paste0(new_license,'\t# [R2pkg] previously: ',old_license)
-          todo <- old_todo
-        }
-    }
-  else if (old_known && !new_known)
-    {
-      license <- paste0(old_license,'\t# [R2pkg] updated to: ',new_license)
-      todo <- '# TODO: '
-    }
-  else if (!old_known && new_known)
-    {
-      license <- paste0(new_license,'\t# [R2pkg] previously: ',old_license)
-      todo <- ''
-    }
+  license <- if (!old_known)
+    paste0(new_license, '\t# [R2pkg] previously: ', old_license)
+  else if (!new_known)
+    paste0(old_license, '\t# [R2pkg] updated to: ', new_license)
+  else if (case.insensitive.equals(old_license, new_license))
+    old_license
   else
-    {
-      license <- paste0(new_license,'\t# [R2pkg] previously: ',old_license)
-      todo <- '# TODO: '
-    }
+    paste0(new_license, '\t# [R2pkg] previously: ', old_license)
 
   df$value[df$key == 'LICENSE'] <- license
-  df$todo[df$key == 'LICENSE'] <- todo
+  df$todo[df$key == 'LICENSE'] <- if (new_known) old_todo else '# TODO: '
 
   df
 }

Index: pkgsrc/pkgtools/R2pkg/files/R2pkg_test.R
diff -u pkgsrc/pkgtools/R2pkg/files/R2pkg_test.R:1.17 pkgsrc/pkgtools/R2pkg/files/R2pkg_test.R:1.18
--- pkgsrc/pkgtools/R2pkg/files/R2pkg_test.R:1.17       Sat Oct 19 18:43:51 2019
+++ pkgsrc/pkgtools/R2pkg/files/R2pkg_test.R    Sat Oct 19 19:10:31 2019
@@ -1,4 +1,4 @@
-# $NetBSD: R2pkg_test.R,v 1.17 2019/10/19 18:43:51 rillig Exp $
+# $NetBSD: R2pkg_test.R,v 1.18 2019/10/19 19:10:31 rillig Exp $
 #
 # Copyright (c) 2019
 #      Roland Illig.  All rights reserved.
@@ -579,9 +579,6 @@ test_that('write.Makefile', {
     ))
 })
 
-# test_that('construct.line', {
-# })
-
 test_that('element', {
     mklines <- make_mklines(
         'COMMENT=\tThe comment',
@@ -619,8 +616,60 @@ test_that('make.comment', {
 # test_that('license.in.pkgsrc', {
 # })
 
-# test_that('make.license', {
-# })
+test_that('make.license, old and new known and equal', {
+    mklines <- make_mklines(
+        'LICENSE=\tgnu-gpl-v2')
+    mklines$new_value <- 'gnu-gpl-v2'
+
+    updated <- make.license(mklines)
+
+    expect_equal(updated$value, 'gnu-gpl-v2')
+    expect_equal(updated$todo, '')
+})
+
+test_that('make.license, old and new known and changed', {
+    mklines <- make_mklines(
+        'LICENSE=\tgnu-gpl-v2')
+    mklines$new_value <- 'gnu-gpl-v3'
+
+    updated <- make.license(mklines)
+
+    expect_equal(updated$value, 'gnu-gpl-v3\t# [R2pkg] previously: gnu-gpl-v2')
+    expect_equal(updated$todo, '')
+})
+
+test_that('make.license, old known, new unknown', {
+    mklines <- make_mklines(
+        'LICENSE=\tgnu-gpl-v2')
+    mklines$new_value <- 'unknown-license'
+
+    updated <- make.license(mklines)
+
+    expect_equal(updated$value, 'gnu-gpl-v2\t# [R2pkg] updated to: unknown-license')
+    expect_equal(updated$todo, '# TODO: ')
+})
+
+test_that('make.license, old unknown, new known', {
+    mklines <- make_mklines(
+        'LICENSE=\tunknown-license')
+    mklines$new_value <- 'gnu-gpl-v2'
+
+    updated <- make.license(mklines)
+
+    expect_equal(updated$value, 'gnu-gpl-v2\t# [R2pkg] previously: unknown-license')
+    expect_equal(updated$todo, '')
+})
+
+test_that('make.license, old unknown, new also unknown', {
+    mklines <- make_mklines(
+        'LICENSE=\tunknown-license')
+    mklines$new_value <- 'new-unknown'
+
+    updated <- make.license(mklines)
+
+    expect_equal(updated$value, 'new-unknown\t# [R2pkg] previously: unknown-license')
+    expect_equal(updated$todo, '# TODO: ')
+})
 
 # test_that('make.r_pkgver', {
 # })



Home | Main Index | Thread Index | Old Index