tests/testthat/test-objective-runtime-option-hoist-contract.R

objective_option_hoist_source <- function() {
  candidates <- c(
    testthat::test_path("..", "..", "src", "jksum.c"),
    testthat::test_path("..", "..", "..", "src", "jksum.c"),
    file.path(Sys.getenv("R_PACKAGE_DIR", ""), "src", "jksum.c"),
    file.path(Sys.getenv("R_PACKAGE_SOURCE", ""), "src", "jksum.c"),
    file.path(getwd(), "src", "jksum.c"),
    file.path(getwd(), "..", "src", "jksum.c")
  )
  candidates <- unique(candidates[nzchar(candidates)])
  hits <- candidates[file.exists(candidates)]
  if (!length(hits))
    return(NULL)
  paste(np_test_read_incumbent_c_source(hits[[1L]], warn = FALSE), collapse = "\n")
}

test_that("LP objectives freeze the Apple acceleration option only per call", {
  text <- objective_option_hoist_source()
  skip_if(is.null(text), "package C sources unavailable")

  expect_match(text, "int runtime_options_frozen;")
  expect_match(
    text,
    "if\\(\\(outer_pack_ctx == NULL\\) \\|\\|\\s*!outer_pack_ctx->runtime_options_frozen\\)"
  )
  expect_match(text, "const NP_OuterPackCtx frozen_runtime_options")
  expect_match(text, "\\.runtime_options_frozen = 1")
  expect_match(text, "&frozen_runtime_options")
  expect_match(text, "&objective_pack_ctx")
  expect_gte(length(regmatches(
    text, gregexpr("&objective_pack_ctx,", text, fixed = TRUE)
  )[[1L]]), 2L)
})

Try the np package in your browser

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

np documentation built on Nov. 25, 2026, 1:06 a.m.