Skip to content

test!: migrate custom check() suite to tinytest - #65

Merged
davidbudzynski merged 32 commits into
fastverse:masterfrom
davidbudzynski:test/54-tinytest-migration
Sep 20, 2026
Merged

davidbudzynski merged 32 commits into
fastverse:masterfrom
davidbudzynski:test/54-tinytest-migration

Conversation

@davidbudzynski

Copy link
Copy Markdown
Collaborator

Closes #54. Supersedes #64 (testthat 3e approach pivoted to tinytest — rationale in #54 (comment)).

Problem

tests/test_kit.R:7-34 defined check(test,x,y,error,warning) that only did cat("Check ... failed.\n") with no stop()/stopifnot(). Result: R CMD check always green even with regressions (1286 silent checks).

Why tinytest instead of testthat

  • kit is lean C code, zero Imports, R >= 3.1.0. tinytest is zero-dependency, R >= 3.0; testthat 3.x is ~15k lines + 22 deps and needs R >= 4.1.
  • This suite needs nothing testthat-only (expect_identical / expect_error / tolerant numeric compares; no snapshots, mocking, or reporters).
  • Tests ship in inst/tinytest/ and stay runnable post-install via tinytest::test_package("kit") — useful for a compiled package.
  • covr is framework-agnostic, so test-coverage.yaml needs no change.

What this PR does

  • DESCRIPTION: Suggests: tinytest (drop testthat + Config/testthat/edition)
  • New runner tests/tinytest.R (tinytest::test_package("kit"))
  • New suite in inst/tinytest/ (29 atomic commits, 1 file each):
    • test-topn.R, test-iif-nif.R, test-parallel.R (psum/pprod/fpmin/fpmax/prange/pall/pany/pmean), test-share.R, plus test-fpos.R, test-setlevels.R, test-vswitch-nswitch.R, test-count.R, test-unique.R, test-psort.R, test-charToFact.R, test-pfirst-plast.R, helper-kit.R
  • Mapping:
    • check(id, expr, expected) -> expect_identical(..., info="id") (test_that wrappers unwrapped, legacy IDs as info= labels, function-prefixed for uniqueness)
    • 31 tolerant cases where identical() is FALSE but legacy all.equal()+typeof() is TRUE (complex NA imaginary NA vs 0, C-vs-R floating-point order in pmean/pprod/vswitch) -> expect_kit_equal(..., info="id") helper (mirrors legacy logic via expect_true)
    • check(..., error=) -> expect_error(pattern=, fixed=TRUE, info="id") (mirrors legacy grep fixed=TRUE substring match)
    • 2 warning cases (0001.068, 0020.001) -> expect_warning(..., fixed=TRUE) + value comparison
    • skip_if (shareData) -> exit_file
  • Setup and expectations stay interleaved in legacy order (later sections redefine x/y/out_vec, so setup is not hoisted).
  • Delete legacy tests/test_kit.R. 17 commented-out psort checks from the legacy file are omitted (were commented).
  • test-coverage.yaml: no change needed — covr::codecov() auto-detects tests/tinytest.R.

Verification

  • Rscript tests/tinytest.R: All ok, 1271 results, 0 failures (parity with the testthat conversion in test!: migrate custom check() suite to testthat 3e #64).
  • Mutation check: 3 deliberately wrong expectations (identical, tolerant-helper, error-pattern) -> all 3 detected with legacy-ID labels. Old suite would only cat() and exit 0.
  • R CMD check --no-manual --no-build-vignettes on built tarball: Running 'tinytest.R' ... OK (only pre-existing vignette inst/doc warnings from --no-build-vignettes/missing pandoc).
  • Tarball ships inst/tinytest/; tinytest::test_package("kit") on the installed package: 1271/1271 pass.

Notes for reviewers

  • helper-kit.R must be loaded with sys.source("helper-kit.R", envir = environment()), not source() — plain source() evaluates in globalenv() where tinytest's recording expect_* aren't visible (noted in the file).
  • expect_kit_equal() is intentionally narrow (31 cases). If we prefer strict comparison for those too, we would need to update expected values (e.g. complex NA imaginary) — left as legacy-tolerant for a green baseline.

Legacy tests/test_kit.R defined check() that only cat()ed on failure
and never called stop(), so R CMD check stayed green despite
regressions (1286 silent checks).

- Add Config/testthat/edition: 3 + Suggests testthat (>= 3.0.0)
- Split into tests/testthat/test-topn.R, test-iif-nif.R,
  test-parallel.R, test-share.R, plus per-area files
  (fpos, setlevels, vswitch-nswitch, count, unique, psort,
  charToFact, pfirst-plast) with helper-kit.R
- Map check(id, expr, expected) -> expect_identical(), 31 tolerant
  cases (identical FALSE but all.equal+typeof TRUE) -> expect_kit_equal(),
  check(..., error=) -> expect_error(regexp=, fixed=TRUE),
  warning cases -> expect_warning() + value comparison
- Preserve legacy IDs as test_that labels (function-prefixed for
  uniqueness) and keep setup interleaved (later sections redefine
  x/y/out_vec)
- Delete legacy tests/test_kit.R (replaced by tests/testthat.R runner)
- Verified: test_dir passes (1271 expectations, 0 failures);
  R CMD check runs testthat.R OK; deliberately mutated topn return
  fails as expected (topn-0001.001)

Closes fastverse#54
@davidbudzynski

Copy link
Copy Markdown
Collaborator Author

All 11 checks green now. Note the latest commit (ci: install knitr from source on macOS) is unrelated to the tinytest migration — it works around an upstream issue: knitr 1.52 (released 2026-09-06) has no usable macOS binary right now (PPM serves a zstd-compressed .tgz that pak can't extract, CRAN mirrors 404). The macOS job failed 3x in dependency setup before any test ran. The step is marked TEMPORARY in the workflow and should be reverted once upstream publishes a readable binary.

@davidbudzynski
davidbudzynski merged commit dcfafbe into fastverse:master Sep 20, 2026
11 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

test!: custom check() never fails - migrate to testthat3

1 participant