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: make license hand...



details:   https://anonhg.NetBSD.org/pkgsrc/rev/26cbd2795bff
branches:  trunk
changeset: 342484:26cbd2795bff
user:      rillig <rillig%pkgsrc.org@localhost>
date:      Sat Oct 19 19:10:31 2019 +0000

description:
pkgtools/R2pkg: make license handling code simpler

diffstat:

 pkgtools/R2pkg/files/R2pkg.R      |  48 +++++------------------------
 pkgtools/R2pkg/files/R2pkg_test.R |  61 +++++++++++++++++++++++++++++++++++---
 2 files changed, 64 insertions(+), 45 deletions(-)

diffs (154 lines):

diff -r 078f20354528 -r 26cbd2795bff pkgtools/R2pkg/files/R2pkg.R
--- a/pkgtools/R2pkg/files/R2pkg.R      Sat Oct 19 18:47:59 2019 +0000
+++ b/pkgtools/R2pkg/files/R2pkg.R      Sat Oct 19 19:10:31 2019 +0000
@@ -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 @@
   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 @@
   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
 }
diff -r 078f20354528 -r 26cbd2795bff pkgtools/R2pkg/files/R2pkg_test.R
--- a/pkgtools/R2pkg/files/R2pkg_test.R Sat Oct 19 18:47:59 2019 +0000
+++ b/pkgtools/R2pkg/files/R2pkg_test.R Sat Oct 19 19:10:31 2019 +0000
@@ -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('construct.line', {
-# })
-
 test_that('element', {
     mklines <- make_mklines(
         'COMMENT=\tThe comment',
@@ -619,8 +616,60 @@
 # 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