File: test-backport_linter.R

package info (click to toggle)
r-cran-lintr 3.2.0-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 4,396 kB
  • sloc: sh: 13; xml: 10; makefile: 2
file content (85 lines) | stat: -rw-r--r-- 2,498 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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
test_that("backport_linter produces error when R version misspecified", {
  expect_error(
    lint(text = "numToBits(2)", linters = backport_linter(420L)),
    "`r_version` must be an R version number"
  )
})

test_that("backport_linter detects backwards-incompatibility", {
  # default should be current R version; all of these are included on our dependency
  expect_lint(".getNamespaceInfo(dir.exists(lapply(x, toTitleCase)))", NULL, backport_linter())
  expect_lint(".getNamespaceInfo(dir.exists(lapply(x, toTitleCase)))", NULL, backport_linter("release"))
  expect_lint(".getNamespaceInfo(dir.exists(lapply(x, toTitleCase)))", NULL, backport_linter("devel"))

  expect_lint(
    "numToBits(2)",
    rex::rex("numToBits (R 4.1.0) is not available for dependency R >= 4.0.0."),
    backport_linter("4.0.0")
  )
  # symbols as well as calls
  expect_lint(
    "lapply(1:10, numToBits)",
    rex::rex("numToBits (R 4.1.0) is not available for dependency R >= 4.0.0."),
    backport_linter("4.0.0")
  )

  expect_lint(
    trim_some("
      trimws(
        ...names()
      )
    "),
    list(
      list(rex::rex("trimws (R 3.2.0) is not available for dependency R >= 3.0.0."), line_number = 1L),
      list(rex::rex("...names (R 4.1.0) is not available for dependency R >= 3.0.0."), line_number = 2L)
    ),
    backport_linter("3.0.0")
  )

  # oldrel specification
  expect_lint(
    "R_compiled_by()",
    rex::rex("R_compiled_by (R 4.3.0) is not available for dependency R >= 4.2.3."),
    backport_linter("oldrel")
  )

  expect_error(
    backport_linter("oldrel-99"),
    "`r_version` is not valid"
  )

  expect_lint(
    "numToBits(2)",
    rex::rex("numToBits (R 4.1.0) is not available for dependency R >= 4.0.5."),
    backport_linter("oldrel-3")
  )
  # no interference from namespace-qualification (even of base functions)
  expect_lint(
    "base::numToBits(2)",
    rex::rex("numToBits (R 4.1.0) is not available for dependency R >= 4.0.5."),
    backport_linter("oldrel-3")
  )

  # except is honored
  expect_lint(
    trim_some("
      numToBits(2)
      R_user_dir('mypkg')
    "),
    NULL,
    backport_linter("3.0.0", except = c("numToBits", "R_user_dir"))
  )
})

test_that("backport_linter generates expected warnings", {
  tmp <- withr::local_tempfile(lines = "x <- x + 1")

  expect_warning(
    {
      l <- lint(tmp, backport_linter("2.0.0"))
    },
    'version older than "3.0.0"',
    fixed = TRUE
  )
  expect_identical(l, lint(tmp, backport_linter("3.0.0")))
})