-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Cleanup usages of IsTestProject #49838
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
Changes from 5 commits
611d422
63abd1a
e696b07
55d3bd9
8b82d23
50e4bcf
f267018
1ad64cf
9d9f317
713ebba
2cc87e7
656ea32
3b9debf
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -323,9 +323,10 @@ public void ReferencedExeCanRunWhenPublishedWithTrimming(bool referenceExeInCode | |
| } | ||
|
|
||
| [RequiresMSBuildVersionTheory("17.0.0.32901")] | ||
| [InlineData("xunit")] | ||
| [InlineData("mstest")] | ||
| public void TestProjectCanReferenceExe(string testTemplateName) | ||
| [CombinatorialData] | ||
| public void TestProjectCanReferenceExe( | ||
| [CombinatorialValues("xunit", "mstest")] string testTemplateName, | ||
| bool setSelfContainedProperty) | ||
| { | ||
| var testConsoleProject = new TestProject("ConsoleApp") | ||
| { | ||
|
|
@@ -334,6 +335,11 @@ public void TestProjectCanReferenceExe(string testTemplateName) | |
| RuntimeIdentifier = EnvironmentInfo.GetCompatibleRid() | ||
| }; | ||
|
|
||
| if (setSelfContainedProperty) | ||
| { | ||
| testConsoleProject.SelfContained = "true"; | ||
| } | ||
|
|
||
| var testAsset = _testAssetsManager.CreateTestProject(testConsoleProject, identifier: testTemplateName); | ||
|
|
||
| var testProjectDirectory = Path.Combine(testAsset.TestRoot, "TestProject"); | ||
|
|
@@ -359,6 +365,123 @@ public void TestProjectCanReferenceExe(string testTemplateName) | |
|
|
||
| } | ||
|
|
||
| [Theory] | ||
| [CombinatorialData] | ||
| public void SelfContainedExecutableCannotBeReferencedByNonSelfContainedMTPTestProject(bool setIsTestingPlatformApplicationEarly) | ||
| { | ||
| // The setup of this test is as follows: | ||
| // ConsoleApp is a self-contained executable project. | ||
| // MTPTestProject is an executable test project that references ConsoleApp. | ||
| // Building MTPTestProject should fail because it references a self-contained executable project. | ||
| // A self-contained executable cannot be referenced by a non self-contained executable. | ||
| var testConsoleProjectSelfContained = new TestProject("ConsoleApp") | ||
| { | ||
| IsExe = true, | ||
| TargetFrameworks = ToolsetInfo.CurrentTargetFramework, | ||
| SelfContained = "true", | ||
| }; | ||
|
|
||
| var testAssetSelfContained = _testAssetsManager.CreateTestProject(testConsoleProjectSelfContained); | ||
|
|
||
| var mtpNotSelfContained = new TestProject("MTPTestProject") | ||
| { | ||
| TargetFrameworks = ToolsetInfo.CurrentTargetFramework, | ||
| IsExe = true, | ||
| IsTestProject = true, | ||
| }; | ||
|
|
||
| if (setIsTestingPlatformApplicationEarly) | ||
| { | ||
| mtpNotSelfContained.IsTestingPlatformApplication = true; | ||
| } | ||
|
|
||
| var testAssetMTP = _testAssetsManager.CreateTestProject(mtpNotSelfContained); | ||
|
|
||
| var mtpProjectDirectory = Path.Combine(testAssetMTP.Path, "MTPTestProject"); | ||
| Assert.True(Directory.Exists(mtpProjectDirectory), $"Expected directory {mtpProjectDirectory} to exist."); | ||
| Assert.True(File.Exists(Path.Combine(mtpProjectDirectory, "MTPTestProject.csproj")), $"Expected file MTPTestProject.csproj to exist in {mtpProjectDirectory}."); | ||
Youssef1313 marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| if (!setIsTestingPlatformApplicationEarly) | ||
| { | ||
| File.WriteAllText(Path.Combine(mtpProjectDirectory, "Directory.Build.targets"), """ | ||
| <Project> | ||
| <PropertyGroup> | ||
| <IsTestingPlatformApplication>true</IsTestingPlatformApplication> | ||
| </PropertyGroup> | ||
| </Project> | ||
| """); | ||
| } | ||
|
|
||
| new DotnetCommand(Log, "add", "reference", Path.Combine(testAssetSelfContained.Path, testConsoleProjectSelfContained.Name)) | ||
Youssef1313 marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| .WithWorkingDirectory(mtpProjectDirectory) | ||
| .Execute() | ||
| .Should() | ||
| .Pass(); | ||
|
|
||
| var result = new BuildCommand(Log, mtpProjectDirectory).Execute(); | ||
| result.Should().HaveStdOutContaining("NETSDK1151").And.ExitWith(1); | ||
Youssef1313 marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| } | ||
|
|
||
| [Theory] | ||
| [CombinatorialData] | ||
| public void MTPNonSelfContainedExecutableCannotBeReferencedBySelfContained(bool setIsTestingPlatformApplicationEarly) | ||
| { | ||
| // The setup of this test is as follows: | ||
| // ConsoleApp is a self-contained executable project, which references a non-self-contained MTP executable test project. | ||
| // Building ConsoleApp should fail because it references a non-self-contained MTP executable project. | ||
| // A non self-contained executable cannot be referenced by a self-contained executable. | ||
| var testConsoleProjectSelfContained = new TestProject("ConsoleApp") | ||
| { | ||
| IsExe = true, | ||
| TargetFrameworks = ToolsetInfo.CurrentTargetFramework, | ||
| SelfContained = "true", | ||
| }; | ||
|
|
||
| var testAssetSelfContained = _testAssetsManager.CreateTestProject(testConsoleProjectSelfContained); | ||
|
|
||
| var mtpNotSelfContained = new TestProject("MTPTestProject") | ||
| { | ||
| TargetFrameworks = ToolsetInfo.CurrentTargetFramework, | ||
| IsExe = true, | ||
| IsTestProject = true, | ||
| }; | ||
|
|
||
| if (setIsTestingPlatformApplicationEarly) | ||
| { | ||
| mtpNotSelfContained.IsTestingPlatformApplication = true; | ||
| } | ||
|
|
||
| var testAssetMTP = _testAssetsManager.CreateTestProject(mtpNotSelfContained); | ||
|
|
||
| var mtpProjectDirectory = Path.Combine(testAssetMTP.Path, mtpNotSelfContained.Name); | ||
| Assert.True(Directory.Exists(mtpProjectDirectory), $"Expected directory {mtpProjectDirectory} to exist."); | ||
| Assert.True(File.Exists(Path.Combine(mtpProjectDirectory, "MTPTestProject.csproj")), $"Expected file MTPTestProject.csproj to exist in {mtpProjectDirectory}."); | ||
|
|
||
| if (!setIsTestingPlatformApplicationEarly) | ||
| { | ||
| File.WriteAllText(Path.Combine(mtpProjectDirectory, "Directory.Build.targets"), """ | ||
| <Project> | ||
| <PropertyGroup> | ||
| <IsTestingPlatformApplication>true</IsTestingPlatformApplication> | ||
| </PropertyGroup> | ||
| </Project> | ||
| """); | ||
| } | ||
|
|
||
| var consoleAppDirectory = Path.Combine(testAssetSelfContained.Path, testConsoleProjectSelfContained.Name); | ||
| Assert.True(Directory.Exists(consoleAppDirectory), $"Expected directory {consoleAppDirectory} to exist."); | ||
| Assert.True(File.Exists(Path.Combine(consoleAppDirectory, "ConsoleApp.csproj")), $"Expected file ConsoleApp.csproj to exist in {consoleAppDirectory}."); | ||
|
|
||
| new DotnetCommand(Log, "add", "reference", Path.Combine(testAssetMTP.Path, mtpNotSelfContained.Name)) | ||
| .WithWorkingDirectory(consoleAppDirectory) | ||
| .Execute() | ||
| .Should() | ||
| .Pass(); | ||
|
|
||
| var result = new BuildCommand(Log, consoleAppDirectory).Execute(); | ||
| result.Should().HaveStdOutContaining("NETSDK1150").And.ExitWith(1); | ||
| } | ||
|
|
||
| [RequiresMSBuildVersionTheory("17.0.0.32901")] | ||
| [InlineData("xunit")] | ||
| [InlineData("mstest")] | ||
|
|
@@ -396,5 +519,45 @@ public void ExeProjectCanReferenceTestProject(string testTemplateName) | |
| .Should() | ||
| .Pass(); | ||
| } | ||
|
|
||
| [Theory] | ||
| [CombinatorialData] | ||
| public void MTPCanBeBuiltAsSelfContained(bool setIsTestingPlatformApplicationEarly) | ||
| { | ||
| var mtpSelfContained = new TestProject("MTPTestProject") | ||
| { | ||
| TargetFrameworks = ToolsetInfo.CurrentTargetFramework, | ||
| IsExe = true, | ||
| IsTestProject = true, | ||
| SelfContained = "true", | ||
| }; | ||
|
|
||
| if (setIsTestingPlatformApplicationEarly) | ||
| { | ||
| mtpSelfContained.IsTestingPlatformApplication = true; | ||
| } | ||
|
|
||
| var testAssetMTP = _testAssetsManager.CreateTestProject(mtpSelfContained); | ||
|
|
||
| var mtpProjectDirectory = Path.Combine(testAssetMTP.Path, mtpSelfContained.Name); | ||
| Assert.True(Directory.Exists(mtpProjectDirectory), $"Expected directory {mtpProjectDirectory} to exist."); | ||
| Assert.True(File.Exists(Path.Combine(mtpProjectDirectory, "MTPTestProject.csproj")), $"Expected file MTPTestProject.csproj to exist in {mtpProjectDirectory}."); | ||
|
|
||
| if (!setIsTestingPlatformApplicationEarly) | ||
| { | ||
| File.WriteAllText(Path.Combine(mtpProjectDirectory, "Directory.Build.targets"), """ | ||
| <Project> | ||
| <PropertyGroup> | ||
| <IsTestingPlatformApplication>true</IsTestingPlatformApplication> | ||
| </PropertyGroup> | ||
| </Project> | ||
| """); | ||
| } | ||
|
|
||
| new BuildCommand(Log, mtpProjectDirectory) | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. In this case, you might want to also check that the self-contained app correctly runs and runs tests. That will take a bit more time, so I'm not sure if it's a good idea or not.
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. There is nothing special here I think as there is no special casing around MTP. If a typical console app runs correctly as self-contained, then this case shouldn't be different at all. We can follow-up and add an extra test though, maybe even try to do it with both |
||
| .Execute() | ||
| .Should() | ||
| .Pass(); | ||
| } | ||
| } | ||
| } | ||
Uh oh!
There was an error while loading. Please reload this page.