Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support attributes in subtests #14

Open
bitwizeshift opened this issue Mar 16, 2023 · 0 comments
Open

Support attributes in subtests #14

bitwizeshift opened this issue Mar 16, 2023 · 0 comments
Labels
🔨 Enhancement New feature or request

Comments

@bitwizeshift
Copy link
Owner

bitwizeshift commented Mar 16, 2023

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.

@bitwizeshift bitwizeshift added the 🔨 Enhancement New feature or request label Mar 16, 2023
bitwizeshift added a commit that referenced this issue May 22, 2023
The existing `subtest!` syntax was a little foreign to work with due
to the custom `|<ident>|` syntax, which feels a little unnatural for
normal rust. This effectively formed a DSL that does not exist in
other parts of the language in any capacity, and it also posed
challenges for things like introducing attributes for subtests, and
even for IDE intellisense to provide better completion-syntax.

As an alternative, a new syntax of `subtest!(<ident>, <block>)` has been
put forward for testing in this change. This drops the custom `|<ident>|`
naming convention in favor of an explicit ident first-argument, followed
by a true `block` input.

Passing a block here will provide better context for parsing and
general intellisense, and enables more room for future-growth for
supporting things like attributes in subtests as defined in #14.

Existing tests/examples have been updated to reflect the new syntax.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
🔨 Enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

1 participant