From c0804098bd8588c2cdd1d5a04ffff8963c48f3f8 Mon Sep 17 00:00:00 2001 From: Daniel Palme Date: Thu, 14 Mar 2024 20:06:44 +0100 Subject: [PATCH] #656 Changed handling of files which are not found in source directory --- src/Readme.txt | 4 ++++ .../Parser/Analysis/CodeFileTest.cs | 8 +++---- .../Parser/Analysis/CodeFile.cs | 6 ++++-- .../Reporting/Builders/XmlReportBuilder.cs | 21 ++++++++----------- 4 files changed, 21 insertions(+), 18 deletions(-) diff --git a/src/Readme.txt b/src/Readme.txt index 69725008..968d8a34 100644 --- a/src/Readme.txt +++ b/src/Readme.txt @@ -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 diff --git a/src/ReportGenerator.Core.Test/Parser/Analysis/CodeFileTest.cs b/src/ReportGenerator.Core.Test/Parser/Analysis/CodeFileTest.cs index 0f161d75..be84fa23 100644 --- a/src/ReportGenerator.Core.Test/Parser/Analysis/CodeFileTest.cs +++ b/src/ReportGenerator.Core.Test/Parser/Analysis/CodeFileTest.cs @@ -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()); } /// @@ -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(), out error), Times.Once); fileReaderMock.Verify(f => f.LoadFile(It.IsAny(), out error), Times.Once); diff --git a/src/ReportGenerator.Core/Parser/Analysis/CodeFile.cs b/src/ReportGenerator.Core/Parser/Analysis/CodeFile.cs index 1b02f351..dc6add3f 100644 --- a/src/ReportGenerator.Core/Parser/Analysis/CodeFile.cs +++ b/src/ReportGenerator.Core/Parser/Analysis/CodeFile.cs @@ -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 branchesOfLine = null; foreach (var line in lines) diff --git a/src/ReportGenerator.Core/Reporting/Builders/XmlReportBuilder.cs b/src/ReportGenerator.Core/Reporting/Builders/XmlReportBuilder.cs index 15dbd000..818fce9b 100644 --- a/src/ReportGenerator.Core/Reporting/Builders/XmlReportBuilder.cs +++ b/src/ReportGenerator.Core/Reporting/Builders/XmlReportBuilder.cs @@ -125,21 +125,18 @@ public override void CreateClassReport(Class @class, IEnumerable 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);