|
5 | 5 | using System.Collections;
|
6 | 6 | using System.Collections.Generic;
|
7 | 7 | using System.IO;
|
| 8 | +using System.Text; |
8 | 9 | using Microsoft.Build.Construction;
|
9 | 10 | using Microsoft.Build.Exceptions;
|
10 | 11 | using Microsoft.Build.Shared;
|
|
16 | 17 |
|
17 | 18 | namespace Microsoft.Build.UnitTests.Construction
|
18 | 19 | {
|
19 |
| - public class SolutionFile_Tests |
| 20 | + public class SolutionFile_OldParser_Tests |
20 | 21 | {
|
21 | 22 | public ITestOutputHelper TestOutputHelper { get; }
|
22 | 23 |
|
23 |
| - public SolutionFile_Tests(ITestOutputHelper testOutputHelper) |
| 24 | + public SolutionFile_OldParser_Tests(ITestOutputHelper testOutputHelper) |
24 | 25 | {
|
25 | 26 | TestOutputHelper = testOutputHelper;
|
26 | 27 | }
|
@@ -104,6 +105,42 @@ public void ParseFirstProjectLineWithDifferentSpacing()
|
104 | 105 | proj.ProjectGuid.ShouldBe("Unique name-GUID");
|
105 | 106 | }
|
106 | 107 |
|
| 108 | + /// <summary> |
| 109 | + /// A slightly more complicated test where there is some different whitespace. |
| 110 | + /// </summary> |
| 111 | + [Fact] |
| 112 | + public void ParseSolutionWithDifferentSpacing() |
| 113 | + { |
| 114 | + string solutionFileContents = |
| 115 | + @" |
| 116 | + Microsoft Visual Studio Solution File, Format Version 9.00 |
| 117 | + # Visual Studio 2005 |
| 118 | + Project(' { Project GUID} ') = ' Project name ', ' Relative path to project file ' , ' {0ABED153-9451-483C-8140-9E8D7306B216} ' |
| 119 | + EndProject |
| 120 | + Global |
| 121 | + GlobalSection(SolutionConfigurationPlatforms) = preSolution |
| 122 | + Debug|AnyCPU = Debug|AnyCPU |
| 123 | + Release|AnyCPU = Release|AnyCPU |
| 124 | + EndGlobalSection |
| 125 | + GlobalSection(ProjectConfigurationPlatforms) = postSolution |
| 126 | + {0ABED153-9451-483C-8140-9E8D7306B216}.Debug|AnyCPU.ActiveCfg = Debug|AnyCPU |
| 127 | + {0ABED153-9451-483C-8140-9E8D7306B216}.Debug|AnyCPU.Build.0 = Debug|AnyCPU |
| 128 | + {0ABED153-9451-483C-8140-9E8D7306B216}.Release|AnyCPU.ActiveCfg = Release|AnyCPU |
| 129 | + {0ABED153-9451-483C-8140-9E8D7306B216}.Release|AnyCPU.Build.0 = Release|AnyCPU |
| 130 | + EndGlobalSection |
| 131 | + GlobalSection(SolutionProperties) = preSolution |
| 132 | + HideSolutionNode = FALSE |
| 133 | + EndGlobalSection |
| 134 | + EndGlobal |
| 135 | + "; |
| 136 | + |
| 137 | + SolutionFile solution = ParseSolutionHelper(solutionFileContents); |
| 138 | + |
| 139 | + Assert.Equal("Project name", solution.ProjectsInOrder[0].ProjectName); |
| 140 | + Assert.Equal("Relative path to project file", solution.ProjectsInOrder[0].RelativePath); |
| 141 | + Assert.Equal("{0ABED153-9451-483C-8140-9E8D7306B216}", solution.ProjectsInOrder[0].ProjectGuid); |
| 142 | + } |
| 143 | + |
107 | 144 | /// <summary>
|
108 | 145 | /// First project line with an empty project name. This is somewhat malformed, but we should
|
109 | 146 | /// still behave reasonably instead of crashing.
|
@@ -687,6 +724,43 @@ public void ParseFirstProjectLineWhereProjectNameHasSpecialCharacters()
|
687 | 724 | proj.ProjectGuid.ShouldBe("Unique name-GUID");
|
688 | 725 | }
|
689 | 726 |
|
| 727 | + /// <summary> |
| 728 | + /// Test some characters that are valid in a file name but that also could be |
| 729 | + /// considered a delimiter by a parser. Does quoting work for special characters? |
| 730 | + /// </summary> |
| 731 | + [Fact] |
| 732 | + public void ParseSolutionWhereProjectNameHasSpecialCharacters() |
| 733 | + { |
| 734 | + string solutionFileContents = |
| 735 | + @" |
| 736 | + Microsoft Visual Studio Solution File, Format Version 9.00 |
| 737 | + # Visual Studio 2005 |
| 738 | + Project('{Project GUID}') = 'MyProject,(=IsGreat)', 'Relative path to project file' , '{0ABED153-9451-483C-8140-9E8D7306B216}' |
| 739 | + EndProject |
| 740 | + Global |
| 741 | + GlobalSection(SolutionConfigurationPlatforms) = preSolution |
| 742 | + Debug|AnyCPU = Debug|AnyCPU |
| 743 | + Release|AnyCPU = Release|AnyCPU |
| 744 | + EndGlobalSection |
| 745 | + GlobalSection(ProjectConfigurationPlatforms) = postSolution |
| 746 | + {0ABED153-9451-483C-8140-9E8D7306B216}.Debug|AnyCPU.ActiveCfg = Debug|AnyCPU |
| 747 | + {0ABED153-9451-483C-8140-9E8D7306B216}.Debug|AnyCPU.Build.0 = Debug|AnyCPU |
| 748 | + {0ABED153-9451-483C-8140-9E8D7306B216}.Release|AnyCPU.ActiveCfg = Release|AnyCPU |
| 749 | + {0ABED153-9451-483C-8140-9E8D7306B216}.Release|AnyCPU.Build.0 = Release|AnyCPU |
| 750 | + EndGlobalSection |
| 751 | + GlobalSection(SolutionProperties) = preSolution |
| 752 | + HideSolutionNode = FALSE |
| 753 | + EndGlobalSection |
| 754 | + EndGlobal |
| 755 | + "; |
| 756 | + |
| 757 | + SolutionFile solution = ParseSolutionHelper(solutionFileContents); |
| 758 | + |
| 759 | + Assert.Equal("MyProject,(=IsGreat)", solution.ProjectsInOrder[0].ProjectName); |
| 760 | + Assert.Equal("Relative path to project file", solution.ProjectsInOrder[0].RelativePath); |
| 761 | + Assert.Equal("{0ABED153-9451-483C-8140-9E8D7306B216}", solution.ProjectsInOrder[0].ProjectGuid); |
| 762 | + } |
| 763 | + |
690 | 764 | /// <summary>
|
691 | 765 | /// Test some characters that are valid in a file name but that also could be
|
692 | 766 | /// considered a delimiter by a parser. Does quoting work for special characters?
|
@@ -2355,5 +2429,58 @@ public void ParseSolutionWithParentedPaths()
|
2355 | 2429 | solution.ProjectsInOrder[0].AbsolutePath.ShouldBe(Path.GetFullPath(Path.Combine(Path.GetDirectoryName(solution.FullPath)!, expectedRelativePath)));
|
2356 | 2430 | solution.ProjectsInOrder[0].ProjectGuid.ShouldBe("{0ABED153-9451-483C-8140-9E8D7306B216}");
|
2357 | 2431 | }
|
| 2432 | + |
| 2433 | + /// <summary> |
| 2434 | + /// Parse solution file with comments |
| 2435 | + /// </summary> |
| 2436 | + [Fact] |
| 2437 | + public void ParseSolutionWithComments() |
| 2438 | + { |
| 2439 | + const string solutionFileContent = @" |
| 2440 | + Microsoft Visual Studio Solution File, Format Version 12.00 |
| 2441 | + # Visual Studio Version 16 |
| 2442 | + VisualStudioVersion = 16.0.29123.89 |
| 2443 | + MinimumVisualStudioVersion = 10.0.40219.1 |
| 2444 | + Project('{9A19103F-16F7-4668-BE54-9A1E7A4F7556}') = 'SlnCommentTest', 'SlnCommentTest.csproj', '{00000000-0000-0000-FFFF-FFFFFFFFFFFF}' |
| 2445 | + EndProject |
| 2446 | + Project('{2150E333-8FDC-42A3-9474-1A3956D46DE8}') = 'Solution Items', 'Solution Items', '{054DED3B-B890-4652-B449-839F581E5D86}' |
| 2447 | + ProjectSection(SolutionItems) = preProject |
| 2448 | + SlnFile.txt = SlnFile.txt |
| 2449 | + EndProjectSection |
| 2450 | + EndProject |
| 2451 | + Global |
| 2452 | + GlobalSection(SolutionConfigurationPlatforms) = preSolution |
| 2453 | + Debug|Any CPU = Debug|Any CPU |
| 2454 | + Release|Any CPU = Release|Any CPU |
| 2455 | + EndGlobalSection |
| 2456 | + GlobalSection(ProjectConfigurationPlatforms) = postSolution |
| 2457 | + {00000000-0000-0000-FFFF-FFFFFFFFFFFF}.Debug|Any CPU.ActiveCfg = Debug|Any CPU |
| 2458 | + {00000000-0000-0000-FFFF-FFFFFFFFFFFF}.Debug|Any CPU.Build.0 = Debug|Any CPU |
| 2459 | + {00000000-0000-0000-FFFF-FFFFFFFFFFFF}.Release|Any CPU.ActiveCfg = Release|Any CPU |
| 2460 | + {00000000-0000-0000-FFFF-FFFFFFFFFFFF}.Release|Any CPU.Build.0 = Release|Any CPU |
| 2461 | + EndGlobalSection |
| 2462 | + GlobalSection(SolutionProperties) = preSolution |
| 2463 | + HideSolutionNode = FALSE |
| 2464 | + EndGlobalSection |
| 2465 | + GlobalSection(ExtensibilityGlobals) = postSolution |
| 2466 | + SolutionGuid = {FFFFFFFF-FFFF-FFFF-0000-000000000000} |
| 2467 | + EndGlobalSection |
| 2468 | + EndGlobal |
| 2469 | + "; |
| 2470 | + |
| 2471 | + StringBuilder stringBuilder = new StringBuilder(); |
| 2472 | + |
| 2473 | + // Put comment between all lines |
| 2474 | + const string comment = "\t# comment"; |
| 2475 | + string[] lines = solutionFileContent.Split(new string[] { Environment.NewLine }, StringSplitOptions.RemoveEmptyEntries); |
| 2476 | + for (int i = 0; i < lines.Length; i++) |
| 2477 | + { |
| 2478 | + stringBuilder.AppendLine(comment); |
| 2479 | + stringBuilder.AppendLine(lines[i]); |
| 2480 | + } |
| 2481 | + stringBuilder.AppendLine(comment); |
| 2482 | + |
| 2483 | + Should.NotThrow(() => ParseSolutionHelper(stringBuilder.ToString())); |
| 2484 | + } |
2358 | 2485 | }
|
2359 | 2486 | }
|
0 commit comments