tests/testthat/test-print.R

mk_result <- function(complete = TRUE) {
  structure(list(
    code = "stop('boom')", original = c("x <- 1", "stop('boom')"),
    n_original = 2L, n_minimal = 1L, oracle_calls = 4L,
    target = list(message = "boom", classes = "simpleError",
                  conditions = list(), failing_index = 2L),
    match = "message", backend = "callr", complete = complete,
    algorithm = "cdd", condition = "error", max_oracle_calls = Inf, trace = NULL
  ), class = "minex_result")
}

test_that("complete result prints without an incomplete note", {
  expect_output(print(mk_result(TRUE)), "reduced to 1")
  expect_output(print(mk_result(TRUE)), "boom")
})

test_that("incomplete result prints an incomplete header and reducible note", {
  out <- capture.output(print(mk_result(FALSE)))
  expect_true(any(grepl("incomplete", out)))
  expect_true(any(grepl("may still be reducible", out)))
})

test_that("print returns its input invisibly", {
  expect_invisible(print(mk_result()))
})

test_that("expression-granularity result prints a char-reduction line", {
  res <- structure(list(
    code = "x |> log('oops')", original = c("x <- 1","result <- x |> rev() |> log('oops')"),
    n_original = 2L, n_minimal = 1L, oracle_calls = 5L,
    target = list(message = "boom", classes = "simpleError", conditions = list(), failing_index = 2L),
    match = "message", backend = "callr", complete = TRUE, algorithm = "cdd",
    condition = "error", max_oracle_calls = Inf, trace = NULL,
    granularity = "expression", n_chars_original = 60L, n_chars_minimal = 16L
  ), class = "minex_result")
  out <- capture.output(print(res))
  expect_true(any(grepl("char", out)))
})

test_that("statement-granularity result does NOT print the char line", {
  res <- structure(list(
    code = "log('x')", original = c("a<-1","log('x')"), n_original = 2L, n_minimal = 1L,
    oracle_calls = 3L, target = list(message="x", classes="simpleError"),
    match = "message", backend = "callr", complete = TRUE, algorithm = "cdd",
    condition = "error", max_oracle_calls = Inf, trace = NULL, granularity = "statement"
  ), class = "minex_result")
  out <- capture.output(print(res))
  expect_false(any(grepl("char", out)))
})

Try the minex package in your browser

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

minex documentation built on Aug. 30, 2026, 1:07 a.m.