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

Refactor AbstractModuleTestSupport and InlineConfigParser to support XML configs in Input files without extra detalization on modules #14653

Closed
romani opened this issue Mar 12, 2024 · 2 comments

Comments

@romani
Copy link
Member

romani commented Mar 12, 2024

detected at https://github.com/checkstyle/checkstyle/pull/14462/files#r1521442922

When we use full XML config in header comment, we parse it, split by modules, and later on assemble back to DefaultConfiguration

parsing of full XML:

if (isXmlConfig) {
            final String stringXmlConfig = LATEST_DTD + String.join("", inlineConfig);
            final InputSource inputSource = new InputSource(new StringReader(stringXmlConfig));
            final Configuration xmlConfig = ConfigurationLoader.loadConfiguration(
                inputSource, new PropertiesExpander(System.getProperties()),
                    ConfigurationLoader.IgnoredModulesOptions.EXECUTE
            );

resulted config is fully ready to be used in validation execution.

problem comes from createConfigurationWithoutFilters and other methods that are used not in general tests but in Filter tests:
https://github.com/checkstyle/checkstyle/blob/master/src/test/java/com/puppycrawl/tools/checkstyle/AbstractModuleTestSupport.java

    protected final void verifyFilterWithInlineConfigParser(String filePath,
                                                            String[] expectedUnfiltered,
                                                            String... expectedFiltered)
            throws Exception {
        final TestInputConfiguration testInputConfiguration =
                InlineConfigParser.parseWithFilteredViolations(filePath);
        final DefaultConfiguration configWithoutFilters =
                testInputConfiguration.createConfigurationWithoutFilters();
        final List<TestInputViolation> violationsWithoutFilters =
                new ArrayList<>(testInputConfiguration.getViolations());
        violationsWithoutFilters.addAll(testInputConfiguration.getFilteredViolations());
        Collections.sort(violationsWithoutFilters);
        verifyViolations(configWithoutFilters, filePath, violationsWithoutFilters);
        verify(configWithoutFilters, filePath, expectedUnfiltered);
        final DefaultConfiguration configWithFilters =
                testInputConfiguration.createConfiguration();

Detailed slicing and dicing by modules was required for property config in this case we need to recreate config and do bunch of assumptions on Checker and Treewalker. But in XML config all detals are provided, just use it as is.

Expected:
this code should not do any extra operations on config, and after parsing from xml should be used as is.

protected final void verifyWithInlineConfigParser(String filePath, String... expected)
throws Exception {
final TestInputConfiguration testInputConfiguration =
InlineConfigParser.parse(filePath);
final DefaultConfiguration parsedConfig =
testInputConfiguration.createConfiguration();
verifyViolations(parsedConfig, filePath, testInputConfiguration.getViolations());

instead of createConfiguration() we should have simple getConfiguration()

@Lmh-java
Copy link
Contributor

I am working on it

@romani
Copy link
Member Author

romani commented Mar 16, 2024

fix is merged

@romani romani closed this as completed Mar 16, 2024
@github-actions github-actions bot added this to the 10.14.2 milestone Mar 16, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants