File: test-ci.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 (62 lines) | stat: -rw-r--r-- 2,167 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
test_that("GitHub Actions functionality works", {
  withr::local_envvar(list(GITHUB_ACTIONS = "true", IN_PKGDOWN = "false"))
  withr::local_options(lintr.rstudio_source_markers = FALSE)
  tmp <- withr::local_tempfile(lines = "x <- 1:nrow(y)")

  l <- lint(tmp)
  expect_output(print(l), "::warning file", fixed = TRUE)
})

test_that("GitHub Actions functionality works in a subdirectory", {
  pkg_path <- test_path("dummy_packages", "assignmentLinter")
  withr::local_envvar(list(GITHUB_ACTIONS = "true"))
  withr::local_options(lintr.rstudio_source_markers = FALSE, lintr.github_annotation_project_dir = pkg_path)

  l <- lint_package(
    pkg_path,
    linters = list(assignment_linter()),
    parse_settings = FALSE
  )
  expect_output(
    print(l),
    paste0("::warning file=", file.path(pkg_path, "R(/|\\\\)abc\\.R"))
  )
})

patrick::with_parameters_test_that(
  "GitHub Actions - error on lint works",
  {
    withr::local_envvar(list(GITHUB_ACTIONS = "true", IN_PKGDOWN = "", LINTR_ERROR_ON_LINT = env_var_value))
    withr::local_options(lintr.rstudio_source_markers = FALSE)
    tmp <- withr::local_tempfile(lines = "x <- 1:nrow(y)")

    l <- lint(tmp)

    local_mocked_bindings(quit = function(...) cat("Tried to quit.\n"))
    expect_output(print(l), "::warning file", fixed = TRUE)
  },
  env_var_value = list("T", "true")
)

patrick::with_parameters_test_that(
  "GitHub Actions - env var for error on lint is converted to logical",
  {
    withr::local_envvar(list(GITHUB_ACTIONS = "true", LINTR_ERROR_ON_LINT = env_var_value))
    withr::local_options(lintr.rstudio_source_markers = FALSE)
    tmp <- withr::local_tempfile(lines = "x <- 1:nrow(y)")

    l <- lint(tmp)

    expect_output(print(l), "::warning file", fixed = TRUE)
  },
  env_var_value = list("", "F", NA, NULL)
)

test_that("GitHub Actions log is skipped in pkgdown websites", {
  withr::local_envvar(list(GITHUB_ACTIONS = "true", IN_PKGDOWN = "true"))
  withr::local_options(lintr.rstudio_source_markers = FALSE)
  tmp <- withr::local_tempfile(lines = "x <- 1:nrow(y)")

  l <- lint(tmp, linters = seq_linter())
  expect_output(print(l), "warning: [seq_linter]", fixed = TRUE)
})