Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
// <auto-generated/>
// <auto-generated/>
#pragma warning disable

#nullable enable
namespace TUnit.Generated;
[global::System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverageAttribute]
[global::System.CodeDom.Compiler.GeneratedCode("TUnit", "1.0.0.0")]
internal sealed class TUnit_TestProject_GenericMethodTests_AggregateBy_HasExpectedOutput__IEnumerable_TSource__Func_TSource__TKey__Func_TKey__TAccumulate__Func_TAccumulate__TSource__TAccumulate__IEqualityComparer_TKey___IEnumerable_KeyValuePair_TKey__TAccumulate___TestSource : global::TUnit.Core.Interfaces.SourceGenerator.ITestSource, global::TUnit.Core.Interfaces.SourceGenerator.ITestDescriptorSource
internal sealed class TUnit_TestProject_GenericMethodTests_AggregateBy_HasExpectedOutput__IEnumerable_TSource__Func_TSource__TKey__Func_TKey__TAccumulate__Func_TAccumulate__TSource__TAccumulate__IEqualityComp_06BD488B_TestSource : global::TUnit.Core.Interfaces.SourceGenerator.ITestSource, global::TUnit.Core.Interfaces.SourceGenerator.ITestDescriptorSource
{
public async global::System.Collections.Generic.IAsyncEnumerable<global::TUnit.Core.TestMetadata> GetTestsAsync(string testSessionId, [global::System.Runtime.CompilerServices.EnumeratorCancellation] global::System.Threading.CancellationToken cancellationToken = default)
{
Expand Down Expand Up @@ -440,11 +440,11 @@ internal sealed class TUnit_TestProject_GenericMethodTests_AggregateBy_HasExpect
};
}
}
internal static class TUnit_TestProject_GenericMethodTests_AggregateBy_HasExpectedOutput__IEnumerable_TSource__Func_TSource__TKey__Func_TKey__TAccumulate__Func_TAccumulate__TSource__TAccumulate__IEqualityComparer_TKey___IEnumerable_KeyValuePair_TKey__TAccumulate___ModuleInitializer
internal static class TUnit_TestProject_GenericMethodTests_AggregateBy_HasExpectedOutput__IEnumerable_TSource__Func_TSource__TKey__Func_TKey__TAccumulate__Func_TAccumulate__TSource__TAccumulate__IEqualityComp_06BD488B_ModuleInitializer
{
[global::System.Runtime.CompilerServices.ModuleInitializer]
public static void Initialize()
{
global::TUnit.Core.SourceRegistrar.Register(typeof(global::TUnit.TestProject.GenericMethodTests), new TUnit_TestProject_GenericMethodTests_AggregateBy_HasExpectedOutput__IEnumerable_TSource__Func_TSource__TKey__Func_TKey__TAccumulate__Func_TAccumulate__TSource__TAccumulate__IEqualityComparer_TKey___IEnumerable_KeyValuePair_TKey__TAccumulate___TestSource());
global::TUnit.Core.SourceRegistrar.Register(typeof(global::TUnit.TestProject.GenericMethodTests), new TUnit_TestProject_GenericMethodTests_AggregateBy_HasExpectedOutput__IEnumerable_TSource__Func_TSource__TKey__Func_TKey__TAccumulate__Func_TAccumulate__TSource__TAccumulate__IEqualityComp_06BD488B_TestSource());
}
}
36 changes: 34 additions & 2 deletions TUnit.Core.SourceGenerator/Helpers/FileNameHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,10 @@ internal static class FileNameHelper
/// <param name="typeSymbol">The type symbol for the test class</param>
/// <param name="methodSymbol">The method symbol for the test method</param>
/// <returns>A deterministic filename like "MyNamespace_MyClass_MyMethod__Int32_String.g.cs"</returns>
// Conservative limit to avoid PathTooLongException on Windows with net472,
// which enforces the legacy 260-character MAX_PATH limit in Roslyn's AddSource.
private const int MaxHintNameLength = 200;

public static string GetDeterministicFileNameForMethod(INamedTypeSymbol typeSymbol, IMethodSymbol methodSymbol)
{
var sb = new StringBuilder();
Expand Down Expand Up @@ -71,8 +75,36 @@ public static string GetDeterministicFileNameForMethod(INamedTypeSymbol typeSymb
}
}

sb.Append(".g.cs");
return sb.ToString();
var baseName = sb.ToString();

// Truncate and append a hash if the name would exceed the limit
const int suffixLength = 5; // ".g.cs"
if (baseName.Length + suffixLength > MaxHintNameLength)
{
var hashSuffix = $"_{GetStableHashCode(baseName):X8}";
var maxBaseLength = MaxHintNameLength - suffixLength - hashSuffix.Length;
baseName = baseName.Substring(0, maxBaseLength) + hashSuffix;
}

return baseName + ".g.cs";
}

/// <summary>
/// Computes a deterministic hash code for a string (FNV-1a).
/// Unlike string.GetHashCode(), this is stable across processes and platforms.
/// </summary>
private static uint GetStableHashCode(string str)
{
unchecked
{
uint hash = 2166136261;
foreach (var c in str)
{
hash ^= c;
hash *= 16777619;
}
return hash;
}
}

/// <summary>
Expand Down
Loading