-
Notifications
You must be signed in to change notification settings - Fork 186
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
8ae6da6
commit caa26d6
Showing
2 changed files
with
74 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
# 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, | ||
# 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" | ||
|
||
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) | ||
|
||
pkgload::load_all() | ||
|
||
report <- test_dir( | ||
"tests/testthat", | ||
filter = "linter$", | ||
stop_on_failure = FALSE, | ||
reporter = SilentReporter$new() | ||
) | ||
names(report) <- vapply(report, `[[`, "file", FUN.VALUE = character(1L)) | ||
|
||
# Hack the nested structure of the testthat report to identify which files have | ||
# any failed test | ||
failed <- report |> | ||
vapply( | ||
\(x) any(vapply(x$results, inherits, "expectation_failure", FUN.VALUE = logical(1L))), | ||
logical(1L) | ||
) |> | ||
which() |> | ||
names() |> | ||
unique() |> | ||
gsub(pattern = "^test-|\\.R$", replacement = "") | ||
|
||
passed <- setdiff( | ||
available_linters(tags = NULL)$linter, | ||
failed | ||
) | ||
|
||
if (length(passed) > 0L) { | ||
stop("Please add tests of lint metadata for the following linters: ", toString(passed)) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
# Ensure lint metadata is tested | ||
on: | ||
push: | ||
branches: [main] | ||
pull_request: | ||
branches: [main] | ||
|
||
name: ensure-metadata-tests | ||
|
||
jobs: | ||
ensure-metadata-tests: | ||
runs-on: ubuntu-latest | ||
env: | ||
GITHUB_PAT: ${{ secrets.GITHUB_TOKEN }} | ||
|
||
steps: | ||
- uses: actions/checkout@v3 | ||
|
||
- uses: r-lib/actions/setup-r@v2 | ||
with: | ||
r-version: "release" | ||
use-public-rspm: true | ||
|
||
- uses: r-lib/actions/setup-r-dependencies@v2 | ||
- name: Ensure lint metadata is tested | ||
run: | | ||
options(crayon.enabled = TRUE) | ||
callr::rscript(".dev/lint_metadata_test.R") | ||
shell: Rscript {0} |