From ee2e078f5e01f4767a4008fd0028f2251c5ef3f3 Mon Sep 17 00:00:00 2001 From: Dennis Jensen Date: Sun, 27 Aug 2023 11:22:01 +0200 Subject: [PATCH] Feature: Implemented C# support Changes: - Removing a BOM character for xml parsing --- .github/workflows/ci.yml | 2 +- Dockerfile | 2 +- Dockerfile.build | 2 +- README.md | 5 +- assets/coberta_coverage/c_sharp.xml | 140 ++++++++++++++++++++++++++++ src/coberta_xml_parser.rs | 17 +++- 6 files changed, 162 insertions(+), 6 deletions(-) create mode 100644 assets/coberta_coverage/c_sharp.xml diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 7a2088f..5866f19 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -113,7 +113,7 @@ jobs: with: name: coverage-file - - uses: dennisjensen95/coverage-scope@v0.3.2 + - uses: dennisjensen95/coverage-scope@v0.5.0 with: coverage-filepath: cobertura.xml branch: main diff --git a/Dockerfile b/Dockerfile index 2c7d93d..085fdf0 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,4 +1,4 @@ -FROM dennisjensen95/coverage-scope:v0.4.2 +FROM dennisjensen95/coverage-scope:v0.5.0 COPY entrypoint.sh /entrypoint.sh diff --git a/Dockerfile.build b/Dockerfile.build index 1c7f8ce..121ccf4 100644 --- a/Dockerfile.build +++ b/Dockerfile.build @@ -8,7 +8,7 @@ COPY Cargo.lock Cargo.lock RUN cargo build --release -FROM debian:bullseye-slim +FROM rust:latest RUN apt-get update && apt-get install -y git && rm -rf /var/lib/apt/lists/* COPY --from=BUILD /app/target/release/coverage_scope /coverage_scope COPY entrypoint.sh /entrypoint.sh diff --git a/README.md b/README.md index db3cd32..0f2d4e2 100644 --- a/README.md +++ b/README.md @@ -19,6 +19,9 @@ The package currently has only been tested with the following coding languages: - Rust - Golang - Dart +- C# +- Angular +- React These are the only languages that have been tested. However, the logic should be applicable for other languages. @@ -40,7 +43,7 @@ when measuring changed files coverage, and the minimum threshold for both the total coverage and the changed files coverage. ```yaml -- uses: dennisjensen95/coverage-scope@v0.4.2 +- uses: dennisjensen95/coverage-scope@v0.5.0 with: coverage-filepath: cobertura.xml branch: main diff --git a/assets/coberta_coverage/c_sharp.xml b/assets/coberta_coverage/c_sharp.xml new file mode 100644 index 0000000..3037e1c --- /dev/null +++ b/assets/coberta_coverage/c_sharp.xml @@ -0,0 +1,140 @@ + + + + /Users/dennisjensen/GIT/energy-grid/apps/EnergyAnalyzer/EnergyAnalyzerWebApp/ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/src/coberta_xml_parser.rs b/src/coberta_xml_parser.rs index 8782301..1fc29c4 100644 --- a/src/coberta_xml_parser.rs +++ b/src/coberta_xml_parser.rs @@ -20,7 +20,7 @@ pub struct Coverage { #[serde(rename = "branch-rate")] _branch_rate: String, #[serde(rename = "complexity")] - _complexity: String, + _complexity: Option, #[serde(rename = "sources")] sources: Sources, packages: Packages, @@ -149,7 +149,10 @@ impl Package { impl Coverage { pub fn new(file_string: &str) -> Coverage { - let coverage: Coverage = serde_xml_rs::from_str(file_string).unwrap(); + // Remove BOM if it exists (C# support) + let clean_string = file_string.trim_start_matches('\u{feff}'); + + let coverage: Coverage = serde_xml_rs::from_str(clean_string).unwrap(); coverage } @@ -305,6 +308,16 @@ mod tests { assert_eq!(lines_with_code.len(), 11); } + #[test] + fn test_bom_removal() { + let file_string = std::fs::read_to_string("assets/coberta_coverage/c_sharp.xml").unwrap(); + let coverage = Coverage::new(&file_string); + + let lines_with_code = + coverage.get_lines_with_code("Controllers/WeatherForecastController.cs"); + assert_eq!(lines_with_code.len(), 17); + } + #[test] fn test_get_file_extensions() { let file_string =