nest_test: Group Parsed Testthat Code into Logical Test Blocks...

View source: R/map_tests_stf.R

nest_testR Documentation

Group Parsed Testthat Code into Logical Test Blocks (Internal)

Description

This internal helper groups parse data from a testthat test file into logical test blocks based on calls to block‑defining functions such as 'context()', 'test_that()', 'describe()', 'it()', or 'tar_test()'. It identifies top‑level expressions that match a given function‑name regex and returns a named list of data frames—one per detected block—trimmed to the relevant code region.

Usage

nest_test(x, token_text = "^context$")

Arguments

x

data.frame. Parse data produced by utils::getParseData(parse(file, keep.source = TRUE), includeText = TRUE). Must include columns such as token, text, parent, and row names that correspond to node ids.

token_text

Character. A regular expression used to select the block‑starting function names (e.g., "^context$", "^test_that$|^describe$|^tar_test$", or "^it$"). Defaults to "^context$".

Details

The function locates top‑level expressions whose function call tokens (SYMBOL_FUNCTION_CALL) match token_text. For each matching block, it:

  • assigns a human‑readable name using the function name and its string constant argument (when available),

  • trims the block to exclude leading parse noise, and

  • returns the subset of x corresponding to that block.

Block names are prefixed with the function (e.g., "test_that: ...", "describe: ...", "it: ...", "tar_test: ...") when the function is recognized.

Value

A named list of data frames, where each element represents the parse rows for a single detected test block. Names encode the block function and label. If no matching blocks are found, an empty list is returned. This structure is consumed by higher‑level STF mapping helpers (e.g., map_test(), map_tests_stf()) to derive expectations, contexts, and line ranges.

See Also

getParseData, map_test, map_tests_stf

Other stf_utility: create_coverage_skip_stf(), map_test(), map_tests_stf(), run_covr_skip_stf()


test.assessr documentation built on March 3, 2026, 1:06 a.m.