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

CheckstyleTestMakeup: allow getModuleConfigsByIds #890

Open
rnveach opened this issue May 14, 2022 · 2 comments
Open

CheckstyleTestMakeup: allow getModuleConfigsByIds #890

rnveach opened this issue May 14, 2022 · 2 comments

Comments

@rnveach
Copy link
Contributor

rnveach commented May 14, 2022

Identified at checkstyle/checkstyle#11585 ,

$ cat TestClass.java
import static com.puppycrawl.tools.checkstyle.checks.blocks.RightCurlyCheck.MSG_KEY_LINE_ALONE;
import static com.puppycrawl.tools.checkstyle.checks.blocks.RightCurlyCheck.MSG_KEY_LINE_BREAK_BEFORE;
import static com.puppycrawl.tools.checkstyle.checks.blocks.RightCurlyCheck.MSG_KEY_LINE_SAME;

import org.junit.jupiter.api.Test;

import com.google.checkstyle.test.base.AbstractGoogleModuleTestSupport;
import com.puppycrawl.tools.checkstyle.api.Configuration;
import com.puppycrawl.tools.checkstyle.checks.blocks.RightCurlyCheck;
import com.puppycrawl.tools.checkstyle.utils.CommonUtil;

public class TestClass extends AbstractGoogleModuleTestSupport {

    private static final String[] MODULES = new String[] {
            "RightCurlySame", "RightCurlyAlone"
    };

    @Override
    protected String getPackageLocation() {
        return "com/google/checkstyle/test/chapter4formatting/rule412nonemptyblocks";
    }

    @Test
    public void testRightCurlyAlone() throws Exception {
        final String[] expected = {
            "20:17: " + getCheckMessage(RightCurlyCheck.class, MSG_KEY_LINE_SAME, "}", 17),
            "32:13: " + getCheckMessage(RightCurlyCheck.class, MSG_KEY_LINE_SAME, "}", 13),
            "79:27: " + getCheckMessage(RightCurlyCheck.class, MSG_KEY_LINE_BREAK_BEFORE, "}", 27),
            "97:5: " + getCheckMessage(RightCurlyCheck.class, MSG_KEY_LINE_ALONE, "}", 5),
            "108:5: " + getCheckMessage(RightCurlyCheck.class, MSG_KEY_LINE_ALONE, "}", 5),
        };

        final Configuration checkConfig = createTreeWalkerConfig(getModuleConfigsByIds(MODULES)); // violation
        final String filePath = getPath("InputRightCurlyOther.java");

        final Integer[] warnList = getLinesWithWarn(filePath);
        verify(checkConfig, filePath, expected, warnList);
    }
}

$ cat TestConfig.xml
<?xml version="1.0"?>
<!DOCTYPE module PUBLIC
          "-//Puppy Crawl//DTD Check Configuration 1.3//EN"
          "https://checkstyle.org/dtds/configuration_1_3.dtd">

<module name="Checker">
    <property name="charset" value="UTF-8"/>

    <module name="TreeWalker">
<module name="com.github.sevntu.checkstyle.checks.design.CheckstyleTestMakeupCheck" />
    </module>
</module>

$ java -jar checkstyle-9.1-sevntu-1.40.0-all.jar -c TestConfig.xml TestClass.java
Starting audit...
[ERROR] TestClass.java:33:41: DefaultConfiguration was not assigned by an allowed create configuration method. [CheckstyleTestMakeup]
Audit done.
Checkstyle ends with 1 errors.

No violations should be printed.

@rnveach rnveach added approved and removed approved labels May 14, 2022
@rnveach
Copy link
Contributor Author

rnveach commented May 14, 2022

I am holding off on approving for some of test restructuring to be merged to come back and see if parts of the test code can be made a bit simpler.

@rnveach
Copy link
Contributor Author

rnveach commented May 16, 2022

A new version will be coming to the main repo. I made a simplified:
final Configuration checkConfig = getModuleConfigById(MODULES);

We should just add getModuleConfigById as an approved method.

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

No branches or pull requests

1 participant