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
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>CA1822;CS1591;CS0649;xUnit1026;xUnit1013;CS1573;VerifyTestsProjectDir;VerifySetParameters;PolyFillTargetsForNuget;xUnit1051;NU1608;NU1109</NoWarn>
<Version>31.7.2</Version>
<Version>31.7.4</Version>
<ImplicitUsings>enable</ImplicitUsings>
<LangVersion>preview</LangVersion>
<AssemblyVersion>1.0.0</AssemblyVersion>
Expand Down
4 changes: 4 additions & 0 deletions src/RawTempUsage/GlobalUsings.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
// Global using directives

global using VerifyTests;
global using Xunit;
14 changes: 14 additions & 0 deletions src/RawTempUsage/RawTempUsage.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
public class RawTempUsage
{
[Fact]
public void Directory()
{
using var directory = new TempDirectory();
}

[Fact]
public void File()
{
using var file = new TempFile();
}
}
21 changes: 21 additions & 0 deletions src/RawTempUsage/RawTempUsage.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>net10.0</TargetFramework>
<GenerateAssemblyInfo>true</GenerateAssemblyInfo>
<PlatformTarget>x64</PlatformTarget>
<OutputType>Exe</OutputType>
<NoWarn>$(NoWarn);CS8002</NoWarn>
<RootNamespace>Fake</RootNamespace>
</PropertyGroup>

<ItemGroup>
<ProjectReference Include="..\Verify\Verify.csproj" />
<PackageReference Include="Microsoft.NET.Test.Sdk" />
<PackageReference Include="ProjectDefaults" PrivateAssets="all" />
<PackageReference Include="MarkdownSnippets.MsBuild" PrivateAssets="all" />
<PackageReference Include="xunit.runner.visualstudio" PrivateAssets="all" />
<PackageReference Include="xunit.v3" />
</ItemGroup>

</Project>
3 changes: 2 additions & 1 deletion src/Verify.slnx
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,12 @@
<Project Path="Benchmarks/Benchmarks.csproj" />
<Project Path="DeterministicTests/DeterministicTests.csproj" />
<Project Path="DisableScrubbersTests/DisableScrubbersTests.csproj" />
<Project Path="DisableVerifyFileNestingTests/DisableVerifyFileNestingTests.csproj" Type="C#" />
<Project Path="DisableVerifyFileNestingTests/DisableVerifyFileNestingTests.csproj" />
<Project Path="FakeDiffTool/FakeDiffTool.csproj" />
<Project Path="FSharpTests/FSharpTests.fsproj" />
<Project Path="ModuleInitDocs/ModuleInitDocs.csproj" />
<Project Path="NullComparer/NullComparer.csproj" />
<Project Path="RawTempUsage/RawTempUsage.csproj" />
<Project Path="StaticSettingsTests/StaticSettingsTests.csproj" />
<Project Path="StrictJsonTests/StrictJsonTests.csproj" />
<Project Path="TargetLibrary/TargetLibrary.csproj" />
Expand Down
20 changes: 12 additions & 8 deletions src/Verify/TempDirectory.cs
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@ namespace VerifyTests;
public class TempDirectory :
IDisposable
{
List<string> paths;

/// <summary>
/// The full path to the directory.
/// </summary>
Expand Down Expand Up @@ -58,16 +60,17 @@ public static void Init()
before: () =>
{
},
after: () => paths.Value = null);
after: () => asyncPaths.Value = null);

VerifierSettings.GlobalScrubbers.Add((scrubber, _, _) =>
{
if (paths.Value == null)
var pathsValue = asyncPaths.Value;
if (pathsValue == null)
{
return;
}

foreach (var path in paths.Value)
foreach (var path in pathsValue)
{
scrubber.Replace(path, "{TempDirectory}");
}
Expand All @@ -76,7 +79,7 @@ public static void Init()
Cleanup();
}

static AsyncLocal<List<string>?> paths = new();
static AsyncLocal<List<string>?> asyncPaths = new();

internal static void Cleanup()
{
Expand Down Expand Up @@ -118,13 +121,14 @@ public TempDirectory()
Path = IoPath.Combine(RootDirectory, IoPath.GetRandomFileName());
Directory.CreateDirectory(Path);

if (paths.Value == null)
paths = asyncPaths.Value!;
if (paths == null)
{
paths.Value = [Path];
paths = asyncPaths.Value = [Path];
}
else
{
paths.Value!.Add(Path);
paths.Add(Path);
}
}

Expand All @@ -135,7 +139,7 @@ public void Dispose()
Directory.Delete(Path, true);
}

paths.Value!.Remove(Path);
paths.Remove(Path);
}

/// <summary>
Expand Down
20 changes: 12 additions & 8 deletions src/Verify/TempFile.cs
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@ namespace VerifyTests;
public class TempFile :
IDisposable
{
List<string> paths;

/// <summary>
/// The full path to the file.
/// </summary>
Expand Down Expand Up @@ -61,16 +63,17 @@ public static void Init()
before: () =>
{
},
after: () => paths.Value = null);
after: () => asyncPaths.Value = null);

VerifierSettings.GlobalScrubbers.Add((scrubber, _, _) =>
{
if (paths.Value == null)
var pathsValue = asyncPaths.Value;
if (pathsValue == null)
{
return;
}

foreach (var path in paths.Value)
foreach (var path in pathsValue)
{
scrubber.Replace(path, "{TempFile}");
}
Expand All @@ -79,7 +82,7 @@ public static void Init()
Cleanup();
}

static AsyncLocal<List<string>?> paths = new();
static AsyncLocal<List<string>?> asyncPaths = new();

internal static void Cleanup()
{
Expand Down Expand Up @@ -132,13 +135,14 @@ public TempFile(string? extension = null)

Path = IoPath.Combine(RootDirectory, fileName);

if (paths.Value == null)
paths = asyncPaths.Value!;
if (paths == null)
{
paths.Value = [Path];
paths = asyncPaths.Value = [Path];
}
else
{
paths.Value!.Add(Path);
paths.Add(Path);
}
}

Expand All @@ -162,7 +166,7 @@ public void Dispose()
File.Delete(Path);
}

paths.Value!.Remove(Path);
paths.Remove(Path);
}

/// <summary>
Expand Down
5 changes: 3 additions & 2 deletions src/VerifyCore.slnf
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
{
{
"solution": {
"path": "Verify.slnx",
"projects": [
"DisableScrubbersTests\\DisableScrubbersTests.csproj",
"RawTempUsage\\RawTempUsage.csproj",
"TargetLibrary\\TargetLibrary.csproj",
"Verify.NUnit\\Verify.NUnit.csproj",
"Verify.SamplePlugin\\Verify.SamplePlugin.csproj",
"Verify.Tests\\Verify.Tests.csproj",
"Verify.XunitV3\\Verify.XunitV3.csproj",
"DisableScrubbersTests\\DisableScrubbersTests.csproj",
"Verify\\Verify.csproj"
]
}
Expand Down