map_test: Map the Structure of Expectations in a Testthat File

View source: R/map_tests_stf.R

map_testR Documentation

Map the Structure of Expectations in a Testthat File

Description

This function parses a single testthat test file and extracts a structured representation of the expectations it contains. It identifies top‑level test blocks (e.g., 'test_that()', 'describe()', 'tar_test()') and any nested expectation blocks (e.g., 'it()'). The result maps expectation location, context, and source line ranges for downstream analysis.

Usage

map_test(path)

Arguments

path

Character. Path to a single test file (typically named 'test-*.R').

Details

The function uses 'utils::getParseData()' to inspect parse information from the test file and constructs a hierarchical mapping of:

  • test block context (e.g., 'describe()', 'test_that()')

  • test labels or sub‑contexts (e.g., 'it()' blocks)

  • expectation type

  • source line ranges associated with each expectation

If the file does not contain any parseable test blocks or expectations, 'NULL' is returned.

Value

A 'data.frame' in which each row corresponds to an expectation identified in the test file. Typical columns include:

description

Context or test block label derived from the test file.

expectation

The expectation type (e.g., 'expect_equal').

linerange

Numeric vector giving the range of lines associated with the expectation.

test

Test label (combined description and nested block label, if applicable).

This structured output is used internally by STF test‑mapping functions (e.g., 'map_tests_stf()') for coverage analysis, skip mapping, and test reporting.

See Also

getParseData

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


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