Skip to content

Commit

Permalink
cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
SimonCropp committed Jul 28, 2024
1 parent 1a6d232 commit 1c95317
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 35 deletions.
4 changes: 2 additions & 2 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -222,7 +222,7 @@ public Task ScrubLines()

## Ignoring Files

To ignore specific source text use `IgnoreGeneratedResultInstance`. This uses an expression of type `Func<GeneratedSourceResult, bool>` to determine which outputs are ignored.
To ignore specific source text use `IgnoreGeneratedResult`. This uses an expression of type `Func<GeneratedSourceResult, bool>` to determine which outputs are ignored.

For example to ignore files with the name `helper` or that contain the text `static void SayHello()`:

Expand All @@ -235,7 +235,7 @@ public Task IgnoreFile()
var driver = GeneratorDriver();

return Verify(driver)
.IgnoreGeneratedResultInstance(
.IgnoreGeneratedResult(
_ => _.HintName.Contains("helper") ||
_.SourceText
.ToString()
Expand Down
4 changes: 2 additions & 2 deletions src/Tests/IgnoreTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ public Task IgnoreFile()
var driver = GeneratorDriver();

return Verify(driver)
.IgnoreGeneratedResultInstance(
.IgnoreGeneratedResult(
_ => _.HintName.Contains("helper") ||
_.SourceText
.ToString()
Expand All @@ -22,7 +22,7 @@ public Task SettingsIgnoreFile()
{
var driver = GeneratorDriver();
var settings = new VerifySettings();
settings.IgnoreGeneratedResultInstance(
settings.IgnoreGeneratedResult(
_ => _.HintName.Contains("helper") ||
_.SourceText
.ToString()
Expand Down
26 changes: 25 additions & 1 deletion src/Verify.SourceGenerators/VerifySourceGenerators.cs
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ static ConversionResult Convert(GeneratorDriverRunResult target, IReadOnlyDictio

static List<Func<GeneratedSourceResult, bool>>? GetIgnoreResults(IReadOnlyDictionary<string, object> context)
{
if (context.TryGetValue(VerifySourceGeneratorsExtensions.IgnoreContextName, out var value))
if (context.TryGetValue(IgnoreContextName, out var value))
{
return (List<Func<GeneratedSourceResult, bool>>)value;
}
Expand All @@ -94,4 +94,28 @@ static Target SourceToTarget(GeneratedSourceResult source)

static ConversionResult Convert(GeneratorDriver target, IReadOnlyDictionary<string, object> context) =>
Convert(target.GetRunResult(), context);

internal const string IgnoreContextName = $"{nameof(VerifySourceGenerators)}.{nameof(IgnoreGeneratedResult)}";

public static SettingsTask IgnoreGeneratedResult(this SettingsTask settingsTask, Func<GeneratedSourceResult, bool> shouldIgnore)
{
settingsTask.CurrentSettings.IgnoreGeneratedResult(shouldIgnore);
return settingsTask;
}

public static void IgnoreGeneratedResult(this VerifySettings verifySettings, Func<GeneratedSourceResult, bool> shouldIgnore)
{
if (!verifySettings.Context.TryGetValue(IgnoreContextName, out var value))
{
value = new List<Func<GeneratedSourceResult, bool>>();
verifySettings.Context.Add(IgnoreContextName, value);
}

if (value is not List<Func<GeneratedSourceResult, bool>> ignoreList)
{
throw new($"Unexpected value in {nameof(verifySettings.Context)}, type is not {nameof(List<Func<GeneratedSourceResult, bool>>)}");
}

ignoreList.Add(shouldIgnore);
}
}
30 changes: 0 additions & 30 deletions src/Verify.SourceGenerators/VerifySourceGeneratorsExtensions.cs

This file was deleted.

0 comments on commit 1c95317

Please sign in to comment.