From b4db3c25df1e359dceff00a6bec9302131ab4bc5 Mon Sep 17 00:00:00 2001 From: Dennis Jensen Date: Mon, 26 Jun 2023 07:25:35 +0000 Subject: [PATCH] Bugfix: PArsing empty files Changes: - Parsing empty files with lines --- Dockerfile | 2 +- assets/coberta_coverage/coverage.xml | 4 ++++ src/coberta_xml_parser.rs | 18 +++++++++++++----- 3 files changed, 18 insertions(+), 6 deletions(-) diff --git a/Dockerfile b/Dockerfile index 2cfc65b..e9b0c9b 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,4 +1,4 @@ -FROM dennisjensen95/coverage-scope:v0.3.1 +FROM dennisjensen95/coverage-scope:v0.3.2 COPY entrypoint.sh /entrypoint.sh diff --git a/assets/coberta_coverage/coverage.xml b/assets/coberta_coverage/coverage.xml index 8b1665e..bb8ab28 100644 --- a/assets/coberta_coverage/coverage.xml +++ b/assets/coberta_coverage/coverage.xml @@ -26,6 +26,10 @@ + + + + diff --git a/src/coberta_xml_parser.rs b/src/coberta_xml_parser.rs index fc875d9..19b9fe7 100644 --- a/src/coberta_xml_parser.rs +++ b/src/coberta_xml_parser.rs @@ -78,7 +78,7 @@ struct Methods {} #[derive(Debug, Deserialize, Clone)] struct Lines { - line: Vec, + line: Option>, } #[derive(Debug, Deserialize, Clone)] @@ -103,7 +103,11 @@ impl Class { fn get_lines_covered(&self) -> Vec { let mut lines_covered: Vec = Vec::new(); - for line in &self.lines.line { + if self.lines.line.is_none() { + return lines_covered; + } + + for line in &self.lines.line.clone().unwrap() { if line.hits != "0" { let line_number = line.number.parse::(); match line_number { @@ -118,7 +122,11 @@ impl Class { fn get_all_lines(&self) -> Vec { let mut all_lines: Vec = Vec::new(); - for line in &self.lines.line { + if self.lines.line.is_none() { + return all_lines; + } + + for line in &self.lines.line.clone().unwrap() { let line_number = line.number.parse::(); match line_number { Ok(n) => all_lines.push(n), @@ -238,7 +246,7 @@ mod tests { let coverage = Coverage::new(&file_string); let files_covered = coverage.packages.list_of_packages[0].classes.class.clone(); - assert_eq!(files_covered.len(), 2); + assert_eq!(files_covered.len(), 3); // new.py files covered 0 let lines_covered = coverage.get_lines_covered("test_repo/new.py"); @@ -255,7 +263,7 @@ mod tests { let coverage = Coverage::new(&file_string); let files_covered = coverage.packages.list_of_packages[0].classes.class.clone(); - assert_eq!(files_covered.len(), 2); + assert_eq!(files_covered.len(), 3); } #[test]