Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/ensure-metadata' into ensure-met…
Browse files Browse the repository at this point in the history
…adata
  • Loading branch information
MichaelChirico committed Dec 6, 2023
2 parents 586e4ff + a73f80a commit cfea37f
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 14 deletions.
30 changes: 18 additions & 12 deletions .dev/lint_metadata_test.R
Original file line number Diff line number Diff line change
@@ -1,17 +1,24 @@
# This script is designed to find linters that lack metadata tests.
# To do so, it forces xml_nodes_to_lints() to give the wrong information,
# To do so, it forces Lint() to give the wrong information,
# runs the test suite, and finds linters that nevertheless pass all their tests.
library(testthat)

xml_nodes_to_lints_file <- "R/xml_nodes_to_lints.R"
lint_file <- "R/lint.R"

xml_nodes_to_lints_file |>
readLines() |>
sub(
pattern = "line_number = as.integer(line1)",
replacement = "line_number = as.integer(2^31 - 1)"
) |>
writeLines(xml_nodes_to_lints_file)
original <- readLines(lint_file)
expected_line <- "line_number = as.integer(line_number)"
if (!any(grepl(expected_line, original, fixed = TRUE))) {
stop(sprintf(
"Please update this workflow -- didn't find expected line '%s' in file '%s'.",
expected_line, lint_file
))
}
writeLines(
sub(expected_line, "line_number = as.integer(2^31 - 1)", original, fixed = TRUE),
lint_file
)
# Not useful in CI but good when running locally.
withr::defer(writeLines(original, lint_file))

pkgload::load_all()

Expand All @@ -21,7 +28,7 @@ report <- test_dir(
stop_on_failure = FALSE,
reporter = SilentReporter$new()
)
names(report) <- vapply(report, `[[`, "file", FUN.VALUE = character(1L))
names(report) <- gsub("^test-|\\.R$", "", vapply(report, `[[`, "file", FUN.VALUE = character(1L)))

# Hack the nested structure of the testthat report to identify which files have
# any failed test
Expand All @@ -32,8 +39,7 @@ failed <- report |>
) |>
which() |>
names() |>
unique() |>
gsub(pattern = "^test-|\\.R$", replacement = "")
unique()

passed <- setdiff(
available_linters(tags = NULL)$linter,
Expand Down
1 change: 1 addition & 0 deletions .github/workflows/ensure-metadata-tests.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ jobs:
use-public-rspm: true

- uses: r-lib/actions/setup-r-dependencies@v2

- name: Ensure lint metadata is tested
run: |
options(crayon.enabled = TRUE)
Expand Down
4 changes: 2 additions & 2 deletions tests/testthat/test-absolute_path_linter.R
Original file line number Diff line number Diff line change
Expand Up @@ -197,9 +197,9 @@ test_that("lints vectorize", {
'~'
}"),
list(
list(lint_msg, line_number = 1L),
list(lint_msg, line_number = 2L),
list(lint_msg, line_number = 4L)
list(lint_msg, line_number = 3L),
list(lint_msg, line_number = 5L)
),
absolute_path_linter(lax = FALSE)
)
Expand Down

0 comments on commit cfea37f

Please sign in to comment.