Skip to content

Commit 5822ff6

Browse files
zippy1978Gilles Grousset
andauthored
feat(Tests): support for multiple test reports (#191)
Co-authored-by: Gilles Grousset <[email protected]>
1 parent dea7fa9 commit 5822ff6

File tree

2 files changed

+22
-17
lines changed

2 files changed

+22
-17
lines changed

README.md

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -185,14 +185,14 @@ You may follow and upvote these related issue if interested:
185185

186186
All options are configurable in the SonarQube UI, via `sonar-project.properties` or `-D` parameters.
187187

188-
| Name | Options | Default | Description |
189-
|----------------------------------------|--------------------------------------------------------------------------|----------|-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
190-
| `sonar.dart.analyzer.mode` | <code>DETECT&#124;DART&#124;FLUTTER&#124;MANUAL&#124;DARTANALYZER</code> | `DETECT` | By default the plugin attempts to detect a fitting analyzer (`flutter analyze` or `dart analyze`) by parsing the `environment` from `pubspec.yaml`. This can be set to `MANUAL` to provide and existing report file. For compatibility with older Dart versions, this can be set to `DARTANALYZER`. |
191-
| `sonar.dart.analyzer.options.override` | <code>true&#124;false</code> | `true` | By default any local `analysis_options.yaml` will be replaced for the analysis. This can be prevented by setting this to `false`. |
192-
| `sonar.dart.analyzer.report.mode` | <code>DETECT&#124;MACHINE&#124;LEGACY</code> | `DETECT` | The new machine readable output can be automatically detected if Dart SDK is available on the $PATH. |
193-
| `sonar.dart.analyzer.report.path` | A file path | - | This is required if the analyzer mode is set to `MANUAL`. |
194-
| `sonar.flutter.tests.reportPath` | A file path | - | The path to the test report JSON file. |
195-
| `sonar.flutter.coverage.reportPath` | A file path | - | The path to the test coverage file in LCOV format. |
188+
| Name | Options | Default | Description |
189+
|----------------------------------------|--------------------------------------------------------------------------|----------------------|-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
190+
| `sonar.dart.analyzer.mode` | <code>DETECT&#124;DART&#124;FLUTTER&#124;MANUAL&#124;DARTANALYZER</code> | `DETECT` | By default the plugin attempts to detect a fitting analyzer (`flutter analyze` or `dart analyze`) by parsing the `environment` from `pubspec.yaml`. This can be set to `MANUAL` to provide and existing report file. For compatibility with older Dart versions, this can be set to `DARTANALYZER`. |
191+
| `sonar.dart.analyzer.options.override` | <code>true&#124;false</code> | `true` | By default any local `analysis_options.yaml` will be replaced for the analysis. This can be prevented by setting this to `false`. |
192+
| `sonar.dart.analyzer.report.mode` | <code>DETECT&#124;MACHINE&#124;LEGACY</code> | `DETECT` | The new machine readable output can be automatically detected if Dart SDK is available on the $PATH. |
193+
| `sonar.dart.analyzer.report.path` | A file path | - | This is required if the analyzer mode is set to `MANUAL`. |
194+
| `sonar.flutter.tests.reportPath` | Comma separated list of file paths (wildcard not supported) | `tests.output` | The path to the test report JSON file. |
195+
| `sonar.flutter.coverage.reportPath` | A file path | `coverage/lcov.info` | The path to the test coverage file in LCOV format. |
196196

197197

198198
## Contributing

sonar-flutter-plugin/src/main/java/fr/insideapp/sonarqube/flutter/tests/FlutterTestSensor.java

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -46,21 +46,26 @@ public void describe(SensorDescriptor sensorDescriptor) {
4646

4747
@Override
4848
public void execute(SensorContext sensorContext) {
49-
File reportFile = sensorContext.fileSystem().resolvePath(reportPath(sensorContext));
5049

5150
FlutterTestReportParser parser = new FlutterTestReportParser();
52-
try {
53-
List<FlutterUnitTestSuite> suites = parser.parse(reportFile);
54-
suites.forEach(s -> saveSuite(s, sensorContext));
55-
} catch (IOException e) {
56-
throw new IllegalStateException("Failed to parse test report", e);
51+
for (String reportPath : reportPaths(sensorContext)) {
52+
File reportFile = new File(reportPath);
53+
LOGGER.debug("Parsing test report: {}", reportPath);
54+
try {
55+
List<FlutterUnitTestSuite> suites = parser.parse(reportFile);
56+
suites.forEach(s -> saveSuite(s, sensorContext));
57+
} catch (IOException e) {
58+
throw new IllegalStateException("Failed to parse test report", e);
59+
}
60+
5761
}
62+
5863
}
5964

60-
private String reportPath(SensorContext sensorContext) {
65+
private String[] reportPaths(SensorContext sensorContext) {
6166
return sensorContext.config()
6267
.get(REPORT_PATH_KEY)
63-
.orElse(DEFAULT_REPORT_PATH);
68+
.orElse(DEFAULT_REPORT_PATH).split(",");
6469
}
6570

6671
private void saveSuite(FlutterUnitTestSuite suite, SensorContext sensorContext) {
@@ -72,7 +77,7 @@ private void saveSuite(FlutterUnitTestSuite suite, SensorContext sensorContext)
7277
return;
7378
}
7479

75-
LOGGER.debug("Parsing tests from {}", suite.getPath());
80+
LOGGER.debug("Parsing tests from {}, ({} test(s))", suite.getPath(), suite.getCount());
7681

7782
saveMeasure(sensorContext, inputFile, CoreMetrics.SKIPPED_TESTS, (int) suite.getSkippedCount());
7883
saveMeasure(sensorContext, inputFile, CoreMetrics.TESTS, (int) (suite.getCount()));

0 commit comments

Comments
 (0)