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

Remove TestListResolver#optionallyWildcardFilter #499

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

slawekjaranowski
Copy link
Member

Following this checklist to help us incorporate your
contribution quickly and easily:

  • Make sure there is a JIRA issue filed
    for the change (usually before you start working on it). Trivial changes like typos do not
    require a JIRA issue. Your pull request should address just this issue, without
    pulling in other changes.
  • Each commit in the pull request should have a meaningful subject line and body.
  • Format the pull request title like [SUREFIRE-XXX] - Fixes bug in ApproximateQuantiles,
    where you replace SUREFIRE-XXX with the appropriate JIRA issue. Best practice
    is to use the JIRA issue title in the pull request title and in the first line of the
    commit message.
  • Write a pull request description that is detailed enough to understand what the pull request does, how, and why.
  • Run mvn clean install to make sure basic checks pass. A more thorough check will
    be performed on your pull request automatically.
  • You have run the integration tests successfully (mvn -Prun-its clean install).

If your pull request is about ~20 lines of code you don't need to sign an
Individual Contributor License Agreement if you are unsure
please ask on the developers list.

To make clear that you license your contribution under
the Apache License Version 2.0, January 2004
you have to acknowledge this by using the following check-box.

@slawekjaranowski
Copy link
Member Author

@Tibor17

  • build pass
  • code is more readable for me
  • after review issue will be created

@@ -267,13 +270,16 @@ public void testShouldRunAny()
public void testClassFilter()
{
TestListResolver resolver = new TestListResolver( "#test" );
assertTrue( resolver.shouldRun( "pkg/MyTest.class", null ) );
assertTrue( resolver.shouldRun( "pkg/MyTest.class", "test" ) );
Copy link
Contributor

@Tibor17 Tibor17 Mar 25, 2022

Choose a reason for hiding this comment

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

Don't change the assertions.
It makes whole PR not trusty.

Copy link
Member Author

Choose a reason for hiding this comment

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

try:

        resolver = new TestListResolver( "#abc" );
        assertTrue( resolver.shouldRun( "pkg/MyTest.class", null ) );

        resolver = new TestListResolver( "#test" );
        assertTrue( resolver.shouldRun( "pkg/Abc.class", null ) );

what we verify here?

Copy link
Contributor

Choose a reason for hiding this comment

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

It means that whatever class should run.
This verifies ParentRunner in JUnit4.

If you type resolver.shouldRun( "pkg/Abc.class", "otherMethod" ), it returns false because it verifies the child of ParentRunner. Methods do not match * = Abc but abc !=otherMethod

If shouldRun has null method then we compare classes => ParentRunner, and in this case * matches Abc => true
If shouldRun has non-null method, we evaluate test method.

@@ -401,19 +406,6 @@ public void testInclusiveWithDefaultExclusivePattern()
assertTrue( runnable );
}

public void testWildcard()
Copy link
Contributor

Choose a reason for hiding this comment

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

This use case is still valid and the test should not be removed.

Copy link
Member Author

Choose a reason for hiding this comment

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

but I removed ... #optionallyWildcardFilter so what I should check?

Copy link
Contributor

Choose a reason for hiding this comment

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

@slawekjaranowski
This test would be too simple if we have rewrite optionallyWildcardFilter to **/*.class.

return EMPTY;
}

public final boolean isWildcard()
Copy link
Contributor

Choose a reason for hiding this comment

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

This is still a valid case.
If TLR is empty (nothing) or a wildcard (everything), the provider would ignore TLR. But both corner cases may happen in the config.

Copy link
Member Author

Choose a reason for hiding this comment

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

only one case is true for isWildcard:

        tlr = new TestListResolver( "*.class" );
        assertTrue( tlr.isWildcard() );

@@ -432,7 +430,6 @@ private static boolean hasFilteredOutAllChildren( Description description )

private Filter createMethodFilter()
{
TestListResolver methodFilter = optionallyWildcardFilter( testResolver );
return methodFilter.isEmpty() || methodFilter.isWildcard() ? null : new TestResolverFilter( methodFilter );
return testResolver != null && testResolver.hasMethodPatterns() ? new TestResolverFilter( testResolver ) : null;
Copy link
Contributor

Choose a reason for hiding this comment

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

We are missing methodFilter.isWildcard() in this PR.

Copy link
Contributor

@Tibor17 Tibor17 Mar 25, 2022

Choose a reason for hiding this comment

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

Wildcard class and wildcard method (i.e. *#*, or **/*#*) returns true from hasMethodPatterns()? If it is any wildcard, even this special case, the filter should be returned as null.

Copy link
Member Author

Choose a reason for hiding this comment

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

I removed isWildcard also ...

Test for master code:

        tlr = new TestListResolver( "*.class" );
        assertTrue( tlr.isWildcard() );
        assertFalse( tlr.hasMethodPatterns() );

        tlr = new TestListResolver( "*#*" );
        assertFalse( tlr.isWildcard() );
        assertTrue( tlr.hasMethodPatterns() );

        tlr = new TestListResolver( "**/*#*" );
        assertFalse( tlr.isWildcard() );
        assertTrue( tlr.hasMethodPatterns() );

isWildicard() return true only for *.class

Copy link
Member Author

Choose a reason for hiding this comment

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

In expresion:

        TestListResolver methodFilter = optionallyWildcardFilter( testResolver );
        return methodFilter.isEmpty() || methodFilter.isWildcard() 
             ? null : new TestResolverFilter( methodFilter );

methodFilter.isEmpty() always return false

methodFilter.isWildcard() != methodFilter.hasMethodPatterns() is always true

Copy link
Contributor

Choose a reason for hiding this comment

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

@slawekjaranowski
I know what you mean but the problem is that the expression
methodFilter.isWildcard() != methodFilter.hasMethodPatterns()
talks about implementation behavior.
The whole problem is that we adapt the tests for implementation behavior to pass because we trust the current behavior more than the tests.
Maybe the wildcard was not very properly implemented. Maybe it was, I do not remember, but if we remove some test or method we should compensate it with such strong tests and assertions where we would prove your logical expression. If hasMethodPatterns() is enough, why do not you write unit test asserting isWildcard() != hasMethodPatterns() for wildcards. That's the reason why I started the discussion.
The filter is useless and should be null or should not be used for wildcards and empty method patterns.
Why should we slow down the JUnit or TestNG with wildcard filters or why should we let the filtering mechanism to open some unknown bug?

tlr = new TestListResolver( "*#*" );
assertFalse( tlr.isWildcard() );
assertTrue( tlr.hasMethodPatterns() );

@Tibor17
Copy link
Contributor

Tibor17 commented Apr 19, 2022

Hi @slawekjaranowski ,

I will have time today late evening.

@slawekjaranowski
Copy link
Member Author

Kindly reminder @Tibor17 or someone else ... 😄

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
2 participants