tests/testthat/test-generics.R

test_that("diagnostics and report are S3 generics with helpful defaults", {
  expect_true(is.function(diagnostics))
  expect_true(is.function(report))

  expect_true(any(grepl('UseMethod("diagnostics")', deparse(body(diagnostics)),
                        fixed = TRUE)))
  expect_true(any(grepl('UseMethod("report")', deparse(body(report)),
                        fixed = TRUE)))

  expect_error(diagnostics(list(a = 1)),
               "No diagnostics\\(\\) method for objects of class <list>")
  expect_error(report(list(a = 1)),
               "No report\\(\\) method for objects of class <list>")
})

test_that("registered diagnostics and report methods dispatch", {
  registerS3method("diagnostics", "llmr_test_result",
                   function(x, ...) list(surface = "diagnostics", value = x$value),
                   envir = environment(diagnostics))
  registerS3method("report", "llmr_test_result",
                   function(x, ...) list(surface = "report", value = x$value),
                   envir = environment(report))

  x <- structure(list(value = 42L), class = "llmr_test_result")
  expect_identical(diagnostics(x), list(surface = "diagnostics", value = 42L))
  expect_identical(report(x), list(surface = "report", value = 42L))
})

test_that("reset is an S3 generic with a helpful erroring default", {
  expect_true(is.function(reset))
  expect_true(any(grepl('UseMethod("reset")', deparse(body(reset)), fixed = TRUE)))
  expect_error(reset(list(a = 1)),
               "No reset\\(\\) method for objects of class <list>")
})

Try the LLMR package in your browser

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

LLMR documentation built on July 11, 2026, 1:06 a.m.