Skip to content

Commit

Permalink
(cake-buildGH-3143) Recreate the issue with a test
Browse files Browse the repository at this point in the history
(cake-buildGH-3143) Don't try to parse empty solution file lines
  • Loading branch information
nmbro committed Feb 16, 2021
1 parent bfb0cb4 commit 55e8342
Show file tree
Hide file tree
Showing 4 changed files with 86 additions and 0 deletions.
17 changes: 17 additions & 0 deletions src/Cake.Common.Tests/Properties/Resources.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

44 changes: 44 additions & 0 deletions src/Cake.Common.Tests/Properties/Resources.resx
Original file line number Diff line number Diff line change
Expand Up @@ -900,6 +900,50 @@ Global
{5D553DC6-36AB-4823-85BD-A33F57C81381} = {69930DD1-1688-4407-B4AB-B9E2C0BFB284}
EndGlobalSection
EndGlobal</value>
</data>
<data name="Solution_WithProjectsAndFoldersAndMissingLine" xml:space="preserve">
<value>Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio 14
VisualStudioVersion = 14.0.25123.0
MinimumVisualStudioVersion = 10.0.40219.1
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "src", "src", "{2400A22B-695E-4BDF-93CB-8757F5FB3FB7}"
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "test", "test", "{69930DD1-1688-4407-B4AB-B9E2C0BFB284}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "dummy", "src\dummy\dummy.csproj", "{ADCB37DA-2469-462F-99F6-9D4FB7691A3B}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "dummy.Tests", "test\dummy.Tests\dummy.Tests.csproj", "{5D553DC6-36AB-4823-85BD-A33F57C81381}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "executable", "executable\executable.csproj", "{CF305C72-F3E0-44AA-9474-6F12C5276F9F}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Release|Any CPU = Release|Any CPU
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{ADCB37DA-2469-462F-99F6-9D4FB7691A3B}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{ADCB37DA-2469-462F-99F6-9D4FB7691A3B}.Debug|Any CPU.Build.0 = Debug|Any CPU
{ADCB37DA-2469-462F-99F6-9D4FB7691A3B}.Release|Any CPU.ActiveCfg = Release|Any CPU
{ADCB37DA-2469-462F-99F6-9D4FB7691A3B}.Release|Any CPU.Build.0 = Release|Any CPU
{5D553DC6-36AB-4823-85BD-A33F57C81381}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{5D553DC6-36AB-4823-85BD-A33F57C81381}.Debug|Any CPU.Build.0 = Debug|Any CPU
{5D553DC6-36AB-4823-85BD-A33F57C81381}.Release|Any CPU.ActiveCfg = Release|Any CPU
{5D553DC6-36AB-4823-85BD-A33F57C81381}.Release|Any CPU.Build.0 = Release|Any CPU
{CF305C72-F3E0-44AA-9474-6F12C5276F9F}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{CF305C72-F3E0-44AA-9474-6F12C5276F9F}.Debug|Any CPU.Build.0 = Debug|Any CPU
{CF305C72-F3E0-44AA-9474-6F12C5276F9F}.Release|Any CPU.ActiveCfg = Release|Any CPU
{CF305C72-F3E0-44AA-9474-6F12C5276F9F}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
GlobalSection(NestedProjects) = preSolution

{ADCB37DA-2469-462F-99F6-9D4FB7691A3B} = {2400A22B-695E-4BDF-93CB-8757F5FB3FB7}
{5D553DC6-36AB-4823-85BD-A33F57C81381} = {69930DD1-1688-4407-B4AB-B9E2C0BFB284}
EndGlobalSection
EndGlobal</value>
</data>
<data name="Nuspec_Metadata_PackWithTargetFrameworkDependencies" xml:space="preserve">
<value>&lt;?xml version="1.0" encoding="utf-8"?&gt;
Expand Down
19 changes: 19 additions & 0 deletions src/Cake.Common.Tests/Unit/Solution/SolutionParserTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,25 @@ public void Should_Properly_Parse_Relation_Between_Project_And_Folder()
Assert.Contains(dummyProject, srcFolder.Items);
Assert.Equal(srcFolder, dummyProject.Parent);
}

[Fact]
public void Should_Properly_Parse_Projects_With_Empty_Lines()
{
// Given
var fixture = new SolutionParserFixture();
var slnFilePath = fixture.WithSolutionFile(Resources.Solution_WithProjectsAndFoldersAndMissingLine);
var solutionParser = new SolutionParser(fixture.FileSystem, fixture.Environment);

// When
var result = solutionParser.Parse(slnFilePath);

// Then
Assert.NotNull(result);
Assert.NotNull(result.Projects);
Assert.Equal(5, result.Projects.Count);
var onlyProjects = result.Projects.Where(x => !(x is SolutionFolder)).ToList();
Assert.Equal(3, onlyProjects.Count);
}
}
}
}
6 changes: 6 additions & 0 deletions src/Cake.Common/Solution/SolutionParser.cs
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,12 @@ public SolutionParserResult Parse(FilePath solutionPath)
foreach (var line in file.ReadLines(Encoding.UTF8))
{
var trimmed = line.Trim();

if (trimmed == string.Empty)
{
continue;
}

if (line.StartsWith("Project(\"{"))
{
var project = ParseSolutionProjectLine(file, line);
Expand Down

0 comments on commit 55e8342

Please sign in to comment.