Skip to content

Commit

Permalink
Issue #13809: Kill mutation ConfigurationLoader2
Browse files Browse the repository at this point in the history
  • Loading branch information
Kevin222004 authored and rnveach committed Nov 7, 2023
1 parent cb933fd commit ab7ac57
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 9 deletions.
9 changes: 0 additions & 9 deletions config/pitest-suppressions/pitest-common-suppressions.xml
Original file line number Diff line number Diff line change
Expand Up @@ -27,15 +27,6 @@
<lineContent>this.severity = SeverityLevel.getInstance(severity);</lineContent>
</mutation>

<mutation unstable="false">
<sourceFile>ConfigurationLoader.java</sourceFile>
<mutatedClass>com.puppycrawl.tools.checkstyle.ConfigurationLoader</mutatedClass>
<mutatedMethod>replaceProperties</mutatedMethod>
<mutator>org.pitest.mutationtest.engine.gregor.mutators.NonVoidMethodCallMutator</mutator>
<description>removed call to java/lang/StringBuilder::length</description>
<lineContent>sb.replace(0, sb.length(), defaultValue);</lineContent>
</mutation>

<mutation unstable="false">
<sourceFile>LocalizedMessage.java</sourceFile>
<mutatedClass>com.puppycrawl.tools.checkstyle.LocalizedMessage</mutatedClass>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -769,4 +769,24 @@ public void testLoadConfiguration3() throws Exception {
.contains("query");
}
}

@Test
public void testDefaultValuesForNonDefinedProperties() throws Exception {
final Properties props = new Properties();
props.setProperty("checkstyle.charset.base", "UTF");

final File file = new File(
getPath("InputConfigurationLoaderDefaultProperty.xml"));
final DefaultConfiguration config =
(DefaultConfiguration) ConfigurationLoader.loadConfiguration(
file.toURI().toString(), new PropertiesExpander(props));

final Properties expectedPropertyValues = new Properties();
expectedPropertyValues.setProperty("tabWidth", "2");
expectedPropertyValues.setProperty("basedir", ".");
// charset property uses 2 variables, one is not defined, so default becomes a result value
expectedPropertyValues.setProperty("charset", "ASCII");
verifyConfigNode(config, "Checker", 0, expectedPropertyValues);
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<?xml version="1.0" encoding="UTF-8"?>

<!DOCTYPE module PUBLIC
"-//Checkstyle//DTD Checkstyle Configuration 1.3//EN"
"https://checkstyle.org/dtds/configuration_1_3.dtd">

<module name="Checker">
<property name="tabWidth" value="${checkstyle.tabsize}" default="2"/>
<property name="basedir" value="src/${checkstyle.baseDirectory}" default="."/>
<property name="charset"
value="${checkstyle.charset.base}-${checkstyle.charset.number}" default="ASCII"/>

</module>
5 changes: 5 additions & 0 deletions src/xdocs/config.xml
Original file line number Diff line number Diff line change
Expand Up @@ -244,6 +244,11 @@
&lt;/module&gt;
</source>

<p>
ATTENTION: default value is applied to module property value if at least one expansion
property is not defined.
</p>

<p>
This feature is a great help when setting up a centralized
configuration file (e.g. one file for the whole company) to
Expand Down

0 comments on commit ab7ac57

Please sign in to comment.