Skip to content

Commit

Permalink
Feature: Implemented C# support
Browse files Browse the repository at this point in the history
Changes:
- Removing a BOM character for xml parsing
  • Loading branch information
DennisJensen95 committed Aug 27, 2023
1 parent 88c3490 commit ee2e078
Show file tree
Hide file tree
Showing 6 changed files with 162 additions and 6 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
FROM dennisjensen95/coverage-scope:v0.4.2
FROM dennisjensen95/coverage-scope:v0.5.0

COPY entrypoint.sh /entrypoint.sh

Expand Down
2 changes: 1 addition & 1 deletion Dockerfile.build
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
5 changes: 4 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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
Expand Down
140 changes: 140 additions & 0 deletions assets/coberta_coverage/c_sharp.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,140 @@
<?xml version="1.0" encoding="utf-8"?>
<coverage line-rate="0.5714" branch-rate="0" version="1.9" timestamp="1693126215" lines-covered="20" lines-valid="35" branches-covered="0" branches-valid="2">
<sources>
<source>/Users/dennisjensen/GIT/energy-grid/apps/EnergyAnalyzer/EnergyAnalyzerWebApp/</source>
</sources>
<packages>
<package name="EnergyAnalyzer" line-rate="0.5714" branch-rate="0" complexity="9">
<classes>
<class name="Program" filename="Program.cs" line-rate="0" branch-rate="0" complexity="2">
<methods>
<method name="&lt;Main&gt;$" signature="(System.String[])" line-rate="0" branch-rate="0" complexity="2">
<lines>
<line number="1" hits="0" branch="False" />
<line number="3" hits="0" branch="False" />
<line number="5" hits="0" branch="False" />
<line number="6" hits="0" branch="False" />
<line number="8" hits="0" branch="False" />
<line number="11" hits="0" branch="True" condition-coverage="0% (0/2)">
<conditions>
<condition number="64" type="jump" coverage="0%" />
</conditions>
</line>
<line number="12" hits="0" branch="False" />
<line number="13" hits="0" branch="False" />
<line number="14" hits="0" branch="False" />
<line number="15" hits="0" branch="False" />
<line number="17" hits="0" branch="False" />
<line number="19" hits="0" branch="False" />
<line number="21" hits="0" branch="False" />
<line number="23" hits="0" branch="False" />
</lines>
</method>
</methods>
<lines>
<line number="1" hits="0" branch="False" />
<line number="3" hits="0" branch="False" />
<line number="5" hits="0" branch="False" />
<line number="6" hits="0" branch="False" />
<line number="8" hits="0" branch="False" />
<line number="11" hits="0" branch="True" condition-coverage="0% (0/2)">
<conditions>
<condition number="64" type="jump" coverage="0%" />
</conditions>
</line>
<line number="12" hits="0" branch="False" />
<line number="13" hits="0" branch="False" />
<line number="14" hits="0" branch="False" />
<line number="15" hits="0" branch="False" />
<line number="17" hits="0" branch="False" />
<line number="19" hits="0" branch="False" />
<line number="21" hits="0" branch="False" />
<line number="23" hits="0" branch="False" />
</lines>
</class>
<class name="EnergyAnalyzer.WeatherForecast" filename="WeatherForecast.cs" line-rate="0.75" branch-rate="1" complexity="4">
<methods>
<method name="get_Date" signature="()" line-rate="1" branch-rate="1" complexity="1">
<lines>
<line number="5" hits="5" branch="False" />
</lines>
</method>
<method name="get_TemperatureC" signature="()" line-rate="1" branch-rate="1" complexity="1">
<lines>
<line number="7" hits="15" branch="False" />
</lines>
</method>
<method name="get_TemperatureF" signature="()" line-rate="0" branch-rate="1" complexity="1">
<lines>
<line number="9" hits="0" branch="False" />
</lines>
</method>
<method name="get_Summary" signature="()" line-rate="1" branch-rate="1" complexity="1">
<lines>
<line number="11" hits="10" branch="False" />
</lines>
</method>
</methods>
<lines>
<line number="5" hits="5" branch="False" />
<line number="7" hits="15" branch="False" />
<line number="9" hits="0" branch="False" />
<line number="11" hits="10" branch="False" />
</lines>
</class>
<class name="EnergyAnalyzer.Controllers.WeatherForecastController" filename="Controllers/WeatherForecastController.cs" line-rate="1" branch-rate="1" complexity="3">
<methods>
<method name="Get" signature="()" line-rate="1" branch-rate="1" complexity="1">
<lines>
<line number="23" hits="1" branch="False" />
<line number="24" hits="6" branch="False" />
<line number="25" hits="6" branch="False" />
<line number="26" hits="6" branch="False" />
<line number="27" hits="6" branch="False" />
<line number="28" hits="6" branch="False" />
<line number="29" hits="6" branch="False" />
<line number="30" hits="1" branch="False" />
<line number="31" hits="1" branch="False" />
</lines>
</method>
<method name=".ctor" signature="(Microsoft.Extensions.Logging.ILogger`1&lt;EnergyAnalyzer.Controllers.WeatherForecastController&gt;)" line-rate="1" branch-rate="1" complexity="1">
<lines>
<line number="16" hits="1" branch="False" />
<line number="17" hits="1" branch="False" />
<line number="18" hits="1" branch="False" />
<line number="19" hits="1" branch="False" />
</lines>
</method>
<method name=".cctor" signature="()" line-rate="1" branch-rate="1" complexity="1">
<lines>
<line number="9" hits="1" branch="False" />
<line number="10" hits="1" branch="False" />
<line number="11" hits="1" branch="False" />
<line number="12" hits="1" branch="False" />
</lines>
</method>
</methods>
<lines>
<line number="23" hits="1" branch="False" />
<line number="24" hits="6" branch="False" />
<line number="25" hits="6" branch="False" />
<line number="26" hits="6" branch="False" />
<line number="27" hits="6" branch="False" />
<line number="28" hits="6" branch="False" />
<line number="29" hits="6" branch="False" />
<line number="30" hits="1" branch="False" />
<line number="31" hits="1" branch="False" />
<line number="16" hits="1" branch="False" />
<line number="17" hits="1" branch="False" />
<line number="18" hits="1" branch="False" />
<line number="19" hits="1" branch="False" />
<line number="9" hits="1" branch="False" />
<line number="10" hits="1" branch="False" />
<line number="11" hits="1" branch="False" />
<line number="12" hits="1" branch="False" />
</lines>
</class>
</classes>
</package>
</packages>
</coverage>
17 changes: 15 additions & 2 deletions src/coberta_xml_parser.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ pub struct Coverage {
#[serde(rename = "branch-rate")]
_branch_rate: String,
#[serde(rename = "complexity")]
_complexity: String,
_complexity: Option<String>,
#[serde(rename = "sources")]
sources: Sources,
packages: Packages,
Expand Down Expand Up @@ -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
}

Expand Down Expand Up @@ -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 =
Expand Down

0 comments on commit ee2e078

Please sign in to comment.