Skip to content

Commit

Permalink
Bugfix: PArsing empty files
Browse files Browse the repository at this point in the history
Changes:
- Parsing empty files with lines
  • Loading branch information
DennisJensen95 committed Jun 26, 2023
1 parent abb1ef3 commit b4db3c2
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 6 deletions.
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.3.1
FROM dennisjensen95/coverage-scope:v0.3.2

COPY entrypoint.sh /entrypoint.sh

Expand Down
4 changes: 4 additions & 0 deletions assets/coberta_coverage/coverage.xml
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,10 @@
<line number="6" hits="0"/>
</lines>
</class>
<class name="some_other_module.py" filename="test_repo/some_other_module.py" complexity="0" line-rate="0.2" branch-rate="0">
<methods/>
<lines/>
</class>
</classes>
</package>
</packages>
Expand Down
18 changes: 13 additions & 5 deletions src/coberta_xml_parser.rs
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ struct Methods {}

#[derive(Debug, Deserialize, Clone)]
struct Lines {
line: Vec<Line>,
line: Option<Vec<Line>>,
}

#[derive(Debug, Deserialize, Clone)]
Expand All @@ -103,7 +103,11 @@ impl Class {
fn get_lines_covered(&self) -> Vec<usize> {
let mut lines_covered: Vec<usize> = 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::<usize>();
match line_number {
Expand All @@ -118,7 +122,11 @@ impl Class {
fn get_all_lines(&self) -> Vec<usize> {
let mut all_lines: Vec<usize> = 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::<usize>();
match line_number {
Ok(n) => all_lines.push(n),
Expand Down Expand Up @@ -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");
Expand All @@ -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]
Expand Down

0 comments on commit b4db3c2

Please sign in to comment.