From 594c89a2355b63f0fc4fe693c7590add5b5e8b50 Mon Sep 17 00:00:00 2001 From: phil-allen-msft Date: Tue, 5 Nov 2024 17:00:29 -0800 Subject: [PATCH] Revert "Some random clean up and improvements (#11095)" This reverts commit 76cd92a65ea7104cc600d03cc50db4ad9438b488, reversing changes made to a37ee126f87e6f5f0a9c0e51f085f8f097875315. --- .../DesignTimeNodeWriterTest.cs | 4 +- .../test/DefaultRazorProjectFileSystemTest.cs | 10 +- ...soft.AspNetCore.Razor.Language.Test.csproj | 1 + .../src/CSharp/FilePathComparer.cs | 4 +- .../src/CSharp/FilePathComparison.cs | 4 +- .../CodeGeneration/CodeWriterExtensions.cs | 4 +- .../DefaultLanguageServerFeatureOptions.cs | 5 +- .../RemoteRazorProjectFileSystem.cs | 3 +- .../Utilities/FilePathNormalizer.cs | 4 +- .../Utilities/RazorProjectInfoFactory.cs | 3 +- .../RazorDynamicFileInfoProvider.cs | 4 +- src/Razor/src/rzls/Program.cs | 6 +- ...or.ExternalAccess.LegacyEditor.Test.csproj | 1 + ...ExternalAccess.RoslynWorkspace.Test.csproj | 1 + ...extDocumentUriPresentationEndpointTests.cs | 8 +- .../FindNodeTests.cs | 4 +- ...spNetCore.Razor.LanguageServer.Test.csproj | 1 + .../IProjectSnapshotManagerExtensionsTest.cs | 2 +- .../RemoteRazorProjectFileSystemTest.cs | 4 +- .../Semantic/SemanticTokensTest.cs | 6 +- .../FilePathNormalizerTest.cs | 10 +- ...etCore.Razor.ProjectEngineHost.Test.csproj | 1 + .../RazorToolingIntegrationTestBase.cs | 6 +- .../PathUtilities.cs | 3 +- .../TestProjectData.cs | 4 +- ....CodeAnalysis.Razor.Workspaces.Test.csproj | 1 + .../ProjectSystem/ProjectKeyTests.cs | 2 +- .../UriExtensionsTest.cs | 14 +- ...nguageServer.ContainedLanguage.Test.csproj | 4 + .../UriExtensionsTest.cs | 6 +- .../RazorDocumentOptionsServiceTest.cs | 4 +- .../test/OSSkipConditionFactAttribute.cs | 52 +++++ .../ConditionalFactAttribute.cs | 192 ------------------ .../RazorIntegrationTestBase.cs | 6 +- ...NetCore.Razor.Utilities.Shared.Test.csproj | 1 - .../Utilities/PlatformInformation.cs | 19 -- 36 files changed, 131 insertions(+), 273 deletions(-) create mode 100644 src/Razor/test/OSSkipConditionFactAttribute.cs delete mode 100644 src/Shared/Microsoft.AspNetCore.Razor.Test.Common/ConditionalFactAttribute.cs delete mode 100644 src/Shared/Microsoft.AspNetCore.Razor.Utilities.Shared/Utilities/PlatformInformation.cs diff --git a/src/Compiler/Microsoft.AspNetCore.Razor.Language/test/CodeGeneration/DesignTimeNodeWriterTest.cs b/src/Compiler/Microsoft.AspNetCore.Razor.Language/test/CodeGeneration/DesignTimeNodeWriterTest.cs index b974231f2d..d34c08ea4b 100644 --- a/src/Compiler/Microsoft.AspNetCore.Razor.Language/test/CodeGeneration/DesignTimeNodeWriterTest.cs +++ b/src/Compiler/Microsoft.AspNetCore.Razor.Language/test/CodeGeneration/DesignTimeNodeWriterTest.cs @@ -493,7 +493,7 @@ Render Children ignoreLineEndingDifferences: true); } - [ConditionalTheory(Is.Windows)] + [OSSkipConditionTheory(new[] { "Linux", "OSX" })] [InlineData(@"test.cshtml", @"test.cshtml")] [InlineData(@"pages/test.cshtml", @"pages\test.cshtml")] [InlineData(@"pages\test.cshtml", @"pages\test.cshtml")] @@ -540,7 +540,7 @@ Render Children ignoreLineEndingDifferences: true); } - [ConditionalTheory(Is.Windows)] + [OSSkipConditionTheory(new[] { "Linux", "OSX" })] [InlineData(@"test.cshtml", @"test.cshtml")] [InlineData(@"pages/test.cshtml", @"pages\test.cshtml")] [InlineData(@"pages\test.cshtml", @"pages\test.cshtml")] diff --git a/src/Compiler/Microsoft.AspNetCore.Razor.Language/test/DefaultRazorProjectFileSystemTest.cs b/src/Compiler/Microsoft.AspNetCore.Razor.Language/test/DefaultRazorProjectFileSystemTest.cs index c4440c4878..9835901f4d 100644 --- a/src/Compiler/Microsoft.AspNetCore.Razor.Language/test/DefaultRazorProjectFileSystemTest.cs +++ b/src/Compiler/Microsoft.AspNetCore.Razor.Language/test/DefaultRazorProjectFileSystemTest.cs @@ -6,6 +6,7 @@ using System; using System.IO; using System.Linq; +using System.Runtime.InteropServices; using Xunit; namespace Microsoft.AspNetCore.Razor.Language; @@ -260,10 +261,15 @@ public class DefaultRazorProjectFileSystemTest Assert.Equal(Path.Combine("Views", "About", "About.cshtml"), item.RelativePhysicalPath); } - // "This test does not makes sense for case sensitive Operating Systems." - [ConditionalFact(Is.Windows)] + [Fact] public void GetItem_MismatchedCase_ReturnsFileFromDisk() { + if (!RuntimeInformation.IsOSPlatform(OSPlatform.Windows)) + { + // "This test does not makes sense for case sensitive Operating Systems." + return; + } + // Arrange var filePath = "/Views/About/About.cshtml"; var lowerCaseTestFolder = TestFolder.ToLowerInvariant(); diff --git a/src/Compiler/Microsoft.AspNetCore.Razor.Language/test/Microsoft.AspNetCore.Razor.Language.Test.csproj b/src/Compiler/Microsoft.AspNetCore.Razor.Language/test/Microsoft.AspNetCore.Razor.Language.Test.csproj index 811cc7994a..7927a8dd84 100644 --- a/src/Compiler/Microsoft.AspNetCore.Razor.Language/test/Microsoft.AspNetCore.Razor.Language.Test.csproj +++ b/src/Compiler/Microsoft.AspNetCore.Razor.Language/test/Microsoft.AspNetCore.Razor.Language.Test.csproj @@ -30,6 +30,7 @@ + diff --git a/src/Compiler/Microsoft.CodeAnalysis.Razor.Compiler/src/CSharp/FilePathComparer.cs b/src/Compiler/Microsoft.CodeAnalysis.Razor.Compiler/src/CSharp/FilePathComparer.cs index 2cefe67496..70237b458f 100644 --- a/src/Compiler/Microsoft.CodeAnalysis.Razor.Compiler/src/CSharp/FilePathComparer.cs +++ b/src/Compiler/Microsoft.CodeAnalysis.Razor.Compiler/src/CSharp/FilePathComparer.cs @@ -2,7 +2,7 @@ // The .NET Foundation licenses this file to you under the MIT license. using System; -using Microsoft.AspNetCore.Razor.Utilities; +using System.Runtime.InteropServices; namespace Microsoft.CodeAnalysis.Razor; @@ -14,7 +14,7 @@ internal static class FilePathComparer { get { - return _instance ??= PlatformInformation.IsLinux + return _instance ??= RuntimeInformation.IsOSPlatform(OSPlatform.Linux) ? StringComparer.Ordinal : StringComparer.OrdinalIgnoreCase; } diff --git a/src/Compiler/Microsoft.CodeAnalysis.Razor.Compiler/src/CSharp/FilePathComparison.cs b/src/Compiler/Microsoft.CodeAnalysis.Razor.Compiler/src/CSharp/FilePathComparison.cs index 34062b5f1c..a85b6fe2d6 100644 --- a/src/Compiler/Microsoft.CodeAnalysis.Razor.Compiler/src/CSharp/FilePathComparison.cs +++ b/src/Compiler/Microsoft.CodeAnalysis.Razor.Compiler/src/CSharp/FilePathComparison.cs @@ -2,7 +2,7 @@ // The .NET Foundation licenses this file to you under the MIT license. using System; -using Microsoft.AspNetCore.Razor.Utilities; +using System.Runtime.InteropServices; namespace Microsoft.CodeAnalysis.Razor; @@ -14,7 +14,7 @@ internal static class FilePathComparison { get { - return _instance ??= PlatformInformation.IsLinux + return _instance ??= RuntimeInformation.IsOSPlatform(OSPlatform.Linux) ? StringComparison.Ordinal : StringComparison.OrdinalIgnoreCase; } diff --git a/src/Compiler/Microsoft.CodeAnalysis.Razor.Compiler/src/Language/CodeGeneration/CodeWriterExtensions.cs b/src/Compiler/Microsoft.CodeAnalysis.Razor.Compiler/src/Language/CodeGeneration/CodeWriterExtensions.cs index 3e87ef8f93..9c2c36d699 100644 --- a/src/Compiler/Microsoft.CodeAnalysis.Razor.Compiler/src/Language/CodeGeneration/CodeWriterExtensions.cs +++ b/src/Compiler/Microsoft.CodeAnalysis.Razor.Compiler/src/Language/CodeGeneration/CodeWriterExtensions.cs @@ -8,8 +8,8 @@ using System.Collections.Generic; using System.Diagnostics; using System.Globalization; using System.Linq; +using System.Runtime.InteropServices; using Microsoft.AspNetCore.Razor.Language.Intermediate; -using Microsoft.AspNetCore.Razor.Utilities; namespace Microsoft.AspNetCore.Razor.Language.CodeGeneration; @@ -661,7 +661,7 @@ internal static class CodeWriterExtensions private static SourceSpan RemapFilePathIfNecessary(SourceSpan sourceSpan, CodeRenderingContext context) { - if (context.Options.RemapLinePragmaPathsOnWindows && PlatformInformation.IsWindows) + if (context.Options.RemapLinePragmaPathsOnWindows && RuntimeInformation.IsOSPlatform(OSPlatform.Windows)) { // ISSUE: https://github.com/dotnet/razor/issues/9108 // The razor tooling normalizes paths to be forward slash based, regardless of OS. diff --git a/src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/DefaultLanguageServerFeatureOptions.cs b/src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/DefaultLanguageServerFeatureOptions.cs index 8911f1c742..cc165ade2b 100644 --- a/src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/DefaultLanguageServerFeatureOptions.cs +++ b/src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/DefaultLanguageServerFeatureOptions.cs @@ -1,7 +1,7 @@ // Copyright (c) .NET Foundation. All rights reserved. // Licensed under the MIT license. See License.txt in the project root for license information. -using Microsoft.AspNetCore.Razor.Utilities; +using System.Runtime.InteropServices; using Microsoft.CodeAnalysis.Razor.Workspaces; namespace Microsoft.AspNetCore.Razor.LanguageServer; @@ -25,7 +25,8 @@ internal class DefaultLanguageServerFeatureOptions : LanguageServerFeatureOption // Code action and rename paths in Windows VS Code need to be prefixed with '/': // https://github.com/dotnet/razor/issues/8131 - public override bool ReturnCodeActionAndRenamePathsWithPrefixedSlash => PlatformInformation.IsWindows; + public override bool ReturnCodeActionAndRenamePathsWithPrefixedSlash + => RuntimeInformation.IsOSPlatform(OSPlatform.Windows); public override bool ShowAllCSharpCodeActions => false; diff --git a/src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/RemoteRazorProjectFileSystem.cs b/src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/RemoteRazorProjectFileSystem.cs index a195a62898..15211a880b 100644 --- a/src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/RemoteRazorProjectFileSystem.cs +++ b/src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/RemoteRazorProjectFileSystem.cs @@ -4,6 +4,7 @@ using System; using System.Collections.Generic; using System.IO; +using System.Runtime.InteropServices; using Microsoft.AspNetCore.Razor.Language; using Microsoft.AspNetCore.Razor.Utilities; using Microsoft.CodeAnalysis.Razor; @@ -81,7 +82,7 @@ internal class RemoteRazorProjectFileSystem : RazorProjectFileSystem static bool IsPathRootedForPlatform(string path) { - if (PlatformInformation.IsWindows && path == "/") + if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows) && path == "/") { // We have to special case windows and "/" because for some reason Path.IsPathRooted returns true on windows for a single "/" path. return false; diff --git a/src/Razor/src/Microsoft.AspNetCore.Razor.ProjectEngineHost/Utilities/FilePathNormalizer.cs b/src/Razor/src/Microsoft.AspNetCore.Razor.ProjectEngineHost/Utilities/FilePathNormalizer.cs index ec419431db..4d3a5e3db8 100644 --- a/src/Razor/src/Microsoft.AspNetCore.Razor.ProjectEngineHost/Utilities/FilePathNormalizer.cs +++ b/src/Razor/src/Microsoft.AspNetCore.Razor.ProjectEngineHost/Utilities/FilePathNormalizer.cs @@ -12,7 +12,7 @@ namespace Microsoft.AspNetCore.Razor.Utilities; internal static class FilePathNormalizer { - private static readonly Func s_charConverter = PlatformInformation.IsLinux + private static readonly Func s_charConverter = RuntimeInformation.IsOSPlatform(OSPlatform.Linux) ? c => c : char.ToLowerInvariant; @@ -223,7 +223,7 @@ internal static class FilePathNormalizer // Replace slashes in our normalized span. NormalizeAndDedupeSlashes(destination, ref charsWritten); - if (PlatformInformation.IsWindows && + if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows) && charsWritten > 1 && destination is ['/', ..] and not ['/', '/', ..]) { diff --git a/src/Razor/src/Microsoft.AspNetCore.Razor.ProjectEngineHost/Utilities/RazorProjectInfoFactory.cs b/src/Razor/src/Microsoft.AspNetCore.Razor.ProjectEngineHost/Utilities/RazorProjectInfoFactory.cs index 7eeb86d7ac..bb518d231a 100644 --- a/src/Razor/src/Microsoft.AspNetCore.Razor.ProjectEngineHost/Utilities/RazorProjectInfoFactory.cs +++ b/src/Razor/src/Microsoft.AspNetCore.Razor.ProjectEngineHost/Utilities/RazorProjectInfoFactory.cs @@ -5,6 +5,7 @@ using System; using System.Collections.Immutable; using System.Diagnostics.CodeAnalysis; using System.IO; +using System.Runtime.InteropServices; using System.Threading; using System.Threading.Tasks; using Microsoft.AspNetCore.Razor.Language; @@ -27,7 +28,7 @@ internal static class RazorProjectInfoFactory static RazorProjectInfoFactory() { - s_stringComparison = PlatformInformation.IsLinux + s_stringComparison = RuntimeInformation.IsOSPlatform(OSPlatform.Linux) ? StringComparison.Ordinal : StringComparison.OrdinalIgnoreCase; } diff --git a/src/Razor/src/Microsoft.VisualStudio.LanguageServices.Razor/DynamicFiles/RazorDynamicFileInfoProvider.cs b/src/Razor/src/Microsoft.VisualStudio.LanguageServices.Razor/DynamicFiles/RazorDynamicFileInfoProvider.cs index 1e004d5bc6..96d41243c6 100644 --- a/src/Razor/src/Microsoft.VisualStudio.LanguageServices.Razor/DynamicFiles/RazorDynamicFileInfoProvider.cs +++ b/src/Razor/src/Microsoft.VisualStudio.LanguageServices.Razor/DynamicFiles/RazorDynamicFileInfoProvider.cs @@ -6,13 +6,13 @@ using System.Collections.Concurrent; using System.Collections.Generic; using System.ComponentModel.Composition; using System.Diagnostics; +using System.Runtime.InteropServices; using System.Text; using System.Threading; using System.Threading.Tasks; using Microsoft.AspNetCore.Razor; using Microsoft.AspNetCore.Razor.ProjectSystem; using Microsoft.AspNetCore.Razor.Threading; -using Microsoft.AspNetCore.Razor.Utilities; using Microsoft.CodeAnalysis; using Microsoft.CodeAnalysis.ExternalAccess.Razor; using Microsoft.CodeAnalysis.Razor; @@ -305,7 +305,7 @@ internal class RazorDynamicFileInfoProvider : IRazorDynamicFileInfoProviderInter // however, it's the only way to get the correct file path for a document to map to a corresponding project // system. - if (PlatformInformation.IsWindows) + if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows)) { // VSWin return uri.GetAbsoluteOrUNCPath().Replace('/', '\\'); diff --git a/src/Razor/src/rzls/Program.cs b/src/Razor/src/rzls/Program.cs index 5c83140c6c..340d149130 100644 --- a/src/Razor/src/rzls/Program.cs +++ b/src/Razor/src/rzls/Program.cs @@ -4,12 +4,12 @@ using System; using System.Diagnostics; using System.Linq; +using System.Runtime.InteropServices; using System.Threading; using System.Threading.Tasks; using Microsoft.AspNetCore.Razor.LanguageServer.Extensions; using Microsoft.AspNetCore.Razor.LanguageServer.Hosting; using Microsoft.AspNetCore.Razor.Telemetry; -using Microsoft.AspNetCore.Razor.Utilities; using Microsoft.CodeAnalysis.Razor.Logging; using Microsoft.CodeAnalysis.Razor.ProjectSystem; using Microsoft.Extensions.DependencyInjection; @@ -30,10 +30,10 @@ public class Program if (args[i].Contains("debug", StringComparison.OrdinalIgnoreCase)) { await Console.Error.WriteLineAsync($"Server started with process ID {Environment.ProcessId}").ConfigureAwait(true); - if (PlatformInformation.IsWindows) + if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows)) { // Debugger.Launch() only works on Windows. - Debugger.Launch(); + _ = Debugger.Launch(); } else { diff --git a/src/Razor/test/Microsoft.AspNetCore.Razor.ExternalAccess.LegacyEditor.Test/Microsoft.AspNetCore.Razor.ExternalAccess.LegacyEditor.Test.csproj b/src/Razor/test/Microsoft.AspNetCore.Razor.ExternalAccess.LegacyEditor.Test/Microsoft.AspNetCore.Razor.ExternalAccess.LegacyEditor.Test.csproj index d7e7c685f7..3590788487 100644 --- a/src/Razor/test/Microsoft.AspNetCore.Razor.ExternalAccess.LegacyEditor.Test/Microsoft.AspNetCore.Razor.ExternalAccess.LegacyEditor.Test.csproj +++ b/src/Razor/test/Microsoft.AspNetCore.Razor.ExternalAccess.LegacyEditor.Test/Microsoft.AspNetCore.Razor.ExternalAccess.LegacyEditor.Test.csproj @@ -6,6 +6,7 @@ + diff --git a/src/Razor/test/Microsoft.AspNetCore.Razor.ExternalAccess.RoslynWorkspace.Test/Microsoft.AspNetCore.Razor.ExternalAccess.RoslynWorkspace.Test.csproj b/src/Razor/test/Microsoft.AspNetCore.Razor.ExternalAccess.RoslynWorkspace.Test/Microsoft.AspNetCore.Razor.ExternalAccess.RoslynWorkspace.Test.csproj index 14814afcfa..38b6311f6e 100644 --- a/src/Razor/test/Microsoft.AspNetCore.Razor.ExternalAccess.RoslynWorkspace.Test/Microsoft.AspNetCore.Razor.ExternalAccess.RoslynWorkspace.Test.csproj +++ b/src/Razor/test/Microsoft.AspNetCore.Razor.ExternalAccess.RoslynWorkspace.Test/Microsoft.AspNetCore.Razor.ExternalAccess.RoslynWorkspace.Test.csproj @@ -6,6 +6,7 @@ + diff --git a/src/Razor/test/Microsoft.AspNetCore.Razor.LanguageServer.Test/DocumentPresentation/TextDocumentUriPresentationEndpointTests.cs b/src/Razor/test/Microsoft.AspNetCore.Razor.LanguageServer.Test/DocumentPresentation/TextDocumentUriPresentationEndpointTests.cs index ffdff50874..0e3e8509ef 100644 --- a/src/Razor/test/Microsoft.AspNetCore.Razor.LanguageServer.Test/DocumentPresentation/TextDocumentUriPresentationEndpointTests.cs +++ b/src/Razor/test/Microsoft.AspNetCore.Razor.LanguageServer.Test/DocumentPresentation/TextDocumentUriPresentationEndpointTests.cs @@ -23,7 +23,7 @@ namespace Microsoft.AspNetCore.Razor.LanguageServer.DocumentPresentation; public class TextDocumentUriPresentationEndpointTests(ITestOutputHelper testOutput) : LanguageServerTestBase(testOutput) { - [ConditionalFact(Is.Windows)] + [OSSkipConditionFact(["OSX", "Linux"])] public async Task Handle_SimpleComponent_ReturnsResult() { // Arrange @@ -83,7 +83,7 @@ public class TextDocumentUriPresentationEndpointTests(ITestOutputHelper testOutp Assert.Equal("", documentEdits[0].Edits[0].NewText); } - [ConditionalFact(Is.Windows)] + [OSSkipConditionFact(["OSX", "Linux"])] public async Task Handle_SimpleComponentWithChildFile_ReturnsResult() { // Arrange @@ -148,7 +148,7 @@ public class TextDocumentUriPresentationEndpointTests(ITestOutputHelper testOutp Assert.Equal("", documentEdits[0].Edits[0].NewText); } - [ConditionalFact(Is.Windows)] + [OSSkipConditionFact(["OSX", "Linux"])] public async Task Handle_ComponentWithRequiredAttribute_ReturnsResult() { // Arrange @@ -308,7 +308,7 @@ public class TextDocumentUriPresentationEndpointTests(ITestOutputHelper testOutp Assert.Null(result); } - [ConditionalFact(Is.Windows)] + [OSSkipConditionFact(["OSX", "Linux"])] public async Task Handle_ComponentWithNestedFiles_ReturnsResult() { // Arrange diff --git a/src/Razor/test/Microsoft.AspNetCore.Razor.LanguageServer.Test/FindNodeTests.cs b/src/Razor/test/Microsoft.AspNetCore.Razor.LanguageServer.Test/FindNodeTests.cs index b9038c5dcb..5adc670335 100644 --- a/src/Razor/test/Microsoft.AspNetCore.Razor.LanguageServer.Test/FindNodeTests.cs +++ b/src/Razor/test/Microsoft.AspNetCore.Razor.LanguageServer.Test/FindNodeTests.cs @@ -1,10 +1,10 @@ // Copyright (c) .NET Foundation. All rights reserved. // Licensed under the MIT license. See License.txt in the project root for license information. +using System.Runtime.InteropServices; using Microsoft.AspNetCore.Razor.Language; using Microsoft.AspNetCore.Razor.Language.Syntax; using Microsoft.AspNetCore.Razor.Test.Common; -using Microsoft.AspNetCore.Razor.Utilities; using Microsoft.CodeAnalysis.Text; using Xunit; using Xunit.Abstractions; @@ -63,7 +63,7 @@ public class FindNodeTests(ITestOutputHelper testOutput) : ToolingTestBase(testO } """; - private static readonly string s_fetchDataContents = PlatformInformation.IsWindows + private static readonly string s_fetchDataContents = RuntimeInformation.IsOSPlatform(OSPlatform.Windows) ? FetchDataContents : FetchDataContents.Replace("\n", "\r\n"); diff --git a/src/Razor/test/Microsoft.AspNetCore.Razor.LanguageServer.Test/Microsoft.AspNetCore.Razor.LanguageServer.Test.csproj b/src/Razor/test/Microsoft.AspNetCore.Razor.LanguageServer.Test/Microsoft.AspNetCore.Razor.LanguageServer.Test.csproj index 0a46c9e035..685173189f 100644 --- a/src/Razor/test/Microsoft.AspNetCore.Razor.LanguageServer.Test/Microsoft.AspNetCore.Razor.LanguageServer.Test.csproj +++ b/src/Razor/test/Microsoft.AspNetCore.Razor.LanguageServer.Test/Microsoft.AspNetCore.Razor.LanguageServer.Test.csproj @@ -10,6 +10,7 @@ + diff --git a/src/Razor/test/Microsoft.AspNetCore.Razor.LanguageServer.Test/ProjectSystem/IProjectSnapshotManagerExtensionsTest.cs b/src/Razor/test/Microsoft.AspNetCore.Razor.LanguageServer.Test/ProjectSystem/IProjectSnapshotManagerExtensionsTest.cs index e8335d1056..c124083560 100644 --- a/src/Razor/test/Microsoft.AspNetCore.Razor.LanguageServer.Test/ProjectSystem/IProjectSnapshotManagerExtensionsTest.cs +++ b/src/Razor/test/Microsoft.AspNetCore.Razor.LanguageServer.Test/ProjectSystem/IProjectSnapshotManagerExtensionsTest.cs @@ -177,7 +177,7 @@ public class IProjectSnapshotManagerExtensionsTest(ITestOutputHelper testOutput) AssertSnapshotsEqual(miscProject, project); } - [ConditionalFact(Is.Windows)] + [OSSkipConditionFact(["OSX", "Linux"])] public async Task TryResolveAllProjects_OwnerProjectDifferentCasing_ReturnsTrue() { // Arrange diff --git a/src/Razor/test/Microsoft.AspNetCore.Razor.LanguageServer.Test/RemoteRazorProjectFileSystemTest.cs b/src/Razor/test/Microsoft.AspNetCore.Razor.LanguageServer.Test/RemoteRazorProjectFileSystemTest.cs index e4a3f8751a..919c0abb20 100644 --- a/src/Razor/test/Microsoft.AspNetCore.Razor.LanguageServer.Test/RemoteRazorProjectFileSystemTest.cs +++ b/src/Razor/test/Microsoft.AspNetCore.Razor.LanguageServer.Test/RemoteRazorProjectFileSystemTest.cs @@ -3,8 +3,8 @@ #nullable disable +using System.Runtime.InteropServices; using Microsoft.AspNetCore.Razor.Test.Common; -using Microsoft.AspNetCore.Razor.Utilities; using Xunit; using Xunit.Abstractions; @@ -54,7 +54,7 @@ public class RemoteRazorProjectFileSystemTest : ToolingTestBase RemoteRazorProjectFileSystem fileSystem; string documentFilePath; - if (PlatformInformation.IsWindows) + if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows)) { fileSystem = new RemoteRazorProjectFileSystem(@"C:\path\to"); documentFilePath = @"C:\otherpath\to\file.cshtml"; diff --git a/src/Razor/test/Microsoft.AspNetCore.Razor.LanguageServer.Test/Semantic/SemanticTokensTest.cs b/src/Razor/test/Microsoft.AspNetCore.Razor.LanguageServer.Test/Semantic/SemanticTokensTest.cs index 20d7a81739..6ef88b7406 100644 --- a/src/Razor/test/Microsoft.AspNetCore.Razor.LanguageServer.Test/Semantic/SemanticTokensTest.cs +++ b/src/Razor/test/Microsoft.AspNetCore.Razor.LanguageServer.Test/Semantic/SemanticTokensTest.cs @@ -8,6 +8,7 @@ using System.IO; using System.Linq; using System.Reflection; using System.Runtime.CompilerServices; +using System.Runtime.InteropServices; using System.Text; using System.Text.RegularExpressions; using System.Threading; @@ -18,7 +19,6 @@ using Microsoft.AspNetCore.Razor.LanguageServer.Hosting; using Microsoft.AspNetCore.Razor.PooledObjects; using Microsoft.AspNetCore.Razor.Test.Common; using Microsoft.AspNetCore.Razor.Test.Common.LanguageServer; -using Microsoft.AspNetCore.Razor.Utilities; using Microsoft.CodeAnalysis; using Microsoft.CodeAnalysis.Razor.ProjectSystem; using Microsoft.CodeAnalysis.Razor.Protocol; @@ -903,7 +903,7 @@ public partial class SemanticTokensTest(ITestOutputHelper testOutput) : TagHelpe else { // Note that the expected lengths are different on Windows vs. Unix. - var expectedCsharpRangeLength = PlatformInformation.IsWindows ? 945 : 911; + var expectedCsharpRangeLength = RuntimeInformation.IsOSPlatform(OSPlatform.Windows) ? 945 : 911; Assert.True(codeDocument.TryGetMinimalCSharpRange(razorRange, out var csharpRange)); var textSpan = csharpSourceText.GetTextSpan(csharpRange); Assert.Equal(expectedCsharpRangeLength, textSpan.Length); @@ -1120,7 +1120,7 @@ public partial class SemanticTokensTest(ITestOutputHelper testOutput) : TagHelpe var baselineContents = semanticFile.ReadAllText(); - if (!PlatformInformation.IsWindows) + if (!RuntimeInformation.IsOSPlatform(OSPlatform.Windows)) { baselineContents = s_matchNewLines.Replace(baselineContents, "\n"); } diff --git a/src/Razor/test/Microsoft.AspNetCore.Razor.ProjectEngineHost.Test/FilePathNormalizerTest.cs b/src/Razor/test/Microsoft.AspNetCore.Razor.ProjectEngineHost.Test/FilePathNormalizerTest.cs index dc7f80d327..4f3215e65c 100644 --- a/src/Razor/test/Microsoft.AspNetCore.Razor.ProjectEngineHost.Test/FilePathNormalizerTest.cs +++ b/src/Razor/test/Microsoft.AspNetCore.Razor.ProjectEngineHost.Test/FilePathNormalizerTest.cs @@ -11,7 +11,7 @@ namespace Microsoft.AspNetCore.Razor.ProjectEngineHost.Test; public class FilePathNormalizerTest(ITestOutputHelper testOutput) : ToolingTestBase(testOutput) { - [ConditionalFact(Is.Windows)] + [OSSkipConditionFact(["OSX", "Linux"])] public void Normalize_Windows_StripsPrecedingSlash() { // Arrange @@ -24,7 +24,7 @@ public class FilePathNormalizerTest(ITestOutputHelper testOutput) : ToolingTestB Assert.Equal("c:/path/to/something", path); } - [ConditionalFact(Is.Windows)] + [OSSkipConditionFact(["OSX", "Linux"])] public void Normalize_Windows_StripsPrecedingSlash_ShortPath() { // Arrange @@ -141,7 +141,7 @@ public class FilePathNormalizerTest(ITestOutputHelper testOutput) : ToolingTestB Assert.Equal("C:/path/to/directory/", normalized); } - [ConditionalFact(Is.Windows)] + [OSSkipConditionFact(["OSX", "Linux"])] public void NormalizeDirectory_Windows_HandlesSingleSlashDirectory() { // Arrange @@ -261,7 +261,7 @@ public class FilePathNormalizerTest(ITestOutputHelper testOutput) : ToolingTestB Assert.Equal("/", normalized); } - [ConditionalFact(Is.Not.Windows)] + [OSSkipConditionFact(["Windows"])] public void Normalize_NonWindows_AddsLeadingForwardSlash() { // Arrange @@ -314,7 +314,7 @@ public class FilePathNormalizerTest(ITestOutputHelper testOutput) : ToolingTestB Assert.Equal("C:/path/to/document.cshtml", normalized); } - [ConditionalTheory(Is.Windows)] + [OSSkipConditionTheory(["OSX", "Linux"])] [InlineData(@"C:\path\to\document.cshtml")] [InlineData(@"c:\path\to\document.cshtml")] [InlineData("C:/path/to/document.cshtml")] diff --git a/src/Razor/test/Microsoft.AspNetCore.Razor.ProjectEngineHost.Test/Microsoft.AspNetCore.Razor.ProjectEngineHost.Test.csproj b/src/Razor/test/Microsoft.AspNetCore.Razor.ProjectEngineHost.Test/Microsoft.AspNetCore.Razor.ProjectEngineHost.Test.csproj index 9ceec560da..19e59e9508 100644 --- a/src/Razor/test/Microsoft.AspNetCore.Razor.ProjectEngineHost.Test/Microsoft.AspNetCore.Razor.ProjectEngineHost.Test.csproj +++ b/src/Razor/test/Microsoft.AspNetCore.Razor.ProjectEngineHost.Test/Microsoft.AspNetCore.Razor.ProjectEngineHost.Test.csproj @@ -6,6 +6,7 @@ + diff --git a/src/Razor/test/Microsoft.AspNetCore.Razor.Test.Common.Tooling/Language/IntegrationTests/RazorToolingIntegrationTestBase.cs b/src/Razor/test/Microsoft.AspNetCore.Razor.Test.Common.Tooling/Language/IntegrationTests/RazorToolingIntegrationTestBase.cs index f59a6dece1..a4ff782e2b 100644 --- a/src/Razor/test/Microsoft.AspNetCore.Razor.Test.Common.Tooling/Language/IntegrationTests/RazorToolingIntegrationTestBase.cs +++ b/src/Razor/test/Microsoft.AspNetCore.Razor.Test.Common.Tooling/Language/IntegrationTests/RazorToolingIntegrationTestBase.cs @@ -8,9 +8,9 @@ using System.Collections.Generic; using System.IO; using System.Linq; using System.Reflection; +using System.Runtime.InteropServices; using Microsoft.AspNetCore.Razor.PooledObjects; using Microsoft.AspNetCore.Razor.Test.Common; -using Microsoft.AspNetCore.Razor.Utilities; using Microsoft.CodeAnalysis; using Microsoft.CodeAnalysis.CSharp; using Microsoft.CodeAnalysis.Razor; @@ -54,7 +54,7 @@ public class RazorToolingIntegrationTestBase : ToolingTestBase Configuration = RazorConfiguration.Default; FileSystem = new VirtualRazorProjectFileSystem(); PathSeparator = Path.DirectorySeparatorChar.ToString(); - WorkingDirectory = PlatformInformation.IsWindows ? ArbitraryWindowsPath : ArbitraryMacLinuxPath; + WorkingDirectory = RuntimeInformation.IsOSPlatform(OSPlatform.Windows) ? ArbitraryWindowsPath : ArbitraryMacLinuxPath; DefaultRootNamespace = "Test"; // Matches the default working directory DefaultFileName = "TestComponent.cshtml"; @@ -316,7 +316,7 @@ public class RazorToolingIntegrationTestBase : ToolingTestBase protected static void AssertSourceEquals(string expected, CompileToCSharpResult generated) { // Normalize the paths inside the expected result to match the OS paths - if (!PlatformInformation.IsWindows) + if (!RuntimeInformation.IsOSPlatform(OSPlatform.Windows)) { var windowsPath = Path.Combine(ArbitraryWindowsPath, generated.CodeDocument.Source.RelativePath).Replace('/', '\\'); expected = expected.Replace(windowsPath, generated.CodeDocument.Source.FilePath); diff --git a/src/Razor/test/Microsoft.AspNetCore.Razor.Test.Common.Tooling/PathUtilities.cs b/src/Razor/test/Microsoft.AspNetCore.Razor.Test.Common.Tooling/PathUtilities.cs index a7c074ee2a..d98a143297 100644 --- a/src/Razor/test/Microsoft.AspNetCore.Razor.Test.Common.Tooling/PathUtilities.cs +++ b/src/Razor/test/Microsoft.AspNetCore.Razor.Test.Common.Tooling/PathUtilities.cs @@ -3,6 +3,7 @@ using System; using System.IO; +using System.Runtime.InteropServices; using Microsoft.AspNetCore.Razor.Utilities; using Xunit; @@ -16,7 +17,7 @@ public static class PathUtilities if (!Path.IsPathRooted(result)) { - result = PlatformInformation.IsWindows + result = RuntimeInformation.IsOSPlatform(OSPlatform.Windows) ? @"C:\" + result : "/" + result; } diff --git a/src/Razor/test/Microsoft.AspNetCore.Razor.Test.Common.Tooling/TestProjectData.cs b/src/Razor/test/Microsoft.AspNetCore.Razor.Test.Common.Tooling/TestProjectData.cs index 815e9588ee..32291f15f8 100644 --- a/src/Razor/test/Microsoft.AspNetCore.Razor.Test.Common.Tooling/TestProjectData.cs +++ b/src/Razor/test/Microsoft.AspNetCore.Razor.Test.Common.Tooling/TestProjectData.cs @@ -2,8 +2,8 @@ // Licensed under the MIT license. See License.txt in the project root for license information. using System.IO; +using System.Runtime.InteropServices; using Microsoft.AspNetCore.Razor.Language; -using Microsoft.AspNetCore.Razor.Utilities; using Microsoft.CodeAnalysis.Razor.ProjectSystem; namespace Microsoft.AspNetCore.Razor.Test.Common; @@ -18,7 +18,7 @@ internal static class TestProjectData { static TestProjectData() { - var baseDirectory = PlatformInformation.IsWindows ? @"c:\users\example\src" : "/home/example"; + var baseDirectory = RuntimeInformation.IsOSPlatform(OSPlatform.Windows) ? "c:\\users\\example\\src" : "/home/example"; SomeProjectPath = Path.Combine(baseDirectory, "SomeProject"); var someProjectObjPath = Path.Combine(SomeProjectPath, "obj"); diff --git a/src/Razor/test/Microsoft.CodeAnalysis.Razor.Workspaces.Test/Microsoft.CodeAnalysis.Razor.Workspaces.Test.csproj b/src/Razor/test/Microsoft.CodeAnalysis.Razor.Workspaces.Test/Microsoft.CodeAnalysis.Razor.Workspaces.Test.csproj index 36c2f7e6ac..232456c372 100644 --- a/src/Razor/test/Microsoft.CodeAnalysis.Razor.Workspaces.Test/Microsoft.CodeAnalysis.Razor.Workspaces.Test.csproj +++ b/src/Razor/test/Microsoft.CodeAnalysis.Razor.Workspaces.Test/Microsoft.CodeAnalysis.Razor.Workspaces.Test.csproj @@ -7,6 +7,7 @@ + diff --git a/src/Razor/test/Microsoft.CodeAnalysis.Razor.Workspaces.Test/ProjectSystem/ProjectKeyTests.cs b/src/Razor/test/Microsoft.CodeAnalysis.Razor.Workspaces.Test/ProjectSystem/ProjectKeyTests.cs index f62e0175a1..ce5c210063 100644 --- a/src/Razor/test/Microsoft.CodeAnalysis.Razor.Workspaces.Test/ProjectSystem/ProjectKeyTests.cs +++ b/src/Razor/test/Microsoft.CodeAnalysis.Razor.Workspaces.Test/ProjectSystem/ProjectKeyTests.cs @@ -40,7 +40,7 @@ public class ProjectKeyTests : WorkspaceTestBase Assert.False(!key1.Equals((object)key2)); } - [ConditionalTheory(Is.Windows)] + [OSSkipConditionTheory(new[] { "OSX", "Linux" })] [InlineData(@"/c:/path/to/dir/", @"c:\path\to\dir")] [InlineData(@"/c:\path/to\dir/", @"c:\path\to\dir")] [InlineData(@"\path\to\dir\", @"path\to\dir")] diff --git a/src/Razor/test/Microsoft.CodeAnalysis.Razor.Workspaces.Test/UriExtensionsTest.cs b/src/Razor/test/Microsoft.CodeAnalysis.Razor.Workspaces.Test/UriExtensionsTest.cs index 6bad640a6c..4c9cd9cc0b 100644 --- a/src/Razor/test/Microsoft.CodeAnalysis.Razor.Workspaces.Test/UriExtensionsTest.cs +++ b/src/Razor/test/Microsoft.CodeAnalysis.Razor.Workspaces.Test/UriExtensionsTest.cs @@ -16,7 +16,7 @@ public class UriExtensionsTest : ToolingTestBase { } - [ConditionalFact(Is.Windows)] + [OSSkipConditionFact(new[] { "OSX", "Linux" })] public void GetAbsoluteOrUNCPath_AbsolutePath_ReturnsAbsolutePath() { // Arrange @@ -29,7 +29,7 @@ public class UriExtensionsTest : ToolingTestBase Assert.Equal(uri.AbsolutePath, path); } - [ConditionalFact(Is.Windows)] + [OSSkipConditionFact(new[] { "OSX", "Linux" })] public void GetAbsoluteOrUNCPath_AbsolutePath_HandlesPlusPaths() { // Arrange @@ -42,7 +42,7 @@ public class UriExtensionsTest : ToolingTestBase Assert.Equal(uri.AbsolutePath, path); } - [ConditionalFact(Is.Windows)] + [OSSkipConditionFact(new[] { "OSX", "Linux" })] public void GetAbsoluteOrUNCPath_AbsolutePath_HandlesSpacePaths() { // Arrange @@ -55,8 +55,7 @@ public class UriExtensionsTest : ToolingTestBase Assert.Equal("c:/Some/path/to/file path.cshtml", path); } - [ConditionalTheory(Is.Windows)] - [WorkItem("https://github.com/dotnet/razor/issues/9365")] + [OSSkipConditionTheory(new[] { "OSX", "Linux" }), WorkItem("https://github.com/dotnet/razor/issues/9365")] [InlineData(@"git:/c%3A/path/to/dir/Index.cshtml", @"c:/_git_/path/to/dir/Index.cshtml")] [InlineData(@"git:/c:/path%2Fto/dir/Index.cshtml?%7B%22p", @"c:/_git_/path/to/dir/Index.cshtml")] [InlineData(@"git:/c:/path/to/dir/Index.cshtml", @"c:/_git_/path/to/dir/Index.cshtml")] @@ -72,7 +71,7 @@ public class UriExtensionsTest : ToolingTestBase Assert.Equal(expected, path); } - [ConditionalTheory(Is.Windows)] + [OSSkipConditionTheory(new[] { "OSX", "Linux" })] [InlineData(@"file:///c:/path/to/dir/Index.cshtml", @"c:/path/to/dir/Index.cshtml")] [InlineData(@"file:///c:\path/to\dir/Index.cshtml", @"c:/path/to/dir/Index.cshtml")] [InlineData(@"file:///C:\path\to\dir\Index.cshtml", @"C:/path/to/dir/Index.cshtml")] @@ -130,8 +129,7 @@ public class UriExtensionsTest : ToolingTestBase Assert.Equal(@"\\some\path\to\file path.cshtml", path); } - [ConditionalTheory(Is.Not.Windows)] - [WorkItem("https://github.com/dotnet/razor/issues/9365")] + [OSSkipConditionTheory(new[] { "Windows" }), WorkItem("https://github.com/dotnet/razor/issues/9365")] [InlineData("git:///path/to/dir/Index.cshtml", "/_git_/path/to/dir/Index.cshtml")] [InlineData("git:///path%2Fto/dir/Index.cshtml", "/_git_/path/to/dir/Index.cshtml")] [InlineData("file:///path/to/dir/Index.cshtml", @"/path/to/dir/Index.cshtml")] diff --git a/src/Razor/test/Microsoft.VisualStudio.LanguageServer.ContainedLanguage.Test/Microsoft.VisualStudio.LanguageServer.ContainedLanguage.Test.csproj b/src/Razor/test/Microsoft.VisualStudio.LanguageServer.ContainedLanguage.Test/Microsoft.VisualStudio.LanguageServer.ContainedLanguage.Test.csproj index 3c89a6a9ed..5f66568e76 100644 --- a/src/Razor/test/Microsoft.VisualStudio.LanguageServer.ContainedLanguage.Test/Microsoft.VisualStudio.LanguageServer.ContainedLanguage.Test.csproj +++ b/src/Razor/test/Microsoft.VisualStudio.LanguageServer.ContainedLanguage.Test/Microsoft.VisualStudio.LanguageServer.ContainedLanguage.Test.csproj @@ -8,6 +8,10 @@ + + + + diff --git a/src/Razor/test/Microsoft.VisualStudio.LanguageServer.ContainedLanguage.Test/UriExtensionsTest.cs b/src/Razor/test/Microsoft.VisualStudio.LanguageServer.ContainedLanguage.Test/UriExtensionsTest.cs index b27574a8d0..24987107c3 100644 --- a/src/Razor/test/Microsoft.VisualStudio.LanguageServer.ContainedLanguage.Test/UriExtensionsTest.cs +++ b/src/Razor/test/Microsoft.VisualStudio.LanguageServer.ContainedLanguage.Test/UriExtensionsTest.cs @@ -17,7 +17,7 @@ public class UriExtensionsTest : ToolingTestBase { } - [ConditionalFact(Is.Windows)] + [OSSkipConditionFact(new[] { "OSX", "Linux" })] public void GetAbsoluteOrUNCPath_AbsolutePath_ReturnsAbsolutePath() { // Arrange @@ -30,7 +30,7 @@ public class UriExtensionsTest : ToolingTestBase Assert.Equal(uri.AbsolutePath, path); } - [ConditionalFact(Is.Windows)] + [OSSkipConditionFact(new[] { "OSX", "Linux" })] public void GetAbsoluteOrUNCPath_AbsolutePath_HandlesPlusPaths() { // Arrange @@ -43,7 +43,7 @@ public class UriExtensionsTest : ToolingTestBase Assert.Equal(uri.AbsolutePath, path); } - [ConditionalFact(Is.Windows)] + [OSSkipConditionFact(new[] { "OSX", "Linux" })] public void GetAbsoluteOrUNCPath_AbsolutePath_HandlesSpacePaths() { // Arrange diff --git a/src/Razor/test/Microsoft.VisualStudio.LanguageServices.Razor.Test/LanguageClient/RazorDocumentOptionsServiceTest.cs b/src/Razor/test/Microsoft.VisualStudio.LanguageServices.Razor.Test/LanguageClient/RazorDocumentOptionsServiceTest.cs index 72570a9016..9e6c078dd9 100644 --- a/src/Razor/test/Microsoft.VisualStudio.LanguageServices.Razor.Test/LanguageClient/RazorDocumentOptionsServiceTest.cs +++ b/src/Razor/test/Microsoft.VisualStudio.LanguageServices.Razor.Test/LanguageClient/RazorDocumentOptionsServiceTest.cs @@ -3,12 +3,12 @@ using System.IO; using System.Linq; +using System.Runtime.InteropServices; using System.Threading.Tasks; using Microsoft.AspNetCore.Razor.Language; using Microsoft.AspNetCore.Razor.ProjectSystem; using Microsoft.AspNetCore.Razor.Test.Common; using Microsoft.AspNetCore.Razor.Test.Common.Workspaces; -using Microsoft.AspNetCore.Razor.Utilities; using Microsoft.CodeAnalysis; using Microsoft.CodeAnalysis.Formatting; using Microsoft.CodeAnalysis.Options; @@ -90,7 +90,7 @@ public class RazorDocumentOptionsServiceTest(ITestOutputHelper testOutput) : Wor // Adds the text to a ProjectSnapshot, generates code, and updates the workspace. private Document InitializeDocument(SourceText sourceText) { - var baseDirectory = PlatformInformation.IsWindows ? @"c:\users\example\src" : "/home/example"; + var baseDirectory = RuntimeInformation.IsOSPlatform(OSPlatform.Windows) ? "c:\\users\\example\\src" : "/home/example"; var hostProject = new HostProject( Path.Combine(baseDirectory, "SomeProject", "SomeProject.csproj"), Path.Combine(baseDirectory, "SomeProject", "obj"), RazorConfiguration.Default, "SomeProject"); var hostDocument = new HostDocument( diff --git a/src/Razor/test/OSSkipConditionFactAttribute.cs b/src/Razor/test/OSSkipConditionFactAttribute.cs new file mode 100644 index 0000000000..1720cad03c --- /dev/null +++ b/src/Razor/test/OSSkipConditionFactAttribute.cs @@ -0,0 +1,52 @@ +// Copyright (c) .NET Foundation. All rights reserved. +// Licensed under the MIT license. See License.txt in the project root for license information. + +using System; +using System.Runtime.InteropServices; +using Xunit; + +namespace Microsoft.AspNetCore.Razor; + +public class OSSkipConditionFactAttribute : FactAttribute +{ + /// + /// A that configures on the specified platforms. + /// + /// Valid values include WINDOWS, LINUX, OSX, and FREEBSD. + /// + public OSSkipConditionFactAttribute(string[] skippedPlatforms) + { + SetSkipIfNecessary(this, skippedPlatforms); + } + + internal static void SetSkipIfNecessary(FactAttribute fact, string[] skippedPlatforms) + { + foreach (var platform in skippedPlatforms) + { + var osPlatform = platform switch + { + "Windows" => OSPlatform.Windows, + "Linux" => OSPlatform.Linux, + "OSX" => OSPlatform.OSX, +#if NET + "FreeBSD" => OSPlatform.FreeBSD, +#endif + _ => throw new NotSupportedException($"Unsupported platform: {platform}") + }; + + if (RuntimeInformation.IsOSPlatform(osPlatform)) + { + fact.Skip = $"Ignored on {platform}"; + break; + } + } + } +} + +public class OSSkipConditionTheoryAttribute : TheoryAttribute +{ + public OSSkipConditionTheoryAttribute(string[] skippedPlatforms) + { + OSSkipConditionFactAttribute.SetSkipIfNecessary(this, skippedPlatforms); + } +} diff --git a/src/Shared/Microsoft.AspNetCore.Razor.Test.Common/ConditionalFactAttribute.cs b/src/Shared/Microsoft.AspNetCore.Razor.Test.Common/ConditionalFactAttribute.cs deleted file mode 100644 index c025e3b34f..0000000000 --- a/src/Shared/Microsoft.AspNetCore.Razor.Test.Common/ConditionalFactAttribute.cs +++ /dev/null @@ -1,192 +0,0 @@ -// Licensed to the .NET Foundation under one or more agreements. -// The .NET Foundation licenses this file to you under the MIT license. - -using System; -using System.Collections.Frozen; -using System.Collections.Generic; -using Microsoft.AspNetCore.Razor.Utilities; -using Xunit; - -namespace Microsoft.AspNetCore.Razor; - -/// -/// A that only executes if each of the given conditions are met. -/// -/// -/// Conditions can be provided using the type. For example, -or- -/// , . -/// -public sealed class ConditionalFactAttribute : FactAttribute -{ - public ConditionalFactAttribute(params string[] conditions) - { - if (!Conditions.AllTrue(conditions)) - { - base.Skip = Reason ?? Conditions.GetSkipReason(conditions); - } - } - - /// - /// This property exists to prevent users of - /// from accidentally putting documentation in the property instead of Reason. - /// Setting would cause the test to be unconditionally skip. - /// - [Obsolete($"{nameof(ConditionalFactAttribute)} should always use {nameof(Reason)} or {nameof(AlwaysSkip)}", error: true)] - public new string Skip - { - get { return base.Skip; } - set { base.Skip = value; } - } - - /// - /// Use to unconditionally skip a test. - /// - /// - /// This is useful in the rare occasion when a conditional test needs to be skipped unconditionally. - /// Typically, this is for a short term reason, such as working on a bug fix. - /// - public string AlwaysSkip - { - get { return base.Skip; } - set { base.Skip = value; } - } - - public string? Reason { get; set; } -} - -/// -/// A that only executes if each of the given conditions are met. -/// -/// -/// Conditions can be provided using the type. For example, -or- -/// , . -/// -public sealed class ConditionalTheoryAttribute : TheoryAttribute -{ - public ConditionalTheoryAttribute(params string[] conditions) - { - if (!Conditions.AllTrue(conditions)) - { - base.Skip = Reason ?? Conditions.GetSkipReason(conditions); - } - } - - /// - /// This property exists to prevent users of - /// from accidentally putting documentation in the property instead of Reason. - /// Setting would cause the test to be unconditionally skip. - /// - [Obsolete($"{nameof(ConditionalFactAttribute)} should always use {nameof(Reason)} or {nameof(AlwaysSkip)}", error: true)] - public new string Skip - { - get { return base.Skip; } - set { base.Skip = value; } - } - - /// - /// Use to unconditionally skip a test. - /// - /// - /// This is useful in the rare occasion when a conditional test needs to be skipped unconditionally. - /// Typically, this is for a short term reason, such as working on a bug fix. - /// - public string AlwaysSkip - { - get { return base.Skip; } - set { base.Skip = value; } - } - - public string? Reason { get; set; } -} - -public static class Is -{ - /// - /// Only execute if the current operating system platform is Windows. - /// - public const string Windows = nameof(Windows); - - /// - /// Only execute if the current operating system platform is Linux. - /// - public const string Linux = nameof(Linux); - - /// - /// Only execute if the current operating system platform is MacOS. - /// - public const string MacOS = nameof(MacOS); - - /// - /// Only execute if the current operating system platform is FreeBSD. - /// - public const string FreeBSD = nameof(FreeBSD); - - public static class Not - { - /// - /// Only execute if the current operating system platform is not Windows. - /// - public const string Windows = $"!{nameof(Windows)}"; - - /// - /// Only execute if the current operating system platform is Linux. - /// - public const string Linux = $"!{nameof(Linux)}"; - - /// - /// Only execute if the current operating system platform is not MacOS. - /// - public const string MacOS = $"!{nameof(MacOS)}"; - - /// - /// Only execute if the current operating system platform is not FreeBSD. - /// - public const string FreeBSD = $"!{nameof(FreeBSD)}"; - } -} - -public static class Conditions -{ - private static readonly FrozenDictionary> s_conditionMap = CreateConditionMap(); - - private static FrozenDictionary> CreateConditionMap() - { - var map = new Dictionary>(StringComparer.OrdinalIgnoreCase); - - Add(Is.Windows, static () => PlatformInformation.IsWindows); - Add(Is.Linux, static () => PlatformInformation.IsLinux); - Add(Is.MacOS, static () => PlatformInformation.IsMacOS); - Add(Is.FreeBSD, static () => PlatformInformation.IsFreeBSD); - - return map.ToFrozenDictionary(); - - void Add(string name, Func predicate) - { - map.Add(name, predicate); - - // Add negated condition - map.Add($"!{name}", () => !predicate()); - } - } - - public static bool AllTrue(string[] conditions) - { - foreach (var condition in conditions) - { - if (!s_conditionMap.TryGetValue(condition, out var predicate)) - { - throw new NotSupportedException($"Encountered unexpected condition: {condition}"); - } - - if (!predicate()) - { - return false; - } - } - - return true; - } - - public static string GetSkipReason(string[] conditions) - => $"The following conditions are not all true: {string.Join(", ", conditions)}"; -} diff --git a/src/Shared/Microsoft.AspNetCore.Razor.Test.Common/Language/IntegrationTests/RazorIntegrationTestBase.cs b/src/Shared/Microsoft.AspNetCore.Razor.Test.Common/Language/IntegrationTests/RazorIntegrationTestBase.cs index 87828d221a..8781a1ffaf 100644 --- a/src/Shared/Microsoft.AspNetCore.Razor.Test.Common/Language/IntegrationTests/RazorIntegrationTestBase.cs +++ b/src/Shared/Microsoft.AspNetCore.Razor.Test.Common/Language/IntegrationTests/RazorIntegrationTestBase.cs @@ -6,9 +6,9 @@ using System.Collections.Generic; using System.Collections.Immutable; using System.IO; using System.Linq; +using System.Runtime.InteropServices; using System.Text; using Microsoft.AspNetCore.Razor.Test.Common; -using Microsoft.AspNetCore.Razor.Utilities; using Microsoft.CodeAnalysis; using Microsoft.CodeAnalysis.CSharp; using Microsoft.CodeAnalysis.Razor; @@ -51,7 +51,7 @@ public class RazorIntegrationTestBase Configuration = RazorConfiguration.Default; FileSystem = new VirtualRazorProjectFileSystem(); PathSeparator = Path.DirectorySeparatorChar.ToString(); - WorkingDirectory = PlatformInformation.IsWindows ? ArbitraryWindowsPath : ArbitraryMacLinuxPath; + WorkingDirectory = RuntimeInformation.IsOSPlatform(OSPlatform.Windows) ? ArbitraryWindowsPath : ArbitraryMacLinuxPath; DefaultRootNamespace = "Test"; // Matches the default working directory DefaultFileName = "TestComponent.cshtml"; @@ -404,7 +404,7 @@ public class RazorIntegrationTestBase protected static void AssertSourceEquals(string expected, CompileToCSharpResult generated) { // Normalize the paths inside the expected result to match the OS paths - if (!PlatformInformation.IsWindows) + if (!RuntimeInformation.IsOSPlatform(OSPlatform.Windows)) { var windowsPath = Path.Combine(ArbitraryWindowsPath, generated.CodeDocument.Source.RelativePath ?? "").Replace('/', '\\'); expected = expected.Replace(windowsPath, generated.CodeDocument.Source.FilePath); diff --git a/src/Shared/Microsoft.AspNetCore.Razor.Utilities.Shared.Test/Microsoft.AspNetCore.Razor.Utilities.Shared.Test.csproj b/src/Shared/Microsoft.AspNetCore.Razor.Utilities.Shared.Test/Microsoft.AspNetCore.Razor.Utilities.Shared.Test.csproj index 1f008203c9..b10885404a 100644 --- a/src/Shared/Microsoft.AspNetCore.Razor.Utilities.Shared.Test/Microsoft.AspNetCore.Razor.Utilities.Shared.Test.csproj +++ b/src/Shared/Microsoft.AspNetCore.Razor.Utilities.Shared.Test/Microsoft.AspNetCore.Razor.Utilities.Shared.Test.csproj @@ -12,7 +12,6 @@ - diff --git a/src/Shared/Microsoft.AspNetCore.Razor.Utilities.Shared/Utilities/PlatformInformation.cs b/src/Shared/Microsoft.AspNetCore.Razor.Utilities.Shared/Utilities/PlatformInformation.cs deleted file mode 100644 index 29a6310f2a..0000000000 --- a/src/Shared/Microsoft.AspNetCore.Razor.Utilities.Shared/Utilities/PlatformInformation.cs +++ /dev/null @@ -1,19 +0,0 @@ -// Copyright (c) .NET Foundation. All rights reserved. -// Licensed under the MIT license. See License.txt in the project root for license information. - -using System.Runtime.InteropServices; - -namespace Microsoft.AspNetCore.Razor.Utilities; - -internal static class PlatformInformation -{ - public static bool IsWindows { get; } = RuntimeInformation.IsOSPlatform(OSPlatform.Windows); - public static bool IsLinux { get; } = RuntimeInformation.IsOSPlatform(OSPlatform.Linux); - public static bool IsMacOS { get; } = RuntimeInformation.IsOSPlatform(OSPlatform.OSX); - -#if NET - public static bool IsFreeBSD { get; } = RuntimeInformation.IsOSPlatform(OSPlatform.FreeBSD); -#else - public static bool IsFreeBSD { get; } = false; -#endif -}