From 73f8fd1dc49f34b79afa4ef16e0204b1369fdd1a Mon Sep 17 00:00:00 2001 From: Alina Smirnova Date: Tue, 27 Jun 2023 18:36:32 +0200 Subject: [PATCH] Use Verify library for approval tests (#2330) * Used Verify library for approval tests * Removed unnecessary item group * Approval -> Verify renaming * Avoid duplication of directory name for VerifyTests * Disabled diff tool for better console experience * Renamed files after classes * Updated documentation --------- Co-authored-by: Alina Smirnova --- docs/articles/contributing/running-tests.md | 8 +++--- ...Tests.cs => ParamsAllValuesVerifyTests.cs} | 27 ++++++++----------- ...eSummary_WithAllValuesOfBool.verified.txt} | 0 ...eSummary_WithAllValuesOfEnum.verified.txt} | 0 ..._WithAllValuesOfNullableBool.verified.txt} | 0 ..._WithAllValuesOfNullableEnum.verified.txt} | 0 ...WithNotAllowedFlagsEnumError.verified.txt} | 0 ...hNotAllowedNullableTypeError.verified.txt} | 0 ...mary_WithNotAllowedTypeError.verified.txt} | 0 .../BenchmarkDotNet.Tests.csproj | 2 +- .../Builders/VerifySettingsFactory.cs | 15 +++++++++++ ...lTests.cs => CommonExporterVerifyTests.cs} | 27 ++++++++----------- ...ests.cs => MarkdownExporterVerifyTests.cs} | 27 ++++++++----------- ...ifyTests.Exporters_Invariant.verified.txt} | 0 ...rVerifyTests.Exporters_en-US.verified.txt} | 0 ...rVerifyTests.Exporters_ru-RU.verified.txt} | 0 ...st_Escape_ParamsAndArguments.verified.txt} | 0 ...Test_Invalid_TwoJobBaselines.verified.txt} | 0 ...t_Invalid_TwoMethodBaselines.verified.txt} | 0 ...Test_JobBaseline_MethodsJobs.verified.txt} | 0 ...obBaseline_MethodsParamsJobs.verified.txt} | 0 ...rTest_MethodBaseline_Methods.verified.txt} | 0 ...t_MethodBaseline_MethodsJobs.verified.txt} | 0 ...MethodBaseline_MethodsParams.verified.txt} | 0 ...odBaseline_MethodsParamsJobs.verified.txt} | 0 ...ethodJobBaseline_MethodsJobs.verified.txt} | 0 ...obBaseline_MethodsJobsParams.verified.txt} | 0 ...NoBaseline_MethodsParamsJobs.verified.txt} | 0 ...MethodsParamsJobs_GroupByAll.verified.txt} | 0 ...dsParamsJobs_GroupByCategory.verified.txt} | 0 ...MethodsParamsJobs_GroupByJob.verified.txt} | 0 ...hodsParamsJobs_GroupByMethod.verified.txt} | 0 ...hodsParamsJobs_GroupByParams.verified.txt} | 0 .../BenchmarkDotNet.Tests/GlobFilterTests.cs | 2 -- .../Portability/Cpu/CpuInfoFormatterTests.cs | 21 +++++++-------- ...nfoFormatterTests.FormatTest.verified.txt} | 0 .../Properties/AssemblyInfo.cs | 2 -- .../XUnit/PatchedXUnit2Reporter.cs | 27 ------------------- 38 files changed, 62 insertions(+), 96 deletions(-) rename tests/BenchmarkDotNet.Tests/Attributes/{ParamsAllValuesApprovalTests.cs => ParamsAllValuesVerifyTests.cs} (82%) rename tests/BenchmarkDotNet.Tests/Attributes/{ApprovedFiles/ParamsAllValuesApprovalTests.BenchmarkShouldProduceSummary.WithAllValuesOfBool.approved.txt => VerifiedFiles/ParamsAllValuesVerifyTests.BenchmarkShouldProduceSummary_WithAllValuesOfBool.verified.txt} (100%) rename tests/BenchmarkDotNet.Tests/Attributes/{ApprovedFiles/ParamsAllValuesApprovalTests.BenchmarkShouldProduceSummary.WithAllValuesOfEnum.approved.txt => VerifiedFiles/ParamsAllValuesVerifyTests.BenchmarkShouldProduceSummary_WithAllValuesOfEnum.verified.txt} (100%) rename tests/BenchmarkDotNet.Tests/Attributes/{ApprovedFiles/ParamsAllValuesApprovalTests.BenchmarkShouldProduceSummary.WithAllValuesOfNullableBool.approved.txt => VerifiedFiles/ParamsAllValuesVerifyTests.BenchmarkShouldProduceSummary_WithAllValuesOfNullableBool.verified.txt} (100%) rename tests/BenchmarkDotNet.Tests/Attributes/{ApprovedFiles/ParamsAllValuesApprovalTests.BenchmarkShouldProduceSummary.WithAllValuesOfNullableEnum.approved.txt => VerifiedFiles/ParamsAllValuesVerifyTests.BenchmarkShouldProduceSummary_WithAllValuesOfNullableEnum.verified.txt} (100%) rename tests/BenchmarkDotNet.Tests/Attributes/{ApprovedFiles/ParamsAllValuesApprovalTests.BenchmarkShouldProduceSummary.WithNotAllowedFlagsEnumError.approved.txt => VerifiedFiles/ParamsAllValuesVerifyTests.BenchmarkShouldProduceSummary_WithNotAllowedFlagsEnumError.verified.txt} (100%) rename tests/BenchmarkDotNet.Tests/Attributes/{ApprovedFiles/ParamsAllValuesApprovalTests.BenchmarkShouldProduceSummary.WithNotAllowedNullableTypeError.approved.txt => VerifiedFiles/ParamsAllValuesVerifyTests.BenchmarkShouldProduceSummary_WithNotAllowedNullableTypeError.verified.txt} (100%) rename tests/BenchmarkDotNet.Tests/Attributes/{ApprovedFiles/ParamsAllValuesApprovalTests.BenchmarkShouldProduceSummary.WithNotAllowedTypeError.approved.txt => VerifiedFiles/ParamsAllValuesVerifyTests.BenchmarkShouldProduceSummary_WithNotAllowedTypeError.verified.txt} (100%) create mode 100644 tests/BenchmarkDotNet.Tests/Builders/VerifySettingsFactory.cs rename tests/BenchmarkDotNet.Tests/Exporters/{CommonExporterApprovalTests.cs => CommonExporterVerifyTests.cs} (81%) rename tests/BenchmarkDotNet.Tests/Exporters/{MarkdownExporterApprovalTests.cs => MarkdownExporterVerifyTests.cs} (92%) rename tests/BenchmarkDotNet.Tests/Exporters/{ApprovedFiles/CommonExporterApprovalTests.Exporters.Invariant.approved.txt => VerifiedFiles/CommonExporterVerifyTests.Exporters_Invariant.verified.txt} (100%) rename tests/BenchmarkDotNet.Tests/Exporters/{ApprovedFiles/CommonExporterApprovalTests.Exporters.en-US.approved.txt => VerifiedFiles/CommonExporterVerifyTests.Exporters_en-US.verified.txt} (100%) rename tests/BenchmarkDotNet.Tests/Exporters/{ApprovedFiles/CommonExporterApprovalTests.Exporters.ru-RU.approved.txt => VerifiedFiles/CommonExporterVerifyTests.Exporters_ru-RU.verified.txt} (100%) rename tests/BenchmarkDotNet.Tests/Exporters/{ApprovedFiles/MarkdownExporterApprovalTests.GroupExporterTest.Escape_ParamsAndArguments.approved.txt => VerifiedFiles/MarkdownExporterVerifyTests.GroupExporterTest_Escape_ParamsAndArguments.verified.txt} (100%) rename tests/BenchmarkDotNet.Tests/Exporters/{ApprovedFiles/MarkdownExporterApprovalTests.GroupExporterTest.Invalid_TwoJobBaselines.approved.txt => VerifiedFiles/MarkdownExporterVerifyTests.GroupExporterTest_Invalid_TwoJobBaselines.verified.txt} (100%) rename tests/BenchmarkDotNet.Tests/Exporters/{ApprovedFiles/MarkdownExporterApprovalTests.GroupExporterTest.Invalid_TwoMethodBaselines.approved.txt => VerifiedFiles/MarkdownExporterVerifyTests.GroupExporterTest_Invalid_TwoMethodBaselines.verified.txt} (100%) rename tests/BenchmarkDotNet.Tests/Exporters/{ApprovedFiles/MarkdownExporterApprovalTests.GroupExporterTest.JobBaseline_MethodsJobs.approved.txt => VerifiedFiles/MarkdownExporterVerifyTests.GroupExporterTest_JobBaseline_MethodsJobs.verified.txt} (100%) rename tests/BenchmarkDotNet.Tests/Exporters/{ApprovedFiles/MarkdownExporterApprovalTests.GroupExporterTest.JobBaseline_MethodsParamsJobs.approved.txt => VerifiedFiles/MarkdownExporterVerifyTests.GroupExporterTest_JobBaseline_MethodsParamsJobs.verified.txt} (100%) rename tests/BenchmarkDotNet.Tests/Exporters/{ApprovedFiles/MarkdownExporterApprovalTests.GroupExporterTest.MethodBaseline_Methods.approved.txt => VerifiedFiles/MarkdownExporterVerifyTests.GroupExporterTest_MethodBaseline_Methods.verified.txt} (100%) rename tests/BenchmarkDotNet.Tests/Exporters/{ApprovedFiles/MarkdownExporterApprovalTests.GroupExporterTest.MethodBaseline_MethodsJobs.approved.txt => VerifiedFiles/MarkdownExporterVerifyTests.GroupExporterTest_MethodBaseline_MethodsJobs.verified.txt} (100%) rename tests/BenchmarkDotNet.Tests/Exporters/{ApprovedFiles/MarkdownExporterApprovalTests.GroupExporterTest.MethodBaseline_MethodsParams.approved.txt => VerifiedFiles/MarkdownExporterVerifyTests.GroupExporterTest_MethodBaseline_MethodsParams.verified.txt} (100%) rename tests/BenchmarkDotNet.Tests/Exporters/{ApprovedFiles/MarkdownExporterApprovalTests.GroupExporterTest.MethodBaseline_MethodsParamsJobs.approved.txt => VerifiedFiles/MarkdownExporterVerifyTests.GroupExporterTest_MethodBaseline_MethodsParamsJobs.verified.txt} (100%) rename tests/BenchmarkDotNet.Tests/Exporters/{ApprovedFiles/MarkdownExporterApprovalTests.GroupExporterTest.MethodJobBaseline_MethodsJobs.approved.txt => VerifiedFiles/MarkdownExporterVerifyTests.GroupExporterTest_MethodJobBaseline_MethodsJobs.verified.txt} (100%) rename tests/BenchmarkDotNet.Tests/Exporters/{ApprovedFiles/MarkdownExporterApprovalTests.GroupExporterTest.MethodJobBaseline_MethodsJobsParams.approved.txt => VerifiedFiles/MarkdownExporterVerifyTests.GroupExporterTest_MethodJobBaseline_MethodsJobsParams.verified.txt} (100%) rename tests/BenchmarkDotNet.Tests/Exporters/{ApprovedFiles/MarkdownExporterApprovalTests.GroupExporterTest.NoBaseline_MethodsParamsJobs.approved.txt => VerifiedFiles/MarkdownExporterVerifyTests.GroupExporterTest_NoBaseline_MethodsParamsJobs.verified.txt} (100%) rename tests/BenchmarkDotNet.Tests/Exporters/{ApprovedFiles/MarkdownExporterApprovalTests.GroupExporterTest.NoBaseline_MethodsParamsJobs_GroupByAll.approved.txt => VerifiedFiles/MarkdownExporterVerifyTests.GroupExporterTest_NoBaseline_MethodsParamsJobs_GroupByAll.verified.txt} (100%) rename tests/BenchmarkDotNet.Tests/Exporters/{ApprovedFiles/MarkdownExporterApprovalTests.GroupExporterTest.NoBaseline_MethodsParamsJobs_GroupByCategory.approved.txt => VerifiedFiles/MarkdownExporterVerifyTests.GroupExporterTest_NoBaseline_MethodsParamsJobs_GroupByCategory.verified.txt} (100%) rename tests/BenchmarkDotNet.Tests/Exporters/{ApprovedFiles/MarkdownExporterApprovalTests.GroupExporterTest.NoBaseline_MethodsParamsJobs_GroupByJob.approved.txt => VerifiedFiles/MarkdownExporterVerifyTests.GroupExporterTest_NoBaseline_MethodsParamsJobs_GroupByJob.verified.txt} (100%) rename tests/BenchmarkDotNet.Tests/Exporters/{ApprovedFiles/MarkdownExporterApprovalTests.GroupExporterTest.NoBaseline_MethodsParamsJobs_GroupByMethod.approved.txt => VerifiedFiles/MarkdownExporterVerifyTests.GroupExporterTest_NoBaseline_MethodsParamsJobs_GroupByMethod.verified.txt} (100%) rename tests/BenchmarkDotNet.Tests/Exporters/{ApprovedFiles/MarkdownExporterApprovalTests.GroupExporterTest.NoBaseline_MethodsParamsJobs_GroupByParams.approved.txt => VerifiedFiles/MarkdownExporterVerifyTests.GroupExporterTest_NoBaseline_MethodsParamsJobs_GroupByParams.verified.txt} (100%) rename tests/BenchmarkDotNet.Tests/Portability/Cpu/{ApprovedFiles/CpuInfoFormatterTests.FormatTest.approved.txt => VerifiedFiles/CpuInfoFormatterTests.FormatTest.verified.txt} (100%) delete mode 100644 tests/BenchmarkDotNet.Tests/XUnit/PatchedXUnit2Reporter.cs diff --git a/docs/articles/contributing/running-tests.md b/docs/articles/contributing/running-tests.md index 431acd9671..866e51edbc 100644 --- a/docs/articles/contributing/running-tests.md +++ b/docs/articles/contributing/running-tests.md @@ -14,8 +14,8 @@ dotnet test -c Release -f net5.0 BenchmarkDotNet.sln You should be able to run all of tests from your IDE as well. -## Approval Tests +## Verify Tests -For some unit tests (e.g. for exporter tests) BenchmarkDotNet uses [approval tests'](https://approvaltests.com/) implementation for .NET: [ApprovalTests.Net](https://github.com/approvals/ApprovalTests.Net). -* The expected value for each test is stored in a `*.approved.txt` file located near the test source file in the repository. ApprovalTests.NET generates approved file's names automatically according test name and its parameters. This files must be added under the source control. -* It also creates a `*.received` file for each failed test. You can use different reporters for convenient file comparison. By default we use XUnit2Reporter, so you can find test run results on the test runner console as usual. You can add [UseReporter(typeof(KDiffReporter))] on test class and then ApprovalTests will open KDiff for each failed test. This way you can easily understand what's the difference between approved and received values and choose the correct one. +For some unit tests (e.g. for exporter tests) BenchmarkDotNet uses [Verify](https://github.com/VerifyTests/Verify). +* The expected value for each test is stored in a `*.verified.txt` file located near the test source file in the repository. Verify generates verified file's names automatically according test name and its parameters. This files must be added under the source control. +* It also creates a `*.received` file for each failed test. You can use diff tools for convenient file comparison. By default you can find test run results on the test runner console as usual. You can comment out the line ```result.DisableDiff()``` in ```VerifySettingsFactory.Create``` method and then Verify will open KDiff for each failed test. This way you can easily understand what's the difference between verified and received values and choose the correct one. diff --git a/tests/BenchmarkDotNet.Tests/Attributes/ParamsAllValuesApprovalTests.cs b/tests/BenchmarkDotNet.Tests/Attributes/ParamsAllValuesVerifyTests.cs similarity index 82% rename from tests/BenchmarkDotNet.Tests/Attributes/ParamsAllValuesApprovalTests.cs rename to tests/BenchmarkDotNet.Tests/Attributes/ParamsAllValuesVerifyTests.cs index 44a7613e87..a1086da1de 100644 --- a/tests/BenchmarkDotNet.Tests/Attributes/ParamsAllValuesApprovalTests.cs +++ b/tests/BenchmarkDotNet.Tests/Attributes/ParamsAllValuesVerifyTests.cs @@ -2,32 +2,27 @@ using System.Diagnostics.CodeAnalysis; using System.Globalization; using System.Linq; -using System.Runtime.CompilerServices; using System.Threading; -using ApprovalTests; -using ApprovalTests.Namers; -using ApprovalTests.Reporters; +using System.Threading.Tasks; using BenchmarkDotNet.Exporters; using BenchmarkDotNet.Loggers; using BenchmarkDotNet.Tests.Mocks; using BenchmarkDotNet.Attributes; -using BenchmarkDotNet.Tests.XUnit; +using BenchmarkDotNet.Tests.Builders; using BenchmarkDotNet.Validators; using JetBrains.Annotations; +using VerifyXunit; using Xunit; namespace BenchmarkDotNet.Tests.Attributes { - // In case of failed approval tests, use the following reporter: - // [UseReporter(typeof(KDiffReporter))] - [UseReporter(typeof(PatchedXUnit2Reporter))] - [UseApprovalSubdirectory("ApprovedFiles")] - [Collection("ApprovalTests")] - public class ParamsAllValuesApprovalTests : IDisposable + [Collection("VerifyTests")] + [UsesVerify] + public class ParamsAllValuesVerifyTests : IDisposable { private readonly CultureInfo initCulture; - public ParamsAllValuesApprovalTests() => initCulture = Thread.CurrentThread.CurrentCulture; + public ParamsAllValuesVerifyTests() => initCulture = Thread.CurrentThread.CurrentCulture; [UsedImplicitly] public static TheoryData GetBenchmarkTypes() @@ -40,10 +35,8 @@ public static TheoryData GetBenchmarkTypes() [Theory] [MemberData(nameof(GetBenchmarkTypes))] - [MethodImpl(MethodImplOptions.NoInlining)] - public void BenchmarkShouldProduceSummary(Type benchmarkType) + public Task BenchmarkShouldProduceSummary(Type benchmarkType) { - NamerFactory.AdditionalInformation = benchmarkType.Name; Thread.CurrentThread.CurrentCulture = CultureInfo.InvariantCulture; var logger = new AccumulationLogger(); @@ -60,7 +53,9 @@ public void BenchmarkShouldProduceSummary(Type benchmarkType) foreach (var error in errors) logger.WriteLineError("* " + error.Message); - Approvals.Verify(logger.GetLog()); + var settings = VerifySettingsFactory.Create(); + settings.UseTextForParameters(benchmarkType.Name); + return Verifier.Verify(logger.GetLog(), settings); } public void Dispose() => Thread.CurrentThread.CurrentCulture = initCulture; diff --git a/tests/BenchmarkDotNet.Tests/Attributes/ApprovedFiles/ParamsAllValuesApprovalTests.BenchmarkShouldProduceSummary.WithAllValuesOfBool.approved.txt b/tests/BenchmarkDotNet.Tests/Attributes/VerifiedFiles/ParamsAllValuesVerifyTests.BenchmarkShouldProduceSummary_WithAllValuesOfBool.verified.txt similarity index 100% rename from tests/BenchmarkDotNet.Tests/Attributes/ApprovedFiles/ParamsAllValuesApprovalTests.BenchmarkShouldProduceSummary.WithAllValuesOfBool.approved.txt rename to tests/BenchmarkDotNet.Tests/Attributes/VerifiedFiles/ParamsAllValuesVerifyTests.BenchmarkShouldProduceSummary_WithAllValuesOfBool.verified.txt diff --git a/tests/BenchmarkDotNet.Tests/Attributes/ApprovedFiles/ParamsAllValuesApprovalTests.BenchmarkShouldProduceSummary.WithAllValuesOfEnum.approved.txt b/tests/BenchmarkDotNet.Tests/Attributes/VerifiedFiles/ParamsAllValuesVerifyTests.BenchmarkShouldProduceSummary_WithAllValuesOfEnum.verified.txt similarity index 100% rename from tests/BenchmarkDotNet.Tests/Attributes/ApprovedFiles/ParamsAllValuesApprovalTests.BenchmarkShouldProduceSummary.WithAllValuesOfEnum.approved.txt rename to tests/BenchmarkDotNet.Tests/Attributes/VerifiedFiles/ParamsAllValuesVerifyTests.BenchmarkShouldProduceSummary_WithAllValuesOfEnum.verified.txt diff --git a/tests/BenchmarkDotNet.Tests/Attributes/ApprovedFiles/ParamsAllValuesApprovalTests.BenchmarkShouldProduceSummary.WithAllValuesOfNullableBool.approved.txt b/tests/BenchmarkDotNet.Tests/Attributes/VerifiedFiles/ParamsAllValuesVerifyTests.BenchmarkShouldProduceSummary_WithAllValuesOfNullableBool.verified.txt similarity index 100% rename from tests/BenchmarkDotNet.Tests/Attributes/ApprovedFiles/ParamsAllValuesApprovalTests.BenchmarkShouldProduceSummary.WithAllValuesOfNullableBool.approved.txt rename to tests/BenchmarkDotNet.Tests/Attributes/VerifiedFiles/ParamsAllValuesVerifyTests.BenchmarkShouldProduceSummary_WithAllValuesOfNullableBool.verified.txt diff --git a/tests/BenchmarkDotNet.Tests/Attributes/ApprovedFiles/ParamsAllValuesApprovalTests.BenchmarkShouldProduceSummary.WithAllValuesOfNullableEnum.approved.txt b/tests/BenchmarkDotNet.Tests/Attributes/VerifiedFiles/ParamsAllValuesVerifyTests.BenchmarkShouldProduceSummary_WithAllValuesOfNullableEnum.verified.txt similarity index 100% rename from tests/BenchmarkDotNet.Tests/Attributes/ApprovedFiles/ParamsAllValuesApprovalTests.BenchmarkShouldProduceSummary.WithAllValuesOfNullableEnum.approved.txt rename to tests/BenchmarkDotNet.Tests/Attributes/VerifiedFiles/ParamsAllValuesVerifyTests.BenchmarkShouldProduceSummary_WithAllValuesOfNullableEnum.verified.txt diff --git a/tests/BenchmarkDotNet.Tests/Attributes/ApprovedFiles/ParamsAllValuesApprovalTests.BenchmarkShouldProduceSummary.WithNotAllowedFlagsEnumError.approved.txt b/tests/BenchmarkDotNet.Tests/Attributes/VerifiedFiles/ParamsAllValuesVerifyTests.BenchmarkShouldProduceSummary_WithNotAllowedFlagsEnumError.verified.txt similarity index 100% rename from tests/BenchmarkDotNet.Tests/Attributes/ApprovedFiles/ParamsAllValuesApprovalTests.BenchmarkShouldProduceSummary.WithNotAllowedFlagsEnumError.approved.txt rename to tests/BenchmarkDotNet.Tests/Attributes/VerifiedFiles/ParamsAllValuesVerifyTests.BenchmarkShouldProduceSummary_WithNotAllowedFlagsEnumError.verified.txt diff --git a/tests/BenchmarkDotNet.Tests/Attributes/ApprovedFiles/ParamsAllValuesApprovalTests.BenchmarkShouldProduceSummary.WithNotAllowedNullableTypeError.approved.txt b/tests/BenchmarkDotNet.Tests/Attributes/VerifiedFiles/ParamsAllValuesVerifyTests.BenchmarkShouldProduceSummary_WithNotAllowedNullableTypeError.verified.txt similarity index 100% rename from tests/BenchmarkDotNet.Tests/Attributes/ApprovedFiles/ParamsAllValuesApprovalTests.BenchmarkShouldProduceSummary.WithNotAllowedNullableTypeError.approved.txt rename to tests/BenchmarkDotNet.Tests/Attributes/VerifiedFiles/ParamsAllValuesVerifyTests.BenchmarkShouldProduceSummary_WithNotAllowedNullableTypeError.verified.txt diff --git a/tests/BenchmarkDotNet.Tests/Attributes/ApprovedFiles/ParamsAllValuesApprovalTests.BenchmarkShouldProduceSummary.WithNotAllowedTypeError.approved.txt b/tests/BenchmarkDotNet.Tests/Attributes/VerifiedFiles/ParamsAllValuesVerifyTests.BenchmarkShouldProduceSummary_WithNotAllowedTypeError.verified.txt similarity index 100% rename from tests/BenchmarkDotNet.Tests/Attributes/ApprovedFiles/ParamsAllValuesApprovalTests.BenchmarkShouldProduceSummary.WithNotAllowedTypeError.approved.txt rename to tests/BenchmarkDotNet.Tests/Attributes/VerifiedFiles/ParamsAllValuesVerifyTests.BenchmarkShouldProduceSummary_WithNotAllowedTypeError.verified.txt diff --git a/tests/BenchmarkDotNet.Tests/BenchmarkDotNet.Tests.csproj b/tests/BenchmarkDotNet.Tests/BenchmarkDotNet.Tests.csproj index 5c8d440eda..eda55784ad 100755 --- a/tests/BenchmarkDotNet.Tests/BenchmarkDotNet.Tests.csproj +++ b/tests/BenchmarkDotNet.Tests/BenchmarkDotNet.Tests.csproj @@ -16,12 +16,12 @@ + all runtime; build; native; contentfiles; analyzers; buildtransitive - diff --git a/tests/BenchmarkDotNet.Tests/Builders/VerifySettingsFactory.cs b/tests/BenchmarkDotNet.Tests/Builders/VerifySettingsFactory.cs new file mode 100644 index 0000000000..027b5272a7 --- /dev/null +++ b/tests/BenchmarkDotNet.Tests/Builders/VerifySettingsFactory.cs @@ -0,0 +1,15 @@ +using VerifyTests; + +namespace BenchmarkDotNet.Tests.Builders +{ + public static class VerifySettingsFactory + { + public static VerifySettings Create() + { + var result = new VerifySettings(); + result.UseDirectory("VerifiedFiles"); + result.DisableDiff(); + return result; + } + } +} \ No newline at end of file diff --git a/tests/BenchmarkDotNet.Tests/Exporters/CommonExporterApprovalTests.cs b/tests/BenchmarkDotNet.Tests/Exporters/CommonExporterVerifyTests.cs similarity index 81% rename from tests/BenchmarkDotNet.Tests/Exporters/CommonExporterApprovalTests.cs rename to tests/BenchmarkDotNet.Tests/Exporters/CommonExporterVerifyTests.cs index 65b99a8cfc..b3e142c6c5 100644 --- a/tests/BenchmarkDotNet.Tests/Exporters/CommonExporterApprovalTests.cs +++ b/tests/BenchmarkDotNet.Tests/Exporters/CommonExporterVerifyTests.cs @@ -1,34 +1,29 @@ using System; using System.Collections.Generic; using System.Globalization; -using System.Runtime.CompilerServices; using System.Threading; -using ApprovalTests; -using ApprovalTests.Namers; -using ApprovalTests.Reporters; +using System.Threading.Tasks; using BenchmarkDotNet.Columns; using BenchmarkDotNet.Configs; using BenchmarkDotNet.Exporters; using BenchmarkDotNet.Exporters.Json; using BenchmarkDotNet.Exporters.Xml; using BenchmarkDotNet.Loggers; +using BenchmarkDotNet.Tests.Builders; using BenchmarkDotNet.Tests.Mocks; -using BenchmarkDotNet.Tests.XUnit; using JetBrains.Annotations; +using VerifyXunit; using Xunit; namespace BenchmarkDotNet.Tests.Exporters { - // In case of failed approval tests, use the following reporter: - // [UseReporter(typeof(KDiffReporter))] - [Collection("ApprovalTests")] - [UseReporter(typeof(PatchedXUnit2Reporter))] - [UseApprovalSubdirectory("ApprovedFiles")] - public class CommonExporterApprovalTests : IDisposable + [Collection("VerifyTests")] + [UsesVerify] + public class CommonExporterVerifyTests : IDisposable { private readonly CultureInfo initCulture; - public CommonExporterApprovalTests() + public CommonExporterVerifyTests() { initCulture = Thread.CurrentThread.CurrentCulture; } @@ -44,12 +39,10 @@ public CommonExporterApprovalTests() public static TheoryData CultureInfoNames => TheoryDataHelper.Create(CultureInfos.Keys); [Theory] - [MethodImpl(MethodImplOptions.NoInlining)] // required by the Approval test framework, do NOT remove [MemberData(nameof(CultureInfoNames))] - public void Exporters(string cultureInfoName) + public Task Exporters(string cultureInfoName) { var cultureInfo = CultureInfos[cultureInfoName]; - NamerFactory.AdditionalInformation = $"{GetName(cultureInfo)}"; Thread.CurrentThread.CurrentCulture = cultureInfo; var logger = new AccumulationLogger(); @@ -61,7 +54,9 @@ public void Exporters(string cultureInfoName) exporter.ExportToLog(MockFactory.CreateSummary(config.WithCultureInfo(cultureInfo)), logger); } - Approvals.Verify(logger.GetLog()); + var settings = VerifySettingsFactory.Create(); + settings.UseTextForParameters(GetName(cultureInfo)); + return Verifier.Verify(logger.GetLog(), settings); } private static void PrintTitle(AccumulationLogger logger, IExporter exporter) diff --git a/tests/BenchmarkDotNet.Tests/Exporters/MarkdownExporterApprovalTests.cs b/tests/BenchmarkDotNet.Tests/Exporters/MarkdownExporterVerifyTests.cs similarity index 92% rename from tests/BenchmarkDotNet.Tests/Exporters/MarkdownExporterApprovalTests.cs rename to tests/BenchmarkDotNet.Tests/Exporters/MarkdownExporterVerifyTests.cs index afa2206ae9..950f8498f8 100644 --- a/tests/BenchmarkDotNet.Tests/Exporters/MarkdownExporterApprovalTests.cs +++ b/tests/BenchmarkDotNet.Tests/Exporters/MarkdownExporterVerifyTests.cs @@ -2,33 +2,28 @@ using System.Diagnostics.CodeAnalysis; using System.Globalization; using System.Linq; -using System.Runtime.CompilerServices; using System.Threading; -using ApprovalTests; -using ApprovalTests.Namers; -using ApprovalTests.Reporters; +using System.Threading.Tasks; using BenchmarkDotNet.Exporters; using BenchmarkDotNet.Loggers; using BenchmarkDotNet.Tests.Mocks; using BenchmarkDotNet.Attributes; using BenchmarkDotNet.Configs; -using BenchmarkDotNet.Tests.XUnit; +using BenchmarkDotNet.Tests.Builders; using BenchmarkDotNet.Validators; using JetBrains.Annotations; +using VerifyXunit; using Xunit; namespace BenchmarkDotNet.Tests.Exporters { - // In case of failed approval tests, use the following reporter: - // [UseReporter(typeof(KDiffReporter))] - [UseReporter(typeof(PatchedXUnit2Reporter))] - [UseApprovalSubdirectory("ApprovedFiles")] - [Collection("ApprovalTests")] - public class MarkdownExporterApprovalTests : IDisposable + [Collection("VerifyTests")] + [UsesVerify] + public class MarkdownExporterVerifyTests : IDisposable { private readonly CultureInfo initCulture; - public MarkdownExporterApprovalTests() => initCulture = Thread.CurrentThread.CurrentCulture; + public MarkdownExporterVerifyTests() => initCulture = Thread.CurrentThread.CurrentCulture; [UsedImplicitly] public static TheoryData GetGroupBenchmarkTypes() @@ -41,10 +36,8 @@ public static TheoryData GetGroupBenchmarkTypes() [Theory] [MemberData(nameof(GetGroupBenchmarkTypes))] - [MethodImpl(MethodImplOptions.NoInlining)] - public void GroupExporterTest(Type benchmarkType) + public Task GroupExporterTest(Type benchmarkType) { - NamerFactory.AdditionalInformation = benchmarkType.Name; Thread.CurrentThread.CurrentCulture = CultureInfo.InvariantCulture; var logger = new AccumulationLogger(); @@ -61,7 +54,9 @@ public void GroupExporterTest(Type benchmarkType) foreach (var error in errors) logger.WriteLineError("* " + error.Message); - Approvals.Verify(logger.GetLog()); + var settings = VerifySettingsFactory.Create(); + settings.UseTextForParameters(benchmarkType.Name); + return Verifier.Verify(logger.GetLog(), settings); } public void Dispose() => Thread.CurrentThread.CurrentCulture = initCulture; diff --git a/tests/BenchmarkDotNet.Tests/Exporters/ApprovedFiles/CommonExporterApprovalTests.Exporters.Invariant.approved.txt b/tests/BenchmarkDotNet.Tests/Exporters/VerifiedFiles/CommonExporterVerifyTests.Exporters_Invariant.verified.txt similarity index 100% rename from tests/BenchmarkDotNet.Tests/Exporters/ApprovedFiles/CommonExporterApprovalTests.Exporters.Invariant.approved.txt rename to tests/BenchmarkDotNet.Tests/Exporters/VerifiedFiles/CommonExporterVerifyTests.Exporters_Invariant.verified.txt diff --git a/tests/BenchmarkDotNet.Tests/Exporters/ApprovedFiles/CommonExporterApprovalTests.Exporters.en-US.approved.txt b/tests/BenchmarkDotNet.Tests/Exporters/VerifiedFiles/CommonExporterVerifyTests.Exporters_en-US.verified.txt similarity index 100% rename from tests/BenchmarkDotNet.Tests/Exporters/ApprovedFiles/CommonExporterApprovalTests.Exporters.en-US.approved.txt rename to tests/BenchmarkDotNet.Tests/Exporters/VerifiedFiles/CommonExporterVerifyTests.Exporters_en-US.verified.txt diff --git a/tests/BenchmarkDotNet.Tests/Exporters/ApprovedFiles/CommonExporterApprovalTests.Exporters.ru-RU.approved.txt b/tests/BenchmarkDotNet.Tests/Exporters/VerifiedFiles/CommonExporterVerifyTests.Exporters_ru-RU.verified.txt similarity index 100% rename from tests/BenchmarkDotNet.Tests/Exporters/ApprovedFiles/CommonExporterApprovalTests.Exporters.ru-RU.approved.txt rename to tests/BenchmarkDotNet.Tests/Exporters/VerifiedFiles/CommonExporterVerifyTests.Exporters_ru-RU.verified.txt diff --git a/tests/BenchmarkDotNet.Tests/Exporters/ApprovedFiles/MarkdownExporterApprovalTests.GroupExporterTest.Escape_ParamsAndArguments.approved.txt b/tests/BenchmarkDotNet.Tests/Exporters/VerifiedFiles/MarkdownExporterVerifyTests.GroupExporterTest_Escape_ParamsAndArguments.verified.txt similarity index 100% rename from tests/BenchmarkDotNet.Tests/Exporters/ApprovedFiles/MarkdownExporterApprovalTests.GroupExporterTest.Escape_ParamsAndArguments.approved.txt rename to tests/BenchmarkDotNet.Tests/Exporters/VerifiedFiles/MarkdownExporterVerifyTests.GroupExporterTest_Escape_ParamsAndArguments.verified.txt diff --git a/tests/BenchmarkDotNet.Tests/Exporters/ApprovedFiles/MarkdownExporterApprovalTests.GroupExporterTest.Invalid_TwoJobBaselines.approved.txt b/tests/BenchmarkDotNet.Tests/Exporters/VerifiedFiles/MarkdownExporterVerifyTests.GroupExporterTest_Invalid_TwoJobBaselines.verified.txt similarity index 100% rename from tests/BenchmarkDotNet.Tests/Exporters/ApprovedFiles/MarkdownExporterApprovalTests.GroupExporterTest.Invalid_TwoJobBaselines.approved.txt rename to tests/BenchmarkDotNet.Tests/Exporters/VerifiedFiles/MarkdownExporterVerifyTests.GroupExporterTest_Invalid_TwoJobBaselines.verified.txt diff --git a/tests/BenchmarkDotNet.Tests/Exporters/ApprovedFiles/MarkdownExporterApprovalTests.GroupExporterTest.Invalid_TwoMethodBaselines.approved.txt b/tests/BenchmarkDotNet.Tests/Exporters/VerifiedFiles/MarkdownExporterVerifyTests.GroupExporterTest_Invalid_TwoMethodBaselines.verified.txt similarity index 100% rename from tests/BenchmarkDotNet.Tests/Exporters/ApprovedFiles/MarkdownExporterApprovalTests.GroupExporterTest.Invalid_TwoMethodBaselines.approved.txt rename to tests/BenchmarkDotNet.Tests/Exporters/VerifiedFiles/MarkdownExporterVerifyTests.GroupExporterTest_Invalid_TwoMethodBaselines.verified.txt diff --git a/tests/BenchmarkDotNet.Tests/Exporters/ApprovedFiles/MarkdownExporterApprovalTests.GroupExporterTest.JobBaseline_MethodsJobs.approved.txt b/tests/BenchmarkDotNet.Tests/Exporters/VerifiedFiles/MarkdownExporterVerifyTests.GroupExporterTest_JobBaseline_MethodsJobs.verified.txt similarity index 100% rename from tests/BenchmarkDotNet.Tests/Exporters/ApprovedFiles/MarkdownExporterApprovalTests.GroupExporterTest.JobBaseline_MethodsJobs.approved.txt rename to tests/BenchmarkDotNet.Tests/Exporters/VerifiedFiles/MarkdownExporterVerifyTests.GroupExporterTest_JobBaseline_MethodsJobs.verified.txt diff --git a/tests/BenchmarkDotNet.Tests/Exporters/ApprovedFiles/MarkdownExporterApprovalTests.GroupExporterTest.JobBaseline_MethodsParamsJobs.approved.txt b/tests/BenchmarkDotNet.Tests/Exporters/VerifiedFiles/MarkdownExporterVerifyTests.GroupExporterTest_JobBaseline_MethodsParamsJobs.verified.txt similarity index 100% rename from tests/BenchmarkDotNet.Tests/Exporters/ApprovedFiles/MarkdownExporterApprovalTests.GroupExporterTest.JobBaseline_MethodsParamsJobs.approved.txt rename to tests/BenchmarkDotNet.Tests/Exporters/VerifiedFiles/MarkdownExporterVerifyTests.GroupExporterTest_JobBaseline_MethodsParamsJobs.verified.txt diff --git a/tests/BenchmarkDotNet.Tests/Exporters/ApprovedFiles/MarkdownExporterApprovalTests.GroupExporterTest.MethodBaseline_Methods.approved.txt b/tests/BenchmarkDotNet.Tests/Exporters/VerifiedFiles/MarkdownExporterVerifyTests.GroupExporterTest_MethodBaseline_Methods.verified.txt similarity index 100% rename from tests/BenchmarkDotNet.Tests/Exporters/ApprovedFiles/MarkdownExporterApprovalTests.GroupExporterTest.MethodBaseline_Methods.approved.txt rename to tests/BenchmarkDotNet.Tests/Exporters/VerifiedFiles/MarkdownExporterVerifyTests.GroupExporterTest_MethodBaseline_Methods.verified.txt diff --git a/tests/BenchmarkDotNet.Tests/Exporters/ApprovedFiles/MarkdownExporterApprovalTests.GroupExporterTest.MethodBaseline_MethodsJobs.approved.txt b/tests/BenchmarkDotNet.Tests/Exporters/VerifiedFiles/MarkdownExporterVerifyTests.GroupExporterTest_MethodBaseline_MethodsJobs.verified.txt similarity index 100% rename from tests/BenchmarkDotNet.Tests/Exporters/ApprovedFiles/MarkdownExporterApprovalTests.GroupExporterTest.MethodBaseline_MethodsJobs.approved.txt rename to tests/BenchmarkDotNet.Tests/Exporters/VerifiedFiles/MarkdownExporterVerifyTests.GroupExporterTest_MethodBaseline_MethodsJobs.verified.txt diff --git a/tests/BenchmarkDotNet.Tests/Exporters/ApprovedFiles/MarkdownExporterApprovalTests.GroupExporterTest.MethodBaseline_MethodsParams.approved.txt b/tests/BenchmarkDotNet.Tests/Exporters/VerifiedFiles/MarkdownExporterVerifyTests.GroupExporterTest_MethodBaseline_MethodsParams.verified.txt similarity index 100% rename from tests/BenchmarkDotNet.Tests/Exporters/ApprovedFiles/MarkdownExporterApprovalTests.GroupExporterTest.MethodBaseline_MethodsParams.approved.txt rename to tests/BenchmarkDotNet.Tests/Exporters/VerifiedFiles/MarkdownExporterVerifyTests.GroupExporterTest_MethodBaseline_MethodsParams.verified.txt diff --git a/tests/BenchmarkDotNet.Tests/Exporters/ApprovedFiles/MarkdownExporterApprovalTests.GroupExporterTest.MethodBaseline_MethodsParamsJobs.approved.txt b/tests/BenchmarkDotNet.Tests/Exporters/VerifiedFiles/MarkdownExporterVerifyTests.GroupExporterTest_MethodBaseline_MethodsParamsJobs.verified.txt similarity index 100% rename from tests/BenchmarkDotNet.Tests/Exporters/ApprovedFiles/MarkdownExporterApprovalTests.GroupExporterTest.MethodBaseline_MethodsParamsJobs.approved.txt rename to tests/BenchmarkDotNet.Tests/Exporters/VerifiedFiles/MarkdownExporterVerifyTests.GroupExporterTest_MethodBaseline_MethodsParamsJobs.verified.txt diff --git a/tests/BenchmarkDotNet.Tests/Exporters/ApprovedFiles/MarkdownExporterApprovalTests.GroupExporterTest.MethodJobBaseline_MethodsJobs.approved.txt b/tests/BenchmarkDotNet.Tests/Exporters/VerifiedFiles/MarkdownExporterVerifyTests.GroupExporterTest_MethodJobBaseline_MethodsJobs.verified.txt similarity index 100% rename from tests/BenchmarkDotNet.Tests/Exporters/ApprovedFiles/MarkdownExporterApprovalTests.GroupExporterTest.MethodJobBaseline_MethodsJobs.approved.txt rename to tests/BenchmarkDotNet.Tests/Exporters/VerifiedFiles/MarkdownExporterVerifyTests.GroupExporterTest_MethodJobBaseline_MethodsJobs.verified.txt diff --git a/tests/BenchmarkDotNet.Tests/Exporters/ApprovedFiles/MarkdownExporterApprovalTests.GroupExporterTest.MethodJobBaseline_MethodsJobsParams.approved.txt b/tests/BenchmarkDotNet.Tests/Exporters/VerifiedFiles/MarkdownExporterVerifyTests.GroupExporterTest_MethodJobBaseline_MethodsJobsParams.verified.txt similarity index 100% rename from tests/BenchmarkDotNet.Tests/Exporters/ApprovedFiles/MarkdownExporterApprovalTests.GroupExporterTest.MethodJobBaseline_MethodsJobsParams.approved.txt rename to tests/BenchmarkDotNet.Tests/Exporters/VerifiedFiles/MarkdownExporterVerifyTests.GroupExporterTest_MethodJobBaseline_MethodsJobsParams.verified.txt diff --git a/tests/BenchmarkDotNet.Tests/Exporters/ApprovedFiles/MarkdownExporterApprovalTests.GroupExporterTest.NoBaseline_MethodsParamsJobs.approved.txt b/tests/BenchmarkDotNet.Tests/Exporters/VerifiedFiles/MarkdownExporterVerifyTests.GroupExporterTest_NoBaseline_MethodsParamsJobs.verified.txt similarity index 100% rename from tests/BenchmarkDotNet.Tests/Exporters/ApprovedFiles/MarkdownExporterApprovalTests.GroupExporterTest.NoBaseline_MethodsParamsJobs.approved.txt rename to tests/BenchmarkDotNet.Tests/Exporters/VerifiedFiles/MarkdownExporterVerifyTests.GroupExporterTest_NoBaseline_MethodsParamsJobs.verified.txt diff --git a/tests/BenchmarkDotNet.Tests/Exporters/ApprovedFiles/MarkdownExporterApprovalTests.GroupExporterTest.NoBaseline_MethodsParamsJobs_GroupByAll.approved.txt b/tests/BenchmarkDotNet.Tests/Exporters/VerifiedFiles/MarkdownExporterVerifyTests.GroupExporterTest_NoBaseline_MethodsParamsJobs_GroupByAll.verified.txt similarity index 100% rename from tests/BenchmarkDotNet.Tests/Exporters/ApprovedFiles/MarkdownExporterApprovalTests.GroupExporterTest.NoBaseline_MethodsParamsJobs_GroupByAll.approved.txt rename to tests/BenchmarkDotNet.Tests/Exporters/VerifiedFiles/MarkdownExporterVerifyTests.GroupExporterTest_NoBaseline_MethodsParamsJobs_GroupByAll.verified.txt diff --git a/tests/BenchmarkDotNet.Tests/Exporters/ApprovedFiles/MarkdownExporterApprovalTests.GroupExporterTest.NoBaseline_MethodsParamsJobs_GroupByCategory.approved.txt b/tests/BenchmarkDotNet.Tests/Exporters/VerifiedFiles/MarkdownExporterVerifyTests.GroupExporterTest_NoBaseline_MethodsParamsJobs_GroupByCategory.verified.txt similarity index 100% rename from tests/BenchmarkDotNet.Tests/Exporters/ApprovedFiles/MarkdownExporterApprovalTests.GroupExporterTest.NoBaseline_MethodsParamsJobs_GroupByCategory.approved.txt rename to tests/BenchmarkDotNet.Tests/Exporters/VerifiedFiles/MarkdownExporterVerifyTests.GroupExporterTest_NoBaseline_MethodsParamsJobs_GroupByCategory.verified.txt diff --git a/tests/BenchmarkDotNet.Tests/Exporters/ApprovedFiles/MarkdownExporterApprovalTests.GroupExporterTest.NoBaseline_MethodsParamsJobs_GroupByJob.approved.txt b/tests/BenchmarkDotNet.Tests/Exporters/VerifiedFiles/MarkdownExporterVerifyTests.GroupExporterTest_NoBaseline_MethodsParamsJobs_GroupByJob.verified.txt similarity index 100% rename from tests/BenchmarkDotNet.Tests/Exporters/ApprovedFiles/MarkdownExporterApprovalTests.GroupExporterTest.NoBaseline_MethodsParamsJobs_GroupByJob.approved.txt rename to tests/BenchmarkDotNet.Tests/Exporters/VerifiedFiles/MarkdownExporterVerifyTests.GroupExporterTest_NoBaseline_MethodsParamsJobs_GroupByJob.verified.txt diff --git a/tests/BenchmarkDotNet.Tests/Exporters/ApprovedFiles/MarkdownExporterApprovalTests.GroupExporterTest.NoBaseline_MethodsParamsJobs_GroupByMethod.approved.txt b/tests/BenchmarkDotNet.Tests/Exporters/VerifiedFiles/MarkdownExporterVerifyTests.GroupExporterTest_NoBaseline_MethodsParamsJobs_GroupByMethod.verified.txt similarity index 100% rename from tests/BenchmarkDotNet.Tests/Exporters/ApprovedFiles/MarkdownExporterApprovalTests.GroupExporterTest.NoBaseline_MethodsParamsJobs_GroupByMethod.approved.txt rename to tests/BenchmarkDotNet.Tests/Exporters/VerifiedFiles/MarkdownExporterVerifyTests.GroupExporterTest_NoBaseline_MethodsParamsJobs_GroupByMethod.verified.txt diff --git a/tests/BenchmarkDotNet.Tests/Exporters/ApprovedFiles/MarkdownExporterApprovalTests.GroupExporterTest.NoBaseline_MethodsParamsJobs_GroupByParams.approved.txt b/tests/BenchmarkDotNet.Tests/Exporters/VerifiedFiles/MarkdownExporterVerifyTests.GroupExporterTest_NoBaseline_MethodsParamsJobs_GroupByParams.verified.txt similarity index 100% rename from tests/BenchmarkDotNet.Tests/Exporters/ApprovedFiles/MarkdownExporterApprovalTests.GroupExporterTest.NoBaseline_MethodsParamsJobs_GroupByParams.approved.txt rename to tests/BenchmarkDotNet.Tests/Exporters/VerifiedFiles/MarkdownExporterVerifyTests.GroupExporterTest_NoBaseline_MethodsParamsJobs_GroupByParams.verified.txt diff --git a/tests/BenchmarkDotNet.Tests/GlobFilterTests.cs b/tests/BenchmarkDotNet.Tests/GlobFilterTests.cs index 82347de4cc..60ca3fdb6e 100644 --- a/tests/BenchmarkDotNet.Tests/GlobFilterTests.cs +++ b/tests/BenchmarkDotNet.Tests/GlobFilterTests.cs @@ -1,6 +1,4 @@ using System.Linq; -using System.Threading; -using ApprovalUtilities.Utilities; using BenchmarkDotNet.Attributes; using BenchmarkDotNet.Filters; using BenchmarkDotNet.Running; diff --git a/tests/BenchmarkDotNet.Tests/Portability/Cpu/CpuInfoFormatterTests.cs b/tests/BenchmarkDotNet.Tests/Portability/Cpu/CpuInfoFormatterTests.cs index 8b9ce62268..83d14685a4 100644 --- a/tests/BenchmarkDotNet.Tests/Portability/Cpu/CpuInfoFormatterTests.cs +++ b/tests/BenchmarkDotNet.Tests/Portability/Cpu/CpuInfoFormatterTests.cs @@ -1,22 +1,18 @@ -using System.Runtime.CompilerServices; -using System.Text; -using ApprovalTests; -using ApprovalTests.Namers; -using ApprovalTests.Reporters; +using System.Text; +using System.Threading.Tasks; using BenchmarkDotNet.Portability.Cpu; -using BenchmarkDotNet.Tests.XUnit; +using BenchmarkDotNet.Tests.Builders; +using VerifyXunit; using Xunit; namespace BenchmarkDotNet.Tests.Portability.Cpu { - [Collection("ApprovalTests")] - [UseReporter(typeof(PatchedXUnit2Reporter))] - [UseApprovalSubdirectory("ApprovedFiles")] + [Collection("VerifyTests")] + [UsesVerify] public class CpuInfoFormatterTests { [Fact] - [MethodImpl(MethodImplOptions.NoInlining)] - public void FormatTest() + public Task FormatTest() { var captions = new StringBuilder(); foreach (var processorName in new[] { null, "", "Intel" }) @@ -28,7 +24,8 @@ public void FormatTest() captions.AppendLine(CpuInfoFormatter.Format(mockCpuInfo)); } - Approvals.Verify(captions.ToString()); + var settings = VerifySettingsFactory.Create(); + return Verifier.Verify(captions.ToString(), settings); } } } diff --git a/tests/BenchmarkDotNet.Tests/Portability/Cpu/ApprovedFiles/CpuInfoFormatterTests.FormatTest.approved.txt b/tests/BenchmarkDotNet.Tests/Portability/Cpu/VerifiedFiles/CpuInfoFormatterTests.FormatTest.verified.txt similarity index 100% rename from tests/BenchmarkDotNet.Tests/Portability/Cpu/ApprovedFiles/CpuInfoFormatterTests.FormatTest.approved.txt rename to tests/BenchmarkDotNet.Tests/Portability/Cpu/VerifiedFiles/CpuInfoFormatterTests.FormatTest.verified.txt diff --git a/tests/BenchmarkDotNet.Tests/Properties/AssemblyInfo.cs b/tests/BenchmarkDotNet.Tests/Properties/AssemblyInfo.cs index f6118550f1..3dbcf1ae2e 100644 --- a/tests/BenchmarkDotNet.Tests/Properties/AssemblyInfo.cs +++ b/tests/BenchmarkDotNet.Tests/Properties/AssemblyInfo.cs @@ -1,5 +1,3 @@ using System.Runtime.InteropServices; -using ApprovalTests.Reporters; [assembly: Guid("16c47abf-43e0-4db4-8151-36ca7a4082ae")] -[assembly: IgnoreLineEndings(true)] diff --git a/tests/BenchmarkDotNet.Tests/XUnit/PatchedXUnit2Reporter.cs b/tests/BenchmarkDotNet.Tests/XUnit/PatchedXUnit2Reporter.cs deleted file mode 100644 index baff5acac0..0000000000 --- a/tests/BenchmarkDotNet.Tests/XUnit/PatchedXUnit2Reporter.cs +++ /dev/null @@ -1,27 +0,0 @@ -using System; -using System.IO; -using System.Linq; -using ApprovalTests.Reporters; - -namespace BenchmarkDotNet.Tests.XUnit -{ - public class PatchedXUnit2Reporter : XUnit2Reporter - { - public override void InvokeEqualsMethod(Type type, string[] parameters) - { - var method = type.GetMethods().First(m => - m.Name == areEqual && - !m.IsGenericMethod && - m.GetParameters().Length == 2); - method.Invoke(null, parameters); - } - - public override void AssertFileContents(string approved, string received) - { - string approvedContent = File.Exists(approved) ? File.ReadAllText(approved).Replace("\r", "") : ""; - string receivedContent = File.ReadAllText(received).Replace("\r", ""); - QuietReporter.DisplayCommandLineApproval(approved, received); - AssertEqual(approvedContent, receivedContent); - } - } -} \ No newline at end of file