Skip to content

Instantly share code, notes, and snippets.

@PietrH
Created June 28, 2024 12:55
Show Gist options
  • Save PietrH/54b88f01ef9198b6e60ec09a7bd2104b to your computer and use it in GitHub Desktop.
Save PietrH/54b88f01ef9198b6e60ec09a7bd2104b to your computer and use it in GitHub Desktop.
Do all exported functions have a corresponding testthat unit test file?
library(magrittr)
exported_functions <-
readr::read_lines("NAMESPACE") %>%
stringr::str_extract("(?<=export\\().+(?=\\))") %>%
.[!is.na(.)]
unit_tests <-
list.files("tests/testthat/") %>%
stringr::str_extract("(?<=test-).+(?=\\.R)") %>%
.[!is.na(.)]
# Do all exported functions have a unit test file named after them?
all(exported_functions %in% unit_tests)
# Which ones do not?
exported_functions[!exported_functions %in% unit_tests]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment