igraph / rigraph

igraph R package
https://r.igraph.org
532 stars 200 forks source link

replace all occurrences of expect_that in tests #1331

Closed maelle closed 2 weeks ago

maelle commented 3 months ago

Often they'll be replaceable by expect_equal().

maelle commented 2 months ago
maelle commented 2 months ago
parse_script <- function(path) {

  cli::cli_alert_info("Reading {path}.")

  lines <- brio::read_lines(path)

  xml <- path |>
    parse(keep.source = TRUE) |>
    xmlparsedata::xml_parse_data(pretty = TRUE) |>
    xml2::read_xml()

  deprecated <- xml2::xml_find_all(
    xml,
    ".//SYMBOL_FUNCTION_CALL[text()='expect_that']"
  )

  purrr::map(deprecated, treat_deprecated, path = path) |>
    unlist() |>
    unique()
}

treat_deprecated <- function(xml, path) {
  siblings <- xml2::xml_parent(xml) |> xml2::xml_siblings()
  xml2::xml_text(siblings[[4]])|>
    stringr::str_remove_all("\\(.*")
}

paths <- fs::dir_ls("tests/testthat", regex = "test-")

purrr::map(paths, parse_script) |> unlist() |> unique()