Skip to content

test!: migrate custom check() suite to testthat 3e - #64

Open
davidbudzynski wants to merge 1 commit into
fastverse:masterfrom
davidbudzynski:test/54-testthat3-migration
Open

test!: migrate custom check() suite to testthat 3e#64
davidbudzynski wants to merge 1 commit into
fastverse:masterfrom
davidbudzynski:test/54-testthat3-migration

Conversation

@davidbudzynski

Copy link
Copy Markdown
Contributor

Closes #54.

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).

What this PR does

  • DESCRIPTION: add Config/testthat/edition: 3 + Suggests: testthat (>= 3.0.0)
  • New runner tests/testthat.R (test_check("kit"))
  • Split suite into tests/testthat/:
    • test-topn.R, test-iif-nif.R, test-parallel.R (psum/pprod/fpmin/fpmax/prange/pall/pany/pmean), test-share.R (as requested in test!: custom check() never fails - migrate to testthat3 #54), 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()
    • 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() helper (mirrors legacy logic via expect())
    • check(..., error=) -> expect_error(regexp=, fixed=TRUE) (mirrors legacy grep fixed=TRUE substring match)
    • 2 warning cases (0001.068, 0020.001) -> expect_warning(..., fixed=TRUE) + value comparison
  • Legacy IDs preserved as test_that() labels, function-prefixed for uniqueness (topn-0001.001, vswitch-0008.001 vs fpmin-0008.001, etc.). Duplicate legacy IDs (0002.101, 0016.065) get -2 suffix.
  • 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 (replaced by runner). 17 commented-out psort checks from legacy file are omitted (were commented).
  • test-coverage.yaml: no change needed — verified remotes::install_deps(dependencies=TRUE) already picks up Suggests: testthat and covr::codecov() auto-detects tests/testthat.

Verification

  • test_dir("tests/testthat"): 1271 expectations, 0 failures (1268 test_that blocks covering 1269 legacy checks).
  • R CMD check --no-manual --no-vignettes: Running 'testthat.R' ... OK (only pre-existing vignette inst/doc warnings from --no-build-vignettes).
  • Mutation check: temporarily changed topn-0001.001 expected to 999L -> suite fails as expected (Expected topn(...) to be identical to 999L / actual: 5), then restored. Old suite would only cat() and exit 0.

Notes for reviewers

  • expect_kit_equal() is intentionally narrow (31 cases). If we prefer strict waldo for those too, we would need to update expected values (e.g. complex NA imaginary) — left as legacy-tolerant for a green baseline.
  • Happy to split further or rename files if you prefer 1-file-per-function.

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
davidbudzynski marked this pull request as ready for review September 8, 2026 19:34
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