diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 03331660a89..be147658f9d 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -68,8 +68,10 @@ jobs: name: logs-${{ matrix.os }} path: | msbuild.binlog + test/**/TestResults/*.log test/**/TestResults/*.trx test/**/TestResults/*.html + test/**/TestResults/*.ctrf - uses: actions/upload-artifact@v4 if: ${{ failure() && matrix.os == 'ubuntu-latest' }} diff --git a/docfx.sln b/docfx.sln index a5974afe119..d6b801de64a 100644 --- a/docfx.sln +++ b/docfx.sln @@ -15,6 +15,7 @@ EndProject Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "test", "test", "{926A0726-B806-4215-82EF-AF8E22D0FACF}" ProjectSection(SolutionItems) = preProject test\Directory.Build.props = test\Directory.Build.props + test\xunit.runner.json = test\xunit.runner.json test\Directory.Packages.props = test\Directory.Packages.props EndProjectSection EndProject diff --git a/test/Directory.Build.props b/test/Directory.Build.props index 58979e35535..5fbeb4b8bcb 100644 --- a/test/Directory.Build.props +++ b/test/Directory.Build.props @@ -2,23 +2,52 @@ false en + true false + + + + true + true + true + + + true + + + --results-directory "$(MSBuildThisFileDirectory)TestResults" + $(TestingPlatformCommandLineArguments) --output Detailed + + + $(TestingPlatformCommandLineArguments) --ignore-exit-code 8 + + + + + $(TestingPlatformCommandLineArguments) --no-progress + + + $(TestingPlatformCommandLineArguments) --report-xunit-trx --report-xunit-trx-filename TestResults-$(MSBuildProjectName)-$(TargetFramework)-$(RUNNER_OS).trx + $(TestingPlatformCommandLineArguments) --report-xunit-html --report-xunit-html-filename TestResults-$(MSBuildProjectName)-$(TargetFramework)-$(RUNNER_OS).html + $(TestingPlatformCommandLineArguments) --report-ctrf --report-ctrf-filename TestResults-$(MSBuildProjectName)-$(TargetFramework)-$(RUNNER_OS).ctrf + + $(MSBuildThisFileDirectory)TestResults $(VSTestLogger);trx%3BLogFileName=TestResults-$(MSBuildProjectName)-$(TargetFramework)-$(RUNNER_OS).trx $(VSTestLogger);html%3BLogFileName=TestResults-$(MSBuildProjectName)-$(TargetFramework)-$(RUNNER_OS).html @@ -28,6 +57,6 @@ - + diff --git a/test/Docfx.Build.Common.Tests/Docfx.Build.Common.Tests.csproj b/test/Docfx.Build.Common.Tests/Docfx.Build.Common.Tests.csproj index 474324b4f13..cf3b83368f6 100644 --- a/test/Docfx.Build.Common.Tests/Docfx.Build.Common.Tests.csproj +++ b/test/Docfx.Build.Common.Tests/Docfx.Build.Common.Tests.csproj @@ -1,4 +1,8 @@ + + Exe + + diff --git a/test/Docfx.Build.ManagedReference.Tests/Docfx.Build.ManagedReference.Tests.csproj b/test/Docfx.Build.ManagedReference.Tests/Docfx.Build.ManagedReference.Tests.csproj index 943a81c22c2..1dca5ab1ccd 100644 --- a/test/Docfx.Build.ManagedReference.Tests/Docfx.Build.ManagedReference.Tests.csproj +++ b/test/Docfx.Build.ManagedReference.Tests/Docfx.Build.ManagedReference.Tests.csproj @@ -1,4 +1,8 @@ + + Exe + + diff --git a/test/Docfx.Build.OverwriteDocuments.Tests/Docfx.Build.OverwriteDocuments.Tests.csproj b/test/Docfx.Build.OverwriteDocuments.Tests/Docfx.Build.OverwriteDocuments.Tests.csproj index ada9e2ab801..6c32f390084 100644 --- a/test/Docfx.Build.OverwriteDocuments.Tests/Docfx.Build.OverwriteDocuments.Tests.csproj +++ b/test/Docfx.Build.OverwriteDocuments.Tests/Docfx.Build.OverwriteDocuments.Tests.csproj @@ -1,7 +1,12 @@ + + Exe + + + diff --git a/test/Docfx.Build.RestApi.Tests/Docfx.Build.RestApi.Tests.csproj b/test/Docfx.Build.RestApi.Tests/Docfx.Build.RestApi.Tests.csproj index 6632e67a6a9..4d288bd43de 100644 --- a/test/Docfx.Build.RestApi.Tests/Docfx.Build.RestApi.Tests.csproj +++ b/test/Docfx.Build.RestApi.Tests/Docfx.Build.RestApi.Tests.csproj @@ -1,4 +1,8 @@ + + Exe + + diff --git a/test/Docfx.Build.RestApi.WithPlugins.Tests/Docfx.Build.RestApi.WithPlugins.Tests.csproj b/test/Docfx.Build.RestApi.WithPlugins.Tests/Docfx.Build.RestApi.WithPlugins.Tests.csproj index ac834570ef9..5557482545f 100644 --- a/test/Docfx.Build.RestApi.WithPlugins.Tests/Docfx.Build.RestApi.WithPlugins.Tests.csproj +++ b/test/Docfx.Build.RestApi.WithPlugins.Tests/Docfx.Build.RestApi.WithPlugins.Tests.csproj @@ -1,4 +1,8 @@ + + Exe + + diff --git a/test/Docfx.Build.SchemaDriven.Tests/Docfx.Build.SchemaDriven.Tests.csproj b/test/Docfx.Build.SchemaDriven.Tests/Docfx.Build.SchemaDriven.Tests.csproj index 4ed255dbd06..6307460d93d 100644 --- a/test/Docfx.Build.SchemaDriven.Tests/Docfx.Build.SchemaDriven.Tests.csproj +++ b/test/Docfx.Build.SchemaDriven.Tests/Docfx.Build.SchemaDriven.Tests.csproj @@ -1,4 +1,8 @@ + + Exe + + diff --git a/test/Docfx.Build.Tests/Docfx.Build.Tests.csproj b/test/Docfx.Build.Tests/Docfx.Build.Tests.csproj index 61c730cef26..92b71aea685 100644 --- a/test/Docfx.Build.Tests/Docfx.Build.Tests.csproj +++ b/test/Docfx.Build.Tests/Docfx.Build.Tests.csproj @@ -1,4 +1,8 @@ + + Exe + + diff --git a/test/Docfx.Build.Tests/ExtractSearchIndexFromHtmlTest.cs b/test/Docfx.Build.Tests/ExtractSearchIndexFromHtmlTest.cs index 41b97201b79..704db079818 100644 --- a/test/Docfx.Build.Tests/ExtractSearchIndexFromHtmlTest.cs +++ b/test/Docfx.Build.Tests/ExtractSearchIndexFromHtmlTest.cs @@ -219,7 +219,7 @@ This is article title manifest.Files.Add(manifestItem); // process the fake manifest, using tempTestFolder as the output folder - _extractor.Process(manifest, tempTestFolder); + _extractor.Process(manifest, tempTestFolder, TestContext.Current.CancellationToken); var expectedIndexJSON = @"{ ""index.html"": { diff --git a/test/Docfx.Build.Tests/PostProcessors/SitemapGeneratorTests.cs b/test/Docfx.Build.Tests/PostProcessors/SitemapGeneratorTests.cs index 4e8658a653b..f1ab2da080d 100644 --- a/test/Docfx.Build.Tests/PostProcessors/SitemapGeneratorTests.cs +++ b/test/Docfx.Build.Tests/PostProcessors/SitemapGeneratorTests.cs @@ -5,7 +5,6 @@ using Docfx.Plugins; using Docfx.Tests.Common; using Xunit; -using Xunit.Abstractions; using DocumentType = Docfx.DataContracts.Common.Constants.DocumentType; namespace Docfx.Build.Engine.Tests; @@ -58,7 +57,7 @@ public void TestSitemapGenerator() var sitemapPath = Path.Combine(outputFolder, "sitemap.xml"); // Act - manifest = sitemapGenerator.Process(manifest, outputFolder); + manifest = sitemapGenerator.Process(manifest, outputFolder, TestContext.Current.CancellationToken); // Assert Assert.Equal("https://example.com/", manifest.Sitemap.BaseUrl); diff --git a/test/Docfx.Build.Tests/RemoveDebugInfoTest.cs b/test/Docfx.Build.Tests/RemoveDebugInfoTest.cs index 588155d564b..e86739f3176 100644 --- a/test/Docfx.Build.Tests/RemoveDebugInfoTest.cs +++ b/test/Docfx.Build.Tests/RemoveDebugInfoTest.cs @@ -43,7 +43,7 @@ public void TestBasicFeature() new HtmlPostProcessor { Handlers = { new RemoveDebugInfo() } - }.Process(manifest, _outputFolder); + }.Process(manifest, _outputFolder, TestContext.Current.CancellationToken); var actual = File.ReadAllText(Path.Combine(_outputFolder, "a.html")); Assert.Equal("

sectionMicrosoft Bing

", actual); diff --git a/test/Docfx.Build.Tests/ValidateBookmarkTest.cs b/test/Docfx.Build.Tests/ValidateBookmarkTest.cs index 24cc7edf5de..72d155b67df 100644 --- a/test/Docfx.Build.Tests/ValidateBookmarkTest.cs +++ b/test/Docfx.Build.Tests/ValidateBookmarkTest.cs @@ -63,7 +63,7 @@ public void TestBasicFeature() new HtmlPostProcessor { Handlers = { new ValidateBookmark() } - }.Process(manifest, _outputFolder); + }.Process(manifest, _outputFolder, TestContext.Current.CancellationToken); } finally { @@ -107,7 +107,7 @@ public void TestNoCheck() new HtmlPostProcessor { Handlers = { new ValidateBookmark() } - }.Process(manifest, _outputFolder); + }.Process(manifest, _outputFolder, TestContext.Current.CancellationToken); } finally { @@ -150,7 +150,7 @@ public void TestLinkThatContainsNonAsciiChars() new HtmlPostProcessor { Handlers = { new ValidateBookmark() } - }.Process(manifest, _outputFolder); + }.Process(manifest, _outputFolder, TestContext.Current.CancellationToken); } finally { diff --git a/test/Docfx.Build.Tests/XRefArchiveBuilderTest.cs b/test/Docfx.Build.Tests/XRefArchiveBuilderTest.cs index 65314446a06..6a721e57e75 100644 --- a/test/Docfx.Build.Tests/XRefArchiveBuilderTest.cs +++ b/test/Docfx.Build.Tests/XRefArchiveBuilderTest.cs @@ -20,7 +20,7 @@ public async Task TestDownload() // sorted: true // references: [] // ``` - Assert.True(await builder.DownloadAsync(new Uri("http://dotnet.github.io/docfx/xrefmap.yml"), ZipFile)); + Assert.True(await builder.DownloadAsync(new Uri("http://dotnet.github.io/docfx/xrefmap.yml"), ZipFile, TestContext.Current.CancellationToken)); using (var xar = XRefArchive.Open(ZipFile, XRefArchiveMode.Read)) { diff --git a/test/Docfx.Build.Tests/XRefMapDownloaderTest.cs b/test/Docfx.Build.Tests/XRefMapDownloaderTest.cs index b3557df9c27..752e9b664d7 100644 --- a/test/Docfx.Build.Tests/XRefMapDownloaderTest.cs +++ b/test/Docfx.Build.Tests/XRefMapDownloaderTest.cs @@ -13,7 +13,7 @@ public class XRefMapDownloadTest public async Task BaseUrlIsSet() { var downloader = new XRefMapDownloader(); - var xrefs = await downloader.DownloadAsync(new Uri("https://dotnet.github.io/docfx/xrefmap.yml")) as XRefMap; + var xrefs = await downloader.DownloadAsync(new Uri("https://dotnet.github.io/docfx/xrefmap.yml"), TestContext.Current.CancellationToken) as XRefMap; Assert.NotNull(xrefs); Assert.Equal("https://dotnet.github.io/docfx/", xrefs.BaseUrl); } @@ -27,7 +27,7 @@ public async Task ReadLocalXRefMapWithFallback() // Get fallback TestData/xrefmap.yml which contains uid: 'str' var reader = await new XRefCollection(from u in xrefmaps - select new Uri(u, UriKind.RelativeOrAbsolute)).GetReaderAsync(basePath, fallbackFolders); + select new Uri(u, UriKind.RelativeOrAbsolute)).GetReaderAsync(basePath, fallbackFolders, TestContext.Current.CancellationToken); var xrefSpec = reader.Find("str"); Assert.NotNull(xrefSpec); @@ -41,7 +41,7 @@ public async Task ReadLocalXRefMapJsonFileTest() var path = Path.Combine(Directory.GetCurrentDirectory(), "TestData", "xrefmap.json"); var downloader = new XRefMapDownloader(); - var xrefMap = await downloader.DownloadAsync(new Uri(path)) as XRefMap; + var xrefMap = await downloader.DownloadAsync(new Uri(path), TestContext.Current.CancellationToken) as XRefMap; // Assert xrefMap.Should().NotBeNull(); @@ -55,7 +55,7 @@ public async Task ReadLocalXRefMapGZippedJsonFileTest() var path = Path.Combine(Directory.GetCurrentDirectory(), "TestData", "xrefmap.json.gz"); var downloader = new XRefMapDownloader(); - var xrefMap = await downloader.DownloadAsync(new Uri(path)) as XRefMap; + var xrefMap = await downloader.DownloadAsync(new Uri(path), TestContext.Current.CancellationToken) as XRefMap; // Assert xrefMap.Should().NotBeNull(); @@ -69,7 +69,7 @@ public async Task ReadLocalXRefMapGZippedYamlFileTest() var path = Path.Combine(Directory.GetCurrentDirectory(), "TestData", "xrefmap.yml.gz"); var downloader = new XRefMapDownloader(); - var xrefMap = await downloader.DownloadAsync(new Uri(path)) as XRefMap; + var xrefMap = await downloader.DownloadAsync(new Uri(path), TestContext.Current.CancellationToken) as XRefMap; // Assert xrefMap.Should().NotBeNull(); @@ -86,7 +86,7 @@ public async Task ReadRemoteXRefMapYamlFileTest1() var path = "https://horizongir.github.io/ZedGraph/xrefmap.yml"; var downloader = new XRefMapDownloader(); - var xrefMap = await downloader.DownloadAsync(new Uri(path)) as XRefMap; + var xrefMap = await downloader.DownloadAsync(new Uri(path), TestContext.Current.CancellationToken) as XRefMap; // Assert xrefMap.Sorted.Should().BeTrue(); @@ -115,7 +115,7 @@ public async Task ReadRemoteXRefMapJsonFileTest2() var path = "https://normanderwan.github.io/UnityXrefMaps/xrefmap.yml"; var downloader = new XRefMapDownloader(); - var xrefMap = await downloader.DownloadAsync(new Uri(path)) as XRefMap; + var xrefMap = await downloader.DownloadAsync(new Uri(path), TestContext.Current.CancellationToken) as XRefMap; // Assert xrefMap.Sorted.Should().BeTrue(); diff --git a/test/Docfx.Build.UniversalReference.Tests/Docfx.Build.UniversalReference.Tests.csproj b/test/Docfx.Build.UniversalReference.Tests/Docfx.Build.UniversalReference.Tests.csproj index 3aeb509bbd8..b3ea8731c4d 100644 --- a/test/Docfx.Build.UniversalReference.Tests/Docfx.Build.UniversalReference.Tests.csproj +++ b/test/Docfx.Build.UniversalReference.Tests/Docfx.Build.UniversalReference.Tests.csproj @@ -1,4 +1,8 @@ + + Exe + + diff --git a/test/Docfx.Common.Tests/Docfx.Common.Tests.csproj b/test/Docfx.Common.Tests/Docfx.Common.Tests.csproj index 241d5099754..3099e43dd67 100644 --- a/test/Docfx.Common.Tests/Docfx.Common.Tests.csproj +++ b/test/Docfx.Common.Tests/Docfx.Common.Tests.csproj @@ -1,4 +1,8 @@ + + Exe + + diff --git a/test/Docfx.Dotnet.Tests/Docfx.Dotnet.Tests.csproj b/test/Docfx.Dotnet.Tests/Docfx.Dotnet.Tests.csproj index b5042bdb201..4e48bc27346 100644 --- a/test/Docfx.Dotnet.Tests/Docfx.Dotnet.Tests.csproj +++ b/test/Docfx.Dotnet.Tests/Docfx.Dotnet.Tests.csproj @@ -1,4 +1,8 @@ + + Exe + + diff --git a/test/Docfx.Dotnet.Tests/GenerateMetadataFromAssemblyTest.cs b/test/Docfx.Dotnet.Tests/GenerateMetadataFromAssemblyTest.cs index 9ef41b066c9..eceb01ef205 100644 --- a/test/Docfx.Dotnet.Tests/GenerateMetadataFromAssemblyTest.cs +++ b/test/Docfx.Dotnet.Tests/GenerateMetadataFromAssemblyTest.cs @@ -14,7 +14,7 @@ public void TestGenerateMetadataFromAssembly() { { var (compilation, assembly) = CompilationHelper.CreateCompilationFromAssembly("TestData/CatLibrary.dll"); - Assert.Empty(compilation.GetDeclarationDiagnostics()); + Assert.Empty(compilation.GetDeclarationDiagnostics(TestContext.Current.CancellationToken)); var output = assembly.GenerateMetadataItem(compilation); var @class = output.Items[0].Items[2]; @@ -26,7 +26,7 @@ public void TestGenerateMetadataFromAssembly() { var (compilation, assembly) = CompilationHelper.CreateCompilationFromAssembly("TestData/CatLibrary2.dll"); - Assert.Empty(compilation.GetDeclarationDiagnostics()); + Assert.Empty(compilation.GetDeclarationDiagnostics(TestContext.Current.CancellationToken)); var output = assembly.GenerateMetadataItem(compilation); var @class = output.Items[0].Items[0]; @@ -40,7 +40,7 @@ public void TestGenerateMetadataFromAssembly() public void TestGenerateMetadataFromAssemblyWithReferences() { var (compilation, assembly) = CompilationHelper.CreateCompilationFromAssembly("TestData/TupleLibrary.dll"); - Assert.Empty(compilation.GetDeclarationDiagnostics()); + Assert.Empty(compilation.GetDeclarationDiagnostics(TestContext.Current.CancellationToken)); var output = assembly.GenerateMetadataItem(compilation); var @class = output.Items[0].Items[0]; diff --git a/test/Docfx.Glob.Tests/Docfx.Glob.Tests.csproj b/test/Docfx.Glob.Tests/Docfx.Glob.Tests.csproj index 38cbb3cdba2..4723025afbb 100644 --- a/test/Docfx.Glob.Tests/Docfx.Glob.Tests.csproj +++ b/test/Docfx.Glob.Tests/Docfx.Glob.Tests.csproj @@ -1,4 +1,8 @@ + + Exe + + diff --git a/test/Docfx.MarkdigEngine.Extensions.Tests/Docfx.MarkdigEngine.Extensions.Tests.csproj b/test/Docfx.MarkdigEngine.Extensions.Tests/Docfx.MarkdigEngine.Extensions.Tests.csproj index 6bb49f20177..3948569b174 100644 --- a/test/Docfx.MarkdigEngine.Extensions.Tests/Docfx.MarkdigEngine.Extensions.Tests.csproj +++ b/test/Docfx.MarkdigEngine.Extensions.Tests/Docfx.MarkdigEngine.Extensions.Tests.csproj @@ -1,4 +1,8 @@ + + Exe + + diff --git a/test/Docfx.MarkdigEngine.Tests/Docfx.MarkdigEngine.Tests.csproj b/test/Docfx.MarkdigEngine.Tests/Docfx.MarkdigEngine.Tests.csproj index 8c61517ccfb..4135f1d78c8 100644 --- a/test/Docfx.MarkdigEngine.Tests/Docfx.MarkdigEngine.Tests.csproj +++ b/test/Docfx.MarkdigEngine.Tests/Docfx.MarkdigEngine.Tests.csproj @@ -1,4 +1,8 @@ + + Exe + + diff --git a/test/Docfx.Tests.Common/Docfx.Tests.Common.csproj b/test/Docfx.Tests.Common/Docfx.Tests.Common.csproj index 230ab4eeb47..e2e7e0e7ff2 100644 --- a/test/Docfx.Tests.Common/Docfx.Tests.Common.csproj +++ b/test/Docfx.Tests.Common/Docfx.Tests.Common.csproj @@ -1,6 +1,10 @@ + Library false + false + false + false diff --git a/test/docfx.Snapshot.Tests/docfx.Snapshot.Tests.csproj b/test/docfx.Snapshot.Tests/docfx.Snapshot.Tests.csproj index 56c718ed26b..9fc45aa7574 100644 --- a/test/docfx.Snapshot.Tests/docfx.Snapshot.Tests.csproj +++ b/test/docfx.Snapshot.Tests/docfx.Snapshot.Tests.csproj @@ -1,12 +1,13 @@ + Exe net8.0 - + - + diff --git a/test/docfx.Tests/JsonSchemaTest.cs b/test/docfx.Tests/JsonSchemaTest.cs index aeed970aa31..7ebbd78a245 100644 --- a/test/docfx.Tests/JsonSchemaTest.cs +++ b/test/docfx.Tests/JsonSchemaTest.cs @@ -7,7 +7,6 @@ using Docfx.Tests.Common; using FluentAssertions; using Json.Schema; -using Xunit.Abstractions; using YamlDotNet.Serialization; namespace Docfx.Tests; diff --git a/test/docfx.Tests/MetadataCommandTest.cs b/test/docfx.Tests/MetadataCommandTest.cs index e01761fb414..70987717c32 100644 --- a/test/docfx.Tests/MetadataCommandTest.cs +++ b/test/docfx.Tests/MetadataCommandTest.cs @@ -22,6 +22,10 @@ public MetadataCommandTest() { _outputFolder = GetRandomFolder(); _projectFolder = GetRandomFolder(); + + // Create empty `Directory.Build.props` file. + var propsFilePath = Path.Combine(_projectFolder, "Directory.Build.props"); + File.WriteAllText(propsFilePath, ""); } [Fact] diff --git a/test/docfx.Tests/SerializationTests/TestData/TestDataAttribute.cs b/test/docfx.Tests/SerializationTests/TestData/TestDataAttribute.cs index 1e53e2bc5ec..f2f7e21345f 100644 --- a/test/docfx.Tests/SerializationTests/TestData/TestDataAttribute.cs +++ b/test/docfx.Tests/SerializationTests/TestData/TestDataAttribute.cs @@ -3,12 +3,15 @@ using System.Reflection; using Xunit.Sdk; +using Xunit.v3; namespace docfx.Tests; public class TestDataAttribute : DataAttribute { - public override IEnumerable GetData(MethodInfo testMethod) + public override bool SupportsDiscoveryEnumeration() => true; + + public override ValueTask> GetData(MethodInfo testMethod, DisposalTracker disposalTracker) { var key = GetTestDataKey(); var paths = TestData.GetTestDataFilePaths(key); @@ -28,7 +31,9 @@ public override IEnumerable GetData(MethodInfo testMethod) throw new NotSupportedException($"{className} is not supported."); } - return new TheoryData(paths); + var results = paths.Select(x => new TheoryDataRow(x)).ToArray(); + + return ValueTask.FromResult>(results); } private static string GetTestDataKey() diff --git a/test/docfx.Tests/docfx.Tests.csproj b/test/docfx.Tests/docfx.Tests.csproj index 4dd4811307a..583dade9b41 100644 --- a/test/docfx.Tests/docfx.Tests.csproj +++ b/test/docfx.Tests/docfx.Tests.csproj @@ -1,11 +1,14 @@ - + + Exe + + - + diff --git a/test/xunit.runner.json b/test/xunit.runner.json new file mode 100644 index 00000000000..3fc436c2b3f --- /dev/null +++ b/test/xunit.runner.json @@ -0,0 +1,5 @@ +{ + "$schema": "https://xunit.net/schema/current/xunit.runner.schema.json", + "diagnosticMessages": true, + "internalDiagnosticMessages": true +}