From 83ca6cb1245def5d0d572567362c969180d2823f Mon Sep 17 00:00:00 2001 From: Andy Gocke Date: Mon, 29 Sep 2025 14:57:33 -0700 Subject: [PATCH 01/21] Move hosting tests to XUnit 3 The primary advantage in this change is that test assemblies are now executables, not libraries. This makes debugging easier, as the executable can be run directly under the debugger. It also makes deployment of the tests easier, as we only need to copy the executable and set DOTNET_ROOT to the pre-built framework. This is also a kind of trial-balloon. Many other tests (esp. libraries tests) in this repo would benefit from the execution advantages. However, they are built in more configurations today and are more complex. The host tests are an easier lift. --- .../AppHost.Bundle.Tests.csproj | 4 +- .../tests/AppHost.Bundle.Tests/AppLaunch.cs | 31 ++++--- .../BundledAppWithSubDirs.cs | 5 +- .../AppHost.Bundle.Tests/NativeLibraries.cs | 4 +- src/installer/tests/Directory.Build.props | 10 +- src/installer/tests/Directory.Build.targets | 5 + .../tests/HostActivation.Tests/Breadcrumbs.cs | 4 +- .../AdditionalProbingPath.cs | 12 +-- .../DependencyResolution/DepsFile.cs | 4 +- .../DependencyResolution/LocalPath.cs | 18 ++-- ...mblyVersionResolutionMultipleFrameworks.cs | 2 +- .../RidAssetResolution.cs | 12 +-- .../SharedTestStateBase.cs | 2 +- .../DotnetArgValidation.cs | 14 +-- .../FrameworkDependentAppLaunch.cs | 93 +++++++++---------- .../FrameworkResolution.cs | 6 +- .../FrameworkResolutionBase.cs | 2 +- .../IncludedFrameworksSettings.cs | 2 +- .../FrameworkResolution/MultilevelLookup.cs | 4 +- .../HostActivation.Tests.csproj | 2 + .../HostActivation.Tests/HostCommands.cs | 36 +++---- .../HostVersionCompatibility.cs | 12 +-- .../HostActivation.Tests/InstallLocation.cs | 60 ++++++------ .../tests/HostActivation.Tests/InvalidHost.cs | 6 +- .../MachOHostSigningTests.cs | 3 +- .../HostActivation.Tests/NativeHostApis.cs | 78 ++++++++-------- .../NativeHosting/ApplicationExecution.cs | 4 +- .../NativeHosting/Comhost.cs | 21 +++-- .../NativeHosting/ComhostSideBySide.cs | 9 +- .../NativeHosting/GetFunctionPointer.cs | 4 +- .../GetNativeSearchDirectories.cs | 2 +- ...tContext.FrameworkCompatibilityTestData.cs | 2 +- ...stContext.PropertyCompatibilityTestData.cs | 2 +- .../NativeHosting/HostContext.cs | 26 +++--- .../NativeHosting/Ijwhost.cs | 30 +++--- .../NativeHosting/LoadAssembly.cs | 6 +- .../LoadAssemblyAndGetFunctionPointer.cs | 8 +- .../NativeHosting/Nethost.cs | 14 +-- .../RegisteredInstallLocationOverride.cs | 2 +- .../HostActivation.Tests/RuntimeProperties.cs | 4 +- .../tests/HostActivation.Tests/SDKLookup.cs | 4 +- .../SelfContainedAppLaunch.cs | 35 +++---- .../HostActivation.Tests/StartupHooks.cs | 12 +-- .../HostActivation.Tests/SymbolicLinks.cs | 14 +-- .../tests/HostActivation.Tests/Tracing.cs | 18 ++-- .../WindowsSpecificBehavior.cs | 15 +-- .../NETCoreTests.cs | 4 +- .../NuGetArtifactTester.cs | 4 +- .../AppHost/CreateAppHost.cs | 13 ++- .../Bundle/BundlerConsistencyTests.cs | 4 +- .../MachObjectSigning/MachObjectTests.cs | 4 +- .../MachObjectSigning/SigningTests.cs | 11 +-- .../Microsoft.NET.HostModel.Tests.csproj | 3 + src/installer/tests/TestUtils/Binaries.cs | 6 +- .../tests/TestUtils/CommandExtensions.cs | 4 +- .../tests/TestUtils/DotNetBuilder.cs | 2 +- .../{TestContext.cs => HostTestContext.cs} | 4 +- .../PlatformSpecificFactAttribute.cs | 44 +++++++++ .../PlatformSpecificTheoryAttribute.cs | 19 ++++ .../TestUtils/RepoDirectoriesProvider.cs | 2 +- .../tests/TestUtils/SingleFileTestApp.cs | 18 ++-- src/installer/tests/TestUtils/TestApp.cs | 8 +- src/installer/tests/TestUtils/TestArtifact.cs | 2 +- .../tests/TestUtils/TestUtils.csproj | 4 +- 64 files changed, 448 insertions(+), 371 deletions(-) rename src/installer/tests/TestUtils/{TestContext.cs => HostTestContext.cs} (97%) create mode 100644 src/installer/tests/TestUtils/PlatformSpecificFactAttribute.cs create mode 100644 src/installer/tests/TestUtils/PlatformSpecificTheoryAttribute.cs diff --git a/src/installer/tests/AppHost.Bundle.Tests/AppHost.Bundle.Tests.csproj b/src/installer/tests/AppHost.Bundle.Tests/AppHost.Bundle.Tests.csproj index 13a9b59f64feb7..93fc95c57691c1 100644 --- a/src/installer/tests/AppHost.Bundle.Tests/AppHost.Bundle.Tests.csproj +++ b/src/installer/tests/AppHost.Bundle.Tests/AppHost.Bundle.Tests.csproj @@ -2,6 +2,7 @@ Apphost Bundle Tests + Exe $(TestInfraTargetFramework) AppHost.Bundle.Tests true @@ -9,7 +10,8 @@ ahb - $(NoWarn);NU1511 + $(NoWarn);NU1511;xUnit1004 + XUnitV3 diff --git a/src/installer/tests/AppHost.Bundle.Tests/AppLaunch.cs b/src/installer/tests/AppHost.Bundle.Tests/AppLaunch.cs index 67179e1577a625..775f7458dcc2a7 100644 --- a/src/installer/tests/AppHost.Bundle.Tests/AppLaunch.cs +++ b/src/installer/tests/AppHost.Bundle.Tests/AppLaunch.cs @@ -27,7 +27,7 @@ private void RunTheApp(string path, bool selfContained) Command.Create(path) .CaptureStdErr() .CaptureStdOut() - .DotNetRoot(selfContained ? null : TestContext.BuiltDotNet.BinPath) + .DotNetRoot(selfContained ? null : HostTestContext.BuiltDotNet.BinPath) .Execute() .Should().Pass() .And.HaveStdOutContaining("Hello World!"); @@ -75,9 +75,9 @@ private void RunApp(bool selfContained) if (OperatingSystem.IsWindows()) { // StandaloneApp sets FileVersion to NETCoreApp version. On Windows, this should be copied to singlefilehost resources. - string expectedVersion = TestContext.MicrosoftNETCoreAppVersion.Contains('-') - ? TestContext.MicrosoftNETCoreAppVersion[..TestContext.MicrosoftNETCoreAppVersion.IndexOf('-')] - : TestContext.MicrosoftNETCoreAppVersion; + string expectedVersion = HostTestContext.MicrosoftNETCoreAppVersion.Contains('-') + ? HostTestContext.MicrosoftNETCoreAppVersion[..HostTestContext.MicrosoftNETCoreAppVersion.IndexOf('-')] + : HostTestContext.MicrosoftNETCoreAppVersion; Assert.Equal(expectedVersion, System.Diagnostics.FileVersionInfo.GetVersionInfo(singleFile).FileVersion); } } @@ -103,18 +103,20 @@ private void NonAsciiCharacterSelfContainedApp() if (OperatingSystem.IsWindows()) { // StandaloneApp sets FileVersion to NETCoreApp version. On Windows, this should be copied to singlefilehost resources. - string expectedVersion = TestContext.MicrosoftNETCoreAppVersion.Contains('-') - ? TestContext.MicrosoftNETCoreAppVersion[..TestContext.MicrosoftNETCoreAppVersion.IndexOf('-')] - : TestContext.MicrosoftNETCoreAppVersion; + string expectedVersion = HostTestContext.MicrosoftNETCoreAppVersion.Contains('-') + ? HostTestContext.MicrosoftNETCoreAppVersion[..HostTestContext.MicrosoftNETCoreAppVersion.IndexOf('-')] + : HostTestContext.MicrosoftNETCoreAppVersion; Assert.Equal(expectedVersion, System.Diagnostics.FileVersionInfo.GetVersionInfo(singleFile).FileVersion); } } - [ConditionalTheory(typeof(Binaries.CetCompat), nameof(Binaries.CetCompat.IsSupported))] + [Theory] [InlineData(true)] [InlineData(false)] public void DisableCetCompat(bool selfContained) { + Assert.SkipUnless(Binaries.CetCompat.IsSupported, "CET not supported on this platform"); + SingleFileTestApp app = selfContained ? sharedTestState.SelfContainedApp.Copy() : sharedTestState.FrameworkDependentApp.Copy(); @@ -124,12 +126,12 @@ public void DisableCetCompat(bool selfContained) Command.Create(singleFile) .CaptureStdErr() .CaptureStdOut() - .DotNetRoot(TestContext.BuiltDotNet.BinPath, TestContext.BuildArchitecture) + .DotNetRoot(HostTestContext.BuiltDotNet.BinPath, HostTestContext.BuildArchitecture) .MultilevelLookup(false) .Execute() .Should().Pass() .And.HaveStdOutContaining("Hello World") - .And.HaveStdOutContaining(TestContext.MicrosoftNETCoreAppVersion); + .And.HaveStdOutContaining(HostTestContext.MicrosoftNETCoreAppVersion); } [Theory] @@ -158,7 +160,7 @@ public void FrameworkDependent_NoBundleEntryPoint() using (var dotnetWithMockHostFxr = TestArtifact.Create("mockhostfxrFrameworkMissingFailure")) { - var dotnet = new DotNetBuilder(dotnetWithMockHostFxr.Location, TestContext.BuiltDotNet.BinPath, null) + var dotnet = new DotNetBuilder(dotnetWithMockHostFxr.Location, HostTestContext.BuiltDotNet.BinPath, null) .RemoveHostFxr() .AddMockHostFxr(new Version(2, 2, 0)) .Build(); @@ -176,8 +178,7 @@ public void FrameworkDependent_NoBundleEntryPoint() } } - [Fact] - [PlatformSpecific(TestPlatforms.Windows)] // GUI app host is only supported on Windows. + [PlatformSpecificFact(TestPlatforms.Windows)] // GUI app host is only supported on Windows. public void FrameworkDependent_GUI_DownlevelHostFxr_ErrorDialog() { var singleFile = sharedTestState.FrameworkDependentApp.Bundle(); @@ -188,14 +189,14 @@ public void FrameworkDependent_GUI_DownlevelHostFxr_ErrorDialog() { string expectedErrorCode = Constants.ErrorCode.BundleExtractionFailure.ToString("x"); - var dotnet = new DotNetBuilder(dotnetWithMockHostFxr.Location, TestContext.BuiltDotNet.BinPath, null) + var dotnet = new DotNetBuilder(dotnetWithMockHostFxr.Location, HostTestContext.BuiltDotNet.BinPath, null) .RemoveHostFxr() .AddMockHostFxr(new Version(5, 0, 0)) .Build(); Command command = Command.Create(singleFile) .EnableTracingAndCaptureOutputs() - .DotNetRoot(dotnet.BinPath, TestContext.BuildArchitecture) + .DotNetRoot(dotnet.BinPath, HostTestContext.BuildArchitecture) .Start(); WindowsUtils.WaitForPopupFromProcess(command.Process); diff --git a/src/installer/tests/AppHost.Bundle.Tests/BundledAppWithSubDirs.cs b/src/installer/tests/AppHost.Bundle.Tests/BundledAppWithSubDirs.cs index 5e1b5ef42bcac5..baaddbbdf7c8e7 100644 --- a/src/installer/tests/AppHost.Bundle.Tests/BundledAppWithSubDirs.cs +++ b/src/installer/tests/AppHost.Bundle.Tests/BundledAppWithSubDirs.cs @@ -24,7 +24,7 @@ private FluentAssertions.AndConstraint RunTheApp(string { CommandResult result = Command.Create(path) .EnableTracingAndCaptureOutputs() - .DotNetRoot(selfContained ? null : TestContext.BuiltDotNet.BinPath) + .DotNetRoot(selfContained ? null : HostTestContext.BuiltDotNet.BinPath) .MultilevelLookup(false) .Execute(); if (deleteExtracted) @@ -138,8 +138,7 @@ public void FrameworkDependent_Targeting50(BundleOptions options) } } - [Fact] - [ActiveIssue("https://github.com/dotnet/runtime/issues/54234")] + [Fact(Skip = "https://github.com/dotnet/runtime/issues/54234")] // NOTE: when enabling this test take a look at commented code marked by "ACTIVE ISSUE:" in SharedTestState public void SelfContained_R2R_Composite() { diff --git a/src/installer/tests/AppHost.Bundle.Tests/NativeLibraries.cs b/src/installer/tests/AppHost.Bundle.Tests/NativeLibraries.cs index 627c3e15da0b8b..f3ef14d0260826 100644 --- a/src/installer/tests/AppHost.Bundle.Tests/NativeLibraries.cs +++ b/src/installer/tests/AppHost.Bundle.Tests/NativeLibraries.cs @@ -38,7 +38,7 @@ private void PInvoke(bool selfContained, bool bundleNative) Command.Create(app, "load_native_library_pinvoke") .CaptureStdErr() .CaptureStdOut() - .DotNetRoot(selfContained ? null : TestContext.BuiltDotNet.BinPath) + .DotNetRoot(selfContained ? null : HostTestContext.BuiltDotNet.BinPath) // Specify an extraction root that will get cleaned up by the test app artifact .EnvironmentVariable(Constants.BundleExtractBase.EnvironmentVariable, extractionRoot) .Execute() @@ -66,7 +66,7 @@ private void TryLoad(bool selfContained, bool bundleNative) Command.Create(app, "load_native_library_api") .CaptureStdErr() .CaptureStdOut() - .DotNetRoot(selfContained ? null : TestContext.BuiltDotNet.BinPath) + .DotNetRoot(selfContained ? null : HostTestContext.BuiltDotNet.BinPath) // Specify an extraction root that will get cleaned up by the test app artifact .EnvironmentVariable(Constants.BundleExtractBase.EnvironmentVariable, extractionRoot) .Execute() diff --git a/src/installer/tests/Directory.Build.props b/src/installer/tests/Directory.Build.props index e56691554aaae4..fa2eb44e9d9c12 100644 --- a/src/installer/tests/Directory.Build.props +++ b/src/installer/tests/Directory.Build.props @@ -4,13 +4,13 @@ $(ArtifactsDir)tests\host\$(TargetOS).$(TargetArchitecture).$(Configuration)\ $(NetCoreAppToolCurrent) - category!=failing - --filter $(TestCaseFilter) -v detailed + /[category!=failing] + --filter-query $(TestCaseFilter) - $(TestRunnerAdditionalArguments) --blame-crash-dump-type full - $(TestRunnerAdditionalArguments) --blame-hang-timeout 5m --blame-hang-dump-type full - true + $(TestRunnerAdditionalArguments) --crashdump + $(TestRunnerAdditionalArguments) --hangdump --hangdump-timeout 5m --hangdump-type full false + XUnitV3 diff --git a/src/installer/tests/Directory.Build.targets b/src/installer/tests/Directory.Build.targets index 098f499376ffed..e4218ebb7b53f4 100644 --- a/src/installer/tests/Directory.Build.targets +++ b/src/installer/tests/Directory.Build.targets @@ -92,6 +92,11 @@ $(TestCaseFilter) + + + + + diff --git a/src/installer/tests/HostActivation.Tests/Breadcrumbs.cs b/src/installer/tests/HostActivation.Tests/Breadcrumbs.cs index 4997a574ad983c..df8451274823fe 100644 --- a/src/installer/tests/HostActivation.Tests/Breadcrumbs.cs +++ b/src/installer/tests/HostActivation.Tests/Breadcrumbs.cs @@ -22,7 +22,7 @@ public Breadcrumbs(SharedTestState fixture) [Fact] public void BreadcrumbThreadFinishes() { - TestContext.BuiltDotNet.Exec(sharedTestState.App.AppDll) + HostTestContext.BuiltDotNet.Exec(sharedTestState.App.AppDll) .EnvironmentVariable(Constants.Breadcrumbs.EnvironmentVariable, sharedTestState.BreadcrumbLocation) .EnableTracingAndCaptureOutputs() .Execute() @@ -34,7 +34,7 @@ public void BreadcrumbThreadFinishes() [Fact] public void UnhandledException_BreadcrumbThreadDoesNotFinish() { - TestContext.BuiltDotNet.Exec(sharedTestState.App.AppDll, "throw_exception") + HostTestContext.BuiltDotNet.Exec(sharedTestState.App.AppDll, "throw_exception") .EnvironmentVariable(Constants.Breadcrumbs.EnvironmentVariable, sharedTestState.BreadcrumbLocation) .EnableTracingAndCaptureOutputs() .DisableDumps() // Expected to throw an exception diff --git a/src/installer/tests/HostActivation.Tests/DependencyResolution/AdditionalProbingPath.cs b/src/installer/tests/HostActivation.Tests/DependencyResolution/AdditionalProbingPath.cs index 4914f5b7b95a4d..e4732fc5726bf8 100644 --- a/src/installer/tests/HostActivation.Tests/DependencyResolution/AdditionalProbingPath.cs +++ b/src/installer/tests/HostActivation.Tests/DependencyResolution/AdditionalProbingPath.cs @@ -111,24 +111,24 @@ public class SharedTestState : SharedTestStateBase public SharedTestState() { DotNetWithNetCoreApp = DotNet("WithNetCoreApp") - .AddMicrosoftNETCoreAppFrameworkMockCoreClr(TestContext.MicrosoftNETCoreAppVersion) + .AddMicrosoftNETCoreAppFrameworkMockCoreClr(HostTestContext.MicrosoftNETCoreAppVersion) .Build(); - string nativeDependencyRelPath = $"{TestContext.BuildRID}/{Binaries.GetSharedLibraryFileNameForCurrentPlatform("native")}"; - FrameworkReferenceApp = CreateFrameworkReferenceApp(Constants.MicrosoftNETCoreApp, TestContext.MicrosoftNETCoreAppVersion, b => b + string nativeDependencyRelPath = $"{HostTestContext.BuildRID}/{Binaries.GetSharedLibraryFileNameForCurrentPlatform("native")}"; + FrameworkReferenceApp = CreateFrameworkReferenceApp(Constants.MicrosoftNETCoreApp, HostTestContext.MicrosoftNETCoreAppVersion, b => b .WithProject(DependencyName, DependencyVersion, p => p .WithAssemblyGroup(null, g => g .WithAsset($"{DependencyName}.dll", f => f.NotOnDisk())) - .WithNativeLibraryGroup(TestContext.BuildRID, g => g + .WithNativeLibraryGroup(HostTestContext.BuildRID, g => g .WithAsset(nativeDependencyRelPath, f => f.NotOnDisk())))); RuntimeConfig.FromFile(FrameworkReferenceApp.RuntimeConfigJson) - .WithTfm(TestContext.Tfm) + .WithTfm(HostTestContext.Tfm) .Save(); AdditionalProbingPath = Path.Combine(Location, "probe"); (DependencyPath, NativeDependencyDirectory) = AddDependencies(AdditionalProbingPath); - AdditionalProbingPath_ArchTfm = Path.Combine(AdditionalProbingPath, TestContext.BuildArchitecture, TestContext.Tfm); + AdditionalProbingPath_ArchTfm = Path.Combine(AdditionalProbingPath, HostTestContext.BuildArchitecture, HostTestContext.Tfm); (DependencyPath_ArchTfm, NativeDependencyDirectory_ArchTfm) = AddDependencies(AdditionalProbingPath_ArchTfm); (string, string) AddDependencies(string probeDir) diff --git a/src/installer/tests/HostActivation.Tests/DependencyResolution/DepsFile.cs b/src/installer/tests/HostActivation.Tests/DependencyResolution/DepsFile.cs index 69bd09bb93063a..cf4eff1807b17b 100644 --- a/src/installer/tests/HostActivation.Tests/DependencyResolution/DepsFile.cs +++ b/src/installer/tests/HostActivation.Tests/DependencyResolution/DepsFile.cs @@ -92,10 +92,10 @@ public class SharedTestState : SharedTestStateBase public SharedTestState() { DotNetWithNetCoreApp = DotNet("WithNetCoreApp") - .AddMicrosoftNETCoreAppFrameworkMockCoreClr(TestContext.MicrosoftNETCoreAppVersion) + .AddMicrosoftNETCoreAppFrameworkMockCoreClr(HostTestContext.MicrosoftNETCoreAppVersion) .Build(); - FrameworkReferenceApp = CreateFrameworkReferenceApp(Constants.MicrosoftNETCoreApp, TestContext.MicrosoftNETCoreAppVersion, b => b + FrameworkReferenceApp = CreateFrameworkReferenceApp(Constants.MicrosoftNETCoreApp, HostTestContext.MicrosoftNETCoreAppVersion, b => b .WithProject(DependencyName, "1.0.0", p => p .WithAssemblyGroup(null, g => g.WithAsset($"{DependencyName}.dll")))); diff --git a/src/installer/tests/HostActivation.Tests/DependencyResolution/LocalPath.cs b/src/installer/tests/HostActivation.Tests/DependencyResolution/LocalPath.cs index bad9c83eacede9..3bd1dcb7e53c80 100644 --- a/src/installer/tests/HostActivation.Tests/DependencyResolution/LocalPath.cs +++ b/src/installer/tests/HostActivation.Tests/DependencyResolution/LocalPath.cs @@ -66,8 +66,8 @@ private void RuntimeAssemblies(bool isSelfContained, bool useLocalPath) { // Add RID-specific assembly (string ridPath, string localRidPath) = GetPaths(libraryType, true); - b.WithRuntimeLibrary(libraryType, $"{library}-{TestContext.BuildRID}", "1.0.0", p => p - .WithAssemblyGroup(TestContext.BuildRID, g => g + b.WithRuntimeLibrary(libraryType, $"{library}-{HostTestContext.BuildRID}", "1.0.0", p => p + .WithAssemblyGroup(HostTestContext.BuildRID, g => g .WithAsset(ridPath, useLocalPath ? f => f.WithLocalPath(localRidPath) : null))); } } @@ -114,7 +114,7 @@ private void RuntimeAssemblies(bool isSelfContained, bool useLocalPath) static (string Path, string LocalPath) GetPaths(RuntimeLibraryType libraryType, bool useRid) { string library = $"Test{libraryType}"; - string path = useRid ? $"lib/{TestContext.BuildRID}/{library}-{TestContext.BuildRID}.dll" : $"lib/{library}.dll"; + string path = useRid ? $"lib/{HostTestContext.BuildRID}/{library}-{HostTestContext.BuildRID}.dll" : $"lib/{library}.dll"; return (path, $"{libraryType}/{path}"); } } @@ -137,9 +137,9 @@ private void NativeLibraries(bool isSelfContained, bool useLocalPath) { // Add RID-specific native library (string ridPath, string localRidPath) = GetPaths(libraryType, true); - b.WithRuntimeLibrary(libraryType, $"{library}-{TestContext.BuildRID}", "1.0.0", p => p - .WithNativeLibraryGroup(TestContext.BuildRID, g => g - .WithAsset($"{ridPath}/{library}-{TestContext.BuildRID}.native", useLocalPath ? f => f.WithLocalPath($"{localRidPath}/{library}-{TestContext.BuildRID}.native") : null))); + b.WithRuntimeLibrary(libraryType, $"{library}-{HostTestContext.BuildRID}", "1.0.0", p => p + .WithNativeLibraryGroup(HostTestContext.BuildRID, g => g + .WithAsset($"{ridPath}/{library}-{HostTestContext.BuildRID}.native", useLocalPath ? f => f.WithLocalPath($"{localRidPath}/{library}-{HostTestContext.BuildRID}.native") : null))); } } @@ -184,7 +184,7 @@ private void NativeLibraries(bool isSelfContained, bool useLocalPath) static (string Path, string LocalPath) GetPaths(NetCoreAppBuilder.RuntimeLibraryType libraryType, bool useRid) { - string path = useRid ? $"native/{TestContext.BuildRID}" : "native"; + string path = useRid ? $"native/{HostTestContext.BuildRID}" : "native"; return (path, $"{libraryType}/{path}"); } } @@ -245,7 +245,7 @@ private static TestApp CreateApp(bool isSelfContained, Action } else { - app.PopulateFrameworkDependent(Constants.MicrosoftNETCoreApp, TestContext.MicrosoftNETCoreAppVersion, customizer); + app.PopulateFrameworkDependent(Constants.MicrosoftNETCoreApp, HostTestContext.MicrosoftNETCoreAppVersion, customizer); } return app; } @@ -257,7 +257,7 @@ public class SharedTestState : SharedTestStateBase public SharedTestState() { DotNetWithNetCoreApp = DotNet("WithNetCoreApp") - .AddMicrosoftNETCoreAppFrameworkMockCoreClr(TestContext.MicrosoftNETCoreAppVersion) + .AddMicrosoftNETCoreAppFrameworkMockCoreClr(HostTestContext.MicrosoftNETCoreAppVersion) .Build(); } } diff --git a/src/installer/tests/HostActivation.Tests/DependencyResolution/PerAssemblyVersionResolutionMultipleFrameworks.cs b/src/installer/tests/HostActivation.Tests/DependencyResolution/PerAssemblyVersionResolutionMultipleFrameworks.cs index 9367927ffb5588..2e158aa8559763 100644 --- a/src/installer/tests/HostActivation.Tests/DependencyResolution/PerAssemblyVersionResolutionMultipleFrameworks.cs +++ b/src/installer/tests/HostActivation.Tests/DependencyResolution/PerAssemblyVersionResolutionMultipleFrameworks.cs @@ -105,7 +105,7 @@ protected override void CustomizeDotNetWithNetCoreApp(DotNetBuilder builder) HighWare, "1.1.1", runtimeConfig => runtimeConfig.WithFramework(Constants.MicrosoftNETCoreApp, "4.0.0"), - path => NetCoreAppBuilder.ForNETCoreApp(HighWare, TestContext.BuildRID) + path => NetCoreAppBuilder.ForNETCoreApp(HighWare, HostTestContext.BuildRID) .WithProject(HighWare, "1.1.1", p => p .WithAssemblyGroup(null, g => g .WithAsset(TestAssemblyWithNoVersions + ".dll") diff --git a/src/installer/tests/HostActivation.Tests/DependencyResolution/RidAssetResolution.cs b/src/installer/tests/HostActivation.Tests/DependencyResolution/RidAssetResolution.cs index 3305b9e1d30908..23217d0b5069d4 100644 --- a/src/installer/tests/HostActivation.Tests/DependencyResolution/RidAssetResolution.cs +++ b/src/installer/tests/HostActivation.Tests/DependencyResolution/RidAssetResolution.cs @@ -94,8 +94,8 @@ protected TestApp UpdateAppConfigForTest(TestApp app, TestSetup setup, bool copy // The fallback RID is a compile-time define for the host. On Windows, it is always win10 and on // other platforms, it matches the build RID (non-portable for source-builds, portable otherwise) private static string FallbackRid = OperatingSystem.IsWindows() - ? $"win10-{TestContext.BuildArchitecture}" - : TestContext.BuildRID; + ? $"win10-{HostTestContext.BuildArchitecture}" + : HostTestContext.BuildRID; protected const string UnknownRid = "unknown-rid"; @@ -332,15 +332,15 @@ public void MostSpecificRidAssemblySelected_RidGraph(string rid, string expected } // The build RID from the test context should match the build RID of the host under test - private static string CurrentRid = TestContext.BuildRID; + private static string CurrentRid = HostTestContext.BuildRID; private static string CurrentRidAsset = $"{CurrentRid}/{CurrentRid}Asset.dll"; // Strip the - from the RID to get the OS - private static string CurrentOS = CurrentRid[..^(TestContext.BuildArchitecture.Length + 1)]; + private static string CurrentOS = CurrentRid[..^(HostTestContext.BuildArchitecture.Length + 1)]; private static string CurrentOSAsset = $"{CurrentOS}/{CurrentOS}Asset.dll"; // Append a different architecture - arm64 if current architecture is x64, otherwise x64 - private static string DifferentArch = $"{CurrentOS}-{(TestContext.BuildArchitecture == "x64" ? "arm64" : "x64")}"; + private static string DifferentArch = $"{CurrentOS}-{(HostTestContext.BuildArchitecture == "x64" ? "arm64" : "x64")}"; private static string DifferentArchAsset = $"{DifferentArch}/{DifferentArch}Asset.dll"; [Theory] @@ -603,7 +603,7 @@ public void MostSpecificRidAssemblySelectedPerTypeMultipleAssets(bool hasRuntime protected static void UseFallbacksFromBuiltDotNet(NetCoreAppBuilder builder) { IReadOnlyList fallbacks; - string depsJson = Path.Combine(TestContext.BuiltDotNet.GreatestVersionSharedFxPath, $"{Constants.MicrosoftNETCoreApp}.deps.json"); + string depsJson = Path.Combine(HostTestContext.BuiltDotNet.GreatestVersionSharedFxPath, $"{Constants.MicrosoftNETCoreApp}.deps.json"); using (FileStream fileStream = File.OpenRead(depsJson)) using (DependencyContextJsonReader reader = new DependencyContextJsonReader()) { diff --git a/src/installer/tests/HostActivation.Tests/DependencyResolution/SharedTestStateBase.cs b/src/installer/tests/HostActivation.Tests/DependencyResolution/SharedTestStateBase.cs index 7fc6019e9e91fc..ba6fa3613cbd99 100644 --- a/src/installer/tests/HostActivation.Tests/DependencyResolution/SharedTestStateBase.cs +++ b/src/installer/tests/HostActivation.Tests/DependencyResolution/SharedTestStateBase.cs @@ -22,7 +22,7 @@ public SharedTestStateBase() public DotNetBuilder DotNet(string name) { - return new DotNetBuilder(_baseDirectory.Location, TestContext.BuiltDotNet.BinPath, name); + return new DotNetBuilder(_baseDirectory.Location, HostTestContext.BuiltDotNet.BinPath, name); } public TestApp CreateFrameworkReferenceApp(string fxName, string fxVersion, Action customizer = null) diff --git a/src/installer/tests/HostActivation.Tests/DotnetArgValidation.cs b/src/installer/tests/HostActivation.Tests/DotnetArgValidation.cs index 18ce6bbf5716fd..d1a7b81bbdccce 100644 --- a/src/installer/tests/HostActivation.Tests/DotnetArgValidation.cs +++ b/src/installer/tests/HostActivation.Tests/DotnetArgValidation.cs @@ -22,7 +22,7 @@ public DotnetArgValidation(DotnetArgValidation.SharedTestState sharedState) public void MuxerExec_MissingAppAssembly_Fails() { string assemblyName = Path.Combine(GetNonexistentAndUnnormalizedPath(), "foo.dll"); - TestContext.BuiltDotNet.Exec("exec", assemblyName) + HostTestContext.BuiltDotNet.Exec("exec", assemblyName) .CaptureStdOut() .CaptureStdErr() .Execute() @@ -34,7 +34,7 @@ public void MuxerExec_MissingAppAssembly_Fails() public void MuxerExec_MissingAppAssembly_BadExtension_Fails() { string assemblyName = Path.Combine(GetNonexistentAndUnnormalizedPath(), "foo.xzy"); - TestContext.BuiltDotNet.Exec("exec", assemblyName) + HostTestContext.BuiltDotNet.Exec("exec", assemblyName) .CaptureStdOut() .CaptureStdErr() .Execute() @@ -46,10 +46,10 @@ public void MuxerExec_MissingAppAssembly_BadExtension_Fails() public void MuxerExec_BadExtension_Fails() { // Get a valid file name, but not exe or dll - string fxDir = TestContext.BuiltDotNet.GreatestVersionSharedFxPath; + string fxDir = HostTestContext.BuiltDotNet.GreatestVersionSharedFxPath; string assemblyName = Path.Combine(fxDir, "Microsoft.NETCore.App.deps.json"); - TestContext.BuiltDotNet.Exec("exec", assemblyName) + HostTestContext.BuiltDotNet.Exec("exec", assemblyName) .CaptureStdOut() .CaptureStdErr() .Execute() @@ -60,7 +60,7 @@ public void MuxerExec_BadExtension_Fails() [Fact] public void MissingArgumentValue_Fails() { - TestContext.BuiltDotNet.Exec("--fx-version") + HostTestContext.BuiltDotNet.Exec("--fx-version") .CaptureStdOut() .CaptureStdErr() .Execute() @@ -72,7 +72,7 @@ public void MissingArgumentValue_Fails() public void InvalidFileOrCommand_NoSDK_ListsPossibleIssues() { string fileName = "NonExistent"; - TestContext.BuiltDotNet.Exec(fileName) + HostTestContext.BuiltDotNet.Exec(fileName) .WorkingDirectory(sharedTestState.BaseDirectory.Location) .CaptureStdOut() .CaptureStdErr() @@ -85,7 +85,7 @@ public void InvalidFileOrCommand_NoSDK_ListsPossibleIssues() // Return a non-existent path that contains a mix of / and \ private string GetNonexistentAndUnnormalizedPath() { - return Path.Combine(TestContext.BuiltDotNet.BinPath, @"x\y/"); + return Path.Combine(HostTestContext.BuiltDotNet.BinPath, @"x\y/"); } public class SharedTestState : IDisposable diff --git a/src/installer/tests/HostActivation.Tests/FrameworkDependentAppLaunch.cs b/src/installer/tests/HostActivation.Tests/FrameworkDependentAppLaunch.cs index e818c74a6e5973..c27eecb8f7baf7 100644 --- a/src/installer/tests/HostActivation.Tests/FrameworkDependentAppLaunch.cs +++ b/src/installer/tests/HostActivation.Tests/FrameworkDependentAppLaunch.cs @@ -26,7 +26,7 @@ public FrameworkDependentAppLaunch(SharedTestState fixture) [Fact] public void Muxer_Default() { - var dotnet = TestContext.BuiltDotNet; + var dotnet = HostTestContext.BuiltDotNet; var appDll = sharedTestState.App.AppDll; dotnet.Exec(appDll) @@ -55,7 +55,7 @@ public void Muxer_AssemblyWithDifferentFileExtension_Fails() File.Copy(appDll, appOtherExt, true); File.Delete(appDll); - TestContext.BuiltDotNet.Exec(appOtherExt) + HostTestContext.BuiltDotNet.Exec(appOtherExt) .CaptureStdErr() .Execute() .Should().Fail() @@ -117,7 +117,7 @@ public void Muxer_AssemblyWithExeExtension() fileStream.SetLength(fileStream.Position); } - TestContext.BuiltDotNet.Exec(appExe) + HostTestContext.BuiltDotNet.Exec(appExe) .CaptureStdOut() .CaptureStdErr() .Execute() @@ -141,7 +141,7 @@ public void Muxer_NonAssemblyWithExeExtension() } // If the app being run is not actually a managed assembly, it should come through as a load failure. - TestContext.BuiltDotNet.Exec(appExe) + HostTestContext.BuiltDotNet.Exec(appExe) .CaptureStdOut() .CaptureStdErr() .DisableDumps() // Expected to throw an exception @@ -154,7 +154,7 @@ public void Muxer_NonAssemblyWithExeExtension() public void Muxer_AltDirectorySeparatorChar() { var appDll = sharedTestState.App.AppDll.Replace(Path.DirectorySeparatorChar, Path.AltDirectorySeparatorChar); - TestContext.BuiltDotNet.Exec(appDll) + HostTestContext.BuiltDotNet.Exec(appDll) .CaptureStdErr() .CaptureStdOut() .Execute() @@ -173,7 +173,7 @@ public void Muxer_SpecificRuntimeConfig() var runtimeConfig = Path.Combine(subdirectory, Path.GetFileName(app.RuntimeConfigJson)); File.Move(app.RuntimeConfigJson, runtimeConfig, overwrite: true); - TestContext.BuiltDotNet.Exec("exec", "--runtimeconfig", runtimeConfig, app.AppDll) + HostTestContext.BuiltDotNet.Exec("exec", "--runtimeconfig", runtimeConfig, app.AppDll) .CaptureStdErr() .CaptureStdOut() .Execute() @@ -191,17 +191,19 @@ public void AppHost() Command.Create(appExe) .CaptureStdErr() .CaptureStdOut() - .DotNetRoot(TestContext.BuiltDotNet.BinPath, TestContext.BuildArchitecture) + .DotNetRoot(HostTestContext.BuiltDotNet.BinPath, HostTestContext.BuildArchitecture) .MultilevelLookup(false) .Execute() .Should().Pass() .And.HaveStdOutContaining("Hello World") - .And.HaveStdOutContaining(TestContext.MicrosoftNETCoreAppVersion); + .And.HaveStdOutContaining(HostTestContext.MicrosoftNETCoreAppVersion); } - [ConditionalFact(typeof(Binaries.CetCompat), nameof(Binaries.CetCompat.IsSupported))] + [Fact] public void AppHost_DisableCetCompat() { + Assert.SkipUnless(Binaries.CetCompat.IsSupported, "CET not supported on this platform"); + TestApp app = sharedTestState.App.Copy(); app.CreateAppHost(disableCetCompat: true); Assert.False(Binaries.CetCompat.IsMarkedCompatible(app.AppExe)); @@ -209,39 +211,38 @@ public void AppHost_DisableCetCompat() Command.Create(app.AppExe) .CaptureStdErr() .CaptureStdOut() - .DotNetRoot(TestContext.BuiltDotNet.BinPath, TestContext.BuildArchitecture) + .DotNetRoot(HostTestContext.BuiltDotNet.BinPath, HostTestContext.BuildArchitecture) .MultilevelLookup(false) .Execute() .Should().Pass() .And.HaveStdOutContaining("Hello World") - .And.HaveStdOutContaining(TestContext.MicrosoftNETCoreAppVersion); + .And.HaveStdOutContaining(HostTestContext.MicrosoftNETCoreAppVersion); } - [Fact] - [PlatformSpecific(TestPlatforms.Windows)] + [PlatformSpecificFact(TestPlatforms.Windows)] public void AppHost_DotNetRoot_DevicePath() { string appExe = sharedTestState.App.AppExe; - string dotnetPath = $@"\\?\{TestContext.BuiltDotNet.BinPath}"; + string dotnetPath = $@"\\?\{HostTestContext.BuiltDotNet.BinPath}"; Command.Create(appExe) .CaptureStdErr() .CaptureStdOut() - .DotNetRoot(dotnetPath, TestContext.BuildArchitecture) + .DotNetRoot(dotnetPath, HostTestContext.BuildArchitecture) .Execute() .Should().Pass() .And.HaveStdOutContaining("Hello World") - .And.HaveStdOutContaining(TestContext.MicrosoftNETCoreAppVersion); + .And.HaveStdOutContaining(HostTestContext.MicrosoftNETCoreAppVersion); - dotnetPath = $@"\\.\{TestContext.BuiltDotNet.BinPath}"; + dotnetPath = $@"\\.\{HostTestContext.BuiltDotNet.BinPath}"; Command.Create(appExe) .CaptureStdErr() .CaptureStdOut() - .DotNetRoot(dotnetPath, TestContext.BuildArchitecture) + .DotNetRoot(dotnetPath, HostTestContext.BuildArchitecture) .Execute() .Should().Pass() .And.HaveStdOutContaining("Hello World") - .And.HaveStdOutContaining(TestContext.MicrosoftNETCoreAppVersion); + .And.HaveStdOutContaining(HostTestContext.MicrosoftNETCoreAppVersion); } [Fact] @@ -263,7 +264,7 @@ public void RuntimeConfig_FilePath_Breaks_MAX_PATH_Threshold() File.Copy(file, Path.Combine(newDir, Path.GetFileName(file)), true); Command.Create(appExe) - .DotNetRoot(TestContext.BuiltDotNet.BinPath) + .DotNetRoot(HostTestContext.BuiltDotNet.BinPath) .EnableTracingAndCaptureOutputs() .MultilevelLookup(false) .Execute() @@ -274,7 +275,7 @@ public void RuntimeConfig_FilePath_Breaks_MAX_PATH_Threshold() [Fact] public void ComputedTPA_NoTrailingPathSeparator() { - TestContext.BuiltDotNet.Exec(sharedTestState.App.AppDll) + HostTestContext.BuiltDotNet.Exec(sharedTestState.App.AppDll) .EnableTracingAndCaptureOutputs() .Execute() .Should().Pass() @@ -290,11 +291,11 @@ public void MissingRuntimeConfig_Fails(bool useAppHost) if (useAppHost) { command = Command.Create(sharedTestState.MockApp.AppExe) - .DotNetRoot(TestContext.BuiltDotNet.BinPath, TestContext.BuildArchitecture); + .DotNetRoot(HostTestContext.BuiltDotNet.BinPath, HostTestContext.BuildArchitecture); } else { - command = TestContext.BuiltDotNet.Exec(sharedTestState.MockApp.AppDll); + command = HostTestContext.BuiltDotNet.Exec(sharedTestState.MockApp.AppDll); } command.EnableTracingAndCaptureOutputs() @@ -318,11 +319,11 @@ public void MissingFrameworkInRuntimeConfig_Fails(bool useAppHost) if (useAppHost) { command = Command.Create(app.AppExe) - .DotNetRoot(TestContext.BuiltDotNet.BinPath, TestContext.BuildArchitecture); + .DotNetRoot(HostTestContext.BuiltDotNet.BinPath, HostTestContext.BuildArchitecture); } else { - command = TestContext.BuiltDotNet.Exec(app.AppDll); + command = HostTestContext.BuiltDotNet.Exec(app.AppDll); } command.EnableTracingAndCaptureOutputs() @@ -339,13 +340,13 @@ public void MissingFrameworkName() TestApp app = sharedTestState.MockApp.Copy(); // Create a runtimeconfig.json with a framework that has no name property - var framework = new RuntimeConfig.Framework(null, TestContext.MicrosoftNETCoreAppVersion); + var framework = new RuntimeConfig.Framework(null, HostTestContext.MicrosoftNETCoreAppVersion); new RuntimeConfig(app.RuntimeConfigJson) .WithFramework(framework) .Save(); Command.Create(app.AppExe) - .DotNetRoot(TestContext.BuiltDotNet.BinPath) + .DotNetRoot(HostTestContext.BuiltDotNet.BinPath) .EnableTracingAndCaptureOutputs() .Execute() .Should().Fail() @@ -364,7 +365,7 @@ public void MissingFrameworkVersion() .Save(); Command.Create(app.AppExe) - .DotNetRoot(TestContext.BuiltDotNet.BinPath) + .DotNetRoot(HostTestContext.BuiltDotNet.BinPath) .EnableTracingAndCaptureOutputs() .Execute() .Should().Fail() @@ -385,18 +386,18 @@ public void AppHost_CLI_MissingRuntimeFramework_ErrorReportedInStdErr(bool missi if (missingHostfxr) { expectedErrorCode = Constants.ErrorCode.CoreHostLibMissingFailure; - expectedStdErr = $"&apphost_version={TestContext.MicrosoftNETCoreAppVersion}"; + expectedStdErr = $"&apphost_version={HostTestContext.MicrosoftNETCoreAppVersion}"; expectedUrlQuery = "missing_runtime=true&"; } else { - new DotNetBuilder(invalidDotNet.Location, TestContext.BuiltDotNet.BinPath, null) + new DotNetBuilder(invalidDotNet.Location, HostTestContext.BuiltDotNet.BinPath, null) .Build(); expectedErrorCode = Constants.ErrorCode.FrameworkMissingFailure; expectedStdErr = $"Framework: '{Constants.MicrosoftNETCoreApp}', " + - $"version '{TestContext.MicrosoftNETCoreAppVersion}' ({TestContext.BuildArchitecture})"; - expectedUrlQuery = $"framework={Constants.MicrosoftNETCoreApp}&framework_version={TestContext.MicrosoftNETCoreAppVersion}"; + $"version '{HostTestContext.MicrosoftNETCoreAppVersion}' ({HostTestContext.BuildArchitecture})"; + expectedUrlQuery = $"framework={Constants.MicrosoftNETCoreApp}&framework_version={HostTestContext.MicrosoftNETCoreAppVersion}"; } CommandResult result = Command.Create(sharedTestState.App.AppExe) @@ -407,14 +408,13 @@ public void AppHost_CLI_MissingRuntimeFramework_ErrorReportedInStdErr(bool missi result.Should().Fail() .And.HaveStdErrContaining($"https://aka.ms/dotnet-core-applaunch?{expectedUrlQuery}") - .And.HaveStdErrContaining($"&rid={TestContext.BuildRID}") + .And.HaveStdErrContaining($"&rid={HostTestContext.BuildRID}") .And.HaveStdErrContaining(expectedStdErr) .And.ExitWith(expectedErrorCode); } } - [Fact] - [PlatformSpecific(TestPlatforms.Windows)] // GUI app host is only supported on Windows. + [PlatformSpecificFact(TestPlatforms.Windows)] // GUI app host is only supported on Windows. public void AppHost_GUI_MissingRuntimeFramework_ErrorReportedInDialog() { TestApp app = sharedTestState.App.Copy(); @@ -425,11 +425,11 @@ public void AppHost_GUI_MissingRuntimeFramework_ErrorReportedInDialog() { string expectedErrorCode; string expectedUrlQuery; - new DotNetBuilder(invalidDotNet.Location, TestContext.BuiltDotNet.BinPath, null) + new DotNetBuilder(invalidDotNet.Location, HostTestContext.BuiltDotNet.BinPath, null) .Build(); expectedErrorCode = Constants.ErrorCode.FrameworkMissingFailure.ToString("x"); - expectedUrlQuery = $"framework={Constants.MicrosoftNETCoreApp}&framework_version={TestContext.MicrosoftNETCoreAppVersion}"; + expectedUrlQuery = $"framework={Constants.MicrosoftNETCoreApp}&framework_version={HostTestContext.MicrosoftNETCoreAppVersion}"; Command command = Command.Create(appExe) .EnableTracingAndCaptureOutputs() .DotNetRoot(invalidDotNet.Location) @@ -439,19 +439,18 @@ public void AppHost_GUI_MissingRuntimeFramework_ErrorReportedInDialog() WindowsUtils.WaitForPopupFromProcess(command.Process); command.Process.Kill(); - string expectedMissingFramework = $"'{Constants.MicrosoftNETCoreApp}', version '{TestContext.MicrosoftNETCoreAppVersion}' ({TestContext.BuildArchitecture})"; + string expectedMissingFramework = $"'{Constants.MicrosoftNETCoreApp}', version '{HostTestContext.MicrosoftNETCoreAppVersion}' ({HostTestContext.BuildArchitecture})"; var result = command.WaitForExit() .Should().Fail() .And.HaveStdErrContaining($"Showing error dialog for application: '{Path.GetFileName(appExe)}' - error code: 0x{expectedErrorCode}") .And.HaveStdErrContaining($"url: 'https://aka.ms/dotnet-core-applaunch?{expectedUrlQuery}") .And.HaveStdErrContaining("&gui=true") - .And.HaveStdErrContaining($"&rid={TestContext.BuildRID}") + .And.HaveStdErrContaining($"&rid={HostTestContext.BuildRID}") .And.HaveStdErrMatching($"details: (?>.|\\s)*{System.Text.RegularExpressions.Regex.Escape(expectedMissingFramework)}"); } } - [Fact] - [PlatformSpecific(TestPlatforms.Windows)] + [PlatformSpecificFact(TestPlatforms.Windows)] public void AppHost_GUI_MissingRuntime_ErrorReportedInDialog() { TestApp app = sharedTestState.App.Copy(); @@ -475,12 +474,11 @@ public void AppHost_GUI_MissingRuntime_ErrorReportedInDialog() .And.HaveStdErrContaining($"Showing error dialog for application: '{Path.GetFileName(appExe)}' - error code: 0x{expectedErrorCode}") .And.HaveStdErrContaining($"url: 'https://aka.ms/dotnet-core-applaunch?missing_runtime=true") .And.HaveStdErrContaining("gui=true") - .And.HaveStdErrContaining($"&apphost_version={TestContext.MicrosoftNETCoreAppVersion}"); + .And.HaveStdErrContaining($"&apphost_version={HostTestContext.MicrosoftNETCoreAppVersion}"); } } - [Fact] - [PlatformSpecific(TestPlatforms.Windows)] // GUI app host is only supported on Windows. + [PlatformSpecificFact(TestPlatforms.Windows)] // GUI app host is only supported on Windows. public void AppHost_GUI_NoCustomErrorWriter_FrameworkMissing_ErrorReportedInDialog() { TestApp app = sharedTestState.App.Copy(); @@ -490,14 +488,14 @@ public void AppHost_GUI_NoCustomErrorWriter_FrameworkMissing_ErrorReportedInDial // The mockhostfxrFrameworkMissingFailure folder name is used by mock hostfxr to return the appropriate error code using (var dotnetWithMockHostFxr = TestArtifact.Create("mockhostfxrFrameworkMissingFailure")) { - var dotnet = new DotNetBuilder(dotnetWithMockHostFxr.Location, TestContext.BuiltDotNet.BinPath, null) + var dotnet = new DotNetBuilder(dotnetWithMockHostFxr.Location, HostTestContext.BuiltDotNet.BinPath, null) .RemoveHostFxr() .AddMockHostFxr(new Version(2, 2, 0)) .Build(); Command command = Command.Create(appExe) .EnableTracingAndCaptureOutputs() - .DotNetRoot(dotnet.BinPath, TestContext.BuildArchitecture) + .DotNetRoot(dotnet.BinPath, HostTestContext.BuildArchitecture) .MultilevelLookup(false) .Start(); @@ -514,8 +512,7 @@ public void AppHost_GUI_NoCustomErrorWriter_FrameworkMissing_ErrorReportedInDial } } - [Fact] - [PlatformSpecific(TestPlatforms.Windows)] // GUI app host is only supported on Windows. + [PlatformSpecificFact(TestPlatforms.Windows)] // GUI app host is only supported on Windows. public void AppHost_GUI_DisabledGUIErrors_DialogNotShown() { TestApp app = sharedTestState.App.Copy(); diff --git a/src/installer/tests/HostActivation.Tests/FrameworkResolution/FrameworkResolution.cs b/src/installer/tests/HostActivation.Tests/FrameworkResolution/FrameworkResolution.cs index b5e993a100a31d..4a6178479c2852 100644 --- a/src/installer/tests/HostActivation.Tests/FrameworkResolution/FrameworkResolution.cs +++ b/src/installer/tests/HostActivation.Tests/FrameworkResolution/FrameworkResolution.cs @@ -74,7 +74,7 @@ public void FrameworkResolutionError_ListOtherArchitectures() string arch = otherArchs[i]; // Create a .NET install with Microsoft.NETCoreApp at the registered location - var dotnet = new DotNetBuilder(otherArchArtifact.Location, TestContext.BuiltDotNet.BinPath, arch) + var dotnet = new DotNetBuilder(otherArchArtifact.Location, HostTestContext.BuiltDotNet.BinPath, arch) .AddMicrosoftNETCoreAppFrameworkMockHostPolicy(requestedVersion) .Build(); installLocations[i] = (arch, dotnet.BinPath); @@ -93,7 +93,7 @@ public void FrameworkResolutionError_ListOtherArchitectures() // Error message should list framework found for other architectures foreach ((string arch, string path) in installLocations) { - if (arch == TestContext.BuildArchitecture) + if (arch == HostTestContext.BuildArchitecture) continue; string expectedPath = System.Text.RegularExpressions.Regex.Escape(Path.Combine(path, "shared", MicrosoftNETCoreApp)); @@ -139,7 +139,7 @@ public void DisabledVersions(string requestedVersion, string disabledVersions, s {value} at [{SharedState.InstalledDotNet.SharedFxPath}] Disabled via {Constants.DisableRuntimeVersions.EnvironmentVariable} environment variable """); - + } } } diff --git a/src/installer/tests/HostActivation.Tests/FrameworkResolution/FrameworkResolutionBase.cs b/src/installer/tests/HostActivation.Tests/FrameworkResolution/FrameworkResolutionBase.cs index 7670ffa18e784a..27f932f4a3f4c3 100644 --- a/src/installer/tests/HostActivation.Tests/FrameworkResolution/FrameworkResolutionBase.cs +++ b/src/installer/tests/HostActivation.Tests/FrameworkResolution/FrameworkResolutionBase.cs @@ -97,7 +97,7 @@ public SharedTestStateBase() public DotNetBuilder DotNet(string name) { - return new DotNetBuilder(_baseDirArtifact.Location, TestContext.BuiltDotNet.BinPath, name); + return new DotNetBuilder(_baseDirArtifact.Location, HostTestContext.BuiltDotNet.BinPath, name); } public TestApp CreateFrameworkReferenceApp() diff --git a/src/installer/tests/HostActivation.Tests/FrameworkResolution/IncludedFrameworksSettings.cs b/src/installer/tests/HostActivation.Tests/FrameworkResolution/IncludedFrameworksSettings.cs index a46105cb933c10..fd31ff4090621c 100644 --- a/src/installer/tests/HostActivation.Tests/FrameworkResolution/IncludedFrameworksSettings.cs +++ b/src/installer/tests/HostActivation.Tests/FrameworkResolution/IncludedFrameworksSettings.cs @@ -48,7 +48,7 @@ public void SelfContainedCanHaveIncludedFrameworks() [Fact] public void MissingName() { - var framework = new RuntimeConfig.Framework(null, TestContext.MicrosoftNETCoreAppVersion); + var framework = new RuntimeConfig.Framework(null, HostTestContext.MicrosoftNETCoreAppVersion); RunSelfContainedTest( new TestSettings() .WithRuntimeConfigCustomizer(runtimeConfig => runtimeConfig diff --git a/src/installer/tests/HostActivation.Tests/FrameworkResolution/MultilevelLookup.cs b/src/installer/tests/HostActivation.Tests/FrameworkResolution/MultilevelLookup.cs index 6933b5a2fc0458..b1fb135e67b62a 100644 --- a/src/installer/tests/HostActivation.Tests/FrameworkResolution/MultilevelLookup.cs +++ b/src/installer/tests/HostActivation.Tests/FrameworkResolution/MultilevelLookup.cs @@ -13,8 +13,6 @@ namespace Microsoft.DotNet.CoreSetup.Test.HostActivation.FrameworkResolution { - // Multi-level lookup was only supported on Windows. - [PlatformSpecific(TestPlatforms.Windows)] public class MultilevelLookup : FrameworkResolutionBase, IClassFixture @@ -23,6 +21,8 @@ public class MultilevelLookup : public MultilevelLookup(SharedTestState sharedState) { + Assert.SkipUnless(OperatingSystem.IsWindows(), "Multi-level lookup is only supported on Windows"); + SharedState = sharedState; } diff --git a/src/installer/tests/HostActivation.Tests/HostActivation.Tests.csproj b/src/installer/tests/HostActivation.Tests/HostActivation.Tests.csproj index b4e00bca436f63..a9148408fc8b57 100644 --- a/src/installer/tests/HostActivation.Tests/HostActivation.Tests.csproj +++ b/src/installer/tests/HostActivation.Tests/HostActivation.Tests.csproj @@ -1,6 +1,7 @@ + Exe $(TestInfraTargetFramework) HostActivation.Tests true @@ -9,6 +10,7 @@ $(NoWarn);NU1511 + XUnitV3 diff --git a/src/installer/tests/HostActivation.Tests/HostCommands.cs b/src/installer/tests/HostActivation.Tests/HostCommands.cs index 5e5d03ba7f2282..5c684a9129f4a8 100644 --- a/src/installer/tests/HostActivation.Tests/HostCommands.cs +++ b/src/installer/tests/HostActivation.Tests/HostCommands.cs @@ -41,9 +41,9 @@ public void Info() .Should().Pass() .And.HaveStdOutContaining(expectedSdksOutput) .And.HaveStdOutContaining(expectedRuntimesOutput) - .And.HaveStdOutMatching($@"Architecture:\s*{TestContext.BuildArchitecture}") + .And.HaveStdOutMatching($@"Architecture:\s*{HostTestContext.BuildArchitecture}") // If an SDK exists, we rely on it to print the RID. The host should not print it again. - .And.NotHaveStdOutMatching($@"RID:\s*{TestContext.BuildRID}"); + .And.NotHaveStdOutMatching($@"RID:\s*{HostTestContext.BuildRID}"); } [Fact] @@ -57,23 +57,23 @@ No SDKs were found string expectedRuntimesOutput = $""" .NET runtimes installed: - {GetListRuntimesOutput(TestContext.BuiltDotNet.BinPath, [TestContext.MicrosoftNETCoreAppVersion], " ")} + {GetListRuntimesOutput(HostTestContext.BuiltDotNet.BinPath, [HostTestContext.MicrosoftNETCoreAppVersion], " ")} """; - TestContext.BuiltDotNet.Exec("--info") + HostTestContext.BuiltDotNet.Exec("--info") .CaptureStdOut() .Execute() .Should().Pass() .And.HaveStdOutContaining(expectedSdksOutput) .And.HaveStdOutContaining(expectedRuntimesOutput) - .And.HaveStdOutMatching($@"Architecture:\s*{TestContext.BuildArchitecture}") - .And.HaveStdOutMatching($@"RID:\s*{TestContext.BuildRID}"); + .And.HaveStdOutMatching($@"Architecture:\s*{HostTestContext.BuildArchitecture}") + .And.HaveStdOutMatching($@"RID:\s*{HostTestContext.BuildRID}"); } [Fact] public void Info_Utf8Path() { string installLocation = Encoding.UTF8.GetString("utf8-龯蝌灋齅ㄥ䶱"u8); - DotNetCli dotnet = new DotNetBuilder(SharedState.Artifact.Location, TestContext.BuiltDotNet.BinPath, installLocation) + DotNetCli dotnet = new DotNetBuilder(SharedState.Artifact.Location, HostTestContext.BuiltDotNet.BinPath, installLocation) .Build(); dotnet.Exec("--info") @@ -87,7 +87,7 @@ public void Info_Utf8Path() [Fact] public void Info_ListEnvironment() { - var command = TestContext.BuiltDotNet.Exec("--info") + var command = HostTestContext.BuiltDotNet.Exec("--info") .CaptureStdOut(); // Add DOTNET_ROOT environment variables @@ -159,7 +159,7 @@ public void Info_ListEnvironment() public void Info_ListEnvironment_LegacyPrefixDetection() { string comPlusEnvVar = "COMPlus_ReadyToRun"; - TestContext.BuiltDotNet.Exec("--info") + HostTestContext.BuiltDotNet.Exec("--info") .EnvironmentVariable(comPlusEnvVar, "0") .CaptureStdOut() .Execute() @@ -175,7 +175,7 @@ public void Info_GlobalJson_InvalidJson() using (TestArtifact workingDir = TestArtifact.Create(nameof(Info_GlobalJson_InvalidJson))) { string globalJsonPath = GlobalJson.Write(workingDir.Location, "{ \"sdk\": { }"); - TestContext.BuiltDotNet.Exec("--info") + HostTestContext.BuiltDotNet.Exec("--info") .WorkingDirectory(workingDir.Location) .CaptureStdOut().CaptureStdErr() .Execute() @@ -196,7 +196,7 @@ public void Info_GlobalJson_InvalidData(string version) using (TestArtifact workingDir = TestArtifact.Create(nameof(Info_GlobalJson_InvalidData))) { string globalJsonPath = GlobalJson.CreateWithVersion(workingDir.Location, version); - TestContext.BuiltDotNet.Exec("--info") + HostTestContext.BuiltDotNet.Exec("--info") .WorkingDirectory(workingDir.Location) .CaptureStdOut().CaptureStdErr() .Execute() @@ -216,7 +216,7 @@ public void Info_GlobalJson_NonExistentFeatureBand(string version) using (TestArtifact workingDir = TestArtifact.Create(nameof(Info_GlobalJson_NonExistentFeatureBand))) { string globalJsonPath = GlobalJson.CreateWithVersion(workingDir.Location, version); - var result = TestContext.BuiltDotNet.Exec("--info") + var result = HostTestContext.BuiltDotNet.Exec("--info") .WorkingDirectory(workingDir.Location) .CaptureStdOut().CaptureStdErr() .Execute() @@ -289,7 +289,7 @@ public void ListRuntimes_OtherArchitecture(bool useRegisteredLocation) public void ListRuntimes_OtherArchitecture_NoInstalls() { // Non-host architecture - arm64 if current architecture is x64, otherwise x64 - string arch = TestContext.BuildArchitecture == "x64" ? "arm64" : "x64"; + string arch = HostTestContext.BuildArchitecture == "x64" ? "arm64" : "x64"; using (var registeredInstallLocationOverride = new RegisteredInstallLocationOverride(SharedState.DotNet.GreatestVersionHostFxrFilePath)) { // Register a location that should have no runtimes installed @@ -306,7 +306,7 @@ public void ListRuntimes_OtherArchitecture_NoInstalls() [Fact] public void ListRuntimes_UnknownArchitecture() { - TestContext.BuiltDotNet.Exec("--list-runtimes", "--arch", "invalid") + HostTestContext.BuiltDotNet.Exec("--list-runtimes", "--arch", "invalid") .CaptureStdOut() .Execute() .Should().Fail() @@ -358,7 +358,7 @@ public void ListSdks_OtherArchitecture(bool useRegisteredLocation) public void ListSdks_OtherArchitecture_NoInstalls() { // Non-host architecture - arm64 if current architecture is x64, otherwise x64 - string arch = TestContext.BuildArchitecture == "x64" ? "arm64" : "x64"; + string arch = HostTestContext.BuildArchitecture == "x64" ? "arm64" : "x64"; using (var registeredInstallLocationOverride = new RegisteredInstallLocationOverride(SharedState.DotNet.GreatestVersionHostFxrFilePath)) { // Register a location that should have no SDKs installed @@ -375,7 +375,7 @@ public void ListSdks_OtherArchitecture_NoInstalls() [Fact] public void ListSdks_UnknownArchitecture() { - TestContext.BuiltDotNet.Exec("--list-sdks", "--arch", "invalid") + HostTestContext.BuiltDotNet.Exec("--list-sdks", "--arch", "invalid") .CaptureStdOut() .Execute() .Should().Fail() @@ -409,7 +409,7 @@ public SharedTestState() { Artifact = TestArtifact.Create(nameof(HostCommands)); - var builder = new DotNetBuilder(Artifact.Location, TestContext.BuiltDotNet.BinPath, "exe"); + var builder = new DotNetBuilder(Artifact.Location, HostTestContext.BuiltDotNet.BinPath, "exe"); foreach (string version in InstalledVersions) { builder.AddMicrosoftNETCoreAppFrameworkMockHostPolicy(version); @@ -419,7 +419,7 @@ public SharedTestState() DotNet = builder.Build(); // Add runtimes and SDKs for other architectures - string[] otherArchs = new[] { "arm64", "x64", "x86" }.Where(a => a != TestContext.BuildArchitecture).ToArray(); + string[] otherArchs = new[] { "arm64", "x64", "x86" }.Where(a => a != HostTestContext.BuildArchitecture).ToArray(); OtherArchInstallLocations = new (string, string)[otherArchs.Length]; for (int i = 0; i < otherArchs.Length; i++) { diff --git a/src/installer/tests/HostActivation.Tests/HostVersionCompatibility.cs b/src/installer/tests/HostActivation.Tests/HostVersionCompatibility.cs index 37a9a4b24e2168..693d456de0fea5 100644 --- a/src/installer/tests/HostActivation.Tests/HostVersionCompatibility.cs +++ b/src/installer/tests/HostActivation.Tests/HostVersionCompatibility.cs @@ -30,8 +30,8 @@ private void LatestHost_OldRuntime_BackwardsCompatible(TestApp previousVersionAp string appExe = app.AppExe; RuntimeConfig appConfig = RuntimeConfig.FromFile(app.RuntimeConfigJson); - Assert.NotEqual(appConfig.Tfm, TestContext.Tfm); - Assert.NotEqual(appConfig.GetIncludedFramework(Constants.MicrosoftNETCoreApp).Version, TestContext.MicrosoftNETCoreAppVersion); + Assert.NotEqual(appConfig.Tfm, HostTestContext.Tfm); + Assert.NotEqual(appConfig.GetIncludedFramework(Constants.MicrosoftNETCoreApp).Version, HostTestContext.MicrosoftNETCoreAppVersion); // Use the newer apphost // This emulates the case when: @@ -43,7 +43,7 @@ private void LatestHost_OldRuntime_BackwardsCompatible(TestApp previousVersionAp .Execute() .Should().Pass() .And.HaveStdOutContaining("Hello World") - .And.HaveStdErrContaining($"--- Invoked apphost [version: {TestContext.MicrosoftNETCoreAppVersion}"); + .And.HaveStdErrContaining($"--- Invoked apphost [version: {HostTestContext.MicrosoftNETCoreAppVersion}"); // Use the newer apphost and hostFxr // This emulates the case when: @@ -55,7 +55,7 @@ private void LatestHost_OldRuntime_BackwardsCompatible(TestApp previousVersionAp .Execute() .Should().Pass() .And.HaveStdOutContaining("Hello World") - .And.HaveStdErrContaining($"--- Invoked apphost [version: {TestContext.MicrosoftNETCoreAppVersion}"); + .And.HaveStdErrContaining($"--- Invoked apphost [version: {HostTestContext.MicrosoftNETCoreAppVersion}"); } [Fact] @@ -71,8 +71,8 @@ private void OldHost_LatestRuntime_ForwardCompatible(TestApp previousVersionApp) RuntimeConfig previousAppConfig = RuntimeConfig.FromFile(previousVersionApp.RuntimeConfigJson); string previousVersion = previousAppConfig.GetIncludedFramework(Constants.MicrosoftNETCoreApp).Version; - Assert.NotEqual(TestContext.Tfm, previousAppConfig.Tfm); - Assert.NotEqual(TestContext.MicrosoftNETCoreAppVersion, previousVersion); + Assert.NotEqual(HostTestContext.Tfm, previousAppConfig.Tfm); + Assert.NotEqual(HostTestContext.MicrosoftNETCoreAppVersion, previousVersion); // Use the older apphost // This emulates the case when: diff --git a/src/installer/tests/HostActivation.Tests/InstallLocation.cs b/src/installer/tests/HostActivation.Tests/InstallLocation.cs index e85e8043177d01..8d71c05aec56ae 100644 --- a/src/installer/tests/HostActivation.Tests/InstallLocation.cs +++ b/src/installer/tests/HostActivation.Tests/InstallLocation.cs @@ -25,39 +25,39 @@ public InstallLocation(SharedTestState fixture) [Fact] public void EnvironmentVariable_CurrentArchitectureIsUsedIfEnvVarSet() { - var arch = TestContext.BuildArchitecture.ToUpper(); + var arch = HostTestContext.BuildArchitecture.ToUpper(); Command.Create(sharedTestState.App.AppExe) .EnableTracingAndCaptureOutputs() - .DotNetRoot(TestContext.BuiltDotNet.BinPath, arch) + .DotNetRoot(HostTestContext.BuiltDotNet.BinPath, arch) .Execute() .Should().Pass() - .And.HaveUsedDotNetRootInstallLocation(TestContext.BuiltDotNet.BinPath, TestContext.BuildRID, arch); + .And.HaveUsedDotNetRootInstallLocation(HostTestContext.BuiltDotNet.BinPath, HostTestContext.BuildRID, arch); } [Fact] public void EnvironmentVariable_IfNoArchSpecificEnvVarIsFoundDotnetRootIsUsed() { - var arch = TestContext.BuildArchitecture.ToUpper(); + var arch = HostTestContext.BuildArchitecture.ToUpper(); Command.Create(sharedTestState.App.AppExe) .EnableTracingAndCaptureOutputs() - .DotNetRoot(TestContext.BuiltDotNet.BinPath) + .DotNetRoot(HostTestContext.BuiltDotNet.BinPath) .Execute() .Should().Pass() - .And.HaveUsedDotNetRootInstallLocation(TestContext.BuiltDotNet.BinPath, TestContext.BuildRID); + .And.HaveUsedDotNetRootInstallLocation(HostTestContext.BuiltDotNet.BinPath, HostTestContext.BuildRID); } [Fact] public void EnvironmentVariable_ArchSpecificDotnetRootIsUsedOverDotnetRoot() { - var arch = TestContext.BuildArchitecture.ToUpper(); - var dotnet = TestContext.BuiltDotNet.BinPath; + var arch = HostTestContext.BuildArchitecture.ToUpper(); + var dotnet = HostTestContext.BuiltDotNet.BinPath; Command.Create(sharedTestState.App.AppExe) .EnableTracingAndCaptureOutputs() .DotNetRoot("non_existent_path") .DotNetRoot(dotnet, arch) .Execute() .Should().Pass() - .And.HaveUsedDotNetRootInstallLocation(dotnet, TestContext.BuildRID, arch) + .And.HaveUsedDotNetRootInstallLocation(dotnet, HostTestContext.BuildRID, arch) .And.NotHaveStdErrContaining("Using environment variable DOTNET_ROOT="); } @@ -66,8 +66,8 @@ public void EnvironmentVariable_DotNetRootIsUsedOverInstallLocationIfSet() { var app = sharedTestState.TestBehaviourEnabledApp; var appExe = app.AppExe; - var arch = TestContext.BuildArchitecture.ToUpper(); - var dotnet = TestContext.BuiltDotNet.BinPath; + var arch = HostTestContext.BuildArchitecture.ToUpper(); + var dotnet = HostTestContext.BuiltDotNet.BinPath; using (var registeredInstallLocationOverride = new RegisteredInstallLocationOverride(appExe)) { @@ -79,7 +79,7 @@ public void EnvironmentVariable_DotNetRootIsUsedOverInstallLocationIfSet() .DotNetRoot(dotnet, arch) .Execute() .Should().Pass() - .And.HaveUsedDotNetRootInstallLocation(dotnet, TestContext.BuildRID, arch) + .And.HaveUsedDotNetRootInstallLocation(dotnet, HostTestContext.BuildRID, arch) .And.NotHaveStdErrContaining("Using global install location"); } } @@ -94,12 +94,12 @@ public void EnvironmentVariable_DotnetRootPathDoesNotExist() .MultilevelLookup(false) .EnvironmentVariable( Constants.TestOnlyEnvironmentVariables.GloballyRegisteredPath, - TestContext.BuiltDotNet.BinPath) + HostTestContext.BuiltDotNet.BinPath) .Execute() .Should().Pass() .And.HaveStdErrContaining("Did not find [DOTNET_ROOT] directory [non_existent_path]") // If DOTNET_ROOT points to a folder that does not exist, we fall back to the global install path. - .And.HaveUsedGlobalInstallLocation(TestContext.BuiltDotNet.BinPath) + .And.HaveUsedGlobalInstallLocation(HostTestContext.BuiltDotNet.BinPath) .And.HaveStdOutContaining("Hello World"); } @@ -113,10 +113,10 @@ public void EnvironmentVariable_DotnetRootPathExistsButHasNoHost() .MultilevelLookup(false) .EnvironmentVariable( Constants.TestOnlyEnvironmentVariables.GloballyRegisteredPath, - TestContext.BuiltDotNet.BinPath) + HostTestContext.BuiltDotNet.BinPath) .Execute() .Should().Fail() - .And.HaveUsedDotNetRootInstallLocation(app.Location, TestContext.BuildRID) + .And.HaveUsedDotNetRootInstallLocation(app.Location, HostTestContext.BuildRID) // If DOTNET_ROOT points to a folder that exists we assume that there's a dotnet installation in it .And.HaveStdErrContaining($"The required library {Binaries.HostFxr.FileName} could not be found."); } @@ -132,11 +132,11 @@ public void DefaultInstallLocation() Command.Create(app.AppExe) .EnableTracingAndCaptureOutputs() .ApplyRegisteredInstallLocationOverride(registeredInstallLocationOverride) - .EnvironmentVariable(Constants.TestOnlyEnvironmentVariables.DefaultInstallPath, TestContext.BuiltDotNet.BinPath) + .EnvironmentVariable(Constants.TestOnlyEnvironmentVariables.DefaultInstallPath, HostTestContext.BuiltDotNet.BinPath) .DotNetRoot(null) .Execute() .Should().Pass() - .And.HaveUsedGlobalInstallLocation(TestContext.BuiltDotNet.BinPath); + .And.HaveUsedGlobalInstallLocation(HostTestContext.BuiltDotNet.BinPath); } } @@ -147,7 +147,7 @@ public void RegisteredInstallLocation() using (var registeredInstallLocationOverride = new RegisteredInstallLocationOverride(app.AppExe)) { registeredInstallLocationOverride.SetInstallLocation( - (TestContext.BuildArchitecture, TestContext.BuiltDotNet.BinPath)); + (HostTestContext.BuildArchitecture, HostTestContext.BuiltDotNet.BinPath)); Command.Create(app.AppExe) .EnableTracingAndCaptureOutputs() @@ -155,8 +155,8 @@ public void RegisteredInstallLocation() .DotNetRoot(null) .Execute() .Should().Pass() - .And.HaveUsedRegisteredInstallLocation(TestContext.BuiltDotNet.BinPath) - .And.HaveUsedGlobalInstallLocation(TestContext.BuiltDotNet.BinPath); + .And.HaveUsedRegisteredInstallLocation(HostTestContext.BuiltDotNet.BinPath) + .And.HaveUsedGlobalInstallLocation(HostTestContext.BuiltDotNet.BinPath); } } @@ -166,7 +166,7 @@ public void RegisteredInstallLocation_ArchSpecificLocationIsPickedFirst() var app = sharedTestState.TestBehaviourEnabledApp; var arch1 = "someArch"; var path1 = "x/y/z"; - var arch2 = TestContext.BuildArchitecture; + var arch2 = HostTestContext.BuildArchitecture; var path2 = "a/b/c"; using (var registeredInstallLocationOverride = new RegisteredInstallLocationOverride(app.AppExe)) @@ -248,7 +248,7 @@ public void RegisteredInstallLocation_DotNetInfo_ListOtherArchitectures() { using (var testArtifact = TestArtifact.Create("listOtherArchs")) { - var dotnet = new DotNetBuilder(testArtifact.Location, TestContext.BuiltDotNet.BinPath, "exe").Build(); + var dotnet = new DotNetBuilder(testArtifact.Location, HostTestContext.BuiltDotNet.BinPath, "exe").Build(); using (var registeredInstallLocationOverride = new RegisteredInstallLocationOverride(dotnet.GreatestVersionHostFxrFilePath)) { var installLocations = new (string, string)[] { @@ -276,7 +276,7 @@ public void RegisteredInstallLocation_DotNetInfo_ListOtherArchitectures() pathOverride = System.Text.RegularExpressions.Regex.Escape(pathOverride); foreach ((string arch, string path) in installLocations) { - if (arch == TestContext.BuildArchitecture) + if (arch == HostTestContext.BuildArchitecture) continue; result.Should() @@ -315,13 +315,13 @@ public void NotFound() .And.HaveStdErrContaining( $""" Environment variable: - DOTNET_ROOT_{TestContext.BuildArchitecture.ToUpper()} = + DOTNET_ROOT_{HostTestContext.BuildArchitecture.ToUpper()} = DOTNET_ROOT = """) .And.HaveStdErrMatching( $""" Registered location: - {System.Text.RegularExpressions.Regex.Escape(registeredLocationOverride)}.*{TestContext.BuildArchitecture}.* = + {System.Text.RegularExpressions.Regex.Escape(registeredLocationOverride)}.*{HostTestContext.BuildArchitecture}.* = """) .And.HaveStdErrContaining( $""" @@ -360,7 +360,7 @@ public void SearchOptions(SearchLocation searchLocation) CommandResult result; using (var installOverride = new RegisteredInstallLocationOverride(app.AppExe)) { - installOverride.SetInstallLocation([(TestContext.BuildArchitecture, globalLocation)]); + installOverride.SetInstallLocation([(HostTestContext.BuildArchitecture, globalLocation)]); result = Command.Create(app.AppExe) .EnableTracingAndCaptureOutputs() .ApplyRegisteredInstallLocationOverride(installOverride) @@ -377,7 +377,7 @@ public void SearchOptions(SearchLocation searchLocation) result.Should().HaveUsedAppRelativeInstallLocation(appRelativeLocation); break; case SearchLocation.EnvironmentVariable: - result.Should().HaveUsedDotNetRootInstallLocation(envLocation, TestContext.BuildRID); + result.Should().HaveUsedDotNetRootInstallLocation(envLocation, HostTestContext.BuildRID); break; case SearchLocation.Global: result.Should().HaveUsedGlobalInstallLocation(globalLocation); @@ -463,7 +463,7 @@ public void SearchOptions_Precedence(SearchLocation expectedResult) CommandResult result; using (var installOverride = new RegisteredInstallLocationOverride(app.AppExe)) { - installOverride.SetInstallLocation([(TestContext.BuildArchitecture, globalLocation)]); + installOverride.SetInstallLocation([(HostTestContext.BuildArchitecture, globalLocation)]); result = Command.Create(app.AppExe) .EnableTracingAndCaptureOutputs() .ApplyRegisteredInstallLocationOverride(installOverride) @@ -480,7 +480,7 @@ public void SearchOptions_Precedence(SearchLocation expectedResult) result.Should().HaveUsedAppRelativeInstallLocation(appRelativeLocation); break; case SearchLocation.EnvironmentVariable: - result.Should().HaveUsedDotNetRootInstallLocation(envLocation, TestContext.BuildRID); + result.Should().HaveUsedDotNetRootInstallLocation(envLocation, HostTestContext.BuildRID); break; case SearchLocation.Global: result.Should().HaveUsedGlobalInstallLocation(globalLocation); diff --git a/src/installer/tests/HostActivation.Tests/InvalidHost.cs b/src/installer/tests/HostActivation.Tests/InvalidHost.cs index 74e765df798fdb..2460481d6236b5 100644 --- a/src/installer/tests/HostActivation.Tests/InvalidHost.cs +++ b/src/installer/tests/HostActivation.Tests/InvalidHost.cs @@ -34,8 +34,7 @@ public void AppHost_NotBound() .And.ExitWith(Constants.ErrorCode.AppHostExeNotBoundFailure); } - [Fact] - [PlatformSpecific(TestPlatforms.Windows)] // GUI app host is only supported on Windows. + [PlatformSpecificFact(TestPlatforms.Windows)] // GUI app host is only supported on Windows. public void AppHost_NotBound_GUI() { Command.Create(sharedTestState.UnboundAppHostGUI) @@ -46,8 +45,7 @@ public void AppHost_NotBound_GUI() .And.HaveStdErrContaining("This executable is not bound to a managed DLL to execute."); } - [Fact] - [PlatformSpecific(TestPlatforms.Windows)] // GUI app host is only supported on Windows. + [PlatformSpecificFact(TestPlatforms.Windows)] // GUI app host is only supported on Windows. public void AppHost_NotBound_GUI_TraceFile() { string traceFilePath; diff --git a/src/installer/tests/HostActivation.Tests/MachOHostSigningTests.cs b/src/installer/tests/HostActivation.Tests/MachOHostSigningTests.cs index 70bc3b86a51eff..cf401da3850ba7 100644 --- a/src/installer/tests/HostActivation.Tests/MachOHostSigningTests.cs +++ b/src/installer/tests/HostActivation.Tests/MachOHostSigningTests.cs @@ -15,8 +15,7 @@ namespace HostActivation.Tests { public class MachOHostSigningTests { - [Fact] - [PlatformSpecific(TestPlatforms.OSX)] + [PlatformSpecificFact(TestPlatforms.OSX)] public void SignedAppHostRuns() { using var testDirectory = TestArtifact.Create(nameof(SignedAppHostRuns)); diff --git a/src/installer/tests/HostActivation.Tests/NativeHostApis.cs b/src/installer/tests/HostActivation.Tests/NativeHostApis.cs index 131133124159cf..3ffe6b75eff6ff 100644 --- a/src/installer/tests/HostActivation.Tests/NativeHostApis.cs +++ b/src/installer/tests/HostActivation.Tests/NativeHostApis.cs @@ -109,7 +109,7 @@ public void Hostfxr_get_available_sdks() string expectedList = string.Join(';', f.LocalSdkPaths); string api = ApiNames.hostfxr_get_available_sdks; - TestContext.BuiltDotNet.Exec(sharedTestState.HostApiInvokerApp.AppDll, api, f.ExeDir) + HostTestContext.BuiltDotNet.Exec(sharedTestState.HostApiInvokerApp.AppDll, api, f.ExeDir) .EnableTracingAndCaptureOutputs() .Execute() .Should().Pass() @@ -130,7 +130,7 @@ public void Hostfxr_resolve_sdk2_NoGlobalJson() }); string api = ApiNames.hostfxr_resolve_sdk2; - TestContext.BuiltDotNet.Exec(sharedTestState.HostApiInvokerApp.AppDll, api, f.ExeDir, NoGlobalJson, "0") + HostTestContext.BuiltDotNet.Exec(sharedTestState.HostApiInvokerApp.AppDll, api, f.ExeDir, NoGlobalJson, "0") .EnableTracingAndCaptureOutputs() .Execute() .Should().Pass() @@ -151,7 +151,7 @@ public void Hostfxr_resolve_sdk2_NoGlobalJson_DisallowPrerelease() }); string api = ApiNames.hostfxr_resolve_sdk2; - TestContext.BuiltDotNet.Exec(sharedTestState.HostApiInvokerApp.AppDll, api, f.ExeDir, NoGlobalJson, "disallow_prerelease") + HostTestContext.BuiltDotNet.Exec(sharedTestState.HostApiInvokerApp.AppDll, api, f.ExeDir, NoGlobalJson, "disallow_prerelease") .EnableTracingAndCaptureOutputs() .Execute() .Should().Pass() @@ -175,7 +175,7 @@ public void Hostfxr_resolve_sdk2_NoGlobalJson_NoWriteToStdResolvesTheSame(bool d string api = ApiNames.hostfxr_resolve_sdk2; string flags = do_not_print_errors ? "disallow_prerelease,do_not_print_errors" : "disallow_prerelease"; - TestContext.BuiltDotNet.Exec(sharedTestState.HostApiInvokerApp.AppDll, api, f.ExeDir, NoGlobalJson, flags) + HostTestContext.BuiltDotNet.Exec(sharedTestState.HostApiInvokerApp.AppDll, api, f.ExeDir, NoGlobalJson, flags) .EnableTracingAndCaptureOutputs() .Execute() .Should().Pass() @@ -204,7 +204,7 @@ public void Hostfxr_resolve_sdk2_GlobalJson_DisallowPrerelease() }); string api = ApiNames.hostfxr_resolve_sdk2; - TestContext.BuiltDotNet.Exec(sharedTestState.HostApiInvokerApp.AppDll, api, f.ExeDir, workingDir.Location, "disallow_prerelease") + HostTestContext.BuiltDotNet.Exec(sharedTestState.HostApiInvokerApp.AppDll, api, f.ExeDir, workingDir.Location, "disallow_prerelease") .EnableTracingAndCaptureOutputs() .Execute() .Should().Pass() @@ -235,7 +235,7 @@ public void Hostfxr_resolve_sdk2_GlobalJson_Paths() }); string api = ApiNames.hostfxr_resolve_sdk2; - TestContext.BuiltDotNet.Exec(sharedTestState.HostApiInvokerApp.AppDll, api, f.ExeDir, workingDir.Location, "0") + HostTestContext.BuiltDotNet.Exec(sharedTestState.HostApiInvokerApp.AppDll, api, f.ExeDir, workingDir.Location, "0") .EnableTracingAndCaptureOutputs() .Execute() .Should().Pass() @@ -261,7 +261,7 @@ public void Hostfxr_resolve_sdk2_GlobalJson_InvalidJson() }); string api = ApiNames.hostfxr_resolve_sdk2; - TestContext.BuiltDotNet.Exec(sharedTestState.HostApiInvokerApp.AppDll, api, f.ExeDir, workingDir.Location, "0") + HostTestContext.BuiltDotNet.Exec(sharedTestState.HostApiInvokerApp.AppDll, api, f.ExeDir, workingDir.Location, "0") .EnableTracingAndCaptureOutputs() .Execute() .Should().Pass() @@ -288,7 +288,7 @@ public void Hostfxr_resolve_sdk2_GlobalJson_InvalidData() }); string api = ApiNames.hostfxr_resolve_sdk2; - TestContext.BuiltDotNet.Exec(sharedTestState.HostApiInvokerApp.AppDll, api, f.ExeDir, workingDir.Location, "0") + HostTestContext.BuiltDotNet.Exec(sharedTestState.HostApiInvokerApp.AppDll, api, f.ExeDir, workingDir.Location, "0") .EnableTracingAndCaptureOutputs() .Execute() .Should().Pass() @@ -316,7 +316,7 @@ public void Hostfxr_resolve_sdk2_GlobalJson_InvalidDataNoFallback() }); string api = ApiNames.hostfxr_resolve_sdk2; - TestContext.BuiltDotNet.Exec(sharedTestState.HostApiInvokerApp.AppDll, api, f.ExeDir, workingDir.Location, "0") + HostTestContext.BuiltDotNet.Exec(sharedTestState.HostApiInvokerApp.AppDll, api, f.ExeDir, workingDir.Location, "0") .EnableTracingAndCaptureOutputs() .Execute() .Should().Pass() @@ -337,7 +337,7 @@ public void Hostfxr_resolve_sdk2_FailsToResolve_NoWriteToStd(bool do_not_print_e string invalidVersion = "1.2.0"; // feature band < 1 triggers __invalid_data_no_fallback GlobalJson.CreateWithVersion(workingDir.Location, invalidVersion); - var result = TestContext.BuiltDotNet.Exec(sharedTestState.HostApiInvokerApp.AppDll, api, f.ExeDir, workingDir.Location, do_not_print_errors ? "do_not_print_errors" : "0") + var result = HostTestContext.BuiltDotNet.Exec(sharedTestState.HostApiInvokerApp.AppDll, api, f.ExeDir, workingDir.Location, do_not_print_errors ? "do_not_print_errors" : "0") .CaptureStdOut() .CaptureStdErr() .Execute(); @@ -354,7 +354,7 @@ public void Hostfxr_resolve_sdk2_FailsToResolve_NoWriteToStd(bool do_not_print_e [Fact] public void Hostfxr_corehost_set_error_writer_test() { - TestContext.BuiltDotNet.Exec(sharedTestState.HostApiInvokerApp.AppDll, "Test_hostfxr_set_error_writer") + HostTestContext.BuiltDotNet.Exec(sharedTestState.HostApiInvokerApp.AppDll, "Test_hostfxr_set_error_writer") .EnableTracingAndCaptureOutputs() .Execute() .Should().Pass(); @@ -373,7 +373,7 @@ public void Hostfxr_get_dotnet_environment_info_dotnet_root_only() string expectedFrameworkPaths = string.Join(';', frameworks.Select(fw => Path.Combine(f.LocalFrameworksDir, fw.Name))); string api = ApiNames.hostfxr_get_dotnet_environment_info; - TestContext.BuiltDotNet.Exec(sharedTestState.HostApiInvokerApp.AppDll, api, f.ExeDir) + HostTestContext.BuiltDotNet.Exec(sharedTestState.HostApiInvokerApp.AppDll, api, f.ExeDir) .EnableTracingAndCaptureOutputs() .Execute() .Should().Pass() @@ -402,7 +402,7 @@ public void Hostfxr_get_dotnet_environment_info_DisabledVersions() string expectedFrameworkPaths = string.Join(';', frameworks.Select(fw => Path.Combine(f.LocalFrameworksDir, fw.Name))); string api = ApiNames.hostfxr_get_dotnet_environment_info; - var result = TestContext.BuiltDotNet.Exec(sharedTestState.HostApiInvokerApp.AppDll, api, f.ExeDir) + var result = HostTestContext.BuiltDotNet.Exec(sharedTestState.HostApiInvokerApp.AppDll, api, f.ExeDir) .EnableTracingAndCaptureOutputs() .EnvironmentVariable(Constants.DisableRuntimeVersions.EnvironmentVariable, string.Join(';', disabledVersions)) .Execute(); @@ -423,7 +423,7 @@ public void Hostfxr_get_dotnet_environment_info_DisabledVersions() public void Hostfxr_get_dotnet_environment_info_global_install_path() { string api = ApiNames.hostfxr_get_dotnet_environment_info; - TestContext.BuiltDotNet.Exec(sharedTestState.HostApiInvokerApp.AppDll, api) + HostTestContext.BuiltDotNet.Exec(sharedTestState.HostApiInvokerApp.AppDll, api) .EnableTracingAndCaptureOutputs() .Execute() .Should().Pass() @@ -434,7 +434,7 @@ public void Hostfxr_get_dotnet_environment_info_global_install_path() public void Hostfxr_get_dotnet_environment_info_result_is_nullptr_fails() { string api = ApiNames.hostfxr_get_dotnet_environment_info; - TestContext.BuiltDotNet.Exec(sharedTestState.HostApiInvokerApp.AppDll, api, "test_invalid_result_ptr") + HostTestContext.BuiltDotNet.Exec(sharedTestState.HostApiInvokerApp.AppDll, api, "test_invalid_result_ptr") .EnableTracingAndCaptureOutputs() .Execute() .Should().Pass() @@ -446,7 +446,7 @@ public void Hostfxr_get_dotnet_environment_info_result_is_nullptr_fails() public void Hostfxr_get_dotnet_environment_info_reserved_is_not_nullptr_fails() { string api = ApiNames.hostfxr_get_dotnet_environment_info; - TestContext.BuiltDotNet.Exec(sharedTestState.HostApiInvokerApp.AppDll, api, "test_invalid_reserved_ptr") + HostTestContext.BuiltDotNet.Exec(sharedTestState.HostApiInvokerApp.AppDll, api, "test_invalid_reserved_ptr") .EnableTracingAndCaptureOutputs() .Execute() .Should().Pass() @@ -470,12 +470,12 @@ public void Hostfxr_resolve_frameworks_for_runtime_config(bool isMissing, bool w .WithFramework(requested.Name, requested.Version) .Save(withUtf8Bom); - var builder = new DotNetBuilder(artifact.Location, TestContext.BuiltDotNet.BinPath, "dotnet"); + var builder = new DotNetBuilder(artifact.Location, HostTestContext.BuiltDotNet.BinPath, "dotnet"); if (!isMissing) builder.AddFramework(requested.Name, requested.Version, c => { }); DotNetCli dotnet = builder.Build(); - var result = TestContext.BuiltDotNet.Exec(sharedTestState.HostApiInvokerApp.AppDll, api, configPath, dotnet.BinPath) + var result = HostTestContext.BuiltDotNet.Exec(sharedTestState.HostApiInvokerApp.AppDll, api, configPath, dotnet.BinPath) .CaptureStdOut() .CaptureStdErr() .Execute(); @@ -509,7 +509,7 @@ public void Hostfxr_resolve_frameworks_for_runtime_config_SelfContained() config.Save(); - var result = TestContext.BuiltDotNet.Exec(sharedTestState.HostApiInvokerApp.AppDll, api, configPath) + var result = HostTestContext.BuiltDotNet.Exec(sharedTestState.HostApiInvokerApp.AppDll, api, configPath) .CaptureStdOut() .CaptureStdErr() .Execute(); @@ -577,11 +577,11 @@ Constants.RollForwardSetting.Major or Constants.RollForwardSetting.LatestMajor }; string actualVersion = version.ToString(3); - DotNetCli dotnet = new DotNetBuilder(artifact.Location, TestContext.BuiltDotNet.BinPath, "dotnet") + DotNetCli dotnet = new DotNetBuilder(artifact.Location, HostTestContext.BuiltDotNet.BinPath, "dotnet") .AddFramework(requested.Name, actualVersion, c => { }) .Build(); - var result = TestContext.BuiltDotNet.Exec(sharedTestState.HostApiInvokerApp.AppDll, api, configPath, dotnet.BinPath) + var result = HostTestContext.BuiltDotNet.Exec(sharedTestState.HostApiInvokerApp.AppDll, api, configPath, dotnet.BinPath) .CaptureStdOut() .CaptureStdErr() .Execute(); @@ -611,16 +611,16 @@ public void Hostfxr_resolve_frameworks_for_runtime_config_NoDotnetRoot(bool isMi if (isMissing) { // Request a higher major framework version than the one available relative to the running hostfxr - Version existingVersion = Version.Parse(TestContext.MicrosoftNETCoreAppVersion.Contains('-') - ? TestContext.MicrosoftNETCoreAppVersion[..TestContext.MicrosoftNETCoreAppVersion.IndexOf('-')] - : TestContext.MicrosoftNETCoreAppVersion); + Version existingVersion = Version.Parse(HostTestContext.MicrosoftNETCoreAppVersion.Contains('-') + ? HostTestContext.MicrosoftNETCoreAppVersion[..HostTestContext.MicrosoftNETCoreAppVersion.IndexOf('-')] + : HostTestContext.MicrosoftNETCoreAppVersion); Version newerVersion = new Version(existingVersion.Major + 1, existingVersion.Minor, existingVersion.Build); requestedVersion = newerVersion.ToString(3); } else { // Request the framework version that is available relative to the running hostfxr - requestedVersion = TestContext.MicrosoftNETCoreAppVersion; + requestedVersion = HostTestContext.MicrosoftNETCoreAppVersion; } (string Name, string Version) requested = (Constants.MicrosoftNETCoreApp, requestedVersion); @@ -632,7 +632,7 @@ public void Hostfxr_resolve_frameworks_for_runtime_config_NoDotnetRoot(bool isMi .Save(); // API should use the running hostfxr when dotnet root is not specified - var result = TestContext.BuiltDotNet.Exec(sharedTestState.HostApiInvokerApp.AppDll, api, configPath) + var result = HostTestContext.BuiltDotNet.Exec(sharedTestState.HostApiInvokerApp.AppDll, api, configPath) .CaptureStdOut() .CaptureStdErr() .Execute(); @@ -645,7 +645,7 @@ public void Hostfxr_resolve_frameworks_for_runtime_config_NoDotnetRoot(bool isMi } else { - result.Should().ReturnResolvedFramework(requested.Name, requested.Version, GetFrameworkPath(requested.Name, requested.Version, TestContext.BuiltDotNet.BinPath)); + result.Should().ReturnResolvedFramework(requested.Name, requested.Version, GetFrameworkPath(requested.Name, requested.Version, HostTestContext.BuiltDotNet.BinPath)); } } } @@ -670,7 +670,7 @@ public void Hostfxr_resolve_frameworks_for_runtime_config_MultipleFrameworks(boo config.Save(); - var builder = new DotNetBuilder(artifact.Location, TestContext.BuiltDotNet.BinPath, "dotnet"); + var builder = new DotNetBuilder(artifact.Location, HostTestContext.BuiltDotNet.BinPath, "dotnet"); foreach (var framework in expectedFrameworks) { builder.AddFramework(framework.Name, framework.Version, c => { }); @@ -678,7 +678,7 @@ public void Hostfxr_resolve_frameworks_for_runtime_config_MultipleFrameworks(boo DotNetCli dotnet = builder.Build(); - var result = TestContext.BuiltDotNet.Exec(sharedTestState.HostApiInvokerApp.AppDll, api, configPath, dotnet.BinPath) + var result = HostTestContext.BuiltDotNet.Exec(sharedTestState.HostApiInvokerApp.AppDll, api, configPath, dotnet.BinPath) .CaptureStdOut() .CaptureStdErr() .Execute(); @@ -718,12 +718,12 @@ public void Hostfxr_resolve_frameworks_for_runtime_config_IncompatibleFrameworks config.Save(); var expectedFramework = requested[0]; - DotNetCli dotnet = new DotNetBuilder(artifact.Location, TestContext.BuiltDotNet.BinPath, "dotnet") + DotNetCli dotnet = new DotNetBuilder(artifact.Location, HostTestContext.BuiltDotNet.BinPath, "dotnet") .AddFramework(expectedFramework.Name, expectedFramework.Version, c => c.WithFramework(incompatibleHigher.Name, incompatibleHigher.Version)) .Build(); - TestContext.BuiltDotNet.Exec(sharedTestState.HostApiInvokerApp.AppDll, api, configPath, dotnet.BinPath) + HostTestContext.BuiltDotNet.Exec(sharedTestState.HostApiInvokerApp.AppDll, api, configPath, dotnet.BinPath) .CaptureStdOut() .CaptureStdErr() .Execute() @@ -748,14 +748,14 @@ public void Hostfxr_resolve_frameworks_for_runtime_config_InvalidConfig() .WithFramework(requested.Name, requested.Version) .Save(); - DotNetCli dotnet = new DotNetBuilder(artifact.Location, TestContext.BuiltDotNet.BinPath, "dotnet") + DotNetCli dotnet = new DotNetBuilder(artifact.Location, HostTestContext.BuiltDotNet.BinPath, "dotnet") .AddFramework(requested.Name, requested.Version, c => { }) .Build(); string frameworkPath = Path.Combine(dotnet.BinPath, "shared", requested.Name, requested.Version); File.WriteAllText(Path.Combine(frameworkPath, $"{requested.Name}.runtimeconfig.json"), "{}"); - TestContext.BuiltDotNet.Exec(sharedTestState.HostApiInvokerApp.AppDll, api, configPath, dotnet.BinPath) + HostTestContext.BuiltDotNet.Exec(sharedTestState.HostApiInvokerApp.AppDll, api, configPath, dotnet.BinPath) .CaptureStdOut() .CaptureStdErr() .Execute() @@ -788,7 +788,7 @@ public void Hostfxr_resolve_frameworks_for_runtime_config_MissingVersion(bool se config.Save(); - TestContext.BuiltDotNet.Exec(sharedTestState.HostApiInvokerApp.AppDll, api, configPath, TestContext.BuiltDotNet.BinPath) + HostTestContext.BuiltDotNet.Exec(sharedTestState.HostApiInvokerApp.AppDll, api, configPath, HostTestContext.BuiltDotNet.BinPath) .CaptureStdOut() .CaptureStdErr() .Execute() @@ -801,7 +801,7 @@ public void Hostfxr_resolve_frameworks_for_runtime_config_MissingVersion(bool se [Fact] public void Hostpolicy_corehost_set_error_writer_test() { - TestContext.BuiltDotNet.Exec(sharedTestState.HostApiInvokerApp.AppDll, "Test_corehost_set_error_writer") + HostTestContext.BuiltDotNet.Exec(sharedTestState.HostApiInvokerApp.AppDll, "Test_corehost_set_error_writer") .EnableTracingAndCaptureOutputs() .Execute() .Should().Pass(); @@ -811,12 +811,12 @@ public void Hostpolicy_corehost_set_error_writer_test() public void HostRuntimeContract_get_runtime_property() { TestApp app = sharedTestState.HostApiInvokerApp; - TestContext.BuiltDotNet.Exec(app.AppDll, "host_runtime_contract.get_runtime_property", "APP_CONTEXT_BASE_DIRECTORY", "RUNTIME_IDENTIFIER", "DOES_NOT_EXIST", "ENTRY_ASSEMBLY_NAME") + HostTestContext.BuiltDotNet.Exec(app.AppDll, "host_runtime_contract.get_runtime_property", "APP_CONTEXT_BASE_DIRECTORY", "RUNTIME_IDENTIFIER", "DOES_NOT_EXIST", "ENTRY_ASSEMBLY_NAME") .EnableTracingAndCaptureOutputs() .Execute() .Should().Pass() .And.HaveStdOutContaining($"APP_CONTEXT_BASE_DIRECTORY = {Path.GetDirectoryName(app.AppDll)}") - .And.HaveStdOutContaining($"RUNTIME_IDENTIFIER = {TestContext.BuildRID}") + .And.HaveStdOutContaining($"RUNTIME_IDENTIFIER = {HostTestContext.BuildRID}") .And.HaveStdOutContaining($"DOES_NOT_EXIST = ") .And.HaveStdOutContaining($"ENTRY_ASSEMBLY_NAME = {app.AssemblyName}"); } @@ -824,7 +824,7 @@ public void HostRuntimeContract_get_runtime_property() [Fact] public void HostRuntimeContract_bundle_probe() { - TestContext.BuiltDotNet.Exec(sharedTestState.HostApiInvokerApp.AppDll, "host_runtime_contract.bundle_probe", "APP_CONTEXT_BASE_DIRECTORY", "RUNTIME_IDENTIFIER", "DOES_NOT_EXIST", "ENTRY_ASSEMBLY_NAME") + HostTestContext.BuiltDotNet.Exec(sharedTestState.HostApiInvokerApp.AppDll, "host_runtime_contract.bundle_probe", "APP_CONTEXT_BASE_DIRECTORY", "RUNTIME_IDENTIFIER", "DOES_NOT_EXIST", "ENTRY_ASSEMBLY_NAME") .EnableTracingAndCaptureOutputs() .Execute() .Should().Pass() @@ -847,7 +847,7 @@ public SharedTestState() // On non-Windows, we can't just P/Invoke to already loaded hostfxr, so provide the app with // paths to hostfxr so that it can handle resolving the library. RuntimeConfig.FromFile(HostApiInvokerApp.RuntimeConfigJson) - .WithProperty("HOSTFXR_PATH", TestContext.BuiltDotNet.GreatestVersionHostFxrFilePath) + .WithProperty("HOSTFXR_PATH", HostTestContext.BuiltDotNet.GreatestVersionHostFxrFilePath) .Save(); SdkAndFrameworkFixture = new SdkAndFrameworkFixture(); diff --git a/src/installer/tests/HostActivation.Tests/NativeHosting/ApplicationExecution.cs b/src/installer/tests/HostActivation.Tests/NativeHosting/ApplicationExecution.cs index a91cd009aa20c0..028958ca357814 100644 --- a/src/installer/tests/HostActivation.Tests/NativeHosting/ApplicationExecution.cs +++ b/src/installer/tests/HostActivation.Tests/NativeHosting/ApplicationExecution.cs @@ -69,8 +69,8 @@ public class SharedTestState : SharedTestStateBase public SharedTestState() { - DotNetRoot = TestContext.BuiltDotNet.BinPath; - HostFxrPath = TestContext.BuiltDotNet.GreatestVersionHostFxrFilePath; + DotNetRoot = HostTestContext.BuiltDotNet.BinPath; + HostFxrPath = HostTestContext.BuiltDotNet.GreatestVersionHostFxrFilePath; App = TestApp.CreateFromBuiltAssets("HelloWorld"); } diff --git a/src/installer/tests/HostActivation.Tests/NativeHosting/Comhost.cs b/src/installer/tests/HostActivation.Tests/NativeHosting/Comhost.cs index f16e4e1d0e8e7a..d50c33260ea818 100644 --- a/src/installer/tests/HostActivation.Tests/NativeHosting/Comhost.cs +++ b/src/installer/tests/HostActivation.Tests/NativeHosting/Comhost.cs @@ -12,13 +12,14 @@ namespace Microsoft.DotNet.CoreSetup.Test.HostActivation.NativeHosting { - [PlatformSpecific(TestPlatforms.Windows)] // COM activation is only supported on Windows public class Comhost : IClassFixture { private readonly SharedTestState sharedState; public Comhost(SharedTestState sharedTestState) { + Assert.SkipUnless(OperatingSystem.IsWindows(), "COM activation is only supported on Windows"); + sharedState = sharedTestState; } @@ -35,7 +36,7 @@ public void ActivateClass(int count, bool synchronous) sharedState.ComHostPath, sharedState.ClsidString }; - CommandResult result = sharedState.CreateNativeHostCommand(args, TestContext.BuiltDotNet.BinPath) + CommandResult result = sharedState.CreateNativeHostCommand(args, HostTestContext.BuiltDotNet.BinPath) .Execute(); result.Should().Pass() @@ -68,7 +69,7 @@ public void ActivateClass_ContextConfig(bool inDefaultContext) comHost, sharedState.ClsidString }; - CommandResult result = sharedState.CreateNativeHostCommand(args, TestContext.BuiltDotNet.BinPath) + CommandResult result = sharedState.CreateNativeHostCommand(args, HostTestContext.BuiltDotNet.BinPath) .Execute(); result.Should().Pass() @@ -101,7 +102,7 @@ public void ActivateClass_IgnoreAppLocalHostFxr() comHostWithAppLocalFxr, sharedState.ClsidString }; - CommandResult result = sharedState.CreateNativeHostCommand(args, TestContext.BuiltDotNet.BinPath) + CommandResult result = sharedState.CreateNativeHostCommand(args, HostTestContext.BuiltDotNet.BinPath) .Execute(); result.Should().Pass() @@ -128,15 +129,15 @@ public void ActivateClass_IgnoreWorkingDirectory() sharedState.ComHostPath, sharedState.ClsidString }; - sharedState.CreateNativeHostCommand(args, TestContext.BuiltDotNet.BinPath) + sharedState.CreateNativeHostCommand(args, HostTestContext.BuiltDotNet.BinPath) .WorkingDirectory(cwd.Location) .Execute() .Should().Pass() .And.HaveStdOutContaining("New instance of Server created") .And.HaveStdOutContaining($"Activation of {sharedState.ClsidString} succeeded.") - .And.ResolveHostFxr(TestContext.BuiltDotNet) - .And.ResolveHostPolicy(TestContext.BuiltDotNet) - .And.ResolveCoreClr(TestContext.BuiltDotNet); + .And.ResolveHostFxr(HostTestContext.BuiltDotNet) + .And.ResolveHostPolicy(HostTestContext.BuiltDotNet) + .And.ResolveCoreClr(HostTestContext.BuiltDotNet); } } @@ -155,7 +156,7 @@ public void ActivateClass_ValidateIErrorInfoResult() comHost, sharedState.ClsidString }; - CommandResult result = sharedState.CreateNativeHostCommand(args, TestContext.BuiltDotNet.BinPath) + CommandResult result = sharedState.CreateNativeHostCommand(args, HostTestContext.BuiltDotNet.BinPath) .Execute(); result.Should().Pass() @@ -173,7 +174,7 @@ public void LoadTypeLibraries() sharedState.ComHostPath, sharedState.ClsidString }; - CommandResult result = sharedState.CreateNativeHostCommand(args, TestContext.BuiltDotNet.BinPath) + CommandResult result = sharedState.CreateNativeHostCommand(args, HostTestContext.BuiltDotNet.BinPath) .Execute(); result.Should().Pass() diff --git a/src/installer/tests/HostActivation.Tests/NativeHosting/ComhostSideBySide.cs b/src/installer/tests/HostActivation.Tests/NativeHosting/ComhostSideBySide.cs index e6c70d5bbff0cf..92fcf314add651 100644 --- a/src/installer/tests/HostActivation.Tests/NativeHosting/ComhostSideBySide.cs +++ b/src/installer/tests/HostActivation.Tests/NativeHosting/ComhostSideBySide.cs @@ -11,13 +11,14 @@ namespace Microsoft.DotNet.CoreSetup.Test.HostActivation.NativeHosting { - [PlatformSpecific(TestPlatforms.Windows)] // COM activation is only supported on Windows public class ComhostSideBySide : IClassFixture { private readonly SharedTestState sharedState; public ComhostSideBySide(SharedTestState sharedTestState) { + Assert.SkipUnless(OperatingSystem.IsWindows(), "COM activation is only supported on Windows"); + sharedState = sharedTestState; } @@ -31,7 +32,7 @@ public void ActivateClass() CommandResult result = Command.Create(sharedState.ComSxsPath, args) .EnableTracingAndCaptureOutputs() - .DotNetRoot(TestContext.BuiltDotNet.BinPath) + .DotNetRoot(HostTestContext.BuiltDotNet.BinPath) .MultilevelLookup(false) .Execute(); @@ -49,7 +50,7 @@ public void LocateEmbeddedTlb() CommandResult result = Command.Create(sharedState.ComSxsPath, args) .EnableTracingAndCaptureOutputs() - .DotNetRoot(TestContext.BuiltDotNet.BinPath) + .DotNetRoot(HostTestContext.BuiltDotNet.BinPath) .MultilevelLookup(false) .Execute(); @@ -69,7 +70,7 @@ public void ManagedHost(bool selfContained) TestApp app = selfContained ? sharedState.ManagedHost_SelfContained : sharedState.ManagedHost_FrameworkDependent; CommandResult result = Command.Create(app.AppExe, args) .EnableTracingAndCaptureOutputs() - .DotNetRoot(TestContext.BuiltDotNet.BinPath) + .DotNetRoot(HostTestContext.BuiltDotNet.BinPath) .MultilevelLookup(false) .Execute(); diff --git a/src/installer/tests/HostActivation.Tests/NativeHosting/GetFunctionPointer.cs b/src/installer/tests/HostActivation.Tests/NativeHosting/GetFunctionPointer.cs index 98eadc0b0769c3..8982e39fda6ef9 100644 --- a/src/installer/tests/HostActivation.Tests/NativeHosting/GetFunctionPointer.cs +++ b/src/installer/tests/HostActivation.Tests/NativeHosting/GetFunctionPointer.cs @@ -230,8 +230,8 @@ public class SharedTestState : SharedTestStateBase public SharedTestState() { - DotNetRoot = TestContext.BuiltDotNet.BinPath; - HostFxrPath = TestContext.BuiltDotNet.GreatestVersionHostFxrFilePath; + DotNetRoot = HostTestContext.BuiltDotNet.BinPath; + HostFxrPath = HostTestContext.BuiltDotNet.GreatestVersionHostFxrFilePath; App = TestApp.CreateFromBuiltAssets("AppWithCustomEntryPoints"); Component = TestApp.CreateFromBuiltAssets("Component"); diff --git a/src/installer/tests/HostActivation.Tests/NativeHosting/GetNativeSearchDirectories.cs b/src/installer/tests/HostActivation.Tests/NativeHosting/GetNativeSearchDirectories.cs index d382ff9244bd59..c4c047002d1e09 100644 --- a/src/installer/tests/HostActivation.Tests/NativeHosting/GetNativeSearchDirectories.cs +++ b/src/installer/tests/HostActivation.Tests/NativeHosting/GetNativeSearchDirectories.cs @@ -160,7 +160,7 @@ public class SharedTestState : SharedTestStateBase public SharedTestState() { - DotNet = new DotNetBuilder(BaseDirectory, TestContext.BuiltDotNet.BinPath, "mockRuntime") + DotNet = new DotNetBuilder(BaseDirectory, HostTestContext.BuiltDotNet.BinPath, "mockRuntime") .AddMicrosoftNETCoreAppFrameworkMockCoreClr(NetCoreAppVersion) .Build(); diff --git a/src/installer/tests/HostActivation.Tests/NativeHosting/HostContext.FrameworkCompatibilityTestData.cs b/src/installer/tests/HostActivation.Tests/NativeHosting/HostContext.FrameworkCompatibilityTestData.cs index caa2b8bd9da193..a23c52f5c5a85b 100644 --- a/src/installer/tests/HostActivation.Tests/NativeHosting/HostContext.FrameworkCompatibilityTestData.cs +++ b/src/installer/tests/HostActivation.Tests/NativeHosting/HostContext.FrameworkCompatibilityTestData.cs @@ -4,7 +4,7 @@ using System; using System.Collections.Generic; using Xunit; -using Xunit.Abstractions; +using Xunit.Sdk; namespace Microsoft.DotNet.CoreSetup.Test.HostActivation.NativeHosting { diff --git a/src/installer/tests/HostActivation.Tests/NativeHosting/HostContext.PropertyCompatibilityTestData.cs b/src/installer/tests/HostActivation.Tests/NativeHosting/HostContext.PropertyCompatibilityTestData.cs index 6028068c57ab10..6bc4c11753b4d0 100644 --- a/src/installer/tests/HostActivation.Tests/NativeHosting/HostContext.PropertyCompatibilityTestData.cs +++ b/src/installer/tests/HostActivation.Tests/NativeHosting/HostContext.PropertyCompatibilityTestData.cs @@ -4,7 +4,7 @@ using System; using System.Collections.Generic; using Xunit; -using Xunit.Abstractions; +using Xunit.Sdk; namespace Microsoft.DotNet.CoreSetup.Test.HostActivation.NativeHosting { diff --git a/src/installer/tests/HostActivation.Tests/NativeHosting/HostContext.cs b/src/installer/tests/HostActivation.Tests/NativeHosting/HostContext.cs index d1c87d8ade4064..20cf5f2b749dfb 100644 --- a/src/installer/tests/HostActivation.Tests/NativeHosting/HostContext.cs +++ b/src/installer/tests/HostActivation.Tests/NativeHosting/HostContext.cs @@ -327,10 +327,10 @@ public void RunApp_GetDelegate(string scenario, string checkProperties) } [Theory] - [MemberData(nameof(GetFrameworkCompatibilityTestData), parameters: Scenario.ConfigMultiple)] - [MemberData(nameof(GetFrameworkCompatibilityTestData), parameters: Scenario.Mixed)] - [MemberData(nameof(GetFrameworkCompatibilityTestData), parameters: Scenario.NonContextMixedAppHost)] - [MemberData(nameof(GetFrameworkCompatibilityTestData), parameters: Scenario.NonContextMixedDotnet)] + [MemberData(nameof(GetFrameworkCompatibilityTestData), Scenario.ConfigMultiple)] + [MemberData(nameof(GetFrameworkCompatibilityTestData), Scenario.Mixed)] + [MemberData(nameof(GetFrameworkCompatibilityTestData), Scenario.NonContextMixedAppHost)] + [MemberData(nameof(GetFrameworkCompatibilityTestData), Scenario.NonContextMixedDotnet)] public void CompatibilityCheck_Frameworks(string scenario, FrameworkCompatibilityTestData testData) { if (scenario != Scenario.ConfigMultiple && scenario != Scenario.Mixed && scenario != Scenario.NonContextMixedAppHost && scenario != Scenario.NonContextMixedDotnet) @@ -433,14 +433,14 @@ public void CompatibilityCheck_Frameworks(string scenario, FrameworkCompatibilit } [Theory] - [MemberData(nameof(GetPropertyCompatibilityTestData), parameters: new object[] { Scenario.ConfigMultiple, false })] - [MemberData(nameof(GetPropertyCompatibilityTestData), parameters: new object[] { Scenario.ConfigMultiple, true })] - [MemberData(nameof(GetPropertyCompatibilityTestData), parameters: new object[] { Scenario.Mixed, false })] - [MemberData(nameof(GetPropertyCompatibilityTestData), parameters: new object[] { Scenario.Mixed, true })] - [MemberData(nameof(GetPropertyCompatibilityTestData), parameters: new object[] { Scenario.NonContextMixedAppHost, false })] - [MemberData(nameof(GetPropertyCompatibilityTestData), parameters: new object[] { Scenario.NonContextMixedAppHost, true })] - [MemberData(nameof(GetPropertyCompatibilityTestData), parameters: new object[] { Scenario.NonContextMixedDotnet, false })] - [MemberData(nameof(GetPropertyCompatibilityTestData), parameters: new object[] { Scenario.NonContextMixedDotnet, true })] + [MemberData(nameof(GetPropertyCompatibilityTestData), arguments: new object[] { Scenario.ConfigMultiple, false })] + [MemberData(nameof(GetPropertyCompatibilityTestData), arguments: new object[] { Scenario.ConfigMultiple, true })] + [MemberData(nameof(GetPropertyCompatibilityTestData), arguments: new object[] { Scenario.Mixed, false })] + [MemberData(nameof(GetPropertyCompatibilityTestData), arguments: new object[] { Scenario.Mixed, true })] + [MemberData(nameof(GetPropertyCompatibilityTestData), arguments: new object[] { Scenario.NonContextMixedAppHost, false })] + [MemberData(nameof(GetPropertyCompatibilityTestData), arguments: new object[] { Scenario.NonContextMixedAppHost, true })] + [MemberData(nameof(GetPropertyCompatibilityTestData), arguments: new object[] { Scenario.NonContextMixedDotnet, false })] + [MemberData(nameof(GetPropertyCompatibilityTestData), arguments: new object[] { Scenario.NonContextMixedDotnet, true })] public void CompatibilityCheck_Properties(string scenario, bool hasMultipleProperties, PropertyTestData[] properties) { if (scenario != Scenario.ConfigMultiple && scenario != Scenario.Mixed && scenario != Scenario.NonContextMixedAppHost && scenario != Scenario.NonContextMixedDotnet) @@ -683,7 +683,7 @@ public class SharedTestState : SharedTestStateBase public SharedTestState() { - var dotNet = new DotNetBuilder(BaseDirectory, TestContext.BuiltDotNet.BinPath, "mockRuntime") + var dotNet = new DotNetBuilder(BaseDirectory, HostTestContext.BuiltDotNet.BinPath, "mockRuntime") .AddMicrosoftNETCoreAppFrameworkMockCoreClr(NetCoreAppVersion) .Build(); DotNetRoot = dotNet.BinPath; diff --git a/src/installer/tests/HostActivation.Tests/NativeHosting/Ijwhost.cs b/src/installer/tests/HostActivation.Tests/NativeHosting/Ijwhost.cs index dc8deb024e0fab..44b8693d53c457 100644 --- a/src/installer/tests/HostActivation.Tests/NativeHosting/Ijwhost.cs +++ b/src/installer/tests/HostActivation.Tests/NativeHosting/Ijwhost.cs @@ -1,6 +1,7 @@ // 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.IO; using Microsoft.DotNet.Cli.Build.Framework; @@ -8,13 +9,14 @@ namespace Microsoft.DotNet.CoreSetup.Test.HostActivation.NativeHosting { - [PlatformSpecific(TestPlatforms.Windows)] // IJW is only supported on Windows public class Ijwhost : IClassFixture { private readonly SharedTestState sharedState; public Ijwhost(SharedTestState sharedTestState) { + Assert.SkipUnless(OperatingSystem.IsWindows(), "IJW is only supported on Windows"); + sharedState = sharedTestState; } @@ -37,7 +39,7 @@ public void LoadLibrary(bool no_runtimeconfig) File.Delete(app.RuntimeConfigJson); } - CommandResult result = sharedState.CreateNativeHostCommand(args, TestContext.BuiltDotNet.BinPath) + CommandResult result = sharedState.CreateNativeHostCommand(args, HostTestContext.BuiltDotNet.BinPath) .Execute(); if (no_runtimeconfig) @@ -72,7 +74,7 @@ public void LoadLibrary_ContextConfig(bool load_isolated) .WithProperty("System.Runtime.InteropServices.CppCLI.LoadComponentInIsolatedContext", load_isolated.ToString()) .Save(); - CommandResult result = sharedState.CreateNativeHostCommand(args, TestContext.BuiltDotNet.BinPath) + CommandResult result = sharedState.CreateNativeHostCommand(args, HostTestContext.BuiltDotNet.BinPath) .Execute(); result.Should().Pass() @@ -104,15 +106,15 @@ public void LoadLibrary_IgnoreWorkingDirectory() sharedState.IjwApp.AppDll, "NativeEntryPoint" }; - sharedState.CreateNativeHostCommand(args, TestContext.BuiltDotNet.BinPath) + sharedState.CreateNativeHostCommand(args, HostTestContext.BuiltDotNet.BinPath) .WorkingDirectory(cwd.Location) .Execute() .Should().Pass() .And.HaveStdOutContaining("[C++/CLI] NativeEntryPoint: calling managed class") .And.HaveStdOutContaining("[C++/CLI] ManagedClass: AssemblyLoadContext = \"Default\" System.Runtime.Loader.DefaultAssemblyLoadContext") - .And.ResolveHostFxr(TestContext.BuiltDotNet) - .And.ResolveHostPolicy(TestContext.BuiltDotNet) - .And.ResolveCoreClr(TestContext.BuiltDotNet); + .And.ResolveHostFxr(HostTestContext.BuiltDotNet) + .And.ResolveHostPolicy(HostTestContext.BuiltDotNet) + .And.ResolveCoreClr(HostTestContext.BuiltDotNet); } } @@ -128,13 +130,13 @@ public void LoadLibraryWithoutRuntimeConfigButActiveRuntime() "ijwhost", app.AppDll, "NativeEntryPoint", - TestContext.BuiltDotNet.GreatestVersionHostFxrFilePath, // optional 4th and 5th arguments that tell nativehost to start the runtime before loading the C++/CLI library + HostTestContext.BuiltDotNet.GreatestVersionHostFxrFilePath, // optional 4th and 5th arguments that tell nativehost to start the runtime before loading the C++/CLI library startupConfigPath }; File.Move(app.RuntimeConfigJson, startupConfigPath); - CommandResult result = sharedState.CreateNativeHostCommand(args, TestContext.BuiltDotNet.BinPath) + CommandResult result = sharedState.CreateNativeHostCommand(args, HostTestContext.BuiltDotNet.BinPath) .Execute(); result.Should().Pass() @@ -156,7 +158,7 @@ public void ManagedHost(bool selfContained) TestApp app = selfContained ? sharedState.ManagedHost_SelfContained : sharedState.ManagedHost_FrameworkDependent; CommandResult result = Command.Create(app.AppExe, args) .EnableTracingAndCaptureOutputs() - .DotNetRoot(TestContext.BuiltDotNet.BinPath) + .DotNetRoot(HostTestContext.BuiltDotNet.BinPath) .MultilevelLookup(false) .Execute(); @@ -174,6 +176,12 @@ public class SharedTestState : SharedTestStateBase public SharedTestState() { + if (!OperatingSystem.IsWindows()) + { + // IJW is only supported on Windows, these tests are skipped in the constructor + return; + } + string folder = Path.Combine(BaseDirectory, "ijw"); IjwApp = new TestApp(folder, "ijw"); // Copy over ijwhost @@ -194,7 +202,7 @@ public SharedTestState() // Create a runtimeconfig.json for the C++/CLI test library new RuntimeConfig(Path.Combine(folder, "ijw.runtimeconfig.json")) - .WithFramework(new RuntimeConfig.Framework(Constants.MicrosoftNETCoreApp, TestContext.MicrosoftNETCoreAppVersion)) + .WithFramework(new RuntimeConfig.Framework(Constants.MicrosoftNETCoreApp, HostTestContext.MicrosoftNETCoreAppVersion)) .Save(); ManagedHost_FrameworkDependent = TestApp.CreateFromBuiltAssets("ManagedHost"); diff --git a/src/installer/tests/HostActivation.Tests/NativeHosting/LoadAssembly.cs b/src/installer/tests/HostActivation.Tests/NativeHosting/LoadAssembly.cs index ec221d3f952038..16c44b0aee963a 100644 --- a/src/installer/tests/HostActivation.Tests/NativeHosting/LoadAssembly.cs +++ b/src/installer/tests/HostActivation.Tests/NativeHosting/LoadAssembly.cs @@ -146,11 +146,11 @@ public class SharedTestState : SharedTestStateBase public SharedTestState() { - DotNetRoot = TestContext.BuiltDotNet.BinPath; - HostFxrPath = TestContext.BuiltDotNet.GreatestVersionHostFxrFilePath; + DotNetRoot = HostTestContext.BuiltDotNet.BinPath; + HostFxrPath = HostTestContext.BuiltDotNet.GreatestVersionHostFxrFilePath; Application = TestApp.CreateEmpty("App"); - Application.PopulateFrameworkDependent(Constants.MicrosoftNETCoreApp, TestContext.MicrosoftNETCoreAppVersion); + Application.PopulateFrameworkDependent(Constants.MicrosoftNETCoreApp, HostTestContext.MicrosoftNETCoreAppVersion); SelfContainedApplication = TestApp.CreateEmpty("SelfContainedApp"); SelfContainedApplication.PopulateSelfContained(TestApp.MockedComponent.None); diff --git a/src/installer/tests/HostActivation.Tests/NativeHosting/LoadAssemblyAndGetFunctionPointer.cs b/src/installer/tests/HostActivation.Tests/NativeHosting/LoadAssemblyAndGetFunctionPointer.cs index bb13eeafee1c08..d2e5b194030ef7 100644 --- a/src/installer/tests/HostActivation.Tests/NativeHosting/LoadAssemblyAndGetFunctionPointer.cs +++ b/src/installer/tests/HostActivation.Tests/NativeHosting/LoadAssemblyAndGetFunctionPointer.cs @@ -259,8 +259,8 @@ public void CallDelegateOnComponentContext_IgnoreWorkingDirectory() .Should().Pass() .And.InitializeContextForConfig(component.RuntimeConfigJson) .And.ExecuteFunctionPointer(sharedState.ComponentEntryPoint1, 1, 1) - .And.ResolveHostPolicy(TestContext.BuiltDotNet) - .And.ResolveCoreClr(TestContext.BuiltDotNet); + .And.ResolveHostPolicy(HostTestContext.BuiltDotNet) + .And.ResolveCoreClr(HostTestContext.BuiltDotNet); } } @@ -280,8 +280,8 @@ public class SharedTestState : SharedTestStateBase public SharedTestState() { - DotNetRoot = TestContext.BuiltDotNet.BinPath; - HostFxrPath = TestContext.BuiltDotNet.GreatestVersionHostFxrFilePath; + DotNetRoot = HostTestContext.BuiltDotNet.BinPath; + HostFxrPath = HostTestContext.BuiltDotNet.GreatestVersionHostFxrFilePath; Component = TestApp.CreateFromBuiltAssets("Component"); diff --git a/src/installer/tests/HostActivation.Tests/NativeHosting/Nethost.cs b/src/installer/tests/HostActivation.Tests/NativeHosting/Nethost.cs index 2a3fff034fe684..cf950ca14b669e 100644 --- a/src/installer/tests/HostActivation.Tests/NativeHosting/Nethost.cs +++ b/src/installer/tests/HostActivation.Tests/NativeHosting/Nethost.cs @@ -117,7 +117,7 @@ public void GetHostFxrPath_GlobalInstallation(bool explicitLoad, bool useAssembl { if (useRegisteredLocation) { - registeredInstallLocationOverride.SetInstallLocation((TestContext.BuildArchitecture, installLocation)); + registeredInstallLocationOverride.SetInstallLocation((HostTestContext.BuildArchitecture, installLocation)); } result = Command.Create(sharedState.NativeHostPath, $"{GetHostFxrPath} {explicitLoad} {(useAssemblyPath ? sharedState.TestAssemblyPath : string.Empty)}") @@ -206,7 +206,7 @@ public void GetHostFxrPath_InstallLocationFile(string value, bool shouldUseArchS using (var registeredInstallLocationOverride = new RegisteredInstallLocationOverride(sharedState.NethostPath)) { if (shouldUseArchSpecificInstallLocation) - registeredInstallLocationOverride.SetInstallLocation((TestContext.BuildArchitecture, string.Format(value, installLocation))); + registeredInstallLocationOverride.SetInstallLocation((HostTestContext.BuildArchitecture, string.Format(value, installLocation))); else registeredInstallLocationOverride.SetInstallLocation((string.Empty, string.Format(value, installLocation))); @@ -223,7 +223,7 @@ public void GetHostFxrPath_InstallLocationFile(string value, bool shouldUseArchS { result.Should().HaveLookedForArchitectureSpecificInstallLocation( registeredInstallLocationOverride.PathValueOverride, - TestContext.BuildArchitecture); + HostTestContext.BuildArchitecture); } else { @@ -254,7 +254,7 @@ public void GetHostFxrPath_GlobalInstallation_HasNoDefaultInstallationPath() using (var registeredInstallLocationOverride = new RegisteredInstallLocationOverride(sharedState.NethostPath)) { registeredInstallLocationOverride.SetInstallLocation(new (string, string)[] { - (TestContext.BuildArchitecture, installLocation), + (HostTestContext.BuildArchitecture, installLocation), ("someOtherArch", $"{installLocation}/invalid") }); @@ -270,7 +270,7 @@ public void GetHostFxrPath_GlobalInstallation_HasNoDefaultInstallationPath() result.Should().Pass() .And.HaveLookedForArchitectureSpecificInstallLocation( registeredInstallLocationOverride.PathValueOverride, - TestContext.BuildArchitecture) + HostTestContext.BuildArchitecture) .And.HaveUsedRegisteredInstallLocation(installLocation) .And.HaveStdOutContaining($"hostfxr_path: {sharedState.HostFxrPath}".ToLower()); } @@ -285,7 +285,7 @@ public void GetHostFxrPath_GlobalInstallation_ArchitectureSpecificPathIsPickedOv { registeredInstallLocationOverride.SetInstallLocation(new (string, string)[] { (string.Empty, $"{installLocation}/a/b/c"), - (TestContext.BuildArchitecture, installLocation) + (HostTestContext.BuildArchitecture, installLocation) }); CommandResult result = Command.Create(sharedState.NativeHostPath, GetHostFxrPath) @@ -300,7 +300,7 @@ public void GetHostFxrPath_GlobalInstallation_ArchitectureSpecificPathIsPickedOv result.Should().Pass() .And.HaveLookedForArchitectureSpecificInstallLocation( registeredInstallLocationOverride.PathValueOverride, - TestContext.BuildArchitecture) + HostTestContext.BuildArchitecture) .And.HaveUsedRegisteredInstallLocation(installLocation) .And.HaveStdOutContaining($"hostfxr_path: {sharedState.HostFxrPath}".ToLower()); } diff --git a/src/installer/tests/HostActivation.Tests/RegisteredInstallLocationOverride.cs b/src/installer/tests/HostActivation.Tests/RegisteredInstallLocationOverride.cs index bb2fe9f7785bf1..9fc4e569760d14 100644 --- a/src/installer/tests/HostActivation.Tests/RegisteredInstallLocationOverride.cs +++ b/src/installer/tests/HostActivation.Tests/RegisteredInstallLocationOverride.cs @@ -57,7 +57,7 @@ public RegisteredInstallLocationOverride(string productBinaryPath) // On Linux/macOS the install location is registered in a file which is normally // located in /etc/dotnet/install_location // So we need to redirect it to a different place here. - string directory = Path.Combine(TestContext.TestArtifactsPath, "installLocationOverride" + Process.GetCurrentProcess().Id.ToString()); + string directory = Path.Combine(HostTestContext.TestArtifactsPath, "installLocationOverride" + Process.GetCurrentProcess().Id.ToString()); if (Directory.Exists(directory)) Directory.Delete(directory, true); Directory.CreateDirectory(directory); diff --git a/src/installer/tests/HostActivation.Tests/RuntimeProperties.cs b/src/installer/tests/HostActivation.Tests/RuntimeProperties.cs index 39b872df613288..3bc19014bf379b 100644 --- a/src/installer/tests/HostActivation.Tests/RuntimeProperties.cs +++ b/src/installer/tests/HostActivation.Tests/RuntimeProperties.cs @@ -131,9 +131,9 @@ public class SharedTestState : IDisposable public SharedTestState() { // Make a copy of the built .NET, as we will update the framework's runtime config - copiedDotnet = TestArtifact.CreateFromCopy("runtimeProperties", TestContext.BuiltDotNet.BinPath); + copiedDotnet = TestArtifact.CreateFromCopy("runtimeProperties", HostTestContext.BuiltDotNet.BinPath); - MockSDK = new DotNetBuilder(copiedDotnet.Location, TestContext.BuiltDotNet.BinPath, "mocksdk") + MockSDK = new DotNetBuilder(copiedDotnet.Location, HostTestContext.BuiltDotNet.BinPath, "mocksdk") .AddMicrosoftNETCoreAppFrameworkMockCoreClr("9999.0.0") .AddMockSDK("9999.0.0-dev", "9999.0.0") .Build(); diff --git a/src/installer/tests/HostActivation.Tests/SDKLookup.cs b/src/installer/tests/HostActivation.Tests/SDKLookup.cs index d633ec94d8d0f8..3c6135b09b4a71 100644 --- a/src/installer/tests/HostActivation.Tests/SDKLookup.cs +++ b/src/installer/tests/HostActivation.Tests/SDKLookup.cs @@ -26,7 +26,7 @@ public SDKLookup(SharedTestState sharedState) SharedState = sharedState; string exeDotNetPath = sharedState.BaseArtifact.GetUniqueSubdirectory("exe"); - ExecutableDotNetBuilder = new DotNetBuilder(exeDotNetPath, TestContext.BuiltDotNet.BinPath, null); + ExecutableDotNetBuilder = new DotNetBuilder(exeDotNetPath, HostTestContext.BuiltDotNet.BinPath, null); ExecutableDotNet = ExecutableDotNetBuilder .AddMicrosoftNETCoreAppFrameworkMockHostPolicy("9999.0.0") .Build(); @@ -1224,7 +1224,7 @@ public SharedTestState() // All dirs will be placed inside the base folder // Executable location is created per test as each test adds a different set of SDK versions - var currentWorkingSdk = new DotNetBuilder(BaseArtifact.Location, TestContext.BuiltDotNet.BinPath, "current") + var currentWorkingSdk = new DotNetBuilder(BaseArtifact.Location, HostTestContext.BuiltDotNet.BinPath, "current") .AddMockSDK("10000.0.0", "9999.0.0") .Build(); CurrentWorkingDir = currentWorkingSdk.BinPath; diff --git a/src/installer/tests/HostActivation.Tests/SelfContainedAppLaunch.cs b/src/installer/tests/HostActivation.Tests/SelfContainedAppLaunch.cs index 23f5dd91756d9d..be458178344d23 100644 --- a/src/installer/tests/HostActivation.Tests/SelfContainedAppLaunch.cs +++ b/src/installer/tests/HostActivation.Tests/SelfContainedAppLaunch.cs @@ -37,21 +37,23 @@ public void Default() .Execute() .Should().Pass() .And.HaveStdOutContaining("Hello World") - .And.HaveStdOutContaining(TestContext.MicrosoftNETCoreAppVersion); + .And.HaveStdOutContaining(HostTestContext.MicrosoftNETCoreAppVersion); if (OperatingSystem.IsWindows()) { // App sets FileVersion to NETCoreApp version. On Windows, this should be copied to app resources. - string expectedVersion = TestContext.MicrosoftNETCoreAppVersion.Contains('-') - ? TestContext.MicrosoftNETCoreAppVersion[..TestContext.MicrosoftNETCoreAppVersion.IndexOf('-')] - : TestContext.MicrosoftNETCoreAppVersion; + string expectedVersion = HostTestContext.MicrosoftNETCoreAppVersion.Contains('-') + ? HostTestContext.MicrosoftNETCoreAppVersion[..HostTestContext.MicrosoftNETCoreAppVersion.IndexOf('-')] + : HostTestContext.MicrosoftNETCoreAppVersion; Assert.Equal(expectedVersion, System.Diagnostics.FileVersionInfo.GetVersionInfo(appExe).FileVersion); } } - [ConditionalFact(typeof(Binaries.CetCompat), nameof(Binaries.CetCompat.IsSupported))] + [Fact] public void AppHost_DisableCetCompat() { + Assert.SkipUnless(Binaries.CetCompat.IsSupported, "CET not supported on this platform"); + TestApp app = sharedTestState.App.Copy(); app.CreateAppHost(disableCetCompat: true); Assert.False(Binaries.CetCompat.IsMarkedCompatible(app.AppExe)); @@ -62,7 +64,7 @@ public void AppHost_DisableCetCompat() .Execute() .Should().Pass() .And.HaveStdOutContaining("Hello World") - .And.HaveStdOutContaining(TestContext.MicrosoftNETCoreAppVersion); + .And.HaveStdOutContaining(HostTestContext.MicrosoftNETCoreAppVersion); } [Fact] @@ -80,7 +82,7 @@ public void NoDepsJson_NoRuntimeConfig() .Execute() .Should().Pass() // Note that this is an exact match - we don't expect any output from the host itself - .And.HaveStdOut($"Hello World!{Environment.NewLine}{Environment.NewLine}.NET {TestContext.MicrosoftNETCoreAppVersion}{Environment.NewLine}") + .And.HaveStdOut($"Hello World!{Environment.NewLine}{Environment.NewLine}.NET {HostTestContext.MicrosoftNETCoreAppVersion}{Environment.NewLine}") .And.NotHaveStdErr(); // Make sure tracing indicates there is no runtime config and no deps json @@ -88,7 +90,7 @@ public void NoDepsJson_NoRuntimeConfig() .EnableTracingAndCaptureOutputs() .Execute() .Should().Pass() - .And.HaveStdOut($"Hello World!{Environment.NewLine}{Environment.NewLine}.NET {TestContext.MicrosoftNETCoreAppVersion}{Environment.NewLine}") + .And.HaveStdOut($"Hello World!{Environment.NewLine}{Environment.NewLine}.NET {HostTestContext.MicrosoftNETCoreAppVersion}{Environment.NewLine}") .And.HaveStdErrContaining($"Runtime config does not exist at [{app.RuntimeConfigJson}]") .And.HaveStdErrContaining($"Dependencies manifest does not exist at [{app.DepsJson}]"); } @@ -107,7 +109,7 @@ public void RenameApphost() .Execute() .Should().Pass() .And.HaveStdOutContaining("Hello World") - .And.HaveStdOutContaining(TestContext.MicrosoftNETCoreAppVersion); + .And.HaveStdOutContaining(HostTestContext.MicrosoftNETCoreAppVersion); } [Fact] @@ -134,7 +136,7 @@ public void RelativeEmbeddedPath() .Execute() .Should().Pass() .And.HaveStdOutContaining("Hello World") - .And.HaveStdOutContaining(TestContext.MicrosoftNETCoreAppVersion); + .And.HaveStdOutContaining(HostTestContext.MicrosoftNETCoreAppVersion); } [Fact] @@ -156,12 +158,11 @@ public void DotNetRoot_IncorrectLayout_Fails() .DotNetRoot(app.Location) .Execute() .Should().Fail() - .And.HaveUsedDotNetRootInstallLocation(Path.GetFullPath(app.Location), TestContext.BuildRID) + .And.HaveUsedDotNetRootInstallLocation(Path.GetFullPath(app.Location), HostTestContext.BuildRID) .And.HaveStdErrContaining($"The required library {Binaries.HostFxr.FileName} could not be found."); } - [Fact] - [PlatformSpecific(TestPlatforms.Windows)] + [PlatformSpecificFact(TestPlatforms.Windows)] public void DevicePath() { string appExe = $@"\\?\{sharedTestState.App.AppExe}"; @@ -171,7 +172,7 @@ public void DevicePath() .Execute() .Should().Pass() .And.HaveStdOutContaining("Hello World") - .And.HaveStdOutContaining(TestContext.MicrosoftNETCoreAppVersion); + .And.HaveStdOutContaining(HostTestContext.MicrosoftNETCoreAppVersion); appExe = $@"\\.\{sharedTestState.App.AppExe}"; Command.Create(appExe) @@ -180,7 +181,7 @@ public void DevicePath() .Execute() .Should().Pass() .And.HaveStdOutContaining("Hello World") - .And.HaveStdOutContaining(TestContext.MicrosoftNETCoreAppVersion); + .And.HaveStdOutContaining(HostTestContext.MicrosoftNETCoreAppVersion); } [Fact] @@ -191,7 +192,7 @@ public void CustomRuntimeLocation() { // Find the NETCoreApp runtime pack RuntimeLibraryBuilder netCoreApp = b.RuntimeLibraries.First( - r => r.Type == RuntimeLibraryType.runtimepack.ToString() && r.Name == $"runtimepack.{Constants.MicrosoftNETCoreApp}.Runtime.{TestContext.BuildRID}"); + r => r.Type == RuntimeLibraryType.runtimepack.ToString() && r.Name == $"runtimepack.{Constants.MicrosoftNETCoreApp}.Runtime.{HostTestContext.BuildRID}"); // Update all NETCoreApp asset paths to point to the subdirectory RuntimeAssetGroupBuilder[] groups = [.. netCoreApp.AssemblyGroups, .. netCoreApp.NativeLibraryGroups]; @@ -224,7 +225,7 @@ public void CustomRuntimeLocation() .Execute() .Should().Pass() .And.HaveStdOutContaining("Hello World") - .And.HaveStdOutContaining(TestContext.MicrosoftNETCoreAppVersion) + .And.HaveStdOutContaining(HostTestContext.MicrosoftNETCoreAppVersion) .And.HaveStdErrContaining($"CoreCLR path = '{Path.Join(app.Location, subdirectory, Binaries.CoreClr.FileName)}'"); } diff --git a/src/installer/tests/HostActivation.Tests/StartupHooks.cs b/src/installer/tests/HostActivation.Tests/StartupHooks.cs index f902cdf849d3be..6f535a6112832e 100644 --- a/src/installer/tests/HostActivation.Tests/StartupHooks.cs +++ b/src/installer/tests/HostActivation.Tests/StartupHooks.cs @@ -29,7 +29,7 @@ public void Muxer_activation_of_RuntimeConfig_StartupHook_Succeeds() .Save(); // RuntimeConfig defined startup hook - TestContext.BuiltDotNet.Exec(app.AppDll) + HostTestContext.BuiltDotNet.Exec(app.AppDll) .EnableTracingAndCaptureOutputs() .Execute() .Should().Pass() @@ -55,7 +55,7 @@ public void Muxer_activation_of_RuntimeConfig_And_Environment_StartupHooks_Succe const string wildcardPattern = @"[\r\n\s.]*"; // RuntimeConfig and Environment startup hooks in expected order - TestContext.BuiltDotNet.Exec(app.AppDll) + HostTestContext.BuiltDotNet.Exec(app.AppDll) .EnvironmentVariable(startupHookVarName, startupHook2Dll) .CaptureStdOut() .CaptureStdErr() @@ -73,7 +73,7 @@ public void Muxer_activation_of_RuntimeConfig_And_Environment_StartupHooks_Succe public void Muxer_activation_of_Empty_StartupHook_Variable_Succeeds() { var startupHookVar = ""; - TestContext.BuiltDotNet.Exec(sharedTestState.App.AppDll) + HostTestContext.BuiltDotNet.Exec(sharedTestState.App.AppDll) .EnvironmentVariable(startupHookVarName, startupHookVar) .CaptureStdOut() .CaptureStdErr() @@ -90,7 +90,7 @@ public void Muxer_activation_of_StartupHook_With_Missing_Dependencies_Fails() var startupHookDll = sharedTestState.StartupHookWithAssemblyResolver.AppDll; // Startup hook has a dependency not on the TPA list - TestContext.BuiltDotNet.Exec(sharedTestState.App.AppDll) + HostTestContext.BuiltDotNet.Exec(sharedTestState.App.AppDll) .EnvironmentVariable(startupHookVarName, startupHookDll) // Indicate that the startup hook should try to use a dependency .EnvironmentVariable("TEST_STARTUPHOOK_USE_DEPENDENCY", true.ToString()) @@ -109,7 +109,7 @@ public void Muxer_activation_of_StartupHook_With_Assembly_Resolver() var startupHookDll = sharedTestState.StartupHookWithAssemblyResolver.AppDll; // Startup hook with assembly resolver results in use of injected dependency - TestContext.BuiltDotNet.Exec(sharedTestState.App.AppDll, "load_shared_library") + HostTestContext.BuiltDotNet.Exec(sharedTestState.App.AppDll, "load_shared_library") .EnvironmentVariable(startupHookVarName, startupHookDll) // Indicate that the startup hook should add an assembly resolver .EnvironmentVariable("TEST_STARTUPHOOK_ADD_RESOLVER", true.ToString()) @@ -133,7 +133,7 @@ public void Muxer_activation_of_StartupHook_With_IsSupported_False() // Startup hooks are not executed when the StartupHookSupport // feature switch is set to false. - TestContext.BuiltDotNet.Exec(app.AppDll) + HostTestContext.BuiltDotNet.Exec(app.AppDll) .EnvironmentVariable(startupHookVarName, startupHookDll) .CaptureStdOut() .CaptureStdErr() diff --git a/src/installer/tests/HostActivation.Tests/SymbolicLinks.cs b/src/installer/tests/HostActivation.Tests/SymbolicLinks.cs index 5afab32a0881d2..a80d9c9e014e90 100644 --- a/src/installer/tests/HostActivation.Tests/SymbolicLinks.cs +++ b/src/installer/tests/HostActivation.Tests/SymbolicLinks.cs @@ -46,7 +46,7 @@ public void Symlink_all_files_fx(string symlinkRelativePath) var result = Command.Create(Path.Combine(testDir.Location, symlinkRelativePath, Path.GetFileName(sharedTestState.FrameworkDependentApp.AppExe))) .CaptureStdErr() .CaptureStdOut() - .DotNetRoot(TestContext.BuiltDotNet.BinPath) + .DotNetRoot(HostTestContext.BuiltDotNet.BinPath) .Execute(); // This should succeed on all platforms, but for different reasons: @@ -113,7 +113,7 @@ public void Symlink_split_files_fx(string symlinkRelativePath) var result = Command.Create(Path.Combine(targetPath, appHostName)) .CaptureStdErr() .CaptureStdOut() - .DotNetRoot(TestContext.BuiltDotNet.BinPath) + .DotNetRoot(HostTestContext.BuiltDotNet.BinPath) .Execute(); if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows)) @@ -163,7 +163,7 @@ public void Symlink_all_files_self_contained(string symlinkRelativePath) var result = Command.Create(Path.Combine(testDir.Location, symlinkRelativePath, Path.GetFileName(sharedTestState.FrameworkDependentApp.AppExe))) .CaptureStdErr() .CaptureStdOut() - .DotNetRoot(TestContext.BuiltDotNet.BinPath) + .DotNetRoot(HostTestContext.BuiltDotNet.BinPath) .Execute(); // This should succeed on all platforms, but for different reasons: @@ -272,7 +272,7 @@ public void Run_framework_dependent_app_behind_symlink(string symlinkRelativePat var result = Command.Create(symlink.SrcPath) .CaptureStdErr() .CaptureStdOut() - .DotNetRoot(TestContext.BuiltDotNet.BinPath) + .DotNetRoot(HostTestContext.BuiltDotNet.BinPath) .Execute(); if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows)) @@ -299,7 +299,7 @@ public void Run_framework_dependent_app_with_runtime_behind_symlink() { var dotnetSymlink = Path.Combine(testDir.Location, Binaries.GetExeName("dotnet")); - using var symlink = new SymLink(dotnetSymlink, TestContext.BuiltDotNet.BinPath); + using var symlink = new SymLink(dotnetSymlink, HostTestContext.BuiltDotNet.BinPath); Command.Create(sharedTestState.FrameworkDependentApp.AppExe) .EnvironmentVariable("DOTNET_ROOT", symlink.SrcPath) .CaptureStdErr() @@ -337,7 +337,7 @@ public void Put_dotnet_behind_symlink() { var dotnetSymlink = Path.Combine(testDir.Location, Binaries.DotNet.FileName); - using var symlink = new SymLink(dotnetSymlink, TestContext.BuiltDotNet.DotnetExecutablePath); + using var symlink = new SymLink(dotnetSymlink, HostTestContext.BuiltDotNet.DotnetExecutablePath); var result = Command.Create(symlink.SrcPath, sharedTestState.SelfContainedApp.AppDll) .CaptureStdErr() .CaptureStdOut() @@ -369,7 +369,7 @@ public void Put_app_directory_behind_symlink_and_use_dotnet() Directory.Move(app.Location, newAppDir.Location); using var symlink = new SymLink(app.Location, newAppDir.Location); - TestContext.BuiltDotNet.Exec(app.AppDll) + HostTestContext.BuiltDotNet.Exec(app.AppDll) .CaptureStdErr() .CaptureStdOut() .Execute() diff --git a/src/installer/tests/HostActivation.Tests/Tracing.cs b/src/installer/tests/HostActivation.Tests/Tracing.cs index 9c0eb97c1f08ab..72c1fc2367cd31 100644 --- a/src/installer/tests/HostActivation.Tests/Tracing.cs +++ b/src/installer/tests/HostActivation.Tests/Tracing.cs @@ -18,7 +18,7 @@ public class Tracing [Fact] public void TracingOff() { - TestContext.BuiltDotNet.Exec("--list-runtimes") + HostTestContext.BuiltDotNet.Exec("--list-runtimes") .CaptureStdOut() .CaptureStdErr() .Execute() @@ -30,7 +30,7 @@ public void TracingOff() [Fact] public void TracingOnDefault() { - TestContext.BuiltDotNet.Exec("--list-runtimes") + HostTestContext.BuiltDotNet.Exec("--list-runtimes") .EnableTracingAndCaptureOutputs() .Execute() .Should().Pass() @@ -41,7 +41,7 @@ public void TracingOnDefault() [Fact] public void TracingOnVerbose() { - TestContext.BuiltDotNet.Exec("--list-runtimes") + HostTestContext.BuiltDotNet.Exec("--list-runtimes") .EnableTracingAndCaptureOutputs() .EnvironmentVariable(Constants.HostTracing.VerbosityEnvironmentVariable, "4") .Execute() @@ -53,7 +53,7 @@ public void TracingOnVerbose() [Fact] public void TracingOnInfo() { - TestContext.BuiltDotNet.Exec("--list-runtimes") + HostTestContext.BuiltDotNet.Exec("--list-runtimes") .EnableTracingAndCaptureOutputs() .EnvironmentVariable(Constants.HostTracing.VerbosityEnvironmentVariable, "3") .Execute() @@ -65,7 +65,7 @@ public void TracingOnInfo() [Fact] public void TracingOnWarning() { - TestContext.BuiltDotNet.Exec("--list-runtimes") + HostTestContext.BuiltDotNet.Exec("--list-runtimes") .EnableTracingAndCaptureOutputs() .EnvironmentVariable(Constants.HostTracing.VerbosityEnvironmentVariable, "2") .Execute() @@ -78,7 +78,7 @@ public void TracingOnWarning() public void TracingOnToFileDefault() { string traceFilePath; - TestContext.BuiltDotNet.Exec("--list-runtimes") + HostTestContext.BuiltDotNet.Exec("--list-runtimes") .EnableHostTracingToFile(out traceFilePath) .CaptureStdOut() .CaptureStdErr() @@ -95,7 +95,7 @@ public void TracingOnToFileDefault() [Fact] public void TracingOnToFileBadPathDefault() { - TestContext.BuiltDotNet.Exec("--list-runtimes") + HostTestContext.BuiltDotNet.Exec("--list-runtimes") .EnableTracingAndCaptureOutputs() .EnvironmentVariable(Constants.HostTracing.TraceFileEnvironmentVariable, "badpath/TracingOnToFileBadPathDefault.log") .Execute() @@ -110,7 +110,7 @@ public void TracingOnToDirectory() { using (TestArtifact directory = TestArtifact.Create("trace")) { - var result = TestContext.BuiltDotNet.Exec("--list-runtimes") + var result = HostTestContext.BuiltDotNet.Exec("--list-runtimes") .EnableHostTracingToPath(directory.Location) .CaptureStdOut() .CaptureStdErr() @@ -128,7 +128,7 @@ public void TracingOnToDirectory() [Fact] public void LegacyVariableName() { - TestContext.BuiltDotNet.Exec("--list-runtimes") + HostTestContext.BuiltDotNet.Exec("--list-runtimes") .EnvironmentVariable("COREHOST_TRACE", "1") .CaptureStdErr() .Execute() diff --git a/src/installer/tests/HostActivation.Tests/WindowsSpecificBehavior.cs b/src/installer/tests/HostActivation.Tests/WindowsSpecificBehavior.cs index d81ae928823668..7368993c8b8712 100644 --- a/src/installer/tests/HostActivation.Tests/WindowsSpecificBehavior.cs +++ b/src/installer/tests/HostActivation.Tests/WindowsSpecificBehavior.cs @@ -2,14 +2,13 @@ // The .NET Foundation licenses this file to you under the MIT license. using System; - +using System.Runtime.InteropServices; using Microsoft.DotNet.Cli.Build.Framework; using Microsoft.Win32; using Xunit; namespace Microsoft.DotNet.CoreSetup.Test.HostActivation { - [PlatformSpecific(TestPlatforms.Windows)] public class WindowsSpecificBehavior : IClassFixture { private SharedTestState sharedTestState; @@ -17,12 +16,14 @@ public class WindowsSpecificBehavior : IClassFixture $(TestInfraTargetFramework) + Exe Microsoft.NET.HostModel.Tests true @@ -9,6 +10,7 @@ $(NoWarn);NU1511 + XUnitV3 @@ -17,6 +19,7 @@ + diff --git a/src/installer/tests/TestUtils/Binaries.cs b/src/installer/tests/TestUtils/Binaries.cs index 70837a4557b4fc..1fbda4fa30501b 100644 --- a/src/installer/tests/TestUtils/Binaries.cs +++ b/src/installer/tests/TestUtils/Binaries.cs @@ -44,7 +44,7 @@ public static class AppHost public static class CoreClr { public static string FileName = GetSharedLibraryFileNameForCurrentPlatform("coreclr"); - public static string FilePath = Path.Combine(TestContext.BuiltDotNet.GreatestVersionSharedFxPath, FileName); + public static string FilePath = Path.Combine(HostTestContext.BuiltDotNet.GreatestVersionSharedFxPath, FileName); public static string MockName = GetSharedLibraryFileNameForCurrentPlatform("mockcoreclr"); public static string MockPath = Path.Combine(RepoDirectoriesProvider.Default.HostTestArtifacts, MockName); @@ -90,7 +90,7 @@ public static class SingleFileHost public static (IEnumerable Assemblies, IEnumerable NativeLibraries) GetRuntimeFiles() { - var runtimePackDir = TestContext.BuiltDotNet.GreatestVersionSharedFxPath; + var runtimePackDir = HostTestContext.BuiltDotNet.GreatestVersionSharedFxPath; var assemblies = Directory.GetFiles(runtimePackDir, "*.dll").Where(f => IsAssembly(f)); (string prefix, string suffix) = Binaries.GetSharedLibraryPrefixSuffix(); @@ -114,7 +114,7 @@ static bool IsAssembly(string filePath) public static class CetCompat { // We only support CET shadow stack compatibility for Windows x64 currently - public static bool IsSupported => OperatingSystem.IsWindows() && TestContext.BuildArchitecture == "x64"; + public static bool IsSupported => OperatingSystem.IsWindows() && HostTestContext.BuildArchitecture == "x64"; // https://learn.microsoft.com/windows/win32/debug/pe-format#debug-type private const int IMAGE_DEBUG_TYPE_EX_DLLCHARACTERISTICS = 20; diff --git a/src/installer/tests/TestUtils/CommandExtensions.cs b/src/installer/tests/TestUtils/CommandExtensions.cs index 70c18ab08ae25d..e5d7be4b81bb1c 100644 --- a/src/installer/tests/TestUtils/CommandExtensions.cs +++ b/src/installer/tests/TestUtils/CommandExtensions.cs @@ -17,7 +17,7 @@ public static Command EnableHostTracing(this Command command) public static Command EnableHostTracingToFile(this Command command, out string filePath) { - filePath = Path.Combine(TestContext.TestArtifactsPath, "trace" + Guid.NewGuid().ToString() + ".log"); + filePath = Path.Combine(HostTestContext.TestArtifactsPath, "trace" + Guid.NewGuid().ToString() + ".log"); if (File.Exists(filePath)) { File.Delete(filePath); @@ -48,7 +48,7 @@ public static Command DotNetRoot(this Command command, string dotNetRoot, string // If we are clearing out the variable, make sure we clear out any architecture-specific one too if (string.IsNullOrEmpty(dotNetRoot)) - command = command.EnvironmentVariable($"{Constants.DotnetRoot.ArchitectureEnvironmentVariablePrefix}{TestContext.BuildArchitecture.ToUpperInvariant()}", dotNetRoot); + command = command.EnvironmentVariable($"{Constants.DotnetRoot.ArchitectureEnvironmentVariablePrefix}{HostTestContext.BuildArchitecture.ToUpperInvariant()}", dotNetRoot); return command .EnvironmentVariable(Constants.DotnetRoot.EnvironmentVariable, dotNetRoot) diff --git a/src/installer/tests/TestUtils/DotNetBuilder.cs b/src/installer/tests/TestUtils/DotNetBuilder.cs index db9a316e2704fa..93be973732dde5 100644 --- a/src/installer/tests/TestUtils/DotNetBuilder.cs +++ b/src/installer/tests/TestUtils/DotNetBuilder.cs @@ -131,7 +131,7 @@ public DotNetBuilder AddMicrosoftNETCoreAppFrameworkMockCoreClr(string version, // ./shared/Microsoft.NETCore.App/ - create a mock of the root framework string netCoreAppPath = AddFramework(Constants.MicrosoftNETCoreApp, version); - string currentRid = TestContext.BuildRID; + string currentRid = HostTestContext.BuildRID; NetCoreAppBuilder.ForNETCoreApp(Constants.MicrosoftNETCoreApp, currentRid) .WithStandardRuntimeFallbacks() diff --git a/src/installer/tests/TestUtils/TestContext.cs b/src/installer/tests/TestUtils/HostTestContext.cs similarity index 97% rename from src/installer/tests/TestUtils/TestContext.cs rename to src/installer/tests/TestUtils/HostTestContext.cs index 24bbaebc0ca84d..eb67f6899b38b0 100644 --- a/src/installer/tests/TestUtils/TestContext.cs +++ b/src/installer/tests/TestUtils/HostTestContext.cs @@ -6,7 +6,7 @@ namespace Microsoft.DotNet.CoreSetup.Test { - public sealed class TestContext + public sealed class HostTestContext { public static string BuildArchitecture { get; } public static string BuildRID { get; } @@ -23,7 +23,7 @@ public sealed class TestContext private static string _testContextVariableFilePath { get; } private static ImmutableDictionary _testContextVariables { get; } - static TestContext() + static HostTestContext() { _testContextVariableFilePath = Path.Combine( Directory.GetCurrentDirectory(), diff --git a/src/installer/tests/TestUtils/PlatformSpecificFactAttribute.cs b/src/installer/tests/TestUtils/PlatformSpecificFactAttribute.cs new file mode 100644 index 00000000000000..9f59ab08784726 --- /dev/null +++ b/src/installer/tests/TestUtils/PlatformSpecificFactAttribute.cs @@ -0,0 +1,44 @@ +// 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.Runtime.InteropServices; +using Xunit; + +namespace Microsoft.DotNet.CoreSetup.Test; + +[AttributeUsage(AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +public sealed class PlatformSpecificFactAttribute : FactAttribute +{ + public PlatformSpecificFactAttribute(TestPlatforms platforms) + { + if (!TestPlatformApplies(platforms)) + { + base.Skip = "Test only runs on platform(s): " + platforms; + } + } + + internal static bool TestPlatformApplies(TestPlatforms platforms) + { + if (!platforms.HasFlag(TestPlatforms.Any) + && (!platforms.HasFlag(TestPlatforms.FreeBSD) || !RuntimeInformation.IsOSPlatform(OSPlatform.Create("FREEBSD"))) + && (!platforms.HasFlag(TestPlatforms.Linux) || !RuntimeInformation.IsOSPlatform(OSPlatform.Linux)) + && (!platforms.HasFlag(TestPlatforms.NetBSD) || !RuntimeInformation.IsOSPlatform(OSPlatform.Create("NETBSD"))) + && (!platforms.HasFlag(TestPlatforms.OSX) || !RuntimeInformation.IsOSPlatform(OSPlatform.OSX)) + && (!platforms.HasFlag(TestPlatforms.illumos) || !RuntimeInformation.IsOSPlatform(OSPlatform.Create("ILLUMOS"))) + && (!platforms.HasFlag(TestPlatforms.Solaris) || !RuntimeInformation.IsOSPlatform(OSPlatform.Create("SOLARIS"))) + && (!platforms.HasFlag(TestPlatforms.iOS) || !RuntimeInformation.IsOSPlatform(OSPlatform.Create("IOS")) || RuntimeInformation.IsOSPlatform(OSPlatform.Create("MACCATALYST"))) + && (!platforms.HasFlag(TestPlatforms.tvOS) || !RuntimeInformation.IsOSPlatform(OSPlatform.Create("TVOS"))) + && (!platforms.HasFlag(TestPlatforms.MacCatalyst) || !RuntimeInformation.IsOSPlatform(OSPlatform.Create("MACCATALYST"))) + && (!platforms.HasFlag(TestPlatforms.LinuxBionic) || !RuntimeInformation.IsOSPlatform(OSPlatform.Linux) || string.IsNullOrEmpty(Environment.GetEnvironmentVariable("ANDROID_STORAGE"))) + && (!platforms.HasFlag(TestPlatforms.Android) || !RuntimeInformation.IsOSPlatform(OSPlatform.Create("ANDROID"))) + && (!platforms.HasFlag(TestPlatforms.Browser) || !RuntimeInformation.IsOSPlatform(OSPlatform.Create("BROWSER"))) + && (!platforms.HasFlag(TestPlatforms.Wasi) || !RuntimeInformation.IsOSPlatform(OSPlatform.Create("WASI"))) + && (!platforms.HasFlag(TestPlatforms.Haiku) || !RuntimeInformation.IsOSPlatform(OSPlatform.Create("HAIKU"))) + && (!platforms.HasFlag(TestPlatforms.Windows) || !RuntimeInformation.IsOSPlatform(OSPlatform.Windows))) + { + return false; + } + return true; + } +} \ No newline at end of file diff --git a/src/installer/tests/TestUtils/PlatformSpecificTheoryAttribute.cs b/src/installer/tests/TestUtils/PlatformSpecificTheoryAttribute.cs new file mode 100644 index 00000000000000..2187024a69b4b7 --- /dev/null +++ b/src/installer/tests/TestUtils/PlatformSpecificTheoryAttribute.cs @@ -0,0 +1,19 @@ +// 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 Xunit; + +namespace Microsoft.DotNet.CoreSetup.Test; + +[AttributeUsage(AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +public sealed class PlatformSpecificTheoryAttribute : TheoryAttribute +{ + public PlatformSpecificTheoryAttribute(TestPlatforms platforms) + { + if (!PlatformSpecificFactAttribute.TestPlatformApplies(platforms)) + { + base.Skip = "Test only runs on platform(s): " + platforms; + } + } +} \ No newline at end of file diff --git a/src/installer/tests/TestUtils/RepoDirectoriesProvider.cs b/src/installer/tests/TestUtils/RepoDirectoriesProvider.cs index bf1e51ca44040f..50a92f4a910aa5 100644 --- a/src/installer/tests/TestUtils/RepoDirectoriesProvider.cs +++ b/src/installer/tests/TestUtils/RepoDirectoriesProvider.cs @@ -26,7 +26,7 @@ private RepoDirectoriesProvider() string repoRoot = GetRepoRootDirectory(); BaseArtifactsFolder = Path.Combine(repoRoot, "artifacts"); - string osPlatformConfig = $"{TestContext.BuildRID}.{TestContext.Configuration}"; + string osPlatformConfig = $"{HostTestContext.BuildRID}.{HostTestContext.Configuration}"; string artifacts = Path.Combine(BaseArtifactsFolder, "bin", osPlatformConfig); HostArtifacts = Path.Combine(artifacts, "corehost"); HostTestArtifacts = Path.Combine(artifacts, "corehost_test"); diff --git a/src/installer/tests/TestUtils/SingleFileTestApp.cs b/src/installer/tests/TestUtils/SingleFileTestApp.cs index 74a6df5cdf05da..97902b084c4a6f 100644 --- a/src/installer/tests/TestUtils/SingleFileTestApp.cs +++ b/src/installer/tests/TestUtils/SingleFileTestApp.cs @@ -43,7 +43,7 @@ private SingleFileTestApp(SingleFileTestApp source) /// /// Name of pre-built app /// - /// The is expected to be in + /// The is expected to be in /// and have been built as framework-dependent /// public static SingleFileTestApp CreateFrameworkDependent(string appName) @@ -54,7 +54,7 @@ public static SingleFileTestApp CreateFrameworkDependent(string appName) /// /// Name of pre-built app /// - /// The is expected to be in + /// The is expected to be in /// and have been built as framework-dependent /// public static SingleFileTestApp CreateSelfContained(string appName) @@ -177,23 +177,23 @@ private void PopulateBuiltAppDirectory() { // Copy the compiled app output - the app is expected to have been built as framework-dependent TestArtifact.CopyRecursive( - Path.Combine(TestContext.TestAssetsOutput, AppName), + Path.Combine(HostTestContext.TestAssetsOutput, AppName), builtApp.Location); // Remove any runtimeconfig.json or deps.json - we will be creating new ones File.Delete(builtApp.RuntimeConfigJson); File.Delete(builtApp.DepsJson); - var shortVersion = TestContext.Tfm[3..]; // trim "net" from beginning - var builder = NetCoreAppBuilder.ForNETCoreApp(AppName, TestContext.BuildRID, shortVersion); + var shortVersion = HostTestContext.Tfm[3..]; // trim "net" from beginning + var builder = NetCoreAppBuilder.ForNETCoreApp(AppName, HostTestContext.BuildRID, shortVersion); // Update the .runtimeconfig.json builder.WithRuntimeConfig(c => { - c.WithTfm(TestContext.Tfm); + c.WithTfm(HostTestContext.Tfm); c = selfContained - ? c.WithIncludedFramework(Constants.MicrosoftNETCoreApp, TestContext.MicrosoftNETCoreAppVersion) - : c.WithFramework(Constants.MicrosoftNETCoreApp, TestContext.MicrosoftNETCoreAppVersion); + ? c.WithIncludedFramework(Constants.MicrosoftNETCoreApp, HostTestContext.MicrosoftNETCoreAppVersion) + : c.WithFramework(Constants.MicrosoftNETCoreApp, HostTestContext.MicrosoftNETCoreAppVersion); }); // Add runtime libraries and assets for generating the .deps.json. @@ -205,7 +205,7 @@ private void PopulateBuiltAppDirectory() .WithAsset(Path.GetFileName(builtApp.AppDll), f => f.NotOnDisk()))); if (selfContained) { - builder.WithRuntimePack($"{Constants.MicrosoftNETCoreApp}.Runtime.{TestContext.BuildRID}", TestContext.MicrosoftNETCoreAppVersion, l => l + builder.WithRuntimePack($"{Constants.MicrosoftNETCoreApp}.Runtime.{HostTestContext.BuildRID}", HostTestContext.MicrosoftNETCoreAppVersion, l => l .WithAssemblyGroup(string.Empty, g => { foreach (var file in Binaries.GetRuntimeFiles().Assemblies) diff --git a/src/installer/tests/TestUtils/TestApp.cs b/src/installer/tests/TestUtils/TestApp.cs index ace429ccdbc187..278225386786eb 100644 --- a/src/installer/tests/TestUtils/TestApp.cs +++ b/src/installer/tests/TestUtils/TestApp.cs @@ -57,7 +57,7 @@ public static TestApp CreateFromBuiltAssets(string appName, string assetRelative assetRelativePath = assetRelativePath ?? appName; TestApp app = CreateEmpty(appName); TestArtifact.CopyRecursive( - Path.Combine(TestContext.TestAssetsOutput, assetRelativePath), + Path.Combine(HostTestContext.TestAssetsOutput, assetRelativePath), app.Location); return app; } @@ -107,18 +107,18 @@ public enum MockedComponent public void PopulateSelfContained(MockedComponent mock, Action customizer = null) { - var builder = NetCoreAppBuilder.ForNETCoreApp(Name, TestContext.BuildRID); + var builder = NetCoreAppBuilder.ForNETCoreApp(Name, HostTestContext.BuildRID); // Update the .runtimeconfig.json - add included framework and remove any existing NETCoreApp framework builder.WithRuntimeConfig(c => - c.WithIncludedFramework(Constants.MicrosoftNETCoreApp, TestContext.MicrosoftNETCoreAppVersion) + c.WithIncludedFramework(Constants.MicrosoftNETCoreApp, HostTestContext.MicrosoftNETCoreAppVersion) .RemoveFramework(Constants.MicrosoftNETCoreApp)); // Add main project assembly builder.WithProject(p => p.WithAssemblyGroup(null, g => g.WithMainAssembly())); // Add runtime libraries and assets - builder.WithRuntimePack($"{Constants.MicrosoftNETCoreApp}.Runtime.{TestContext.BuildRID}", TestContext.MicrosoftNETCoreAppVersion, l => + builder.WithRuntimePack($"{Constants.MicrosoftNETCoreApp}.Runtime.{HostTestContext.BuildRID}", HostTestContext.MicrosoftNETCoreAppVersion, l => { if (mock == MockedComponent.None) { diff --git a/src/installer/tests/TestUtils/TestArtifact.cs b/src/installer/tests/TestUtils/TestArtifact.cs index 65062c542992a4..4fdac7380bbe96 100644 --- a/src/installer/tests/TestUtils/TestArtifact.cs +++ b/src/installer/tests/TestUtils/TestArtifact.cs @@ -120,7 +120,7 @@ protected static (string, string) GetNewTestArtifactPath(string artifactName) Exception? lastException = null; for (int i = 0; i < 10; i++) { - var parentPath = Path.Combine(TestContext.TestArtifactsPath, Path.GetRandomFileName()); + var parentPath = Path.Combine(HostTestContext.TestArtifactsPath, Path.GetRandomFileName()); // Create a lock file next to the target folder var lockPath = parentPath + ".lock"; var artifactPath = Path.Combine(parentPath, artifactName); diff --git a/src/installer/tests/TestUtils/TestUtils.csproj b/src/installer/tests/TestUtils/TestUtils.csproj index bc3968f7de2a13..015e97c6efc6af 100644 --- a/src/installer/tests/TestUtils/TestUtils.csproj +++ b/src/installer/tests/TestUtils/TestUtils.csproj @@ -16,8 +16,8 @@ - - + + From af86f90c1b559341df55772ca0cd2df9274d1ae2 Mon Sep 17 00:00:00 2001 From: Andy Gocke Date: Mon, 29 Sep 2025 16:09:30 -0700 Subject: [PATCH 02/21] Remove top-level xunitv3 spec --- src/installer/tests/Directory.Build.props | 1 - 1 file changed, 1 deletion(-) diff --git a/src/installer/tests/Directory.Build.props b/src/installer/tests/Directory.Build.props index fa2eb44e9d9c12..f0c55d9d571149 100644 --- a/src/installer/tests/Directory.Build.props +++ b/src/installer/tests/Directory.Build.props @@ -10,7 +10,6 @@ $(TestRunnerAdditionalArguments) --crashdump $(TestRunnerAdditionalArguments) --hangdump --hangdump-timeout 5m --hangdump-type full false - XUnitV3 From af74901dbd81dcaf2f0b38b169aee0d1c32d14f2 Mon Sep 17 00:00:00 2001 From: Andy Gocke Date: Mon, 29 Sep 2025 23:19:47 -0700 Subject: [PATCH 03/21] Convert packaging tests --- .../Microsoft.DotNet.CoreSetup.Packaging.Tests.csproj | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/installer/tests/Microsoft.DotNet.CoreSetup.Packaging.Tests/Microsoft.DotNet.CoreSetup.Packaging.Tests.csproj b/src/installer/tests/Microsoft.DotNet.CoreSetup.Packaging.Tests/Microsoft.DotNet.CoreSetup.Packaging.Tests.csproj index 247a015b3940d5..ed60bce4638284 100644 --- a/src/installer/tests/Microsoft.DotNet.CoreSetup.Packaging.Tests/Microsoft.DotNet.CoreSetup.Packaging.Tests.csproj +++ b/src/installer/tests/Microsoft.DotNet.CoreSetup.Packaging.Tests/Microsoft.DotNet.CoreSetup.Packaging.Tests.csproj @@ -2,10 +2,12 @@ $(TestInfraTargetFramework) + Exe false $(NoWarn);NU1511 + XUnitV3 From da83a37f36a96717e8741bc72175d158b26ef899 Mon Sep 17 00:00:00 2001 From: Andy Gocke Date: Tue, 30 Sep 2025 20:20:08 -0700 Subject: [PATCH 04/21] Remove dotnet test from the start of helix publish --- src/installer/tests/helixpublish.proj | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/installer/tests/helixpublish.proj b/src/installer/tests/helixpublish.proj index 3db775f566567b..e568bb7bd82d89 100644 --- a/src/installer/tests/helixpublish.proj +++ b/src/installer/tests/helixpublish.proj @@ -47,7 +47,7 @@ - dotnet test $([System.IO.Path]::GetFileName($(_TargetPath))) $(TestRunnerAdditionalArguments) --logger trx --results-directory . + $([System.IO.Path]::GetFileName($(_TargetPath))) $(TestRunnerAdditionalArguments) --logger trx --results-directory . $(_PayloadDirectory) From 9600b1d4bd3b458936a7e133a4d024c7a202d25a Mon Sep 17 00:00:00 2001 From: Andy Gocke Date: Wed, 1 Oct 2025 13:34:46 -0700 Subject: [PATCH 05/21] Update command to use GetFileNameWithoutExtension Quick change for Unix --- src/installer/tests/helixpublish.proj | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/installer/tests/helixpublish.proj b/src/installer/tests/helixpublish.proj index e568bb7bd82d89..74feb52f9c34a2 100644 --- a/src/installer/tests/helixpublish.proj +++ b/src/installer/tests/helixpublish.proj @@ -47,7 +47,7 @@ - $([System.IO.Path]::GetFileName($(_TargetPath))) $(TestRunnerAdditionalArguments) --logger trx --results-directory . + ./$([System.IO.Path]::GetFileNameWithoutExtension($(_TargetPath))) $(TestRunnerAdditionalArguments) --logger trx --results-directory . $(_PayloadDirectory) From 1979e5b982fefd790b2c5f04e210d04d2c7bbaba Mon Sep 17 00:00:00 2001 From: Andy Gocke Date: Wed, 1 Oct 2025 22:15:56 -0700 Subject: [PATCH 06/21] chmod test exe --- src/installer/tests/helixpublish.proj | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/installer/tests/helixpublish.proj b/src/installer/tests/helixpublish.proj index 74feb52f9c34a2..d7da7036f82b4f 100644 --- a/src/installer/tests/helixpublish.proj +++ b/src/installer/tests/helixpublish.proj @@ -45,9 +45,13 @@ + + <_TestExePath>$([System.IO.Path]::GetFileNameWithoutExtension($(_TargetPath))) + + <_HelixPreCommands Include="chmod +x $(_TestExePath)" Condition="'$(TargetOS)' != 'windows'" /> - ./$([System.IO.Path]::GetFileNameWithoutExtension($(_TargetPath))) $(TestRunnerAdditionalArguments) --logger trx --results-directory . + ./$(_TestExePath) $(TestRunnerAdditionalArguments) --logger trx --results-directory . $(_PayloadDirectory) From 63411652576f260f253e01056f6ec40c15a9e760 Mon Sep 17 00:00:00 2001 From: Andy Gocke Date: Thu, 2 Oct 2025 00:44:22 -0700 Subject: [PATCH 07/21] fix option name --- src/installer/tests/helixpublish.proj | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/installer/tests/helixpublish.proj b/src/installer/tests/helixpublish.proj index d7da7036f82b4f..743c982c917652 100644 --- a/src/installer/tests/helixpublish.proj +++ b/src/installer/tests/helixpublish.proj @@ -51,7 +51,7 @@ <_HelixPreCommands Include="chmod +x $(_TestExePath)" Condition="'$(TargetOS)' != 'windows'" /> - ./$(_TestExePath) $(TestRunnerAdditionalArguments) --logger trx --results-directory . + ./$(_TestExePath) $(TestRunnerAdditionalArguments) --report-trx --results-directory . $(_PayloadDirectory) From d04c97e0f5da079a715a60d78d97a8ab08c9746d Mon Sep 17 00:00:00 2001 From: Andy Gocke Date: Thu, 2 Oct 2025 10:29:03 -0700 Subject: [PATCH 08/21] Adjust for Windows --- src/installer/tests/helixpublish.proj | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/src/installer/tests/helixpublish.proj b/src/installer/tests/helixpublish.proj index 743c982c917652..16036c89ee90e7 100644 --- a/src/installer/tests/helixpublish.proj +++ b/src/installer/tests/helixpublish.proj @@ -45,13 +45,15 @@ + - <_TestExePath>$([System.IO.Path]::GetFileNameWithoutExtension($(_TargetPath))) + <_TestExePath>$([System.IO.Path]::GetFileNameWithoutExtension($(_TargetPath)))$(ExeSuffix) + - <_HelixPreCommands Include="chmod +x $(_TestExePath)" Condition="'$(TargetOS)' != 'windows'" /> ./$(_TestExePath) $(TestRunnerAdditionalArguments) --report-trx --results-directory . + chmod +x $(_TestExePath) $(_PayloadDirectory) @@ -62,7 +64,7 @@ %(HostTestProject.PayloadDirectory) %(HostTestProject.Command) - @(_HelixPreCommands) + @(_HelixPreCommands);%(HostTestProject.PreCommands) 00:30:00 From 7a760003ab814c23e5bd3625cdf7c607b61d88e1 Mon Sep 17 00:00:00 2001 From: Andy Gocke Date: Thu, 2 Oct 2025 11:28:51 -0700 Subject: [PATCH 09/21] Fix macos helix RID --- src/installer/tests/helixpublish.proj | 1 + 1 file changed, 1 insertion(+) diff --git a/src/installer/tests/helixpublish.proj b/src/installer/tests/helixpublish.proj index 16036c89ee90e7..c03232bf8c5c25 100644 --- a/src/installer/tests/helixpublish.proj +++ b/src/installer/tests/helixpublish.proj @@ -10,6 +10,7 @@ true sdk + $(TargetOS)-$(TargetArchitecture) From bf4d774fde024775e573e3f314564f90874cfddc Mon Sep 17 00:00:00 2001 From: Andy Gocke Date: Thu, 2 Oct 2025 13:16:55 -0700 Subject: [PATCH 10/21] Inverted condition --- src/installer/tests/helixpublish.proj | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/installer/tests/helixpublish.proj b/src/installer/tests/helixpublish.proj index c03232bf8c5c25..178fbd1715a2b2 100644 --- a/src/installer/tests/helixpublish.proj +++ b/src/installer/tests/helixpublish.proj @@ -54,7 +54,7 @@ ./$(_TestExePath) $(TestRunnerAdditionalArguments) --report-trx --results-directory . - chmod +x $(_TestExePath) + chmod +x $(_TestExePath) $(_PayloadDirectory) From cfc2d9440e6ea8efeec88d929ee89d473cda33c6 Mon Sep 17 00:00:00 2001 From: Andy Gocke Date: Thu, 2 Oct 2025 13:20:13 -0700 Subject: [PATCH 11/21] Use TargetRid instead of constructing manually --- src/installer/tests/helixpublish.proj | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/installer/tests/helixpublish.proj b/src/installer/tests/helixpublish.proj index 178fbd1715a2b2..21e774e66fb32d 100644 --- a/src/installer/tests/helixpublish.proj +++ b/src/installer/tests/helixpublish.proj @@ -10,7 +10,7 @@ true sdk - $(TargetOS)-$(TargetArchitecture) + $(TargetRid) From 79bd903e84c42467008dd511f7e7c04ea3dbecc0 Mon Sep 17 00:00:00 2001 From: Andy Gocke Date: Thu, 2 Oct 2025 18:46:10 -0700 Subject: [PATCH 12/21] Use the target RID as the RID for the test projects --- .../tests/AppHost.Bundle.Tests/AppHost.Bundle.Tests.csproj | 1 + .../tests/HostActivation.Tests/HostActivation.Tests.csproj | 1 + .../Microsoft.DotNet.CoreSetup.Packaging.Tests.csproj | 1 + .../Microsoft.NET.HostModel.Tests.csproj | 1 + 4 files changed, 4 insertions(+) diff --git a/src/installer/tests/AppHost.Bundle.Tests/AppHost.Bundle.Tests.csproj b/src/installer/tests/AppHost.Bundle.Tests/AppHost.Bundle.Tests.csproj index 93fc95c57691c1..51433527076fd0 100644 --- a/src/installer/tests/AppHost.Bundle.Tests/AppHost.Bundle.Tests.csproj +++ b/src/installer/tests/AppHost.Bundle.Tests/AppHost.Bundle.Tests.csproj @@ -3,6 +3,7 @@ Apphost Bundle Tests Exe + $(TargetRid) $(TestInfraTargetFramework) AppHost.Bundle.Tests true diff --git a/src/installer/tests/HostActivation.Tests/HostActivation.Tests.csproj b/src/installer/tests/HostActivation.Tests/HostActivation.Tests.csproj index a9148408fc8b57..6202c71150c9f6 100644 --- a/src/installer/tests/HostActivation.Tests/HostActivation.Tests.csproj +++ b/src/installer/tests/HostActivation.Tests/HostActivation.Tests.csproj @@ -3,6 +3,7 @@ Exe $(TestInfraTargetFramework) + $(TargetRid) HostActivation.Tests true diff --git a/src/installer/tests/Microsoft.DotNet.CoreSetup.Packaging.Tests/Microsoft.DotNet.CoreSetup.Packaging.Tests.csproj b/src/installer/tests/Microsoft.DotNet.CoreSetup.Packaging.Tests/Microsoft.DotNet.CoreSetup.Packaging.Tests.csproj index ed60bce4638284..462623def45dfc 100644 --- a/src/installer/tests/Microsoft.DotNet.CoreSetup.Packaging.Tests/Microsoft.DotNet.CoreSetup.Packaging.Tests.csproj +++ b/src/installer/tests/Microsoft.DotNet.CoreSetup.Packaging.Tests/Microsoft.DotNet.CoreSetup.Packaging.Tests.csproj @@ -3,6 +3,7 @@ $(TestInfraTargetFramework) Exe + $(TargetRid) false diff --git a/src/installer/tests/Microsoft.NET.HostModel.Tests/Microsoft.NET.HostModel.Tests.csproj b/src/installer/tests/Microsoft.NET.HostModel.Tests/Microsoft.NET.HostModel.Tests.csproj index 8438d907dc1a76..808c5e13378118 100644 --- a/src/installer/tests/Microsoft.NET.HostModel.Tests/Microsoft.NET.HostModel.Tests.csproj +++ b/src/installer/tests/Microsoft.NET.HostModel.Tests/Microsoft.NET.HostModel.Tests.csproj @@ -3,6 +3,7 @@ $(TestInfraTargetFramework) Exe + $(TargetRid) Microsoft.NET.HostModel.Tests true From bcfa65f369faf923a57d5dce550ca6abd558dd08 Mon Sep 17 00:00:00 2001 From: Andy Gocke Date: Thu, 2 Oct 2025 23:10:59 -0700 Subject: [PATCH 13/21] Only use ./ on Unix --- src/installer/tests/helixpublish.proj | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/installer/tests/helixpublish.proj b/src/installer/tests/helixpublish.proj index 21e774e66fb32d..7233e1908ddbc8 100644 --- a/src/installer/tests/helixpublish.proj +++ b/src/installer/tests/helixpublish.proj @@ -53,7 +53,8 @@ - ./$(_TestExePath) $(TestRunnerAdditionalArguments) --report-trx --results-directory . + $(_TestExePath) $(TestRunnerAdditionalArguments) --report-trx --results-directory . + ./%(Command) chmod +x $(_TestExePath) $(_PayloadDirectory) From 106e2d51233dcab352141daee81f2df46bd4f4f8 Mon Sep 17 00:00:00 2001 From: Andy Gocke Date: Fri, 3 Oct 2025 11:25:41 -0700 Subject: [PATCH 14/21] Add item qualification --- src/installer/tests/helixpublish.proj | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/installer/tests/helixpublish.proj b/src/installer/tests/helixpublish.proj index 7233e1908ddbc8..057bfed1d4208d 100644 --- a/src/installer/tests/helixpublish.proj +++ b/src/installer/tests/helixpublish.proj @@ -54,7 +54,7 @@ $(_TestExePath) $(TestRunnerAdditionalArguments) --report-trx --results-directory . - ./%(Command) + ./%(HostTestProject.Command) chmod +x $(_TestExePath) $(_PayloadDirectory) From 7fb272e853fb49374e2752e59c26d9cdba7562ea Mon Sep 17 00:00:00 2001 From: Andy Gocke Date: Fri, 3 Oct 2025 16:02:43 -0700 Subject: [PATCH 15/21] Use full conditions in itemgroup --- src/installer/tests/helixpublish.proj | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/installer/tests/helixpublish.proj b/src/installer/tests/helixpublish.proj index 057bfed1d4208d..7ad19673f90ad7 100644 --- a/src/installer/tests/helixpublish.proj +++ b/src/installer/tests/helixpublish.proj @@ -53,8 +53,8 @@ - $(_TestExePath) $(TestRunnerAdditionalArguments) --report-trx --results-directory . - ./%(HostTestProject.Command) + $(_TestExePath) $(TestRunnerAdditionalArguments) --report-trx --results-directory . + ./$(_TestExePath) $(TestRunnerAdditionalArguments) --report-trx --results-directory . chmod +x $(_TestExePath) $(_PayloadDirectory) From 53583a212334752ad7c4e2124b5061e2844f1006 Mon Sep 17 00:00:00 2001 From: Andy Gocke Date: Fri, 3 Oct 2025 17:58:59 -0700 Subject: [PATCH 16/21] Change Packaging RID to use HostRid --- .../Microsoft.DotNet.CoreSetup.Packaging.Tests.csproj | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/installer/tests/Microsoft.DotNet.CoreSetup.Packaging.Tests/Microsoft.DotNet.CoreSetup.Packaging.Tests.csproj b/src/installer/tests/Microsoft.DotNet.CoreSetup.Packaging.Tests/Microsoft.DotNet.CoreSetup.Packaging.Tests.csproj index 462623def45dfc..65fba58869bf6d 100644 --- a/src/installer/tests/Microsoft.DotNet.CoreSetup.Packaging.Tests/Microsoft.DotNet.CoreSetup.Packaging.Tests.csproj +++ b/src/installer/tests/Microsoft.DotNet.CoreSetup.Packaging.Tests/Microsoft.DotNet.CoreSetup.Packaging.Tests.csproj @@ -3,7 +3,8 @@ $(TestInfraTargetFramework) Exe - $(TargetRid) + + $(HostRid) false From 3df0cf1452b5909ae8a98a32da3f9f99840aa8b3 Mon Sep 17 00:00:00 2001 From: Andy Gocke Date: Mon, 13 Oct 2025 14:40:16 -0700 Subject: [PATCH 17/21] Revert addition of PlatformSpecificFact/Theory The existing PlatformSpecific attributes are now available in Arcade. Their usage should still probably be retired since it makes a plain 'dotnet run' fail, but that can be a later improvement --- .../tests/AppHost.Bundle.Tests/AppLaunch.cs | 7 ++- .../FrameworkDependentAppLaunch.cs | 15 ++++--- .../tests/HostActivation.Tests/InvalidHost.cs | 6 ++- .../MachOHostSigningTests.cs | 3 +- .../SelfContainedAppLaunch.cs | 5 ++- .../AppHost/CreateAppHost.cs | 9 ++-- .../MachObjectSigning/MachObjectTests.cs | 3 +- .../MachObjectSigning/SigningTests.cs | 9 ++-- .../PlatformSpecificFactAttribute.cs | 44 ------------------- .../PlatformSpecificTheoryAttribute.cs | 19 -------- .../tests/TestUtils/TestUtils.csproj | 2 +- 11 files changed, 37 insertions(+), 85 deletions(-) delete mode 100644 src/installer/tests/TestUtils/PlatformSpecificFactAttribute.cs delete mode 100644 src/installer/tests/TestUtils/PlatformSpecificTheoryAttribute.cs diff --git a/src/installer/tests/AppHost.Bundle.Tests/AppLaunch.cs b/src/installer/tests/AppHost.Bundle.Tests/AppLaunch.cs index 775f7458dcc2a7..b6d84a1d53a8a4 100644 --- a/src/installer/tests/AppHost.Bundle.Tests/AppLaunch.cs +++ b/src/installer/tests/AppHost.Bundle.Tests/AppLaunch.cs @@ -110,13 +110,11 @@ private void NonAsciiCharacterSelfContainedApp() } } - [Theory] + [ConditionalTheory(typeof(Binaries.CetCompat), nameof(Binaries.CetCompat.IsSupported))] [InlineData(true)] [InlineData(false)] public void DisableCetCompat(bool selfContained) { - Assert.SkipUnless(Binaries.CetCompat.IsSupported, "CET not supported on this platform"); - SingleFileTestApp app = selfContained ? sharedTestState.SelfContainedApp.Copy() : sharedTestState.FrameworkDependentApp.Copy(); @@ -178,7 +176,8 @@ public void FrameworkDependent_NoBundleEntryPoint() } } - [PlatformSpecificFact(TestPlatforms.Windows)] // GUI app host is only supported on Windows. + [Fact] + [PlatformSpecific(TestPlatforms.Windows)] public void FrameworkDependent_GUI_DownlevelHostFxr_ErrorDialog() { var singleFile = sharedTestState.FrameworkDependentApp.Bundle(); diff --git a/src/installer/tests/HostActivation.Tests/FrameworkDependentAppLaunch.cs b/src/installer/tests/HostActivation.Tests/FrameworkDependentAppLaunch.cs index c27eecb8f7baf7..f95f44d281a66c 100644 --- a/src/installer/tests/HostActivation.Tests/FrameworkDependentAppLaunch.cs +++ b/src/installer/tests/HostActivation.Tests/FrameworkDependentAppLaunch.cs @@ -219,7 +219,8 @@ public void AppHost_DisableCetCompat() .And.HaveStdOutContaining(HostTestContext.MicrosoftNETCoreAppVersion); } - [PlatformSpecificFact(TestPlatforms.Windows)] + [Fact] + [PlatformSpecific(TestPlatforms.Windows)] public void AppHost_DotNetRoot_DevicePath() { string appExe = sharedTestState.App.AppExe; @@ -414,7 +415,8 @@ public void AppHost_CLI_MissingRuntimeFramework_ErrorReportedInStdErr(bool missi } } - [PlatformSpecificFact(TestPlatforms.Windows)] // GUI app host is only supported on Windows. + [Fact] + [PlatformSpecific(TestPlatforms.Windows)] // GUI app host is only supported on Windows. public void AppHost_GUI_MissingRuntimeFramework_ErrorReportedInDialog() { TestApp app = sharedTestState.App.Copy(); @@ -450,7 +452,8 @@ public void AppHost_GUI_MissingRuntimeFramework_ErrorReportedInDialog() } } - [PlatformSpecificFact(TestPlatforms.Windows)] + [Fact] + [PlatformSpecific(TestPlatforms.Windows)] public void AppHost_GUI_MissingRuntime_ErrorReportedInDialog() { TestApp app = sharedTestState.App.Copy(); @@ -478,7 +481,8 @@ public void AppHost_GUI_MissingRuntime_ErrorReportedInDialog() } } - [PlatformSpecificFact(TestPlatforms.Windows)] // GUI app host is only supported on Windows. + [Fact] + [PlatformSpecific(TestPlatforms.Windows)] // GUI app host is only supported on Windows. public void AppHost_GUI_NoCustomErrorWriter_FrameworkMissing_ErrorReportedInDialog() { TestApp app = sharedTestState.App.Copy(); @@ -512,7 +516,8 @@ public void AppHost_GUI_NoCustomErrorWriter_FrameworkMissing_ErrorReportedInDial } } - [PlatformSpecificFact(TestPlatforms.Windows)] // GUI app host is only supported on Windows. + [Fact] + [PlatformSpecific(TestPlatforms.Windows)] // GUI app host is only supported on Windows. public void AppHost_GUI_DisabledGUIErrors_DialogNotShown() { TestApp app = sharedTestState.App.Copy(); diff --git a/src/installer/tests/HostActivation.Tests/InvalidHost.cs b/src/installer/tests/HostActivation.Tests/InvalidHost.cs index 2460481d6236b5..74e765df798fdb 100644 --- a/src/installer/tests/HostActivation.Tests/InvalidHost.cs +++ b/src/installer/tests/HostActivation.Tests/InvalidHost.cs @@ -34,7 +34,8 @@ public void AppHost_NotBound() .And.ExitWith(Constants.ErrorCode.AppHostExeNotBoundFailure); } - [PlatformSpecificFact(TestPlatforms.Windows)] // GUI app host is only supported on Windows. + [Fact] + [PlatformSpecific(TestPlatforms.Windows)] // GUI app host is only supported on Windows. public void AppHost_NotBound_GUI() { Command.Create(sharedTestState.UnboundAppHostGUI) @@ -45,7 +46,8 @@ public void AppHost_NotBound_GUI() .And.HaveStdErrContaining("This executable is not bound to a managed DLL to execute."); } - [PlatformSpecificFact(TestPlatforms.Windows)] // GUI app host is only supported on Windows. + [Fact] + [PlatformSpecific(TestPlatforms.Windows)] // GUI app host is only supported on Windows. public void AppHost_NotBound_GUI_TraceFile() { string traceFilePath; diff --git a/src/installer/tests/HostActivation.Tests/MachOHostSigningTests.cs b/src/installer/tests/HostActivation.Tests/MachOHostSigningTests.cs index cf401da3850ba7..70bc3b86a51eff 100644 --- a/src/installer/tests/HostActivation.Tests/MachOHostSigningTests.cs +++ b/src/installer/tests/HostActivation.Tests/MachOHostSigningTests.cs @@ -15,7 +15,8 @@ namespace HostActivation.Tests { public class MachOHostSigningTests { - [PlatformSpecificFact(TestPlatforms.OSX)] + [Fact] + [PlatformSpecific(TestPlatforms.OSX)] public void SignedAppHostRuns() { using var testDirectory = TestArtifact.Create(nameof(SignedAppHostRuns)); diff --git a/src/installer/tests/HostActivation.Tests/SelfContainedAppLaunch.cs b/src/installer/tests/HostActivation.Tests/SelfContainedAppLaunch.cs index be458178344d23..5bad3a3b9e7b3a 100644 --- a/src/installer/tests/HostActivation.Tests/SelfContainedAppLaunch.cs +++ b/src/installer/tests/HostActivation.Tests/SelfContainedAppLaunch.cs @@ -162,8 +162,9 @@ public void DotNetRoot_IncorrectLayout_Fails() .And.HaveStdErrContaining($"The required library {Binaries.HostFxr.FileName} could not be found."); } - [PlatformSpecificFact(TestPlatforms.Windows)] - public void DevicePath() + [Fact] + [PlatformSpecific(TestPlatforms.Windows)] + public void Exe_activation_of_GUI_App() { string appExe = $@"\\?\{sharedTestState.App.AppExe}"; Command.Create(appExe) diff --git a/src/installer/tests/Microsoft.NET.HostModel.Tests/AppHost/CreateAppHost.cs b/src/installer/tests/Microsoft.NET.HostModel.Tests/AppHost/CreateAppHost.cs index 496f998ae69f86..a09f4d2c96dee0 100644 --- a/src/installer/tests/Microsoft.NET.HostModel.Tests/AppHost/CreateAppHost.cs +++ b/src/installer/tests/Microsoft.NET.HostModel.Tests/AppHost/CreateAppHost.cs @@ -231,7 +231,8 @@ public void GUISubsystem_WrongDefault_Fails() } } - [PlatformSpecificFact(TestPlatforms.AnyUnix)] + [Fact] + [PlatformSpecific(TestPlatforms.AnyUnix)] public void ExecutableImage() { using TestArtifact artifact = CreateTestDirectory(); @@ -260,7 +261,8 @@ public void ExecutableImage() .Be(expectedPermissions); } - [PlatformSpecificTheory(TestPlatforms.OSX)] + [Theory] + [PlatformSpecific(TestPlatforms.OSX)] [InlineData("")] [InlineData("dir with spaces")] public void CodeSignMachOAppHost(string subdir) @@ -284,7 +286,8 @@ public void CodeSignMachOAppHost(string subdir) } } - [PlatformSpecificTheory(TestPlatforms.OSX)] + [Theory] + [PlatformSpecific(TestPlatforms.OSX)] [InlineData("")] [InlineData("dir with spaces")] public void SigningExistingAppHostCreatesNewInode(string subdir) diff --git a/src/installer/tests/Microsoft.NET.HostModel.Tests/MachObjectSigning/MachObjectTests.cs b/src/installer/tests/Microsoft.NET.HostModel.Tests/MachObjectSigning/MachObjectTests.cs index 97ac6c0e4b3cd2..902eebdbaae1d4 100644 --- a/src/installer/tests/Microsoft.NET.HostModel.Tests/MachObjectSigning/MachObjectTests.cs +++ b/src/installer/tests/Microsoft.NET.HostModel.Tests/MachObjectSigning/MachObjectTests.cs @@ -148,7 +148,8 @@ public void CanParseCodesignOutput() } // test all the binaries compared to codesinginfo from codesign output - [PlatformSpecificTheory(TestPlatforms.OSX)] + [Theory] + [PlatformSpecific(TestPlatforms.OSX)] [MemberData(nameof(GetTestFilePaths), nameof(EmbeddedSignatureBlobMatchesCodesignInfo))] public void EmbeddedSignatureBlobMatchesCodesignInfo(string filePath, TestArtifact _) { diff --git a/src/installer/tests/Microsoft.NET.HostModel.Tests/MachObjectSigning/SigningTests.cs b/src/installer/tests/Microsoft.NET.HostModel.Tests/MachObjectSigning/SigningTests.cs index dec8a00253c474..003220e9017caf 100644 --- a/src/installer/tests/Microsoft.NET.HostModel.Tests/MachObjectSigning/SigningTests.cs +++ b/src/installer/tests/Microsoft.NET.HostModel.Tests/MachObjectSigning/SigningTests.cs @@ -77,7 +77,8 @@ public void CanUnsignAndResign(string filePath, TestArtifact _) Assert.True(IsSigned(managedSignedPath + ".resigned"), $"Failed to resign {filePath}"); } - [PlatformSpecificTheory(TestPlatforms.OSX)] + [Theory] + [PlatformSpecific(TestPlatforms.OSX)] [MemberData(nameof(GetTestFilePaths), nameof(MatchesCodesignOutput))] public void MatchesCodesignOutput(string filePath, TestArtifact _) { @@ -100,7 +101,8 @@ public void MatchesCodesignOutput(string filePath, TestArtifact _) AssertMachFilesAreEquivalent(codesignFilePath, managedSignedPath, fileName); } - [PlatformSpecificFact(TestPlatforms.OSX)] + [Fact] + [PlatformSpecific(TestPlatforms.OSX)] void SignedMachOExecutableRuns() { using var testArtifact = TestArtifact.Create(nameof(SignedMachOExecutableRuns)); @@ -138,7 +140,8 @@ void ReadSignedMachIsTheSameAsReadAndResigned(string filePath, TestArtifact _) } } - [PlatformSpecificFact(TestPlatforms.OSX)] + [Fact] + [PlatformSpecific(TestPlatforms.OSX)] public void OverwritingExistingBundleClearsMacOsSignatureCache() { // Bundle to a single-file and ensure it is signed diff --git a/src/installer/tests/TestUtils/PlatformSpecificFactAttribute.cs b/src/installer/tests/TestUtils/PlatformSpecificFactAttribute.cs deleted file mode 100644 index 9f59ab08784726..00000000000000 --- a/src/installer/tests/TestUtils/PlatformSpecificFactAttribute.cs +++ /dev/null @@ -1,44 +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.Runtime.InteropServices; -using Xunit; - -namespace Microsoft.DotNet.CoreSetup.Test; - -[AttributeUsage(AttributeTargets.Method, AllowMultiple = false, Inherited = false)] -public sealed class PlatformSpecificFactAttribute : FactAttribute -{ - public PlatformSpecificFactAttribute(TestPlatforms platforms) - { - if (!TestPlatformApplies(platforms)) - { - base.Skip = "Test only runs on platform(s): " + platforms; - } - } - - internal static bool TestPlatformApplies(TestPlatforms platforms) - { - if (!platforms.HasFlag(TestPlatforms.Any) - && (!platforms.HasFlag(TestPlatforms.FreeBSD) || !RuntimeInformation.IsOSPlatform(OSPlatform.Create("FREEBSD"))) - && (!platforms.HasFlag(TestPlatforms.Linux) || !RuntimeInformation.IsOSPlatform(OSPlatform.Linux)) - && (!platforms.HasFlag(TestPlatforms.NetBSD) || !RuntimeInformation.IsOSPlatform(OSPlatform.Create("NETBSD"))) - && (!platforms.HasFlag(TestPlatforms.OSX) || !RuntimeInformation.IsOSPlatform(OSPlatform.OSX)) - && (!platforms.HasFlag(TestPlatforms.illumos) || !RuntimeInformation.IsOSPlatform(OSPlatform.Create("ILLUMOS"))) - && (!platforms.HasFlag(TestPlatforms.Solaris) || !RuntimeInformation.IsOSPlatform(OSPlatform.Create("SOLARIS"))) - && (!platforms.HasFlag(TestPlatforms.iOS) || !RuntimeInformation.IsOSPlatform(OSPlatform.Create("IOS")) || RuntimeInformation.IsOSPlatform(OSPlatform.Create("MACCATALYST"))) - && (!platforms.HasFlag(TestPlatforms.tvOS) || !RuntimeInformation.IsOSPlatform(OSPlatform.Create("TVOS"))) - && (!platforms.HasFlag(TestPlatforms.MacCatalyst) || !RuntimeInformation.IsOSPlatform(OSPlatform.Create("MACCATALYST"))) - && (!platforms.HasFlag(TestPlatforms.LinuxBionic) || !RuntimeInformation.IsOSPlatform(OSPlatform.Linux) || string.IsNullOrEmpty(Environment.GetEnvironmentVariable("ANDROID_STORAGE"))) - && (!platforms.HasFlag(TestPlatforms.Android) || !RuntimeInformation.IsOSPlatform(OSPlatform.Create("ANDROID"))) - && (!platforms.HasFlag(TestPlatforms.Browser) || !RuntimeInformation.IsOSPlatform(OSPlatform.Create("BROWSER"))) - && (!platforms.HasFlag(TestPlatforms.Wasi) || !RuntimeInformation.IsOSPlatform(OSPlatform.Create("WASI"))) - && (!platforms.HasFlag(TestPlatforms.Haiku) || !RuntimeInformation.IsOSPlatform(OSPlatform.Create("HAIKU"))) - && (!platforms.HasFlag(TestPlatforms.Windows) || !RuntimeInformation.IsOSPlatform(OSPlatform.Windows))) - { - return false; - } - return true; - } -} \ No newline at end of file diff --git a/src/installer/tests/TestUtils/PlatformSpecificTheoryAttribute.cs b/src/installer/tests/TestUtils/PlatformSpecificTheoryAttribute.cs deleted file mode 100644 index 2187024a69b4b7..00000000000000 --- a/src/installer/tests/TestUtils/PlatformSpecificTheoryAttribute.cs +++ /dev/null @@ -1,19 +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 Xunit; - -namespace Microsoft.DotNet.CoreSetup.Test; - -[AttributeUsage(AttributeTargets.Method, AllowMultiple = false, Inherited = false)] -public sealed class PlatformSpecificTheoryAttribute : TheoryAttribute -{ - public PlatformSpecificTheoryAttribute(TestPlatforms platforms) - { - if (!PlatformSpecificFactAttribute.TestPlatformApplies(platforms)) - { - base.Skip = "Test only runs on platform(s): " + platforms; - } - } -} \ No newline at end of file diff --git a/src/installer/tests/TestUtils/TestUtils.csproj b/src/installer/tests/TestUtils/TestUtils.csproj index 015e97c6efc6af..a88b817b47ac5b 100644 --- a/src/installer/tests/TestUtils/TestUtils.csproj +++ b/src/installer/tests/TestUtils/TestUtils.csproj @@ -17,7 +17,7 @@ - + From 93162b274cd24adef4e97ef4dc3317dace50b61a Mon Sep 17 00:00:00 2001 From: Andy Gocke Date: Mon, 13 Oct 2025 15:31:43 -0700 Subject: [PATCH 18/21] Revert change to ConditionalFact --- .../Microsoft.NET.HostModel.Tests/AppHost/CreateAppHost.cs | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/src/installer/tests/Microsoft.NET.HostModel.Tests/AppHost/CreateAppHost.cs b/src/installer/tests/Microsoft.NET.HostModel.Tests/AppHost/CreateAppHost.cs index a09f4d2c96dee0..dc69ddb8adc80a 100644 --- a/src/installer/tests/Microsoft.NET.HostModel.Tests/AppHost/CreateAppHost.cs +++ b/src/installer/tests/Microsoft.NET.HostModel.Tests/AppHost/CreateAppHost.cs @@ -437,11 +437,9 @@ public void CetCompat(bool? cetCompatSet) } } - [Fact] + [ConditionalFact(typeof(Binaries.CetCompat), nameof(Binaries.CetCompat.IsSupported))] public void CetCompat_ProductHosts() { - Assert.SkipUnless(Binaries.CetCompat.IsSupported, "CET not supported on this platform"); - using (TestArtifact artifact = CreateTestDirectory()) { string[] hosts = [Binaries.AppHost.FilePath, Binaries.SingleFileHost.FilePath]; From 9c8aac89f5aaf3e28ec68a327d1500e6002649c0 Mon Sep 17 00:00:00 2001 From: Andy Gocke Date: Mon, 13 Oct 2025 15:33:35 -0700 Subject: [PATCH 19/21] A few more conditionalfact instances --- .../tests/HostActivation.Tests/FrameworkDependentAppLaunch.cs | 4 +--- .../tests/HostActivation.Tests/WindowsSpecificBehavior.cs | 4 +--- 2 files changed, 2 insertions(+), 6 deletions(-) diff --git a/src/installer/tests/HostActivation.Tests/FrameworkDependentAppLaunch.cs b/src/installer/tests/HostActivation.Tests/FrameworkDependentAppLaunch.cs index f95f44d281a66c..f721ffc00916e2 100644 --- a/src/installer/tests/HostActivation.Tests/FrameworkDependentAppLaunch.cs +++ b/src/installer/tests/HostActivation.Tests/FrameworkDependentAppLaunch.cs @@ -199,11 +199,9 @@ public void AppHost() .And.HaveStdOutContaining(HostTestContext.MicrosoftNETCoreAppVersion); } - [Fact] + [ConditionalFact(typeof(Binaries.CetCompat), nameof(Binaries.CetCompat.IsSupported))] public void AppHost_DisableCetCompat() { - Assert.SkipUnless(Binaries.CetCompat.IsSupported, "CET not supported on this platform"); - TestApp app = sharedTestState.App.Copy(); app.CreateAppHost(disableCetCompat: true); Assert.False(Binaries.CetCompat.IsMarkedCompatible(app.AppExe)); diff --git a/src/installer/tests/HostActivation.Tests/WindowsSpecificBehavior.cs b/src/installer/tests/HostActivation.Tests/WindowsSpecificBehavior.cs index 7368993c8b8712..d7e09f06a413e8 100644 --- a/src/installer/tests/HostActivation.Tests/WindowsSpecificBehavior.cs +++ b/src/installer/tests/HostActivation.Tests/WindowsSpecificBehavior.cs @@ -56,11 +56,9 @@ private static bool LongPathsEnabled() } } - [Fact] + [ConditionalFact(nameof(LongPathsEnabled))] public void DotNet_LongPath_Succeeds() { - Assert.SkipUnless(LongPathsEnabled(), "Long paths not enabled on this machine"); - HostTestContext.BuiltDotNet.Exec(sharedTestState.App.AppDll, "long_path", sharedTestState.App.Location) .CaptureStdErr() .CaptureStdOut() From e14b4c7bceb0d337fd4eb9549a7ab436ebcc9913 Mon Sep 17 00:00:00 2001 From: Andy Gocke Date: Mon, 13 Oct 2025 20:25:15 -0700 Subject: [PATCH 20/21] Use built-in xunit3 skip --- src/installer/tests/AppHost.Bundle.Tests/AppLaunch.cs | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/installer/tests/AppHost.Bundle.Tests/AppLaunch.cs b/src/installer/tests/AppHost.Bundle.Tests/AppLaunch.cs index b6d84a1d53a8a4..4ec9bb18e135ec 100644 --- a/src/installer/tests/AppHost.Bundle.Tests/AppLaunch.cs +++ b/src/installer/tests/AppHost.Bundle.Tests/AppLaunch.cs @@ -110,7 +110,9 @@ private void NonAsciiCharacterSelfContainedApp() } } - [ConditionalTheory(typeof(Binaries.CetCompat), nameof(Binaries.CetCompat.IsSupported))] + [Theory( + SkipType = typeof(Binaries.CetCompat), + SkipUnless = nameof(Binaries.CetCompat.IsSupported))] [InlineData(true)] [InlineData(false)] public void DisableCetCompat(bool selfContained) From 59bb904fc42c93f0c3731fda87b9f77da0076f4b Mon Sep 17 00:00:00 2001 From: Andy Gocke Date: Tue, 14 Oct 2025 10:09:26 -0700 Subject: [PATCH 21/21] Add skip message --- src/installer/tests/AppHost.Bundle.Tests/AppLaunch.cs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/installer/tests/AppHost.Bundle.Tests/AppLaunch.cs b/src/installer/tests/AppHost.Bundle.Tests/AppLaunch.cs index 4ec9bb18e135ec..121d390fe09b7b 100644 --- a/src/installer/tests/AppHost.Bundle.Tests/AppLaunch.cs +++ b/src/installer/tests/AppHost.Bundle.Tests/AppLaunch.cs @@ -112,7 +112,8 @@ private void NonAsciiCharacterSelfContainedApp() [Theory( SkipType = typeof(Binaries.CetCompat), - SkipUnless = nameof(Binaries.CetCompat.IsSupported))] + SkipUnless = nameof(Binaries.CetCompat.IsSupported), + Skip = "CET is not supported on this platform")] [InlineData(true)] [InlineData(false)] public void DisableCetCompat(bool selfContained)