Skip to content

Commit

Permalink
Easier to read generated Class + Filenames (#1437)
Browse files Browse the repository at this point in the history
  • Loading branch information
thomhurst authored Dec 20, 2024
1 parent a08eb86 commit 203132e
Show file tree
Hide file tree
Showing 4 changed files with 6 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,6 @@ public static string Sanitize(string filename)
.Replace('.', '_')
.Replace('-', '_');

return $"{sanitizedFilename}_{Guid.NewGuid():N}";
return $"{sanitizedFilename}";
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ private void Generate(SourceProductionContext productionContext, IEnumerable<Hoo
{
foreach (var groupedByTypeName in hooks.GroupBy(x => x.MinimalTypeName))
{
var className = FilenameSanitizer.Sanitize($"Hooks_{groupedByTypeName.Key}");
var className = $"Hooks_{groupedByTypeName.Key}";

using var sourceBuilder = new SourceCodeWriter();

Expand Down Expand Up @@ -168,7 +168,7 @@ private void Generate(SourceProductionContext productionContext, IEnumerable<Hoo

sourceBuilder.WriteLine("}");

productionContext.AddSource($"{className}.Generated.cs", sourceBuilder.ToString());
productionContext.AddSource($"{className}-{Guid.NewGuid():N}.Generated.cs", sourceBuilder.ToString());
}
}

Expand Down
4 changes: 2 additions & 2 deletions TUnit.Core.SourceGenerator/CodeGenerators/TestsGenerator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ private void GenerateTests(SourceProductionContext context, TestCollectionDataMo
.TestSourceDataModels
.GroupBy(x => $"{prefix}{x.ClassNameToGenerate}"))
{
var className = FilenameSanitizer.Sanitize(classGrouping.Key);
var className = classGrouping.Key;
var count = classGrouping.Count();

using var sourceBuilder = new SourceCodeWriter();
Expand Down Expand Up @@ -160,7 +160,7 @@ private void GenerateTests(SourceProductionContext context, TestCollectionDataMo

sourceBuilder.WriteLine("}");

context.AddSource($"{className}.Generated.cs", sourceBuilder.ToString());
context.AddSource($"{className}-{Guid.NewGuid():N}.Generated.cs", sourceBuilder.ToString());
}
}
}
2 changes: 1 addition & 1 deletion TUnit.Core.SourceGenerator/Models/TestSourceDataModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ public override int GetHashCode()
public required string AssemblyName { get; init; }
public required string Namespace { get; init; }

public string ClassNameToGenerate => new string([..MinimalTypeName, '_', ..Namespace, '_', ..AssemblyName]).Replace('.', '_');
public string ClassNameToGenerate => MinimalTypeName;

public string MethodVariablesWithCancellationToken()
{
Expand Down

0 comments on commit 203132e

Please sign in to comment.