Skip to content

Commit

Permalink
drop support for null as the root object (#660)
Browse files Browse the repository at this point in the history
  • Loading branch information
SimonCropp authored Sep 23, 2022
1 parent 4801a4a commit 5250c7a
Show file tree
Hide file tree
Showing 40 changed files with 85 additions and 147 deletions.
8 changes: 4 additions & 4 deletions docs/parameterised.md
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,7 @@ public class ComplexParametersSample

[Theory]
[MemberData(nameof(GetComplexMemberData))]
public Task ComplexMemberNullableData(ComplexData? arg)
public Task ComplexMemberNullableData(ComplexData arg)
{
var settings = new VerifySettings();
settings.UseParameters(arg);
Expand All @@ -173,7 +173,7 @@ public class ComplexParametersSample

[Theory]
[MemberData(nameof(GetComplexMemberData))]
public Task ComplexMemberNullableDataFluent(ComplexData? arg) =>
public Task ComplexMemberNullableDataFluent(ComplexData arg) =>
Verify(arg)
.UseParameters(arg);

Expand Down Expand Up @@ -211,7 +211,7 @@ public class ComplexParametersSample

[Theory]
[MemberData(nameof(GetComplexMemberStructData))]
public Task ComplexMemberNullableStructData(ComplexStructData? arg)
public Task ComplexMemberNullableStructData(ComplexStructData arg)
{
var settings = new VerifySettings();
settings.UseParameters(arg);
Expand All @@ -220,7 +220,7 @@ public class ComplexParametersSample

[Theory]
[MemberData(nameof(GetComplexMemberStructData))]
public Task ComplexMemberNullableStructDataFluent(ComplexStructData? arg) =>
public Task ComplexMemberNullableStructDataFluent(ComplexStructData arg) =>
Verify(arg)
.UseParameters(arg);

Expand Down
4 changes: 2 additions & 2 deletions docs/serializer-settings.md
Original file line number Diff line number Diff line change
Expand Up @@ -1592,7 +1592,7 @@ The default mapping is:
}
}
```
<sup><a href='/src/Verify/Serialization/VerifierSettings.cs#L44-L136' title='Snippet source file'>snippet source</a> | <a href='#snippet-typetostringmapping' title='Start of snippet'>anchor</a></sup>
<sup><a href='/src/Verify/Serialization/VerifierSettings.cs#L38-L130' title='Snippet source file'>snippet source</a> | <a href='#snippet-typetostringmapping' title='Start of snippet'>anchor</a></sup>
<!-- endSnippet -->

This bypasses the Guid and DateTime scrubbing mentioned above.
Expand Down Expand Up @@ -1750,7 +1750,7 @@ If the target is a stream or binary file:
public Task Stream() =>
Verify(IoHelpers.OpenRead("sample.txt"));
```
<sup><a href='/src/Verify.Tests/Converters/JsonAppenderTests.cs#L69-L75' title='Snippet source file'>snippet source</a> | <a href='#snippet-jsonappenderstream' title='Start of snippet'>anchor</a></sup>
<sup><a href='/src/Verify.Tests/Converters/JsonAppenderTests.cs#L65-L71' title='Snippet source file'>snippet source</a> | <a href='#snippet-jsonappenderstream' title='Start of snippet'>anchor</a></sup>
<!-- endSnippet -->

Then the appended content will be added to the `.verified.txt` file:
Expand Down
4 changes: 2 additions & 2 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -447,7 +447,7 @@ var result = await Verify(
});
Assert.Contains("Value To Check", result.Text);
```
<sup><a href='/src/Verify.Tests/Tests.cs#L596-L605' title='Snippet source file'>snippet source</a> | <a href='#snippet-verifyresult' title='Start of snippet'>anchor</a></sup>
<sup><a href='/src/Verify.Tests/Tests.cs#L584-L593' title='Snippet source file'>snippet source</a> | <a href='#snippet-verifyresult' title='Start of snippet'>anchor</a></sup>
<!-- endSnippet -->

If using `Verifier.Throws`, the resulting `Exception` will also be accessible
Expand All @@ -458,7 +458,7 @@ If using `Verifier.Throws`, the resulting `Exception` will also be accessible
var result = await Verifier.Throws(MethodThatThrows);
Assert.NotNull(result.Exception);
```
<sup><a href='/src/Verify.Tests/Tests.cs#L640-L645' title='Snippet source file'>snippet source</a> | <a href='#snippet-exceptionresult' title='Start of snippet'>anchor</a></sup>
<sup><a href='/src/Verify.Tests/Tests.cs#L628-L633' title='Snippet source file'>snippet source</a> | <a href='#snippet-exceptionresult' title='Start of snippet'>anchor</a></sup>
<!-- endSnippet -->


Expand Down
2 changes: 1 addition & 1 deletion src/Verify.Expecto/Verifier.cs
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ static async Task<VerifyResult> Verify(

public static Task<VerifyResult> Verify(
string name,
object? target,
object target,
IEnumerable<Target> rawTargets,
VerifySettings? settings = null,
[CallerFilePath] string sourceFile = "")
Expand Down
4 changes: 2 additions & 2 deletions src/Verify.Expecto/Verifier_Directory.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ public static Task<VerifyResult> VerifyDirectory(

/// <summary>
/// Verifies the contents of <param name="path"/>.
/// Differs from passing <see cref="DirectoryInfo"/> to <code>Verify(object? target)</code> which will verify the full path.
/// Differs from passing <see cref="DirectoryInfo"/> to <code>Verify(object target)</code> which will verify the full path.
/// </summary>
public static Task<VerifyResult> VerifyDirectory(
string name,
Expand Down Expand Up @@ -56,7 +56,7 @@ public static Task<VerifyResult> VerifyDirectory(

/// <summary>
/// Verifies the contents of <param name="path"/>.
/// Differs from passing <see cref="DirectoryInfo"/> to <code>Verify(object? target)</code> which will verify the full path.
/// Differs from passing <see cref="DirectoryInfo"/> to <code>Verify(object target)</code> which will verify the full path.
/// </summary>
public static Task<VerifyResult> VerifyDirectory(
string name,
Expand Down
5 changes: 4 additions & 1 deletion src/Verify.Expecto/Verifier_Json.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ public static Task<VerifyResult> Verify<T>(
Task<T> target,
VerifySettings? settings = null,
[CallerFilePath] string sourceFile = "")
where T : notnull
{
var assembly = Assembly.GetCallingAssembly()!;
return Verify(settings, assembly, sourceFile, name, _ => _.Verify(target));
Expand All @@ -19,6 +20,7 @@ public static Task<VerifyResult> Verify<T>(
ValueTask<T> target,
VerifySettings? settings = null,
[CallerFilePath] string sourceFile = "")
where T : notnull
{
var assembly = Assembly.GetCallingAssembly()!;
return Verify(settings, assembly, sourceFile, name, _ => _.Verify(target));
Expand All @@ -29,14 +31,15 @@ public static Task<VerifyResult> Verify<T>(
IAsyncEnumerable<T> target,
VerifySettings? settings = null,
[CallerFilePath] string sourceFile = "")
where T : notnull
{
var assembly = Assembly.GetCallingAssembly()!;
return Verify(settings, assembly, sourceFile, name, _ => _.Verify(target));
}

public static Task<VerifyResult> Verify(
string name,
object? target,
object target,
VerifySettings? settings = null,
[CallerFilePath] string sourceFile = "")
{
Expand Down
2 changes: 1 addition & 1 deletion src/Verify.MSTest/VerifyBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ InnerVerifier BuildVerifier(VerifySettings settings, string sourceFile, bool use
}

public SettingsTask Verify(
object? target,
object target,
IEnumerable<Target> rawTargets,
VerifySettings? settings = null,
[CallerFilePath] string sourceFile = "") =>
Expand Down
11 changes: 7 additions & 4 deletions src/Verify.MSTest/VerifyBase_Json.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,23 +5,26 @@ public partial class VerifyBase
public SettingsTask Verify<T>(
Task<T> target,
VerifySettings? settings = null,
[CallerFilePath] string sourceFile = "") =>
[CallerFilePath] string sourceFile = "")
where T : notnull =>
Verify(settings, sourceFile, _ => _.Verify(target));

public SettingsTask Verify<T>(
ValueTask<T> target,
VerifySettings? settings = null,
[CallerFilePath] string sourceFile = "") =>
[CallerFilePath] string sourceFile = "")
where T : notnull =>
Verify(settings, sourceFile, _ => _.Verify(target));

public SettingsTask Verify<T>(
IAsyncEnumerable<T> target,
VerifySettings? settings = null,
[CallerFilePath] string sourceFile = "") =>
[CallerFilePath] string sourceFile = "")
where T : notnull =>
Verify(settings, sourceFile, _ => _.Verify(target));

public SettingsTask Verify(
object? target,
object target,
VerifySettings? settings = null,
[CallerFilePath] string sourceFile = "") =>
Verify(settings, sourceFile, _ => _.Verify(target));
Expand Down
2 changes: 1 addition & 1 deletion src/Verify.NUnit/Verifier.cs
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ static SettingsTask Verify(
}

public static SettingsTask Verify(
object? target,
object target,
IEnumerable<Target> rawTargets,
VerifySettings? settings = null,
[CallerFilePath] string sourceFile = "") =>
Expand Down
11 changes: 7 additions & 4 deletions src/Verify.NUnit/Verifier_Json.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,23 +5,26 @@ public static partial class Verifier
public static SettingsTask Verify<T>(
Task<T> target,
VerifySettings? settings = null,
[CallerFilePath] string sourceFile = "") =>
[CallerFilePath] string sourceFile = "")
where T : notnull =>
Verify(settings, sourceFile, _ => _.Verify(target));

public static SettingsTask Verify<T>(
ValueTask<T> target,
VerifySettings? settings = null,
[CallerFilePath] string sourceFile = "") =>
[CallerFilePath] string sourceFile = "")
where T : notnull =>
Verify(settings, sourceFile, _ => _.Verify(target));

public static SettingsTask Verify<T>(
IAsyncEnumerable<T> target,
VerifySettings? settings = null,
[CallerFilePath] string sourceFile = "") =>
[CallerFilePath] string sourceFile = "")
where T : notnull =>
Verify(settings, sourceFile, _ => _.Verify(target));

public static SettingsTask Verify(
object? target,
object target,
VerifySettings? settings = null,
[CallerFilePath] string sourceFile = "") =>
Verify(settings, sourceFile, _ => _.Verify(target));
Expand Down
2 changes: 1 addition & 1 deletion src/Verify.NUnit/VerifyBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ public VerifyBase(VerifySettings? settings = null, [CallerFilePath] string sourc
}

public SettingsTask Verify(
object? target,
object target,
IEnumerable<Target> rawTargets,
VerifySettings? settings = null)
{
Expand Down
5 changes: 4 additions & 1 deletion src/Verify.NUnit/VerifyBase_Json.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ public partial class VerifyBase
public SettingsTask Verify<T>(
Task<T> target,
VerifySettings? settings = null)
where T : notnull
{
settings ??= this.settings;
return Verifier.Verify(target, settings, sourceFile);
Expand All @@ -13,6 +14,7 @@ public SettingsTask Verify<T>(
public SettingsTask Verify<T>(
ValueTask<T> target,
VerifySettings? settings = null)
where T : notnull
{
settings ??= this.settings;
return Verifier.Verify(target, settings, sourceFile);
Expand All @@ -21,13 +23,14 @@ public SettingsTask Verify<T>(
public SettingsTask Verify<T>(
IAsyncEnumerable<T> target,
VerifySettings? settings = null)
where T : notnull
{
settings ??= this.settings;
return Verifier.Verify(target, settings, sourceFile);
}

public SettingsTask Verify(
object? target,
object target,
VerifySettings? settings = null)
{
settings ??= this.settings;
Expand Down

This file was deleted.

This file was deleted.

4 changes: 0 additions & 4 deletions src/Verify.Tests/Converters/FileAppenderTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,6 @@ public void Dispose() =>
public Task Text() =>
Verify("Foo");

[Fact]
public Task NullText() =>
Verify((string) null!);

[Fact]
public Task EmptyString() =>
Verify(string.Empty);
Expand Down

This file was deleted.

4 changes: 0 additions & 4 deletions src/Verify.Tests/Converters/JsonAppenderTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -55,10 +55,6 @@ public Task WithDuplicate() =>
.AppendValue("duplicate", "value1")
.AppendValue("duplicate", "value2");

[Fact]
public Task NullText() =>
Verify((string) null!);

[Fact]
public Task Anon() =>
Verify(new
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@

Original file line number Diff line number Diff line change
@@ -0,0 +1 @@

Original file line number Diff line number Diff line change
@@ -0,0 +1 @@

5 changes: 0 additions & 5 deletions src/Verify.Tests/Naming/NamerTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -484,7 +484,6 @@ public Task IgnoreParametersForVerified()
[Fact]
public Task SingleTarget() =>
Verify(
null,
new[]
{
new Target("txt", "data")
Expand All @@ -493,7 +492,6 @@ public Task SingleTarget() =>
[Fact]
public Task SingleTargetWithName() =>
Verify(
null,
new[]
{
new Target("txt", "data", "theNameA")
Expand All @@ -502,7 +500,6 @@ public Task SingleTargetWithName() =>
[Fact]
public Task MultipleTarget() =>
Verify(
null,
new[]
{
new Target("txt", "data"),
Expand All @@ -512,7 +509,6 @@ public Task MultipleTarget() =>
[Fact]
public Task MultipleTargetWithName() =>
Verify(
null,
new[]
{
new Target("txt", "data", "theNameA"),
Expand All @@ -522,7 +518,6 @@ public Task MultipleTargetWithName() =>
[Fact]
public Task MultipleTargetWithDuplicateName() =>
Verify(
null,
new[]
{
new Target("txt", "data", "theNameA"),
Expand Down
2 changes: 1 addition & 1 deletion src/Verify.Tests/Serialization/SerializationTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2329,7 +2329,7 @@ public Task SetProperty()
[Fact]
public Task Property()
{
var target = typeof(SerializationTests).GetProperty("MyProperty");
var target = typeof(SerializationTests).GetProperty("MyProperty")!;
return Verify(target);
}

Expand Down
1 change: 0 additions & 1 deletion src/Verify.Tests/SimpleTypeTests.Null.verified.txt

This file was deleted.

This file was deleted.

10 changes: 1 addition & 9 deletions src/Verify.Tests/SimpleTypeTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,17 +19,9 @@ public Task Run(object arg)
public Task StringWrappedInTask() =>
Verify(Task.FromResult("theString"));

[Fact]
public Task NullWrappedInTask() =>
Verify(Task.FromResult<object?>(null));

[Fact]
public Task StringEmptyWrappedInTask() =>
Verify(Task.FromResult<object?>(string.Empty));

[Fact]
public Task Null() =>
Verify((string) null!);
Verify(Task.FromResult<object>(string.Empty));

[Fact]
public Task StringEmpty() =>
Expand Down
1 change: 0 additions & 1 deletion src/Verify.Tests/Tests.StreamsWithNull.verified.bin

This file was deleted.

1 change: 0 additions & 1 deletion src/Verify.Tests/Tests.StreamsWithNull.verified.txt

This file was deleted.

12 changes: 0 additions & 12 deletions src/Verify.Tests/Tests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -387,18 +387,6 @@ public Task Streams() =>
})
});

[Fact]
public Task StreamsWithNull() =>
Verify(
new List<Stream?>
{
new MemoryStream(new byte[]
{
1
}),
null
});

[Fact]
public async Task ShouldNotIgnoreCase()
{
Expand Down
Loading

0 comments on commit 5250c7a

Please sign in to comment.