File: test-license.R

package info (click to toggle)
r-cran-usethis 3.1.0-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 2,228 kB
  • sloc: sh: 26; makefile: 17; cpp: 6; ansic: 3
file content (50 lines) | stat: -rw-r--r-- 1,509 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
test_that("use_mit_license() works", {
  create_local_package()
  use_mit_license()

  expect_equal(desc::desc_get_field("License"), "MIT + file LICENSE")

  expect_proj_file("LICENSE.md")
  expect_true(is_build_ignored("^LICENSE\\.md$"))

  expect_proj_file("LICENSE")
  expect_false(is_build_ignored("^LICENSE$"))
})

test_that("use_proprietary_license() works", {
  create_local_package()
  use_proprietary_license("foo")

  expect_equal(desc::desc_get_field("License"), "file LICENSE")
  expect_proj_file("LICENSE")
  # TODO add snapshot test
})

test_that("other licenses work without error", {
  create_local_package()

  expect_error(use_agpl_license(3), NA)
  expect_error(use_apache_license(2), NA)
  expect_error(use_cc0_license(), NA)
  expect_error(use_ccby_license(), NA)
  expect_error(use_gpl_license(2), NA)
  expect_error(use_gpl_license(3), NA)
  expect_error(use_lgpl_license(2.1), NA)
  expect_error(use_lgpl_license(3), NA)

  # old fallbacks
  expect_error(use_agpl3_license(), NA)
  expect_error(use_gpl3_license(), NA)
  expect_error(use_apl2_license(), NA)
})

test_that("check license gives useful errors", {
  expect_error(check_license_version(1, 2), "must be 2")
  expect_error(check_license_version(1, 2:4), "must be 2, 3, or 4")
})

test_that("generate correct abbreviations", {
  expect_equal(license_abbr("GPL", 2, TRUE), "GPL (>= 2)")
  expect_equal(license_abbr("GPL", 2, FALSE), "GPL-2")
  expect_equal(license_abbr("Apache License", 2, FALSE), "Apache License (== 2)")
})