File: test-sarif_output.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 (49 lines) | stat: -rw-r--r-- 1,224 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
test_that("`sarif_output` produces expected error", {
  skip_if_not_installed("jsonlite")

  l <- lint(text = "x = 1", linters = assignment_linter())
  expect_error(sarif_output(l), "Package path needs to be a relative path", fixed = TRUE)
})

test_that("`sarif_output` writes expected files", {
  skip_if_not_installed("jsonlite")

  l <- lint_package(
    test_path("dummy_packages", "missing_dep"),
    linters = object_length_linter(),
    parse_settings = FALSE
  )

  withr::with_tempdir({
    sarif_output(l)
    expect_true(file.exists("lintr_results.sarif"))
  })

  withr::with_tempdir({
    sarif_output(l, filename = "myfile.sarif")
    expect_true(file.exists("myfile.sarif"))
  })
})

test_that("`sarif_output` produces valid files", {
  skip_if_not_installed("jsonlite")

  l <- lint_package(
    test_path("dummy_packages", "clean"),
    linters = default_linters,
    parse_settings = FALSE
  )

  withr::with_tempdir({
    sarif <- sarif_output(l)
    sarif <- jsonlite::fromJSON(
      "lintr_results.sarif",
      simplifyVector = TRUE,
      simplifyDataFrame = FALSE,
      simplifyMatrix = FALSE
    )

    expect_false(is.null(sarif$runs))
    expect_false(is.null(sarif$runs[[1L]]$results))
  })
})