Skip to content

Commit

Permalink
#656 Changed handling of files which are not found in source directory
Browse files Browse the repository at this point in the history
  • Loading branch information
danielpalme committed Mar 14, 2024
1 parent 2b0ce9c commit c080409
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 18 deletions.
4 changes: 4 additions & 0 deletions src/Readme.txt
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,10 @@ For further details take a look at LICENSE.txt.

CHANGELOG

5.2.3.0

* Fix: #656 Changed handling of files which are not found in source directory

5.2.2.0

* New: #651 Added setting to add custom prefix to generated history files
Expand Down
8 changes: 4 additions & 4 deletions src/ReportGenerator.Core.Test/Parser/Analysis/CodeFileTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -257,8 +257,8 @@ public void AnalyzeFile_NonExistingFile_AnalysisIsReturned()
Assert.NotNull(fileAnalysis);
Assert.NotNull(fileAnalysis.Error);
Assert.Equal(fileAnalysis.Path, fileAnalysis.Path);
Assert.Null(sut.TotalLines);
Assert.Empty(fileAnalysis.Lines);
Assert.Equal(4, sut.TotalLines);
Assert.Equal(4, fileAnalysis.Lines.Count());
}

/// <summary>
Expand Down Expand Up @@ -311,8 +311,8 @@ public void AnalyzeFile_AdditionFileReaderReturnsError_RegularFileReaderUsed()
Assert.NotNull(fileAnalysis);
Assert.NotNull(fileAnalysis.Error);
Assert.Equal(fileAnalysis.Path, fileAnalysis.Path);
Assert.Null(sut.TotalLines);
Assert.Empty(fileAnalysis.Lines);
Assert.Equal(4, sut.TotalLines);
Assert.Equal(4, fileAnalysis.Lines.Count());

additionalFileReaderMock.Verify(f => f.LoadFile(It.IsAny<string>(), out error), Times.Once);
fileReaderMock.Verify(f => f.LoadFile(It.IsAny<string>(), out error), Times.Once);
Expand Down
6 changes: 4 additions & 2 deletions src/ReportGenerator.Core/Parser/Analysis/CodeFile.cs
Original file line number Diff line number Diff line change
Expand Up @@ -426,14 +426,16 @@ internal FileAnalysis AnalyzeFile(IFileReader fileReader)
if (error != null)
{
Logger.Error(error);
return new FileAnalysis(this.Path, error);
lines = this.lineCoverage
.Select(l => string.Empty)
.ToArray();
}

this.TotalLines = lines.Length;

int currentLineNumber = 0;

var result = new FileAnalysis(this.Path);
var result = new FileAnalysis(this.Path, error);
ICollection<Branch> branchesOfLine = null;

foreach (var line in lines)
Expand Down
21 changes: 9 additions & 12 deletions src/ReportGenerator.Core/Reporting/Builders/XmlReportBuilder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -125,21 +125,18 @@ public override void CreateClassReport(Class @class, IEnumerable<FileAnalysis> f
{
var fileElement = new XElement("File", new XAttribute("name", fileAnalysis.Path));

if (string.IsNullOrEmpty(fileAnalysis.Error))
foreach (var line in fileAnalysis.Lines)
{
foreach (var line in fileAnalysis.Lines)
{
var lineElement = new XElement("LineAnalysis");
var lineElement = new XElement("LineAnalysis");

lineElement.Add(new XAttribute("line", line.LineNumber.ToString(CultureInfo.InvariantCulture)));
lineElement.Add(new XAttribute("visits", line.LineVisits.ToString(CultureInfo.InvariantCulture)));
lineElement.Add(new XAttribute("coverage", line.LineVisitStatus.ToString()));
lineElement.Add(new XAttribute("coveredbranches", line.CoveredBranches.HasValue ? line.CoveredBranches.Value.ToString(CultureInfo.InvariantCulture) : string.Empty));
lineElement.Add(new XAttribute("totalbranches", line.TotalBranches.HasValue ? line.TotalBranches.Value.ToString(CultureInfo.InvariantCulture) : string.Empty));
lineElement.Add(new XAttribute("content", StringHelper.ReplaceInvalidXmlChars(line.LineContent)));
lineElement.Add(new XAttribute("line", line.LineNumber.ToString(CultureInfo.InvariantCulture)));
lineElement.Add(new XAttribute("visits", line.LineVisits.ToString(CultureInfo.InvariantCulture)));
lineElement.Add(new XAttribute("coverage", line.LineVisitStatus.ToString()));
lineElement.Add(new XAttribute("coveredbranches", line.CoveredBranches.HasValue ? line.CoveredBranches.Value.ToString(CultureInfo.InvariantCulture) : string.Empty));
lineElement.Add(new XAttribute("totalbranches", line.TotalBranches.HasValue ? line.TotalBranches.Value.ToString(CultureInfo.InvariantCulture) : string.Empty));
lineElement.Add(new XAttribute("content", StringHelper.ReplaceInvalidXmlChars(line.LineContent)));

fileElement.Add(lineElement);
}
fileElement.Add(lineElement);
}

filesElement.Add(fileElement);
Expand Down

0 comments on commit c080409

Please sign in to comment.