Skip to content

Support attributes in subtests #14

@bitwizeshift

Description

@bitwizeshift

The current mechanism for subtests simply acts as a series of statements defined in a subtest! { ... } macro. Although this functionally works, it suffers the significant drawback that it is unable to have custom attributes specified -- such as #[should_panic]or#[ignore]`, which are needed for testing.

It's unclear what the best direction forward for this is. A couple thoughts come to mind:

  • Extend the DSL to support [<attribute>] syntax, e.g. subtest! { |name| [should_panic][ignore] ... }, this is kind of gross -- but would work.
  • Change the syntax entirely; perhaps using function definitions instead:
    #[neotest::test]
    fn test_vec_index() {
        let vec: Vec<u8> = Vec::default();
    
        #[neotest::subtest]
        #[should_panic]
        fn out_of_bounds_panics() {
            vec[20];
        }
    }
    The downside to this approach is that it's not clear that vec is within fn out_of_bounds_panics() scope, since this typically is not a true closure. The upside is that this has a clear mechanism for identifying attributes, the test ident, etc.

The exact approach is yet to be determined.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions