Revert "Some random clean up and improvements (#11095) (#11169)

Revert "Some random clean up and improvements (#11095) for dev17.13
This commit is contained in:
Phil Allen 2024-11-05 19:19:52 -08:00 коммит произвёл GitHub
Родитель 9b2adb4cde 594c89a235
Коммит 05e142e9a7
Не найден ключ, соответствующий данной подписи
Идентификатор ключа GPG: B5690EEEBB952194
36 изменённых файлов: 131 добавлений и 273 удалений

Просмотреть файл

@ -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")]

Просмотреть файл

@ -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();

Просмотреть файл

@ -30,6 +30,7 @@
<Compile Include="..\..\shared\JsonReaderExtensions.cs" LinkBase="Shared" />
<Compile Include="..\..\shared\RazorDiagnosticJsonConverter.cs" LinkBase="Shared" />
<Compile Include="..\..\shared\TagHelperDescriptorJsonConverter.cs" LinkBase="Shared" />
<Compile Include="..\..\..\Razor\test\OSSkipConditionFactAttribute.cs" LinkBase="Shared" />
</ItemGroup>
<ItemGroup>

Просмотреть файл

@ -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;
}

Просмотреть файл

@ -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;
}

Просмотреть файл

@ -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.

Просмотреть файл

@ -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;

Просмотреть файл

@ -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;

Просмотреть файл

@ -12,7 +12,7 @@ namespace Microsoft.AspNetCore.Razor.Utilities;
internal static class FilePathNormalizer
{
private static readonly Func<char, char> s_charConverter = PlatformInformation.IsLinux
private static readonly Func<char, char> 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 ['/', '/', ..])
{

Просмотреть файл

@ -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;
}

Просмотреть файл

@ -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('/', '\\');

Просмотреть файл

@ -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
{

Просмотреть файл

@ -6,6 +6,7 @@
<ItemGroup>
<None Include="xunit.runner.json" CopyToOutputDirectory="PreserveNewest" />
<Compile Include="..\OSSkipConditionFactAttribute.cs" LinkBase="Shared" />
</ItemGroup>
<ItemGroup>

Просмотреть файл

@ -6,6 +6,7 @@
<ItemGroup>
<None Include="xunit.runner.json" CopyToOutputDirectory="PreserveNewest" />
<Compile Include="..\OSSkipConditionFactAttribute.cs" LinkBase="Shared" />
</ItemGroup>
<ItemGroup>

Просмотреть файл

@ -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("<MyTagHelper />", 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("<MyTagHelper />", 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

Просмотреть файл

@ -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");

Просмотреть файл

@ -10,6 +10,7 @@
<ItemGroup>
<None Include="xunit.runner.json" CopyToOutputDirectory="PreserveNewest" />
<Compile Include="..\OSSkipConditionFactAttribute.cs" LinkBase="Shared" />
</ItemGroup>
<ItemGroup>

Просмотреть файл

@ -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

Просмотреть файл

@ -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";

Просмотреть файл

@ -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");
}

Просмотреть файл

@ -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")]

Просмотреть файл

@ -6,6 +6,7 @@
<ItemGroup>
<None Include="xunit.runner.json" CopyToOutputDirectory="PreserveNewest" />
<Compile Include="..\OSSkipConditionFactAttribute.cs" LinkBase="Shared" />
</ItemGroup>
<ItemGroup>

Просмотреть файл

@ -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);

Просмотреть файл

@ -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;
}

Просмотреть файл

@ -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");

Просмотреть файл

@ -7,6 +7,7 @@
<ItemGroup>
<None Include="xunit.runner.json" CopyToOutputDirectory="PreserveNewest" />
<Compile Include="..\OSSkipConditionFactAttribute.cs" LinkBase="Shared" />
</ItemGroup>
<ItemGroup>

Просмотреть файл

@ -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")]

Просмотреть файл

@ -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")]

Просмотреть файл

@ -8,6 +8,10 @@
<None Include="xunit.runner.json" CopyToOutputDirectory="PreserveNewest" />
</ItemGroup>
<ItemGroup>
<Compile Include="..\OSSkipConditionFactAttribute.cs" LinkBase="Shared" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\..\src\Microsoft.VisualStudio.LanguageServer.ContainedLanguage\Microsoft.VisualStudio.LanguageServer.ContainedLanguage.csproj" />
<ProjectReference Include="..\Microsoft.AspNetCore.Razor.Test.Common.Tooling\Microsoft.AspNetCore.Razor.Test.Common.Tooling.csproj" />

Просмотреть файл

@ -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

Просмотреть файл

@ -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(

Просмотреть файл

@ -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
{
/// <summary>
/// A <see cref="FactAttribute"/> that configures <see cref="FactAttribute.Skip"/> on the specified platforms.
/// </summary>
/// <param name="skippedPlatforms">Valid values include <c>WINDOWS</c>, <c>LINUX</c>, <c>OSX</c>, and <c>FREEBSD</c>.
/// <see href="https://source.dot.net/#System.Runtime.InteropServices.RuntimeInformation/System/Runtime/InteropServices/RuntimeInformation/OSPlatform.cs,26fa53454c093915"/></param>
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);
}
}

Просмотреть файл

@ -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;
/// <summary>
/// A <see cref="FactAttribute"/> that only executes if each of the given conditions are met.
/// </summary>
/// <remarks>
/// Conditions can be provided using the <see cref="Is"/> type. For example, <see cref="Is.Windows"/> -or-
/// <see cref="Is.Not.Linux"/>, <see cref="Is.Not.MacOS"/>.
/// </remarks>
public sealed class ConditionalFactAttribute : FactAttribute
{
public ConditionalFactAttribute(params string[] conditions)
{
if (!Conditions.AllTrue(conditions))
{
base.Skip = Reason ?? Conditions.GetSkipReason(conditions);
}
}
/// <summary>
/// This property exists to prevent users of <see cref="ConditionalFactAttribute"/>
/// from accidentally putting documentation in the <see cref="Skip"/> property instead of Reason.
/// Setting <see cref="Skip"/> would cause the test to be unconditionally skip.
/// </summary>
[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; }
}
/// <summary>
/// Use to unconditionally skip a test.
/// </summary>
/// <remarks>
/// 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.
/// </remarks>
public string AlwaysSkip
{
get { return base.Skip; }
set { base.Skip = value; }
}
public string? Reason { get; set; }
}
/// <summary>
/// A <see cref="TheoryAttribute"/> that only executes if each of the given conditions are met.
/// </summary>
/// <remarks>
/// Conditions can be provided using the <see cref="Is"/> type. For example, <see cref="Is.Windows"/> -or-
/// <see cref="Is.Not.Linux"/>, <see cref="Is.Not.MacOS"/>.
/// </remarks>
public sealed class ConditionalTheoryAttribute : TheoryAttribute
{
public ConditionalTheoryAttribute(params string[] conditions)
{
if (!Conditions.AllTrue(conditions))
{
base.Skip = Reason ?? Conditions.GetSkipReason(conditions);
}
}
/// <summary>
/// This property exists to prevent users of <see cref="ConditionalFactAttribute"/>
/// from accidentally putting documentation in the <see cref="Skip"/> property instead of Reason.
/// Setting <see cref="Skip"/> would cause the test to be unconditionally skip.
/// </summary>
[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; }
}
/// <summary>
/// Use to unconditionally skip a test.
/// </summary>
/// <remarks>
/// 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.
/// </remarks>
public string AlwaysSkip
{
get { return base.Skip; }
set { base.Skip = value; }
}
public string? Reason { get; set; }
}
public static class Is
{
/// <summary>
/// Only execute if the current operating system platform is Windows.
/// </summary>
public const string Windows = nameof(Windows);
/// <summary>
/// Only execute if the current operating system platform is Linux.
/// </summary>
public const string Linux = nameof(Linux);
/// <summary>
/// Only execute if the current operating system platform is MacOS.
/// </summary>
public const string MacOS = nameof(MacOS);
/// <summary>
/// Only execute if the current operating system platform is FreeBSD.
/// </summary>
public const string FreeBSD = nameof(FreeBSD);
public static class Not
{
/// <summary>
/// Only execute if the current operating system platform is not Windows.
/// </summary>
public const string Windows = $"!{nameof(Windows)}";
/// <summary>
/// Only execute if the current operating system platform is Linux.
/// </summary>
public const string Linux = $"!{nameof(Linux)}";
/// <summary>
/// Only execute if the current operating system platform is not MacOS.
/// </summary>
public const string MacOS = $"!{nameof(MacOS)}";
/// <summary>
/// Only execute if the current operating system platform is not FreeBSD.
/// </summary>
public const string FreeBSD = $"!{nameof(FreeBSD)}";
}
}
public static class Conditions
{
private static readonly FrozenDictionary<string, Func<bool>> s_conditionMap = CreateConditionMap();
private static FrozenDictionary<string, Func<bool>> CreateConditionMap()
{
var map = new Dictionary<string, Func<bool>>(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<bool> 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)}";
}

Просмотреть файл

@ -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);

Просмотреть файл

@ -12,7 +12,6 @@
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\Microsoft.AspNetCore.Razor.Test.Common\Microsoft.AspNetCore.Razor.Test.Common.csproj" />
<ProjectReference Include="..\Microsoft.AspNetCore.Razor.Utilities.Shared\Microsoft.AspNetCore.Razor.Utilities.Shared.csproj" />
</ItemGroup>

Просмотреть файл

@ -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
}