Comments (11)
This feature is implemented in #1310. In the next release it will be possible to filter these mutations out by adding the filter string "+funmodifiablecollection"
from pitest.
@hcoles , please share link to some doc or please share how to use ? Or where to put "+funmodifiablecollection" ? We use maven.
Thanks a lot in advance.
May be this https://pitest.org/quickstart/maven/#features ?
from pitest.
Some internal immutable collection is good for engineers express intend, such details might not be easily testable from public methods.
I think it is same level of restrictions that engineers use by placing final
on variable, it is signal for compiler or other engineers that mutation is not recommended or not expected.
Avoiding reporting of survivals would be awesome, may be by options or specific mutator or ....
from pitest.
@hcoles , one more fix is required
Please look at checkstyle/checkstyle#14484 (comment)
Look like you covered the only when code is return ....;
from pitest.
The filter is restricted to direct returns wrapping return values in this way is wide spread idiom where it might be reasonably argued that writing tests to confirm the behaviour isn't a productive use of time. A failure to wrap a return value can be detected by static an analysis rather than a test.
Filtering the calls in other places makes less sense as it means pitest would not highlight redundant code.
The example code in your link
public List<Token> getHiddenBefore() {
List<Token> returnList = null;
if (hiddenBefore != null) {
returnList = Collections.unmodifiableList(hiddenBefore);
}
return returnList;
}
Could be more clearly expressed as
public List<Token> getHiddenBefore() {
if (hiddenBefore != null) {
return Collections.unmodifiableList(hiddenBefore);
}
return hiddenBefore;
}
Or
public List<Token> getHiddenBefore() {
if (hiddenBefore == null) {
return null;
}
return Collections.unmodifiableList(hiddenBefore);
}
To emphasize that the method may return null.
from pitest.
there is another evil "single return from method" , but we refactored it to java8 style of code to reconcile.
I pretty sure there will be numerous examples where usage of unmodifiableList
without return is reasonable.
ok, what about code like (link):
public void setHiddenBefore(List<Token> hiddenBefore) {
this.hiddenBefore = Collections.unmodifiableList(hiddenBefore);
}
from pitest.
still mutation survival:
https://github.com/checkstyle/checkstyle/actions/runs/7916871513/job/21611685470?pr=14484#step:6:458
Source File: "DetailAstImpl.java"
Class: "com.puppycrawl.tools.checkstyle.DetailAstImpl"
Method: "getHiddenAfter"
Line Contents: ".map(Collections::unmodifiableList)"
Mutator: "org.pitest.mutationtest.engine.gregor.mutators.experimental.NakedReceiverMutator"
Description: "replaced call to java/util/Optional::map with receiver"
Line Number: 514
java:
return Optional.ofNullable(hiddenBefore)
.map(Collections::unmodifiableList)
.orElse(null);
from pitest.
public void setHiddenBefore(List<Token> hiddenBefore) {
this.hiddenBefore = Collections.unmodifiableList(hiddenBefore);
}
Wrapping on write is a common idiom, and I agree it would make sense to filter this.
Patterns such as creating an Optional in order to avoid writing an if statement, are not so common and it makes sense for pitest to continue to highlight code not justified by a test in these constructs.
If you wish to avoid mutating calls to unmodifiableList etc completely I think this would be better dealt with by a general purpose "don't mutate this" parameter similar to avoidCallTo.
from pitest.
Do you already have parameter by which we config pitest to skip mutation over unmodifiableList
at all ?
avoidCallTo do no mutation inside method, but still mutate call of method.
from pitest.
avoidCallsTo would work, but it works at the class level, so you have to filter out calls to everything in java.util.Collections.
Filtering out calls to individual methods would need a new parameter.
from pitest.
yes, you are right, we already use avoidCallsTo for classes.
https://github.com/checkstyle/checkstyle/blob/c1ca1b903beaed94923f621fac2197394ae011dd/pom.xml#L3079-L3082
but did not want to exclude all methods from this class, as it has bunch of other methods like sort/...... that is better to question their necessity in main code.
that is why we created new class as wrapper to suppress only unmodifiableXxxx. It would be awesome to let users suppress more granular for specific method of class.
from pitest.
Related Issues (20)
- does not allow performance optimization in logic HOT 1
- Copy of array(collections) to protect data from changes HOT 1
- Support targeting different JUnit TestEngines using PIT HOT 3
- PIT cannot detect tests and classes when package starts with "com" HOT 11
- code might be less elegant if chained call of cast to type is present
- Mutating non-existing lines in Kotlin HOT 3
- Issue in build pulling in old version of java HOT 1
- Conditionals with `isDebugEnabled`
- `avoidCallsTo` not working for internal classes
- Joda-Time Mutation testing requires a green suite Error HOT 1
- Caused by: org.pitest.util.PitError: Coverage generation minion exited abnormally! (MINION_DIED)
- How can i kill this mutation HOT 2
- Allow reusing surefire environmentVariables for pitest HOT 3
- Mutation Coverage failure w/ AspectJ compile-time weaving plus woven deps HOT 1
- PIT Help Error : Couldn't exclude classes / test classes - error - tests did not pass without mutation when calculating line coverage. Mutation testing requires a green suite. HOT 3
- Pitest doesn't recognize exception thrown by assert keyword by default HOT 4
- PIT is generating equivalent mutations
- Drop Java 8 Support HOT 5
- Formula for mutation score calculation HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from pitest.