File: test-api.R

package info (click to toggle)
r-cran-pkgconfig 2.0.3-2
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, bullseye, forky, sid, trixie
  • size: 144 kB
  • sloc: sh: 13; makefile: 2
file content (40 lines) | stat: -rw-r--r-- 1,000 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40

context("Creating a custom API")

test_that("We can create a custom API", {

  on.exit(try(disposables::dispose_packages(pkgs)))
  pkgs <- disposables::make_packages(

    utility123456 = {
      set_opt <- function(...) {
        pars <- list(...)
        names(pars) <- paste0("utility123456::", names(pars))
        do.call(pkgconfig::set_config_in,
                c(pars, list(.in = parent.frame())))
      }
      
      get_opt <- function(key) {
        real_key <- paste0("utility123456::", key)
        pkgconfig::get_config(real_key)
      }
    },

    pkgA = {
      setter <- function() { utility123456::set_opt(key4 = "value_A") }
      getter <- function() { utility123456::get_opt("key4") }
    },

    pkgB = {
      setter <- function() { utility123456::set_opt(key4 = "value_B") }
      getter <- function() { utility123456::get_opt("key4") }
    }
  )

  pkgA::setter()
  pkgB::setter()

  expect_equal(pkgA::getter(), "value_A")
  expect_equal(pkgB::getter(), "value_B")
  
})