-
Notifications
You must be signed in to change notification settings - Fork 288
Write warnings outside of appdomain #5371
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Changes from all commits
Commits
Show all changes
15 commits
Select commit
Hold shift + click to select a range
6500868
Write warnings outside of appdomain
nohwnd b64cb1c
refac
nohwnd 058b40f
Merge branch 'main' into warnings-wip
nohwnd 5a13db9
fix
nohwnd b3c1b8c
Test
nohwnd eb810bf
REvert
nohwnd b19041e
Merge branch 'main' into warnings-wip
nohwnd e9ffc15
ppp
nohwnd 1ba17f9
Finally happy with test
nohwnd 25d855c
whitespace
nohwnd 82e7751
fix duplicated project names, and improve error
nohwnd efa63c3
asset id, not name
nohwnd cfd63aa
Use asset id as the identifier, as it was meant
nohwnd aee5219
Comment on how to use the fixture
nohwnd ea001f5
Fix mocking unit test
nohwnd File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
14 changes: 14 additions & 0 deletions
14
src/Adapter/MSTest.TestAdapter/Discovery/AssemblyEnumerationResult.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,14 @@ | ||
| // Copyright (c) Microsoft Corporation. All rights reserved. | ||
| // Licensed under the MIT license. See LICENSE file in the project root for full license information. | ||
|
|
||
| using Microsoft.VisualStudio.TestPlatform.MSTest.TestAdapter.ObjectModel; | ||
|
|
||
| namespace Microsoft.VisualStudio.TestPlatform.MSTest.TestAdapter.Discovery; | ||
|
|
||
| /// <summary> | ||
| /// Helps us communicate results that were created inside of AppDomain, when AppDomains are available and enabled. | ||
| /// </summary> | ||
| /// <param name="TestElements">The test elements that were discovered.</param> | ||
| /// <param name="Warnings">Warnings that happened during discovery.</param> | ||
| [Serializable] | ||
| internal sealed record AssemblyEnumerationResult(List<UnitTestElement> TestElements, List<string> Warnings); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
132 changes: 132 additions & 0 deletions
132
test/IntegrationTests/MSTest.Acceptance.IntegrationTests/TestDiscoveryWarningsTests.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,132 @@ | ||
| // Copyright (c) Microsoft Corporation. All rights reserved. | ||
| // Licensed under the MIT license. See LICENSE file in the project root for full license information. | ||
|
|
||
| using Microsoft.Testing.Platform.Acceptance.IntegrationTests; | ||
| using Microsoft.Testing.Platform.Acceptance.IntegrationTests.Helpers; | ||
| using Microsoft.Testing.Platform.Helpers; | ||
|
|
||
| namespace MSTest.Acceptance.IntegrationTests; | ||
|
|
||
| [TestClass] | ||
| public class TestDiscoveryWarningsTests : AcceptanceTestBase<TestDiscoveryWarningsTests.TestAssetFixture> | ||
| { | ||
| private const string AssetName = "TestDiscoveryWarnings"; | ||
| private const string BaseClassAssetName = "TestDiscoveryWarningsBaseClass"; | ||
|
|
||
| [TestMethod] | ||
| [DynamicData(nameof(TargetFrameworks.AllForDynamicData), typeof(TargetFrameworks))] | ||
| public async Task DiscoverTests_ShowsWarningsForTestsThatFailedToDiscover(string currentTfm) | ||
| { | ||
| var testHost = TestHost.LocateFrom(AssetFixture.TargetAssetPath, AssetName, currentTfm); | ||
|
|
||
| if (currentTfm.StartsWith("net4", StringComparison.OrdinalIgnoreCase)) | ||
| { | ||
| // .NET Framework will isolate the run into appdomain, there we did not write the warnings out | ||
| // so before running the discovery, we want to ensure that the tests do run in appdomain. | ||
| // We check for appdomain directly in the test, so if tests fail we did not run in appdomain. | ||
| TestHostResult testHostSuccessResult = await testHost.ExecuteAsync(); | ||
|
|
||
| testHostSuccessResult.AssertExitCodeIs(ExitCodes.Success); | ||
| } | ||
|
|
||
| // Delete the TestDiscoveryWarningsBaseClass.dll from the test bin folder on purpose, to break discovering | ||
| // because the type won't be loaded on runtime, and mstest will write warning. | ||
| File.Delete(Path.Combine(testHost.DirectoryName, $"{BaseClassAssetName}.dll")); | ||
|
|
||
| TestHostResult testHostResult = await testHost.ExecuteAsync("--list-tests"); | ||
|
|
||
| testHostResult.AssertExitCodeIsNot(ExitCodes.Success); | ||
| testHostResult.AssertOutputContains("System.IO.FileNotFoundException: Could not load file or assembly 'TestDiscoveryWarningsBaseClass"); | ||
| } | ||
|
|
||
| public sealed class TestAssetFixture() : TestAssetFixtureBase(AcceptanceFixture.NuGetGlobalPackagesFolder) | ||
| { | ||
| public string TargetAssetPath => GetAssetPath(AssetName); | ||
|
|
||
| public string BaseTargetAssetPath => GetAssetPath(BaseClassAssetName); | ||
|
|
||
| public override IEnumerable<(string ID, string Name, string Code)> GetAssetsToGenerate() | ||
| { | ||
| yield return (BaseClassAssetName, BaseClassAssetName, | ||
| BaseClassSourceCode.PatchTargetFrameworks(TargetFrameworks.All)); | ||
|
|
||
| yield return (AssetName, AssetName, | ||
| SourceCode.PatchTargetFrameworks(TargetFrameworks.All) | ||
| .PatchCodeWithReplace("$MSTestVersion$", MSTestVersion)); | ||
| } | ||
|
|
||
| private const string SourceCode = """ | ||
| #file TestDiscoveryWarnings.csproj | ||
| <Project Sdk="Microsoft.NET.Sdk"> | ||
|
|
||
| <PropertyGroup> | ||
| <OutputType>Exe</OutputType> | ||
| <EnableMSTestRunner>true</EnableMSTestRunner> | ||
| <TargetFrameworks>$TargetFrameworks$</TargetFrameworks> | ||
| <LangVersion>latest</LangVersion> | ||
| </PropertyGroup> | ||
|
|
||
| <ItemGroup> | ||
| <ProjectReference Include="../TestDiscoveryWarningsBaseClass/TestDiscoveryWarningsBaseClass.csproj" /> | ||
| </ItemGroup> | ||
| <ItemGroup> | ||
| <PackageReference Include="MSTest.TestAdapter" Version="$MSTestVersion$" /> | ||
| <PackageReference Include="MSTest.TestFramework" Version="$MSTestVersion$" /> | ||
| </ItemGroup> | ||
|
|
||
| </Project> | ||
|
|
||
| #file UnitTest1.cs | ||
|
|
||
| using Base; | ||
|
|
||
| using System; | ||
| using System.Threading.Tasks; | ||
| using Microsoft.VisualStudio.TestTools.UnitTesting; | ||
|
|
||
| [TestClass] | ||
| public class TestClass1 : BaseClass | ||
| { | ||
| [TestMethod] | ||
| public void Test1_1() | ||
| { | ||
| #if NETFRAMEWORK | ||
| // Ensure we run in appdomain, and not directly in host, because we want to ensure that warnings are correctly passed | ||
| // outside of the appdomain to the rest of the engine. | ||
| //\ | ||
| // We set this friendly appdomain name in src\Adapter\MSTestAdapter.PlatformServices\Services\TestSourceHost.cs:163 | ||
| StringAssert.StartsWith(AppDomain.CurrentDomain.FriendlyName, "TestSourceHost: Enumerating source"); | ||
| #endif | ||
| } | ||
| } | ||
|
|
||
| [TestClass] | ||
| public class TestClass2 | ||
| { | ||
| [TestMethod] | ||
| public void Test2_1() {} | ||
| } | ||
| """; | ||
|
|
||
| private const string BaseClassSourceCode = """ | ||
| #file TestDiscoveryWarningsBaseClass.csproj | ||
| <Project Sdk="Microsoft.NET.Sdk"> | ||
|
|
||
| <PropertyGroup> | ||
| <TargetFrameworks>$TargetFrameworks$</TargetFrameworks> | ||
| <IsPackable>false</IsPackable> | ||
| <LangVersion>latest</LangVersion> | ||
| </PropertyGroup> | ||
|
|
||
| </Project> | ||
|
|
||
|
|
||
| #file UnitTest1.cs | ||
| namespace Base; | ||
|
|
||
| public class BaseClass | ||
| { | ||
| } | ||
| """; | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.