Skip to content

Commit

Permalink
Ensure source paths leave 40 characters for root (dotnet#11835)
Browse files Browse the repository at this point in the history
The default path for VS is in the user directory, which ends up being something like `C:\Users\jkuhne\source\repos\winforms`.

Recent paths make the repo impossible to sync. I've added a test that reserves 40 characters for the repro root path and moved files out of subdirectories that violated that.

A longer follow up is to see if we can pick some type names that aren't so long. Additionally we should try to up this check to 50 characters- which would require more renaming.
  • Loading branch information
JeremyKuhne authored Aug 8, 2024
1 parent 4c8f625 commit 7006c1c
Show file tree
Hide file tree
Showing 29 changed files with 44 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -220,6 +220,6 @@ public async Task CS_ApplicationConfigurationGenerator_GenerateInitialize_user_s

private SourceText LoadFileContent(string testName) =>
SourceText.From(
File.ReadAllText($@"System\Windows\Forms\Generators\MockData\{GetType().Name}.{testName}.cs"),
File.ReadAllText($@"Generators\MockData\{GetType().Name}.{testName}.cs"),
Encoding.UTF8);
}
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ public partial class ApplicationConfigurationInitializeBuilderTests
[InlineData("MyProject", "default_boilerplate")]
public void ApplicationConfigurationInitializeBuilder_GenerateInitialize_can_handle_namespace(string? ns, string expectedFileName)
{
string expected = File.ReadAllText($@"System\Windows\Forms\Generators\MockData\{GetType().Name}.{expectedFileName}.cs");
string expected = File.ReadAllText($@"Generators\MockData\{GetType().Name}.{expectedFileName}.cs");

string output = ApplicationConfigurationInitializeBuilder.GenerateInitialize(ns,
new ApplicationConfig(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,8 @@
</ItemGroup>

<ItemGroup>
<Compile Remove="System\Windows\Forms\Generators\MockData\*.cs" />
<None Include="System\Windows\Forms\Generators\MockData\*.*">
<Compile Remove="Generators\MockData\*.cs" />
<None Include="Generators\MockData\*.*">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
</ItemGroup>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,4 @@
<ProjectReference Include="..\..\..\src\System.Windows.Forms.Analyzers.VisualBasic.vbproj" />
</ItemGroup>

<ItemGroup>
<None Include="System\Windows\Forms\Generators\MockData\*.*">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
</ItemGroup>

</Project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.

using FluentAssertions;
using System.IO.Enumeration;

namespace System.Tests;

public class PathLengthTests
{
[Fact]
public void RepoPathsLeaveRoomForRoot()
{
string currentPath = typeof(PathLengthTests).Assembly.Location;
currentPath = Path.GetFullPath(@"..\..\..\..\..\..\src", currentPath);
Directory.Exists(currentPath).Should().BeTrue();

// Current path will be something like C:\Users\jkuhne\source\repos\winforms\src (41 chars, 38 without src).
// We want to reserve 40 characters of the path length for everything past src.
int currentRootLength = currentPath.Length - "src".Length;

const int MaxRootLength = 40;

int maxLength = 260 - (currentRootLength > MaxRootLength
? MaxRootLength
: MaxRootLength + (MaxRootLength - currentRootLength));

FileSystemEnumerable<string> enumerable = new(
currentPath,
(ref FileSystemEntry entry) => entry.ToFullPath(),
new EnumerationOptions() { RecurseSubdirectories = true })
{
ShouldIncludePredicate = (ref FileSystemEntry entry) =>
// Directory doesn't contain a trailing slash
entry.Directory.Length + entry.FileName.Length > maxLength
};

enumerable.Should().BeEmpty();
}
}

0 comments on commit 7006c1c

Please sign in to comment.