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
4 changes: 2 additions & 2 deletions src/Verify.Terminal.IntegrationTests/Harness.cs
Original file line number Diff line number Diff line change
Expand Up @@ -216,10 +216,10 @@ public InlineSnapshot FindSingleInline()
return finder.Find(Directory).Single();
}

public SnapshotResult Accept(ISnapshot snapshot) =>
public static SnapshotResult Accept(ISnapshot snapshot) =>
CreateManager().Accept(snapshot);

public SnapshotResult Reject(ISnapshot snapshot) =>
public static SnapshotResult Reject(ISnapshot snapshot) =>
CreateManager().Reject(snapshot);

private static SnapshotManager CreateManager()
Expand Down
8 changes: 4 additions & 4 deletions src/Verify.Terminal.IntegrationTests/InlineSnapshotTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ public Task Sample() =>
// snapshot pending.
harness.FindFileSnapshots().ShouldBeEmpty();

harness.Accept(snapshot).Succeeded.ShouldBeTrue();
Harness.Accept(snapshot).Succeeded.ShouldBeTrue();

// The literal is written as the raw string Verify reads back, which is what makes the next
// run pass rather than fail against its own snapshot.
Expand Down Expand Up @@ -101,7 +101,7 @@ public Task Sample() =>
snapshot.Expected.ShouldBeEmpty();
snapshot.Received.ShouldBe(Value);

harness.Accept(snapshot).Succeeded.ShouldBeTrue();
Harness.Accept(snapshot).Succeeded.ShouldBeTrue();

harness.ReadSource().ShouldBe(
""""
Expand Down Expand Up @@ -165,7 +165,7 @@ await Fails(

// Accept: asked of the owner, which applies the patch and drops the entry, so every
// surface agrees the snapshot is no longer pending.
harness.Accept(snapshot).Succeeded.ShouldBeTrue();
Harness.Accept(snapshot).Succeeded.ShouldBeTrue();

harness.ReadSource().ShouldBe(
""""
Expand Down Expand Up @@ -201,7 +201,7 @@ public Task Sample() =>
await Fails(harness, _ => _.Snapshot("old snapshot", source, 4, "\"old snapshot\"", "Sample"));
harness.PublishInline().ShouldBe(1);

harness.Reject(harness.FindSingleInline()).Succeeded.ShouldBeTrue();
Harness.Reject(harness.FindSingleInline()).Succeeded.ShouldBeTrue();

harness.ReadSource().ShouldBe(before);

Expand Down
12 changes: 6 additions & 6 deletions src/Verify.Terminal.IntegrationTests/IntegrationTestBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ protected static string AssemblyConfiguration() =>
// snapshots from an older Verify, or when obj is not scanned. Both have to reach the same file.
// Looped rather than a [Theory], since a test method parameter would be appended to the snapshot
// name by Verify and change the very names under assertion.
protected async Task AssertExistingVerifiedIsDetected(
protected static async Task AssertExistingVerifiedIsDetected(
string method,
Action<VerifySettings> configure,
string expectedVerified)
Expand Down Expand Up @@ -83,7 +83,7 @@ async Task Run(bool withMap)
var literal = received.Replace(".received.", ".verified.");
snapshot.IsRerouted.ShouldBe(correctVerified != literal, because);

harness.Accept(snapshot).Succeeded.ShouldBeTrue(because);
Harness.Accept(snapshot).Succeeded.ShouldBeTrue(because);

// The received value now lives at the correct verified name, so Verify passes.
(await Verifies(settings)).ShouldBeTrue(because);
Expand All @@ -93,7 +93,7 @@ async Task Run(bool withMap)
// A brand new snapshot with no verified file on disk. With nothing to pair against, the finder
// falls back to the received-derived name. Whether that is correct depends on whether the correct
// verified name equals the received-derived name.
protected async Task AssertNewSnapshot(
protected static async Task AssertNewSnapshot(
string method,
Action<VerifySettings> configure,
string expectedVerified,
Expand All @@ -118,14 +118,14 @@ protected async Task AssertNewSnapshot(
System.IO.Path.GetFileName(snapshot.Verified.FullPath).ShouldBe(literal);
snapshot.IsRerouted.ShouldBeFalse();

harness.Accept(snapshot).Succeeded.ShouldBeTrue();
Harness.Accept(snapshot).Succeeded.ShouldBeTrue();

(await Verifies(settings)).ShouldBe(expectRoundTrips);
}

// A brand new snapshot, but with Verify's received map available. The map names the verified file,
// so the finder places it correctly instead of falling back to the received-derived name.
protected async Task AssertNewSnapshotWithMap(
protected static async Task AssertNewSnapshotWithMap(
string method,
Action<VerifySettings> configure,
string expectedVerified)
Expand All @@ -149,7 +149,7 @@ protected async Task AssertNewSnapshotWithMap(
System.IO.Path.GetFileName(snapshot.Verified.FullPath).ShouldBe(correctVerified);
snapshot.IsRerouted.ShouldBe(correctVerified != received.Replace(".received.", ".verified."));

harness.Accept(snapshot).Succeeded.ShouldBeTrue();
Harness.Accept(snapshot).Succeeded.ShouldBeTrue();

// The accept landed where Verify expects, so the next run passes.
(await Verifies(settings)).ShouldBeTrue();
Expand Down
65 changes: 26 additions & 39 deletions src/Verify.Terminal.IntegrationTests/ParameterNamingTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ public Task IgnoreTrailingParameter_ExistingVerified_IsDetected(string a, string
// Run against both the map, which is how Verify behaves now, and the fallback, which still applies
// to an older Verify, or when obj is not scanned. Looped rather than another [InlineData], since an extra
// test method parameter would be appended to the snapshot name by Verify.
async Task AssertParametersAreDetected(string name, string a, string b, string? ignored, string expectedVerified)
static async Task AssertParametersAreDetected(string name, string a, string b, string? ignored, string expectedVerified)
{
await Run(withMap: true);
await Run(withMap: false);
Expand All @@ -41,23 +41,18 @@ async Task Run(bool withMap)
{
using var harness = new Harness(name);

VerifySettings Settings()
var settings = harness.CreateSettings();
settings.UseTypeName("N");
settings.UseMethodName("Params");
settings.UseParameters(a, b);
if (ignored != null)
{
var settings = harness.CreateSettings();
settings.UseTypeName("N");
settings.UseMethodName("Params");
settings.UseParameters(a, b);
if (ignored != null)
{
settings.IgnoreParameters(ignored);
}

return settings;
settings.IgnoreParameters(ignored);
}

var because = withMap ? "with map" : "without map";

var correctVerified = await ProduceReceived(Settings());
var correctVerified = await ProduceReceived(settings);
correctVerified.ShouldBe(expectedVerified, because);

var received = harness.ReceivedFileNames().ShouldHaveSingleItem();
Expand All @@ -74,8 +69,8 @@ VerifySettings Settings()
System.IO.Path.GetFileName(snapshot.Verified.FullPath).ShouldBe(correctVerified, because);
snapshot.IsRerouted.ShouldBeTrue(because);

harness.Accept(snapshot).Succeeded.ShouldBeTrue(because);
(await Verifies(Settings())).ShouldBeTrue(because);
Harness.Accept(snapshot).Succeeded.ShouldBeTrue(because);
(await Verifies(settings)).ShouldBeTrue(because);
}
}

Expand All @@ -85,17 +80,13 @@ public async Task IgnoreLeadingParameter_WithMap_IsPlaced(string a, string b)
{
using var harness = new Harness(nameof(IgnoreLeadingParameter_WithMap_IsPlaced));

VerifySettings Settings()
{
var settings = harness.CreateSettings();
settings.UseTypeName("N");
settings.UseMethodName("Params");
settings.UseParameters(a, b);
settings.IgnoreParameters("a");
return settings;
}
var settings = harness.CreateSettings();
settings.UseTypeName("N");
settings.UseMethodName("Params");
settings.UseParameters(a, b);
settings.IgnoreParameters("a");

var correctVerified = await ProduceReceived(Settings());
var correctVerified = await ProduceReceived(settings);
correctVerified.ShouldBe("N.Params_b=2.verified.txt");

harness.SeedVerified(correctVerified, "old-verified");
Expand All @@ -106,8 +97,8 @@ VerifySettings Settings()
System.IO.Path.GetFileName(snapshot.Verified.FullPath).ShouldBe(correctVerified);
snapshot.IsRerouted.ShouldBeTrue();

harness.Accept(snapshot).Succeeded.ShouldBeTrue();
(await Verifies(Settings())).ShouldBeTrue();
Harness.Accept(snapshot).Succeeded.ShouldBeTrue();
(await Verifies(settings)).ShouldBeTrue();
}

[Theory]
Expand All @@ -116,17 +107,13 @@ public async Task IgnoreLeadingParameter_WithoutMap_CannotBePaired(string a, str
{
using var harness = new Harness(nameof(IgnoreLeadingParameter_WithoutMap_CannotBePaired));

VerifySettings Settings()
{
var settings = harness.CreateSettings();
settings.UseTypeName("N");
settings.UseMethodName("Params");
settings.UseParameters(a, b);
settings.IgnoreParameters("a");
return settings;
}
var settings = harness.CreateSettings();
settings.UseTypeName("N");
settings.UseMethodName("Params");
settings.UseParameters(a, b);
settings.IgnoreParameters("a");

var correctVerified = await ProduceReceived(Settings());
var correctVerified = await ProduceReceived(settings);
// The leading parameter `a` is dropped, so the verified name is not a prefix of the received name.
correctVerified.ShouldBe("N.Params_b=2.verified.txt");

Expand All @@ -141,11 +128,11 @@ VerifySettings Settings()
System.IO.Path.GetFileName(snapshot.Verified.FullPath).ShouldBe(literal);
snapshot.IsRerouted.ShouldBeFalse();

harness.Accept(snapshot).Succeeded.ShouldBeTrue();
Harness.Accept(snapshot).Succeeded.ShouldBeTrue();

// A non-trailing ignored parameter cannot be reconstructed from the received name, so the
// accept lands at the wrong verified file and Verify still fails. This is only reachable
// without a map, ie. an older Verify, or when obj is not scanned. See the WithMap case above.
(await Verifies(Settings())).ShouldBeFalse();
(await Verifies(settings)).ShouldBeFalse();
}
}
6 changes: 3 additions & 3 deletions src/Verify.Terminal.Tests/InlineSnapshotFinderTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ public void Should_Merge_Staged_Patches_That_Agree()
// with both sets of files to clear once it is dealt with.
var fileSystem = CreateFileSystem();
InlineTestData.Stage(fileSystem, InlineTestData.Patch("new snapshot"), "DotNet8_0");
InlineTestData.Stage(fileSystem, InlineTestData.Patch("new snapshot"), "DotNet10_0");
InlineTestData.Stage(fileSystem, InlineTestData.Patch("new snapshot"));

var result = Find(fileSystem).ShouldHaveSingleItem();

Expand All @@ -83,7 +83,7 @@ public void Should_Flag_Staged_Patches_That_Disagree()
{
var fileSystem = CreateFileSystem();
InlineTestData.Stage(fileSystem, InlineTestData.Patch("from net8"), "DotNet8_0");
InlineTestData.Stage(fileSystem, InlineTestData.Patch("from net10"), "DotNet10_0");
InlineTestData.Stage(fileSystem, InlineTestData.Patch("from net10"));

var result = Find(fileSystem).ShouldHaveSingleItem();

Expand Down Expand Up @@ -156,7 +156,7 @@ private static InlinePatch Origin(InlinePatch patch, string framework)
}

private static FakeFileSystem CreateFileSystem() =>
new(new FakeEnvironment(PlatformFamily.Linux));
new(new(PlatformFamily.Linux));

private static IReadOnlyList<InlineSnapshot> Find(
FakeFileSystem fileSystem,
Expand Down
6 changes: 3 additions & 3 deletions src/Verify.Terminal.Tests/InlineSnapshotManagerTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -242,7 +242,7 @@ public void Should_Clear_The_Staged_Files_On_Reject()
}

private static FakeFileSystem CreateFileSystem() =>
new(new FakeEnvironment(PlatformFamily.Linux));
new(new(PlatformFamily.Linux));

private static InlineSnapshotManager Create(
IInlineQueueOwner? queue = null,
Expand All @@ -262,7 +262,7 @@ private static IReadOnlyList<StagedInline> Staged(FakeFileSystem fileSystem, Inl
// Through the finder rather than by hand, so the manager is handed what it is handed in a
// real run: the patch as it was read back off disk, beside the files it was read from.
return finder
.Find(new DirectoryPath("/Working"))
.Find(new("/Working"))
.SelectMany(_ => _.Staged)
.ToList();
}
Expand All @@ -271,7 +271,7 @@ private static IReadOnlyList<string> StagedFiles(FakeFileSystem fileSystem)
{
var globber = new Globber(fileSystem, new FakeEnvironment(PlatformFamily.Linux));
return globber
.Match("**/VerifyInline/*", new GlobberSettings { Root = new DirectoryPath("/Working") })
.Match("**/VerifyInline/*", new() { Root = new("/Working") })
.OfType<FilePath>()
.Select(_ => _.FullPath)
.ToList();
Expand Down
2 changes: 1 addition & 1 deletion src/Verify.Terminal.Tests/SnapshotRendererTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ public Task Should_Render_A_Conflicted_Inline_Snapshot()
// are there.
var diff = differ.Diff(
new InlineSnapshot(
InlineTestData.Patch("from net10", "old snapshot"),
InlineTestData.Patch("from net10"),
isQueued: true,
conflict: "net8.0 / net10.0"));

Expand Down
2 changes: 1 addition & 1 deletion src/Verify.Terminal/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,6 @@ private static TypeRegistrar BuildContainer()
services.AddSingleton<SnapshotDiffer>();
services.AddSingleton<SnapshotRenderer>();

return new TypeRegistrar(services);
return new(services);
}
}
10 changes: 5 additions & 5 deletions src/Verify.Terminal/Rendering/ReportBuilder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ public sealed class ReportBuilder
public ReportBuilder(IAnsiConsole console, CharacterSet characters)
{
_console = console.NotNull();
_buffer = new List<Segment>();
_lines = new List<SegmentLine>();
_buffer = new();
_lines = new();

Characters = characters.NotNull();
}
Expand Down Expand Up @@ -42,12 +42,12 @@ public void Append(string text, Color? color = null, Decoration? decoration = nu
text = text[..maxLength.Value];
}

_buffer.Add(new Segment(text, new Style(foreground: color, decoration: decoration)));
_buffer.Add(new(text, new(foreground: color, decoration: decoration)));
}

public void Append(char character, Color? color = null, Decoration? decoration = null)
{
_buffer.Add(new Segment(new string(character, 1), new Style(foreground: color, decoration: decoration)));
_buffer.Add(new(new(character, 1), new(foreground: color, decoration: decoration)));
}

public void AppendRepeated(Character character, int count, Color? color = null)
Expand Down Expand Up @@ -80,7 +80,7 @@ public void CommitLine()
AppendSpace();
}

_lines.Add(new SegmentLine(_buffer));
_lines.Add(new(_buffer));
_buffer.Clear();
}

Expand Down
4 changes: 2 additions & 2 deletions src/Verify.Terminal/Rendering/ReportRenderable.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,12 @@ internal sealed class ReportRenderable : IRenderable

public ReportRenderable(IEnumerable<SegmentLine> lines)
{
_lines = new List<SegmentLine>(lines.NotNull());
_lines = new(lines.NotNull());
}

public Measurement Measure(RenderOptions context, int maxWidth)
{
return new Measurement(maxWidth, maxWidth);
return new(maxWidth, maxWidth);
}

public IEnumerable<Segment> Render(RenderOptions context, int maxWidth)
Expand Down
2 changes: 1 addition & 1 deletion src/Verify.Terminal/SnapshotDiff.cs
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ public SnapshotDiff(ISnapshot snapshot, List<DiffPiece> old, List<DiffPiece> @ne

if (ranges.Count == 0)
{
return new List<(int Start, int Stop)>();
return new();
}

return MergeRanges(ranges);
Expand Down
2 changes: 1 addition & 1 deletion src/Verify.Terminal/SnapshotDiffer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ public SnapshotDiff Diff(ISnapshot snapshot)

var diff = SideBySideDiffBuilder.Instance.BuildDiffModel(oldText, newText, false);

return new SnapshotDiff(snapshot, diff.OldText.Lines, diff.NewText.Lines);
return new(snapshot, diff.OldText.Lines, diff.NewText.Lines);
}

private (string Old, string New) Text(ISnapshot snapshot)
Expand Down
6 changes: 3 additions & 3 deletions src/Verify.Terminal/SnapshotFinder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -42,15 +42,15 @@ public ISet<Snapshot> Find(DirectoryPath? root = null)
foreach (var received in Match(root, "**/*.received.*", "received"))
{
var (verifiedPath, isRerouted) = GetVerified(received, maps, verifiedByDirectory);
result.Add(new Snapshot(received.Path, verifiedPath, isRerouted));
result.Add(new(received.Path, verifiedPath, isRerouted));
}

return result;
}

private IEnumerable<ParsedName> Match(DirectoryPath root, string pattern, string marker) =>
_globber
.Match(pattern, new GlobberSettings { Root = root })
.Match(pattern, new() { Root = root })
.OfType<FilePath>()
.Where(_ => !IsInlineStaging(_))
.Select(_ => ParsedName.Parse(_, marker));
Expand All @@ -63,7 +63,7 @@ private static bool IsInlineStaging(FilePath path) =>
$"/{InlineSnapshotFinder.StagingDirectoryName}/",
StringComparison.OrdinalIgnoreCase);

private (FilePath VerifiedPath, bool IsRerouted) GetVerified(
private static (FilePath VerifiedPath, bool IsRerouted) GetVerified(
ParsedName received,
ReceivedMaps maps,
Dictionary<string, List<ParsedName>> verifiedByDirectory)
Expand Down