dwww Home | Show directory contents | Find package

test_that("extracts typical library()/require() calls", {
  expect_equal(extract_package_attach_(library("blah")), "blah")
  expect_equal(extract_package_attach_(library(blah)), "blah")
  expect_equal(extract_package_attach_(require("blah")), "blah")
  expect_equal(extract_package_attach_(require(blah)), "blah")
})

test_that("detects in nested code", {
  expect_equal(extract_package_attach_({
    library(a)
    x <- 2
    {
      library(b)
      y <- 3
      {
        library(c)
        z <- 4
      }
    }
  }), c("a", "b", "c"))
})

test_that("handles expressions", {
  # which will usually come from parse()d code
  #
  x <- expression(
    x <- 1,
    library("a"),
    y <- 2,
    library("b")
  )
  expect_equal(extract_package_attach(x), c("a", "b"))
})

test_that("detects with non-standard arg order", {
  expect_equal(extract_package_attach_(library(quiet = TRUE, pa = "a")), "a")
  expect_equal(extract_package_attach_(library(quiet = TRUE, a)), "a")
})

test_that("doesn't include if character.only = TRUE", {
  expect_equal(
    extract_package_attach_(library(x, character.only = TRUE)),
    character()
  )
})

test_that("adds packages attached by dependencies", {
  skip_if_not_installed("ggraph")
  expect_true("ggplot2" %in% add_depends("ggraph"))
})

test_that("adds tidyverse packages", {
  skip_if_not_installed("tidyverse")
  expect_true("ggplot2" %in% add_depends("tidyverse"))
})

Generated by dwww version 1.15 on Sat May 18 10:37:13 CEST 2024.