tests/testthat/test_03_show_missing_packages.R

context('show_missing_packages')

test_that('missing packages are found', {
  filename <- 'test_source_show_missing_packages.R'
  test_dir <- 'show_missing_packages'
  temp_dir <- tempdir()
  testpath <- file.path(temp_dir, test_dir)
  filepath <- file.path(testpath, filename)
  dir.create(testpath)

  con <- file(filepath)
  test_source <- 'library(dplyr666)
  # library(notused)
  dplyr667::filter()
  require(dplyr668)'
  writeLines(text = test_source, con = con)

  # check if repo is set, otherwise test is going to fail...
  chooseCRANmirror(graphics=FALSE, ind=1, local.only=TRUE)
  repo <- getOption("repos")
  if (is.null(repo)) {
    repo <- 'https://cloud.R-project.org'
  }

  result <- show_missing_packages(path = testpath, repos = repo)
  close(con)

  expect_equal(nrow(result), 3)
  expect_true(all(result$on_cran) == FALSE)

})

Try the reinstallr package in your browser

Any scripts or data that you put into this service are public.

reinstallr documentation built on Nov. 27, 2021, 9:06 a.m.