diff --git a/src/Directory.Build.props b/src/Directory.Build.props index 72149efdf..04209ed86 100644 --- a/src/Directory.Build.props +++ b/src/Directory.Build.props @@ -2,7 +2,7 @@ CA1822;CS1591;CS0649;xUnit1026;xUnit1013;CS1573;VerifyTestsProjectDir;VerifySetParameters;PolyFillTargetsForNuget;xUnit1051;NU1608;NU1109 - 31.7.2 + 31.7.4 enable preview 1.0.0 diff --git a/src/RawTempUsage/GlobalUsings.cs b/src/RawTempUsage/GlobalUsings.cs new file mode 100644 index 000000000..b109bd652 --- /dev/null +++ b/src/RawTempUsage/GlobalUsings.cs @@ -0,0 +1,4 @@ +// Global using directives + +global using VerifyTests; +global using Xunit; \ No newline at end of file diff --git a/src/RawTempUsage/RawTempUsage.cs b/src/RawTempUsage/RawTempUsage.cs new file mode 100644 index 000000000..7da666416 --- /dev/null +++ b/src/RawTempUsage/RawTempUsage.cs @@ -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(); + } +} \ No newline at end of file diff --git a/src/RawTempUsage/RawTempUsage.csproj b/src/RawTempUsage/RawTempUsage.csproj new file mode 100644 index 000000000..56f32f1df --- /dev/null +++ b/src/RawTempUsage/RawTempUsage.csproj @@ -0,0 +1,21 @@ + + + + net10.0 + true + x64 + Exe + $(NoWarn);CS8002 + Fake + + + + + + + + + + + + diff --git a/src/Verify.slnx b/src/Verify.slnx index e4dee98a3..840bc03d2 100644 --- a/src/Verify.slnx +++ b/src/Verify.slnx @@ -16,11 +16,12 @@ - + + diff --git a/src/Verify/TempDirectory.cs b/src/Verify/TempDirectory.cs index 8e4a5c724..53cc20b5d 100644 --- a/src/Verify/TempDirectory.cs +++ b/src/Verify/TempDirectory.cs @@ -28,6 +28,8 @@ namespace VerifyTests; public class TempDirectory : IDisposable { + List paths; + /// /// The full path to the directory. /// @@ -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}"); } @@ -76,7 +79,7 @@ public static void Init() Cleanup(); } - static AsyncLocal?> paths = new(); + static AsyncLocal?> asyncPaths = new(); internal static void Cleanup() { @@ -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); } } @@ -135,7 +139,7 @@ public void Dispose() Directory.Delete(Path, true); } - paths.Value!.Remove(Path); + paths.Remove(Path); } /// diff --git a/src/Verify/TempFile.cs b/src/Verify/TempFile.cs index 61b7eac3b..33d9f5644 100644 --- a/src/Verify/TempFile.cs +++ b/src/Verify/TempFile.cs @@ -32,6 +32,8 @@ namespace VerifyTests; public class TempFile : IDisposable { + List paths; + /// /// The full path to the file. /// @@ -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}"); } @@ -79,7 +82,7 @@ public static void Init() Cleanup(); } - static AsyncLocal?> paths = new(); + static AsyncLocal?> asyncPaths = new(); internal static void Cleanup() { @@ -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); } } @@ -162,7 +166,7 @@ public void Dispose() File.Delete(Path); } - paths.Value!.Remove(Path); + paths.Remove(Path); } /// diff --git a/src/VerifyCore.slnf b/src/VerifyCore.slnf index f9c7f22d7..a57366b13 100644 --- a/src/VerifyCore.slnf +++ b/src/VerifyCore.slnf @@ -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" ] }