-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
1 changed file
with
51 additions
and
31 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,67 +1,87 @@ | ||
# DBXCResultParser-Sonar | ||
|
||
`DBXCResultParser-Sonar` is a Swift Package Manager tool designed to convert Xcode's test result files (`.xcresult`) into Sonar Generic Test Execution Report format (`.xml`). It can be integrated into your CI/CD pipeline to enhance the visibility of test results in SonarQube or SonarCloud. | ||
The `DBXCResultParser-Sonar` package provides a Swift module for parsing `.xcresult` files generated by Xcode to produce [Sonar Generic Test Execution Report](https://docs.sonarsource.com/sonarqube/9.8/analyzing-source-code/test-coverage/generic-test-data/#generic-test-execution) `.xml`. It can be integrated into your CI/CD pipeline to enhance the visibility of test results in SonarQube or SonarCloud. | ||
|
||
## Installation | ||
|
||
### As a Dependency | ||
|
||
To use `DBXCResultParser-Sonar` as a dependency in your project, add it to the dependencies in your `Package.swift` file: | ||
|
||
```swift | ||
dependencies: [ | ||
.package(url: "https://github.com/dodobrands/DBXCResultParser-Sonar.git", from: "1.0.0") | ||
] | ||
``` | ||
|
||
Then import `DBXCResultParser-Sonar` in your Swift files where you want to use it: | ||
|
||
```swift | ||
import DBXCResultParserSonar | ||
``` | ||
## Usage | ||
|
||
### As a Command Line Tool | ||
|
||
You can use `DBXCResultParser-Sonar` as a command line tool in two ways: | ||
|
||
1. **Prebuilt Binary from Xcode Archive**: | ||
Download the prebuilt binary from the [Releases](https://github.com/dodobrands/DBXCResultParser-Sonar/releases) page on the project's GitHub repository. | ||
1. Clone repo | ||
2. Open in Xcode | ||
3. Product → Archive | ||
4. Distribute Content → Built Products | ||
5. Run exported binary: | ||
```bash | ||
./DBXCResultParser-Sonar --xcresult-path <path> --tests-path <your projects tests folder> | ||
``` | ||
|
||
2. **Using Swift Run**: | ||
|
||
Clone the repository and run the tool using the Swift Package Manager: | ||
|
||
```bash | ||
git clone https://github.com/dodobrands/DBXCResultParser-Sonar.git | ||
cd DBXCResultParser-Sonar | ||
swift run DBXCResultParser-Sonar <arguments> | ||
swift run DBXCResultParser-Sonar --xcresult-path <path> --tests-path <your projects tests folder> | ||
``` | ||
|
||
#### Saving .xml report to file | ||
|
||
You can save report in two ways: | ||
|
||
1. **Using `>` operator**: | ||
|
||
Append `>` at the end of any bash command to redirect it's output into file. | ||
```bash | ||
./DBXCResultParser-Sonar --xcresult-path <path> --tests-path <your projects tests folder> > sonar-test-report.xml | ||
``` | ||
2. **Using `--output-path` option**: | ||
Specify option for resulting file. May be useful when you've provided `--verbode` flag so that it's logs won't conflict with output `.xml`. | ||
```bash | ||
./DBXCResultParser-Sonar --xcresult-path <path> --tests-path <your projects tests folder> --output-path <path to resulting report.xml> | ||
``` | ||
|
||
## Usage | ||
|
||
### As a Dependency | ||
|
||
Create an instance of `SonarGenericTestExecutionReportFormatter` and use it to generate the `.xml` report: | ||
To use `DBXCResultParser-Sonar` in your Swift package, add it to the dependencies for your `Package.swift` file: | ||
|
||
```swift | ||
let formatter = SonarGenericTestExecutionReportFormatter() | ||
// Use formatter to generate the report | ||
let package = Package( | ||
name: "YourPackageName", | ||
dependencies: [ | ||
.package(url: "https://github.com/dodobrands/DBXCResultParser-Sonar", .upToNextMajor(from: "1.0.0")) | ||
], | ||
targets: [ | ||
.target( | ||
name: "YourTargetName", | ||
dependencies: ["DBXCResultParser"] | ||
) | ||
] | ||
) | ||
``` | ||
|
||
### As a Command Line Tool | ||
To parse an `.xcresult` file and access the report data, initialize a `DBXCReportModel` with the path to the `.xcresult` file: | ||
|
||
To generate a Sonar Generic Test Execution Report from the command line, use the following command: | ||
```swift | ||
import DBXCResultParser_Sonar | ||
```bash | ||
swift run DBXCResultParser-Sonar --xcresult-path path/to/tests.xcresult --tests-path path/to/test-files > report.xml | ||
let xcresultPath = URL(fileURLWithPath: "/path/to/your.xcresult") | ||
let reportModel = try DBXCReportModel(xcresultPath: xcresultPath) | ||
let formatter = SonarGenericTestExecutionReportFormatter() | ||
let result = try formatter.sonarTestReport(from: reportModel) | ||
``` | ||
|
||
Replace `path/to/tests.xcresult` with the path to your `.xcresult` file and `path/to/test-files` with the path to your test files. | ||
|
||
## Contributing | ||
|
||
Contributions are welcome! Please feel free to submit a pull request or open an issue on the [GitHub repository](https://github.com/dodobrands/DBXCResultParser-Sonar). | ||
|
||
## License | ||
|
||
This project is licensed under the Apache License - see the [LICENSE](LICENSE) file for details. | ||
``` | ||
This project is licensed under the Apache License - see the [LICENSE](LICENSE) file for details. |