Skip to content

[core] Pmd7 test cleanups#2807

Merged
oowekyala merged 12 commits into
pmd:pmd/7.0.xfrom
oowekyala:pmd7-test-cleanups
Oct 17, 2020
Merged

[core] Pmd7 test cleanups#2807
oowekyala merged 12 commits into
pmd:pmd/7.0.xfrom
oowekyala:pmd7-test-cleanups

Conversation

@oowekyala

Copy link
Copy Markdown
Member

Describe the PR

Cleanup tests by introducing new utilities, like BaseParsingHelper#executeRule(Rule,String) -> Report. This removes a lot of usage sites of RuleContext, and prepares further refactoring of this object.

This also makes many places in the violation reporting codebase more defensive in requiring their parameters be non-null. Many tests build dysfunctional violations by passing a null node or null file name or whatnot, so these needed to be cleaned up.

ParametricRuleViolation is changed to not require a rule context, but instead a file name. This removes a lot of places where we create a rule context just to set the filename or the language version. The RuleViolationFactory interface is also changed, to only require an implementation of createViolation and suppressOrNull.

The longer-term idea, is to expunge RuleContext of all state, by moving getSourceCodeFile and getLanguageVersion onto the Node interface. Given that, RuleContext doesn't need to store this state, and so has no purpose anymore. I think, we can repurpose it to be the API for rules to report violations. It would basically have the overloads of addViolation that AbstractRule has for now, but clearer. In the end, the idea is for rules to have type-safe access to a RuleContext and report violations directly on it instead of using AbstractRule#addViolation(Object, ...).

Related issues

  • Fixes #

Ready?

  • Added unit tests for fixed bug/feature
  • Passing all unit tests
  • Complete build ./mvnw clean verify passes (checked automatically by travis)
  • Added (in-code) documentation (if needed)

@oowekyala oowekyala added this to the 7.0.0 milestone Sep 28, 2020
@ghost

ghost commented Sep 28, 2020

Copy link
Copy Markdown
1 Warning
⚠️ Running pmdtester failed, this message is mainly used to remind the maintainers of PMD.
✅ Good on 'ya.
No java rules are changed!

Generated by 🚫 Danger

The supported API is now just the junit integration
@oowekyala

Copy link
Copy Markdown
Member Author

@adangel I'm going to remove the API-breaking changes from RuleTst (so that we can decide on that later) and merge this PR this week

@oowekyala oowekyala self-assigned this Oct 17, 2020
@oowekyala oowekyala merged commit 4dee15c into pmd:pmd/7.0.x Oct 17, 2020
@oowekyala oowekyala deleted the pmd7-test-cleanups branch October 17, 2020 16:16
/**
* @deprecated Use {@link #ParametricRuleViolation(Rule, String, Node, String)}
*/
@Deprecated

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Deprecated or DeprecatedUntil700?
If deprecated, we need to merge this back to master -> API change...

Comment thread pmd-core/src/main/java/net/sourceforge/pmd/lang/ParserOptions.java
* arguments to embed in the rule violation message
*/
void addViolation(RuleContext ruleContext, Rule rule, @Nullable Node node, String message, Object[] args);
@Deprecated

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Probably DeprecatedUntil700 as well?

*/
public class ParserOptions {
protected String suppressMarker;
private String suppressMarker = PMD.SUPPRESS_MARKER;

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I think, we should deprecate this field on master...

adangel added a commit that referenced this pull request Oct 22, 2020
@oowekyala oowekyala added the in:testing About tests of pmd, eg the module pmd-lang-test or pmd-test [test] label Feb 19, 2021
@adangel adangel mentioned this pull request Jan 23, 2023
55 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

in:testing About tests of pmd, eg the module pmd-lang-test or pmd-test [test]

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants