Skip to content

Commit

Permalink
Add TUnit support (#1296)
Browse files Browse the repository at this point in the history
  • Loading branch information
SimonCropp authored Sep 17, 2024
1 parent 3d4e610 commit ca82a7b
Show file tree
Hide file tree
Showing 165 changed files with 1,925 additions and 31 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -19,4 +19,5 @@ src/Verify.Tests/Tests.TextNegative.verified.tmp
src/Verify.Tests/NewLineTests.StringWithDifferingNewline.verified.txt
src/Verify.MSTest.Tests/Tests.AutoVerifyHasAttachment.verified.txt
src/Verify.NUnit.Tests/Tests.AutoVerifyHasAttachment.verified.txt
src/Verify.TUnit.Tests/Tests.AutoVerifyHasAttachment.verified.txt
/src/Benchmarks/BenchmarkDotNet.Artifacts
31 changes: 31 additions & 0 deletions docs/parameterised.md
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,37 @@ public class TestFixtureSourceUsage(string arg1, int arg2)
}
```
<sup><a href='/src/Verify.NUnit.Tests/TestFixtureSourceUsage.cs#L1-L26' title='Snippet source file'>snippet source</a> | <a href='#snippet-TestFixtureSourceUsage.cs' title='Start of snippet'>anchor</a></sup>
<a id='snippet-TestFixtureSourceUsage.cs-1'></a>
```cs
//TODO:
// [TestFixtureSource(nameof(FixtureArgs))]
// public class TestFixtureSourceUsage(string arg1, int arg2)
// {
// [Test]
// public Task Test() =>
// Verify(
// new
// {
// arg1,
// arg2
// });
//
// static object[] FixtureArgs =
// [
// new object[]
// {
// "Value1",
// 1
// },
// new object[]
// {
// "Value2",
// 2
// }
// ];
// }
```
<sup><a href='/src/Verify.TUnit.Tests/TestFixtureSourceUsage.cs#L1-L27' title='Snippet source file'>snippet source</a> | <a href='#snippet-TestFixtureSourceUsage.cs-1' title='Start of snippet'>anchor</a></sup>
<!-- endSnippet -->

Produces:
Expand Down
2 changes: 1 addition & 1 deletion src/Directory.Build.props
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<Project>
<PropertyGroup>
<NoWarn>CS1591;CS0649;xUnit1026;xUnit1013;CS1573;VerifyTestsProjectDir;VerifySetParameters;PolyFillTargetsForNuget</NoWarn>
<Version>26.4.5</Version>
<Version>26.6.0</Version>
<ImplicitUsings>enable</ImplicitUsings>
<LangVersion>preview</LangVersion>
<AssemblyVersion>1.0.0</AssemblyVersion>
Expand Down
2 changes: 2 additions & 0 deletions src/Directory.Packages.props
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@
<PackageVersion Include="System.Memory" Version="4.5.5" />
<PackageVersion Include="System.Runtime.InteropServices.RuntimeInformation" Version="4.3.0" />
<PackageVersion Include="TextCopy" Version="6.2.1" />
<PackageVersion Include="TUnit" Version="0.1.738" />
<PackageVersion Include="TUnit.Core" Version="0.1.738" />
<PackageVersion Include="Xunit" Version="2.9.0" />
<PackageVersion Include="xunit.abstractions" Version="2.0.3" />
<PackageVersion Include="xunit.extensibility.execution" Version="2.9.0" />
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Value
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Value
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Value
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Value
Empty file.
73 changes: 73 additions & 0 deletions src/Verify.TUnit.DerivePaths.Tests/Tests.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
public class Tests
{
[Test]
public Task Test()
{
DerivePathInfo(
(sourceFile, projectDirectory, methodName, typeName) =>
{
Check(sourceFile, projectDirectory, methodName, typeName).GetAwaiter().GetResult();
return new("CustomDir", "CustomTypeName", "CustomMethodName");
});
return Verify("Value");
}

static async Task Check(string sourceFile, string projectDirectory, Type methodName, MethodInfo typeName)
{
await Assert.That(File.Exists(sourceFile)).IsTrue();
await Assert.That(Directory.Exists(projectDirectory)).IsTrue();
await Assert.That(methodName).IsNotNull();
await Assert.That(typeName).IsNotNull();
}

[Test]
public Task ReturnNulls()
{
DerivePathInfo((_, _, _, _) => new(null));
return Verify("Value");
}

[Test]
public Task ProjectRelativeDirectory()
{
UseProjectRelativeDirectory("Relative");
return Verify("Value");
}

[Test]
public Task SourceFileRelativeDirectory()
{
UseSourceFileRelativeDirectory("Relative");
return Verify("Value");
}

[Test]
public async Task InvalidMethod()
{
DerivePathInfo((_, _, _, _) => new(null, null, Path
.GetInvalidFileNameChars()
.First()
.ToString()));
await Assert.ThrowsAsync<ArgumentException>(() => Verify("Value"));
}

[Test]
public async Task InvalidType()
{
DerivePathInfo((_, _, _, _) => new(null, Path
.GetInvalidFileNameChars()
.First()
.ToString()));
await Assert.ThrowsAsync<ArgumentException>(() => Verify("Value"));
}

[Test]
public async Task InvalidDirectory()
{
DerivePathInfo((_, _, _, _) => new(Path
.GetInvalidPathChars()
.First()
.ToString()));
await Assert.ThrowsAsync<ArgumentException>(() => Verify("Value"));
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net9.0</TargetFramework>
<SignAssembly>false</SignAssembly>
<NoWarn>$(NoWarn);CA1822</NoWarn>
<OutputType>Exe</OutputType>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="ProjectDefaults" PrivateAssets="all" />
<PackageReference Include="TUnit" />
<ProjectReference Include="..\Verify.TUnit\Verify.TUnit.csproj" />
<ProjectReference Include="..\Verify\Verify.csproj" />
</ItemGroup>
<Import Project="$(ProjectDir)..\Verify\buildTransitive\Verify.props" />
<Import Project="$(ProjectDir)..\Verify\buildTransitive\Verify.targets" />
<Import Project="$(ProjectDir)..\Verify.TUnit\buildTransitive\Verify.TUnit.props" />
</Project>
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Foo
3 changes: 3 additions & 0 deletions src/Verify.TUnit.Tests/GlobalUsings.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
// Global using directives

global using Argon;
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Foo
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Foo
10 changes: 10 additions & 0 deletions src/Verify.TUnit.Tests/Inheritance/Base.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
public class Base
{
[Test]
public Task TestInBase() =>
Verify("Foo");

[Test]
public virtual Task TestToOverride() =>
Verify("Foo");
}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Foo
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Foo
10 changes: 10 additions & 0 deletions src/Verify.TUnit.Tests/Inheritance/Inherited.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
[InheritsTests]
public class Inherited : Base
{
[Test]
public override Task TestToOverride()
{
Trace.WriteLine("");
return base.TestToOverride();
}
}
6 changes: 6 additions & 0 deletions src/Verify.TUnit.Tests/MisNamedTests.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
public class DiffNamedTests
{
[Test]
public Task ShouldPass() =>
Verify("Foo");
}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
NestedFoo
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Foo
13 changes: 13 additions & 0 deletions src/Verify.TUnit.Tests/NestedTypeTests.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
public class NestedTypeTests
{
[Test]
public Task ShouldPass() =>
Verify("Foo");

public class Nested
{
[Test]
public Task ShouldPass() =>
Verify("NestedFoo");
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
A B C
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
A B C
31 changes: 31 additions & 0 deletions src/Verify.TUnit.Tests/Scrubbers/ScrubberLevelsSample.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
#region ScrubberLevelsSampleTUnit

public class ScrubberLevelsSample
{
VerifySettings classLevelSettings;

public ScrubberLevelsSample()
{
classLevelSettings = new();
classLevelSettings.AddScrubber(_ => _.Replace("Three", "C"));
}

[Test]
public Task Simple()
{
var settings = new VerifySettings(classLevelSettings);
settings.AddScrubber(_ => _.Replace("Two", "B"));
return Verify("One Two Three", settings);
}

[Test]
public Task SimpleFluent() =>
Verify("One Two Three", classLevelSettings)
.AddScrubber(_ => _.Replace("Two", "B"));

[ModuleInitializer]
public static void Setup() =>
VerifierSettings.AddScrubber(_ => _.Replace("One", "A"));
}

#endregion
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
RowVersion: TheRowVersion
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
RowVersion: TheRowVersion
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
LineA
LineC
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
LineA
LineC
NoMoreLineE
LineI
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
LineA
LineC
NoMoreLineE
LineI
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
linea
linec
Loading

0 comments on commit ca82a7b

Please sign in to comment.