Skip to content

Commit 3419875

Browse files
authored
Fixing failure when .sln is located in root directory (#485)
1 parent 943690f commit 3419875

File tree

7 files changed

+71
-4
lines changed

7 files changed

+71
-4
lines changed
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<Project Sdk="Microsoft.NET.Sdk">
3+
<PropertyGroup>
4+
<TargetFramework>net6</TargetFramework>
5+
</PropertyGroup>
6+
<ItemGroup>
7+
<PackageReference Include="Microsoft.CSharp" Version="4.7.0" />
8+
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.1.0" />
9+
<PackageReference Include="Xunit" Version="2.4.1" />
10+
<PackageReference Include="xunit.runner.visualstudio" Version="2.4.3" />
11+
<PackageReference Include="ProjectDefaults" Version="1.0.68" PrivateAssets="all" />
12+
<ProjectReference Include="..\Verify.Xunit\Verify.Xunit.csproj" />
13+
<ProjectReference Include="..\Verify\Verify.csproj" />
14+
</ItemGroup>
15+
<Import Project="$(ProjectDir)..\Verify\buildTransitive\Verify.props" />
16+
<Import Project="$(ProjectDir)..\Verify\buildTransitive\Verify.targets" />
17+
<Import Project="$(ProjectDir)..\Verify.Xunit\buildTransitive\Verify.Xunit.props" />
18+
</Project>
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
CustomReplace\DisableDirScrubbing
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
CustomReplace\
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
[UsesVerify]
2+
public class ApplyScrubbersTests
3+
{
4+
[Theory]
5+
[InlineData("/", "/project", "/,/project")]
6+
[InlineData("/solution", "/project", "/solution,/project")]
7+
[InlineData("/solution/", "/project/", "/solution,/project")]
8+
[InlineData("/solution//", "/project//", "/solution,/project")]
9+
public void Apply_solution_and_project_directories_scrubbers(
10+
string solutionDirectory,
11+
string projectDirectory,
12+
string input)
13+
{
14+
// Arrange
15+
var extension = string.Empty;
16+
var builder = new StringBuilder(input);
17+
var settings = new VerifySettings();
18+
19+
// Act
20+
ApplyScrubbers.UseAssembly(solutionDirectory, projectDirectory);
21+
ApplyScrubbers.Apply(extension, builder, settings);
22+
23+
// Assert
24+
Assert.Equal("{SolutionDirectory},{ProjectDirectory}", builder.ToString());
25+
}
26+
}

src/Verify.sln

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,8 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Verify.ClipboardAccept", "V
7171
EndProject
7272
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Verify.ClipboardAccept.Tests", "Verify.ClipboardAccept.Tests\Verify.ClipboardAccept.Tests.csproj", "{1E92BEB7-4455-49D4-9317-AF90B97684CD}"
7373
EndProject
74+
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ApplyScrubbersTests", "ApplyScrubbersTests\ApplyScrubbersTests.csproj", "{3DE5EAD9-0C33-4ACB-9D4A-F6DB4AE01208}"
75+
EndProject
7476
Global
7577
GlobalSection(SolutionConfigurationPlatforms) = preSolution
7678
Debug|Any CPU = Debug|Any CPU
@@ -233,6 +235,17 @@ Global
233235
{1E92BEB7-4455-49D4-9317-AF90B97684CD}.DebugNet6|Any CPU.Build.0 = DebugNet6|Any CPU
234236
{1E92BEB7-4455-49D4-9317-AF90B97684CD}.Release|Any CPU.ActiveCfg = Release|Any CPU
235237
{1E92BEB7-4455-49D4-9317-AF90B97684CD}.Release|Any CPU.Build.0 = Release|Any CPU
238+
{1868CA7C-CD2C-488F-9E52-0BB895E5DB18}.Debug|Any CPU.ActiveCfg = Release|Any CPU
239+
{1868CA7C-CD2C-488F-9E52-0BB895E5DB18}.Debug|Any CPU.Build.0 = Release|Any CPU
240+
{1868CA7C-CD2C-488F-9E52-0BB895E5DB18}.DebugNet6|Any CPU.ActiveCfg = DebugNet6|Any CPU
241+
{1868CA7C-CD2C-488F-9E52-0BB895E5DB18}.Release|Any CPU.ActiveCfg = Release|Any CPU
242+
{1868CA7C-CD2C-488F-9E52-0BB895E5DB18}.Release|Any CPU.Build.0 = Release|Any CPU
243+
{3DE5EAD9-0C33-4ACB-9D4A-F6DB4AE01208}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
244+
{3DE5EAD9-0C33-4ACB-9D4A-F6DB4AE01208}.Debug|Any CPU.Build.0 = Debug|Any CPU
245+
{3DE5EAD9-0C33-4ACB-9D4A-F6DB4AE01208}.DebugNet6|Any CPU.ActiveCfg = DebugNet6|Any CPU
246+
{3DE5EAD9-0C33-4ACB-9D4A-F6DB4AE01208}.DebugNet6|Any CPU.Build.0 = DebugNet6|Any CPU
247+
{3DE5EAD9-0C33-4ACB-9D4A-F6DB4AE01208}.Release|Any CPU.ActiveCfg = Release|Any CPU
248+
{3DE5EAD9-0C33-4ACB-9D4A-F6DB4AE01208}.Release|Any CPU.Build.0 = Release|Any CPU
236249
EndGlobalSection
237250
GlobalSection(SolutionProperties) = preSolution
238251
HideSolutionNode = FALSE

src/Verify/InternalsVisibleTo.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,3 +8,4 @@
88
[assembly:InternalsVisibleTo("NamingTests, PublicKey=00240000048000009400000006020000002400005253413100040000010001000f0a8e4bf1639dce01be6592384e7dfc621915b7759fb5cee42ec5d351bcc43460432da1659ee618ca6cab6b8b8e56a5deb5d4ee1a49783d5c2690752502d31ccbfee9b2c697e20359b55ad100cc9370c8e983fd9496f01d761a060d0435bac7243b1832ba95757aa5adbb67df38c213d717b6751e1217cea9fa5c61e9b799dd")]
99
[assembly:InternalsVisibleTo("Verify.Expecto, PublicKey=00240000048000009400000006020000002400005253413100040000010001000f0a8e4bf1639dce01be6592384e7dfc621915b7759fb5cee42ec5d351bcc43460432da1659ee618ca6cab6b8b8e56a5deb5d4ee1a49783d5c2690752502d31ccbfee9b2c697e20359b55ad100cc9370c8e983fd9496f01d761a060d0435bac7243b1832ba95757aa5adbb67df38c213d717b6751e1217cea9fa5c61e9b799dd")]
1010
[assembly:InternalsVisibleTo("Verify.ExceptionParsing.Tests, PublicKey=00240000048000009400000006020000002400005253413100040000010001000f0a8e4bf1639dce01be6592384e7dfc621915b7759fb5cee42ec5d351bcc43460432da1659ee618ca6cab6b8b8e56a5deb5d4ee1a49783d5c2690752502d31ccbfee9b2c697e20359b55ad100cc9370c8e983fd9496f01d761a060d0435bac7243b1832ba95757aa5adbb67df38c213d717b6751e1217cea9fa5c61e9b799dd")]
11+
[assembly:InternalsVisibleTo("ApplyScrubbersTests, PublicKey=00240000048000009400000006020000002400005253413100040000010001000f0a8e4bf1639dce01be6592384e7dfc621915b7759fb5cee42ec5d351bcc43460432da1659ee618ca6cab6b8b8e56a5deb5d4ee1a49783d5c2690752502d31ccbfee9b2c697e20359b55ad100cc9370c8e983fd9496f01d761a060d0435bac7243b1832ba95757aa5adbb67df38c213d717b6751e1217cea9fa5c61e9b799dd")]

src/Verify/Serialization/Scrubbers/ApplyScrubbers.cs

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -81,18 +81,25 @@ static void AddProjectAndSolutionReplacements(string? solutionDir, string projec
8181
}
8282

8383
var altSolutionDir = solutionDir.ReplaceAltDirChar();
84-
var altSolutionDirTrimmed = altSolutionDir.TrimEnd('/', '\\');
85-
var solutionDirectoryTrimmed = solutionDir.TrimEnd('/', '\\');
8684

8785
replacements[projectDir] = "{ProjectDirectory}";
8886
replacements[projectDirTrimmed] = "{ProjectDirectory}";
8987
replacements[altProjectDir] = "{ProjectDirectory}";
9088
replacements[altProjectDirTrimmed] = "{ProjectDirectory}";
9189

9290
replacements[solutionDir] = "{SolutionDirectory}";
93-
replacements[solutionDirectoryTrimmed] = "{SolutionDirectory}";
91+
if (solutionDir.Length > 1)
92+
{
93+
var solutionDirectoryTrimmed = solutionDir.TrimEnd('/', '\\');
94+
replacements[solutionDirectoryTrimmed] = "{SolutionDirectory}";
95+
}
96+
9497
replacements[altSolutionDir] = "{SolutionDirectory}";
95-
replacements[altSolutionDirTrimmed] = "{SolutionDirectory}";
98+
if (solutionDir.Length > 1)
99+
{
100+
var altSolutionDirTrimmed = altSolutionDir.TrimEnd('/', '\\');
101+
replacements[altSolutionDirTrimmed] = "{SolutionDirectory}";
102+
}
96103
}
97104

98105
public static void Apply(string extension, StringBuilder target, VerifySettings settings)

0 commit comments

Comments
 (0)