Function rustc_builtin_macros::test_harness::mk_main

source ·
fn mk_main(cx: &mut TestCtxt<'_>) -> P<Item>
Expand description

Creates a function item for use as the main function of a test build. This function will call the test_runner as specified by the crate attribute

By default this expands to

#[rustc_main]
pub fn main() {
    extern crate test;
    test::test_main_static(&[
        &test_const1,
        &test_const2,
        &test_const3,
    ]);
}

Most of the Ident have the usual def-site hygiene for the AST pass. The exception is the test_consts. These have a syntax context that has two opaque marks: one from the expansion of test or test_case, and one generated in TestHarnessGenerator::flat_map_item. When resolving this identifier after failing to find a matching identifier in the root module we remove the outer mark, and try resolving at its def-site, which will then resolve to test_const.

The expansion here can be controlled by two attributes:

TestCtxt::reexport_test_harness_main provides a different name for the main function and TestCtxt::test_runner provides a path that replaces test::test_main_static.