From 89ee24fcd868fccf2be90744d9ad81c68674408d Mon Sep 17 00:00:00 2001 From: oscarlvp Date: Sun, 16 Jul 2023 12:36:23 +0200 Subject: [PATCH] Static analysis, code style refactoring, method mathing refactoring --- README.md | 10 +- configuration/pmd-rules.xml | 14 + configuration/style.xml | 380 ++++++++++++++++ docs/examples/commons-cli/issues/index.html | 2 +- ....commons.cli.AmbiguousOptionException.html | 26 +- .../org.apache.commons.cli.DefaultParser.html | 20 +- .../issues/org.apache.commons.cli.Option.html | 26 +- docs/output-format.md | 8 +- docs/performance-comparison.md | 46 +- pom.xml | 62 ++- src/docgen/README.md | 18 +- .../descartes/DescartesEngineFactory.java | 101 +++-- .../descartes/DescartesMutater.java | 95 ++-- .../descartes/DescartesMutationEngine.java | 72 +-- .../descartes/annotations/DoNotMutate.java | 3 +- .../descartes/annotations/Operator.java | 5 +- .../codemanipulation/BaseClassVisitor.java | 52 ++- .../codemanipulation/BaseMethodVisitor.java | 15 +- .../codemanipulation/ElementInfo.java | 53 ++- .../codemanipulation/LineCounter.java | 91 ++-- .../codemanipulation/MethodInfo.java | 85 ++-- .../MethodRewritingVisitor.java | 89 +--- .../MutationClassAdapter.java | 61 ++- .../codemanipulation/MutationPointFinder.java | 153 ++++--- .../descartes/codemanipulation/TypeInfo.java | 88 ++-- .../AvoidNullInNotNullFilter.java | 23 +- .../AvoidNullInNotNullFilterFactory.java | 30 +- .../interceptors/MutationFilter.java | 56 +-- .../interceptors/SkipDoNotMutateFilter.java | 86 ++-- .../SkipDoNotMutateFilterFactory.java | 28 +- .../interceptors/SkipShortMethodsFilter.java | 51 ++- .../SkipShortMethodsFilterFactory.java | 45 +- .../stopmethods/InstructionMatchers.java | 97 ++++ .../stopmethods/MethodMatcher.java | 54 +++ .../stopmethods/StopMethodInterceptor.java | 22 +- .../stopmethods/StopMethodMatcher.java | 58 --- .../StopMethodMatcherInterceptorFactory.java | 128 +++--- .../stopmethods/StopMethodMatchers.java | 274 +++++------ .../ArgumentPropagationOperator.java | 27 +- .../operators/ConstantMutationOperator.java | 149 +++--- .../operators/EmptyArrayMutationOperator.java | 35 +- .../operators/InvalidOperatorException.java | 13 +- .../descartes/operators/MutationOperator.java | 98 ++-- .../NewInstanceMutationOperator.java | 168 ++++--- .../operators/NullMutationOperator.java | 22 +- .../operators/OptionalMutationOperator.java | 33 +- .../operators/ThisMutationOperator.java | 18 +- .../operators/VoidMutationOperator.java | 18 +- .../operators/parsing/LiteralParser.java | 283 ++++++------ .../descartes/operators/parsing/Token.java | 52 ++- .../operators/parsing/TokenType.java | 145 +++--- .../reporting/IssuesReportFactory.java | 30 +- .../reporting/IssuesReportListener.java | 196 ++++---- .../reporting/JSONReportFactory.java | 25 -- .../reporting/JSONReportListener.java | 110 ----- .../descartes/reporting/JSONWriter.java | 209 --------- .../reporting/JsonReportFactory.java | 25 ++ .../reporting/JsonReportListener.java | 105 +++++ .../descartes/reporting/JsonWriter.java | 235 ++++++++++ .../reporting/MethodTestingFactory.java | 22 +- .../reporting/MethodTestingListener.java | 158 ++++--- .../models/MethodClassification.java | 27 +- .../reporting/models/MethodRecord.java | 349 +++++++------- .../eu/stamp_project/utils/Converter.java | 111 ++--- .../eu/stamp_project/utils/TypeHelper.java | 116 ++--- .../java/eu/stamp_project/utils/Utils.java | 10 +- ...mutationtest.MutationResultListenerFactory | 2 +- .../descartes/IntegrationTest.java | 190 ++++---- .../AvoidNullInNotNullFilterTest.java | 73 ++- .../interceptors/MutationFilterTest.java | 25 +- .../SkipDoNotMutateFilterTest.java | 95 ++-- .../SkipShortMethodsFilterTest.java | 44 +- .../DelegateMethodMatcherTest.java | 57 ++- .../stopmethods/DeprecatedClassTest.java | 45 +- .../stopmethods/EmptyArrayMatcherTest.java | 54 ++- .../EmptyVoidMethodMatcherTest.java | 25 +- .../stopmethods/EnumMethodMatcherTest.java | 40 +- .../HashcodeMethodMatcherTest.java | 41 +- .../IsKotlinGeneratedSetterMatcherTest.java | 28 +- .../stopmethods/MethodMatcherTest.java | 97 ++-- .../ReturnConstantMatcherTest.java | 62 ++- .../stopmethods/ReturnsNullMatcherTest.java | 36 +- .../ReturnsParameterMethodMatcherTest.java | 41 +- .../ReturnsThisMethodMatcherTest.java | 27 +- .../stopmethods/SimpleGetterMatcherTest.java | 59 ++- .../stopmethods/SimpleSetterMatcherTest.java | 58 ++- .../ToStringMethodMatcherTest.java | 40 +- .../ArgumentPropagationOperatorTest.java | 95 ++-- .../ConstantMutationOperatorTest.java | 147 +++--- .../EmptyArrayMutationOperatorTest.java | 103 +++-- .../operators/MutationOperatorTest.java | 95 ++-- .../NewInstanceMutationOperatorTest.java | 85 ++-- .../operators/NullMutationOperatorTest.java | 108 ++--- .../OptionalMutationOperatorTest.java | 95 ++-- .../operators/ParameterlessOperatorTest.java | 95 ++-- .../operators/ThisMutationOperatorTest.java | 107 ++--- .../operators/VoidMutationOperatorTest.java | 100 +++-- .../descartes/operators/VoidWrapperTest.java | 107 ++--- .../operators/parsing/LiteralParserTest.java | 193 ++++---- .../descartes/reporting/JSONWriterTest.java | 184 ++++---- .../reporting/models/MethodRecordTest.java | 206 ++++----- .../eu/stamp_project/test/Assertions.java | 56 ++- .../test/MethodStreamBuilder.java | 89 ++-- .../eu/stamp_project/test/TestValues.java | 76 ++-- .../java/eu/stamp_project/test/Utils.java | 34 +- .../test/input/AbstractClass.java | 12 +- .../stamp_project/test/input/Calculator.java | 223 +++++---- .../test/input/DeprecatedClass.java | 7 +- .../eu/stamp_project/test/input/Fluent.java | 53 ++- .../eu/stamp_project/test/input/Index.java | 22 +- .../stamp_project/test/input/Interface.java | 3 +- .../test/input/NativeMethodClass.java | 2 +- .../eu/stamp_project/test/input/Numbers.java | 12 +- .../test/input/Parameterless.java | 187 ++++---- .../stamp_project/test/input/SideEffect.java | 15 +- .../input/SkipFalseMutationOnAllButOne.java | 11 +- .../test/input/SkipMutationOnMethod.java | 10 +- .../test/input/SkipMutationTarget.java | 10 +- .../stamp_project/test/input/StopMethods.java | 425 ++++++++++-------- 119 files changed, 5033 insertions(+), 4389 deletions(-) create mode 100644 configuration/pmd-rules.xml create mode 100644 configuration/style.xml create mode 100644 src/main/java/eu/stamp_project/descartes/interceptors/stopmethods/InstructionMatchers.java create mode 100644 src/main/java/eu/stamp_project/descartes/interceptors/stopmethods/MethodMatcher.java delete mode 100644 src/main/java/eu/stamp_project/descartes/interceptors/stopmethods/StopMethodMatcher.java delete mode 100644 src/main/java/eu/stamp_project/descartes/reporting/JSONReportFactory.java delete mode 100644 src/main/java/eu/stamp_project/descartes/reporting/JSONReportListener.java delete mode 100644 src/main/java/eu/stamp_project/descartes/reporting/JSONWriter.java create mode 100644 src/main/java/eu/stamp_project/descartes/reporting/JsonReportFactory.java create mode 100644 src/main/java/eu/stamp_project/descartes/reporting/JsonReportListener.java create mode 100644 src/main/java/eu/stamp_project/descartes/reporting/JsonWriter.java diff --git a/README.md b/README.md index c658e48..1f7c7b5 100644 --- a/README.md +++ b/README.md @@ -37,7 +37,7 @@ cd my-project-under-test mvn clean package org.pitest:pitest-maven:mutationCoverage ``` -All options from PIT can be used. For more details check the [the PIT documentation](https://pitest.org/quickstart/maven/). +All options from PIT can be used. For more details check [the PIT documentation](https://pitest.org/quickstart/maven/). Check ["Running Descartes on your project"](#running-descartes-on-your-project) for additional Descartes configuration options. @@ -65,7 +65,7 @@ If you use a multi-module project take a look at [PitMP](https://github.com/STAM ### Mutation testing Mutation testing allows you to verify if your test suite can detect possible bugs. The technique works by introducing small changes or faults into the original program. These modified versions are called **mutants**. -A good test suite should able to detect or *kill* a mutant. That is, at least one test case should fail when the test suite is executed with the mutant. +A good test suite should be able to detect or *kill* a mutant. That is, at least one test case should fail when the test suite is executed with the mutant. [Read more](https://en.wikipedia.org/wiki/Mutation_testing). Traditional mutation testing works at the instruction level, e.g., replacing ">" by "<=", so the number of generated mutants is huge, as the time required to check the entire test suite. That's why the authors of [Will my tests tell me if I break this code?](http://dl.acm.org/citation.cfm?doid=2896941.2896944) proposed an *Extreme Mutation* strategy, which works at the method level. @@ -399,7 +399,7 @@ PIT reporting extensions work with Descartes and include `XML`, `CSV` and `HTML` Descartes also provides three new reporting extensions: - a general reporting extension supporting `JSON` files. It works also with **Gregor**, the default mutation engine for PIT. To use just set `JSON` as report format for PIT. - a reporting extension designed for Descartes that generates a JSON file with information about pseudo and partially tested methods. To use just set `METHOD` as report format for PIT. - - Descartes can generate a human readable report containing only the list of methods with testing issues by using the `ISSUES` format. + - Descartes can generate a human-readable report containing only the list of methods with testing issues by using the `ISSUES` format. Examples of these reporting extensions for [Apache Commons-CLI](https://github.com/apache/commons-cli/tree/b9ccc94008c78a59695f0c77ebe4ecf284370956) can be checked [here](docs/examples/commons-cli). @@ -498,7 +498,7 @@ To configure the stop methods under consideration Descartes provides a `STOP_MET This feature is enabled by default. The parameter `exclude` can be used to prevent certain methods to be treated as stop methods and bring them back to the analysis. This parameter can take any of the following values: -|`exclude` | Method description | Example | +| `exclude` | Method description | Example | |-----------------|----------------------------------------------------------------------------------------|--------------------------------------------------------------------------------------------------| | `empty` | `void` methods with no instruction. | `public void m() {}` | | `enum` | Methods generated by the compiler to support enum types (`values` and `valueOf`). | | @@ -553,7 +553,7 @@ The feature can be completely disabled: As said before, there are several reporting options provided by Descartes: - `JSON` for a general mutation testing report using that file format. It can be used with **Gregor**. - `METHODS` that produces a `methods.json` file with the list of all methods analyzed and categorized according to the mutation testing result. -- `ISSUES` a human readable report containing only the methods with testing issues. +- `ISSUES` a human-readable report containing only the methods with testing issues. They can be configured and combined as regular PIT report formats: diff --git a/configuration/pmd-rules.xml b/configuration/pmd-rules.xml new file mode 100644 index 0000000..4e63b26 --- /dev/null +++ b/configuration/pmd-rules.xml @@ -0,0 +1,14 @@ + + + + + Rules enforcing an accepted set of coding styles and best practices taken from PMD predefined rules. + This file customizes some of the rules to avoid false positives. + + + + + diff --git a/configuration/style.xml b/configuration/style.xml new file mode 100644 index 0000000..58e25d9 --- /dev/null +++ b/configuration/style.xml @@ -0,0 +1,380 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/docs/examples/commons-cli/issues/index.html b/docs/examples/commons-cli/issues/index.html index 9626a80..76e20be 100644 --- a/docs/examples/commons-cli/issues/index.html +++ b/docs/examples/commons-cli/issues/index.html @@ -1,4 +1,4 @@ - + Testing issues report