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

test(rules): rstest framework #39

Merged
merged 4 commits into from
Jul 19, 2024
Merged

test(rules): rstest framework #39

merged 4 commits into from
Jul 19, 2024

Conversation

supermaxiste
Copy link
Member

Proposed Changes

Replaced previous rule tests with new tests following the rstest framework. Now we have 1 test function per rule, with each function testing different scenarios.
Example of previous code structure:

#[test]
    fn rule1_example1() {
    mask = rule1(example1)
    assert!(mask.is_set())
}
#[test]
    fn rule1_example2() {
    mask = rule1(example2)
    assert!(mask.is_set())
}

Example of ✨ new ✨ code structure:

#[rstest]
#[case(example1)]
#[case(example2)]
   fn rule1(case)  {
   mask = rule1(case)
   assert!(mask.is_set())
}

Addresses #25

Types of Changes

  • A bug fix (non-breaking change which fixes an issue).
  • A new feature (non-breaking change which adds functionality).
  • A breaking change (fix or feature that would cause existing
    functionality to not work as expected).
  • A non-productive update (documentation, tooling, etc. if none of the
    other choices apply).

Checklist

  • I have read the
    CONTRIBUTING
    guidelines.
  • I have added tests that prove my fix is effective or that my feature
    works.
  • I have added the necessary documentation (if appropriate).

@supermaxiste supermaxiste added the enhancement New feature or request label Jul 16, 2024
@supermaxiste supermaxiste self-assigned this Jul 16, 2024
@cmdoret cmdoret changed the title feat: rstest framework for rule tests test(rules): rstest framework Jul 16, 2024
Copy link
Member

@cmdoret cmdoret left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is much better and a perfect fit for this use-case!

I proposed to remove constant arguments with the objective of improving readability. Let me know if you think this is not a good idea.

src/rules.rs Outdated Show resolved Hide resolved
src/rules.rs Outdated Show resolved Hide resolved
src/rules.rs Show resolved Hide resolved
@supermaxiste
Copy link
Member Author

Thank you @cmdoret and very good suggestion!

For 2 out of 3 rules I left a simple assert and removed the argument that were constant across cases 👍
For the type_rule we do test both subjects and objects being either masked or not, so I left the cases as they are.

Copy link
Member

@cmdoret cmdoret left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🙌

@cmdoret cmdoret merged commit bdd2f85 into main Jul 19, 2024
7 checks passed
@cmdoret cmdoret deleted the feat/rule-tests branch July 19, 2024 09:10
@cmdoret cmdoret linked an issue Jul 26, 2024 that may be closed by this pull request
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

Successfully merging this pull request may close these issues.

Test tables
2 participants