Skip to content

Commit d170785

Browse files
authored
Switch StandaloneApp6x to pre-built test asset (#94590)
- Add pre-built test asset for a self-contained net6.0 version of existing `HelloWorld` test asset - Update `HostVersionCompatibility` tests to use the new test asset
1 parent cc78af7 commit d170785

File tree

9 files changed

+59
-65
lines changed

9 files changed

+59
-65
lines changed

eng/Subsets.props

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -489,8 +489,7 @@
489489

490490
<!-- Host.pretest subset (consumes live built libraries assets so needs to come after libraries) -->
491491
<ItemGroup Condition="$(_subset.Contains('+host.pretest+'))">
492-
<ProjectToBuild Include="$(InstallerProjectRoot)tests\Assets\Projects\AppWithSubDirs\AppWithSubDirs.csproj" Category="host" />
493-
<ProjectToBuild Include="$(InstallerProjectRoot)tests\Assets\Projects\HelloWorld\HelloWorld.csproj" Category="host" />
492+
<ProjectToBuild Include="$(InstallerProjectRoot)tests\Assets\Projects\**\*.csproj" Category="host" />
494493
</ItemGroup>
495494

496495
<!-- Host.tests subset (consumes live built libraries assets so needs to come after libraries) -->

src/installer/tests/Assets/Projects/Directory.Build.props

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
<PropertyGroup>
55
<EnableDefaultItems>true</EnableDefaultItems>
66
<UseLocalTargetingRuntimePack>true</UseLocalTargetingRuntimePack>
7-
<UseAppHost>false</UseAppHost>
7+
<AppendRuntimeIdentifierToOutputPath>false</AppendRuntimeIdentifierToOutputPath>
88
<AppendTargetFrameworkToOutputPath>false</AppendTargetFrameworkToOutputPath>
99
<OutputPath>$(ArtifactsDir)tests\host\$(TargetOS).$(TargetArchitecture).$(Configuration)\$(MSBuildProjectName)</OutputPath>
1010
</PropertyGroup>

src/installer/tests/Assets/Projects/Directory.Build.targets

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,10 @@
33

44
<Import Project="$([MSBuild]::GetPathOfFileAbove(Directory.Build.targets, $(MSBuildThisFileDirectory)..))" />
55

6+
<PropertyGroup>
7+
<UseAppHost Condition="'$(UseAppHost)' == '' and '$(SelfContained)' != 'true'">false</UseAppHost>
8+
</PropertyGroup>
9+
610
<!-- Override target from targetingpacks.targets. Use Version instead of ProductVersion (written into runtimeconfig.json).
711
Host tests are run against the built shared framework that has the normal version (with suffixes) -->
812
<Target Name="UpdateRuntimeFrameworkVersion"
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
<Project Sdk="Microsoft.NET.Sdk">
2+
<PropertyGroup>
3+
<AssemblyName>HelloWorld</AssemblyName>
4+
<TargetFramework>net6.0</TargetFramework>
5+
<OutputType>Exe</OutputType>
6+
<SelfContained>true</SelfContained>
7+
<AppendTargetFrameworkToOutputPath>true</AppendTargetFrameworkToOutputPath>
8+
<UseLocalTargetingRuntimePack>false</UseLocalTargetingRuntimePack>
9+
10+
<!-- Set the RID when building on a platform where we support self-contained + apphost -->
11+
<RuntimeIdentifier Condition="'$(TargetsLinux)' == 'true' or '$(TargetsOSX)' == 'true' or '$(TargetsWindows)' == 'true'">$(OutputRID)</RuntimeIdentifier>
12+
</PropertyGroup>
13+
</Project>

src/installer/tests/Assets/TestProjects/StandaloneApp6x/Program.cs

Lines changed: 0 additions & 15 deletions
This file was deleted.

src/installer/tests/Assets/TestProjects/StandaloneApp6x/StandaloneApp6x.csproj

Lines changed: 0 additions & 9 deletions
This file was deleted.

src/installer/tests/HostActivation.Tests/HostVersionCompatibility.cs

Lines changed: 22 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -21,22 +21,23 @@ public HostVersionCompatibility(SharedTestState fixture)
2121
[Fact]
2222
public void LatestHost_OldRuntime_BackwardsCompatible_60()
2323
{
24-
LatestHost_OldRuntime_BackwardsCompatible(sharedTestState.Fixture60);
24+
LatestHost_OldRuntime_BackwardsCompatible(sharedTestState.App60);
2525
}
2626

27-
private void LatestHost_OldRuntime_BackwardsCompatible(TestProjectFixture previousVersionFixture)
27+
private void LatestHost_OldRuntime_BackwardsCompatible(TestApp previousVersionApp)
2828
{
29-
TestProjectFixture fixture = previousVersionFixture.Copy();
30-
string appExe = fixture.TestProject.AppExe;
29+
TestApp app = previousVersionApp.Copy();
30+
string appExe = app.AppExe;
3131

32-
Assert.NotEqual(fixture.Framework, RepoDirectoriesProvider.Default.Tfm);
33-
Assert.NotEqual(fixture.RepoDirProvider.MicrosoftNETCoreAppVersion, RepoDirectoriesProvider.Default.MicrosoftNETCoreAppVersion);
32+
RuntimeConfig appConfig = RuntimeConfig.FromFile(app.RuntimeConfigJson);
33+
Assert.NotEqual(appConfig.Tfm, RepoDirectoriesProvider.Default.Tfm);
34+
Assert.NotEqual(appConfig.GetIncludedFramework(Constants.MicrosoftNETCoreApp).Version, RepoDirectoriesProvider.Default.MicrosoftNETCoreAppVersion);
3435

3536
// Use the newer apphost
3637
// This emulates the case when:
3738
// 1) Newer runtime installed
3839
// 2) Newer runtime uninstalled (installer preserves newer apphost)
39-
fixture.TestProject.BuiltApp.CreateAppHost();
40+
app.CreateAppHost();
4041
Command.Create(appExe)
4142
.EnableTracingAndCaptureOutputs()
4243
.Execute()
@@ -48,7 +49,7 @@ private void LatestHost_OldRuntime_BackwardsCompatible(TestProjectFixture previo
4849
// This emulates the case when:
4950
// 1) Newer runtime installed
5051
// 2) A roll-forward to the newer runtime did not occur
51-
File.Copy(Binaries.HostFxr.FilePath, fixture.TestProject.HostFxrDll, true);
52+
File.Copy(Binaries.HostFxr.FilePath, app.HostFxrDll, true);
5253
Command.Create(appExe)
5354
.EnableTracingAndCaptureOutputs()
5455
.Execute()
@@ -60,28 +61,30 @@ private void LatestHost_OldRuntime_BackwardsCompatible(TestProjectFixture previo
6061
[Fact]
6162
public void OldHost_LatestRuntime_ForwardCompatible_60()
6263
{
63-
OldHost_LatestRuntime_ForwardCompatible(sharedTestState.Fixture60);
64+
OldHost_LatestRuntime_ForwardCompatible(sharedTestState.App60);
6465
}
6566

66-
private void OldHost_LatestRuntime_ForwardCompatible(TestProjectFixture previousVersionFixture)
67+
private void OldHost_LatestRuntime_ForwardCompatible(TestApp previousVersionApp)
6768
{
6869
TestApp app = sharedTestState.AppLatest.Copy();
6970
string appExe = app.AppExe;
7071

71-
Assert.NotEqual(RepoDirectoriesProvider.Default.Tfm, previousVersionFixture.Framework);
72-
Assert.NotEqual(RepoDirectoriesProvider.Default.MicrosoftNETCoreAppVersion, previousVersionFixture.RepoDirProvider.MicrosoftNETCoreAppVersion);
72+
RuntimeConfig previousAppConfig = RuntimeConfig.FromFile(previousVersionApp.RuntimeConfigJson);
73+
string previousVersion = previousAppConfig.GetIncludedFramework(Constants.MicrosoftNETCoreApp).Version;
74+
Assert.NotEqual(RepoDirectoriesProvider.Default.Tfm, previousAppConfig.Tfm);
75+
Assert.NotEqual(RepoDirectoriesProvider.Default.MicrosoftNETCoreAppVersion, previousVersion);
7376

7477
// Use the older apphost
7578
// This emulates the case when:
7679
// 1) Newer runtime installed
7780
// 2) App rolls forward to newer runtime
78-
File.Copy(previousVersionFixture.TestProject.AppExe, appExe, true);
81+
File.Copy(previousVersionApp.AppExe, appExe, true);
7982
Command.Create(appExe)
8083
.EnableTracingAndCaptureOutputs()
8184
.Execute()
8285
.Should().Pass()
8386
.And.HaveStdOutContaining("Hello World")
84-
.And.HaveStdErrContaining($"--- Invoked apphost [version: {previousVersionFixture.RepoDirProvider.MicrosoftNETCoreAppVersion}");
87+
.And.HaveStdErrContaining($"--- Invoked apphost [version: {previousVersion}");
8588

8689
// Use the older apphost and hostfxr
8790
// This emulates the case when:
@@ -90,53 +93,36 @@ private void OldHost_LatestRuntime_ForwardCompatible(TestProjectFixture previous
9093
// Note that we don't have multi-level on hostfxr so we will always find the older\one-off hostfxr
9194
if (OperatingSystem.IsWindows())
9295
{
93-
File.Copy(previousVersionFixture.TestProject.HostFxrDll, app.HostFxrDll, true);
96+
File.Copy(previousVersionApp.HostFxrDll, app.HostFxrDll, true);
9497
Command.Create(appExe)
9598
.EnableTracingAndCaptureOutputs()
9699
.Execute()
97100
.Should().Pass()
98101
.And.HaveStdOutContaining("Hello World")
99-
.And.HaveStdErrContaining($"--- Invoked apphost [version: {previousVersionFixture.RepoDirProvider.MicrosoftNETCoreAppVersion}");
102+
.And.HaveStdErrContaining($"--- Invoked apphost [version: {previousVersion}");
100103
}
101104
}
102105

103106
public class SharedTestState : IDisposable
104107
{
105-
private static RepoDirectoriesProvider RepoDirectories { get; set; }
106-
107-
public TestProjectFixture Fixture60 { get; }
108+
public TestApp App60 { get; }
108109
public TestApp AppLatest { get; }
109110

110111
private const string AppName = "HelloWorld";
111112

112113
public SharedTestState()
113114
{
114-
RepoDirectories = new RepoDirectoriesProvider();
115-
116-
Fixture60 = CreateTestFixture("StandaloneApp6x", "net6.0", "6.0");
115+
App60 = TestApp.CreateFromBuiltAssets(AppName, Path.Combine("SelfContained", "net6.0"));
117116

118117
AppLatest = TestApp.CreateFromBuiltAssets(AppName);
119118
AppLatest.PopulateSelfContained(TestApp.MockedComponent.None);
120119
}
121120

122121
public void Dispose()
123122
{
124-
Fixture60.Dispose();
123+
App60?.Dispose();
125124
AppLatest?.Dispose();
126125
}
127-
128-
private static TestProjectFixture CreateTestFixture(string testName, string netCoreAppFramework, string mnaVersion)
129-
{
130-
var repoDirectories = new RepoDirectoriesProvider(microsoftNETCoreAppVersion: mnaVersion);
131-
132-
// Use standalone instead of framework-dependent for ease of deployment.
133-
var publishFixture = new TestProjectFixture(testName, repoDirectories, framework: netCoreAppFramework, assemblyName: AppName);
134-
publishFixture
135-
.EnsureRestoredForRid(publishFixture.CurrentRid)
136-
.PublishProject(runtime: publishFixture.CurrentRid, selfContained: true, extraArgs: $"/p:AssemblyName={AppName}");
137-
138-
return publishFixture;
139-
}
140126
}
141127
}
142128
}

src/installer/tests/TestUtils/RuntimeConfig.cs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -172,6 +172,8 @@ public static RuntimeConfig Path(string path)
172172
return new RuntimeConfig(path);
173173
}
174174

175+
public string Tfm => _tfm;
176+
175177
public Framework GetFramework(string name)
176178
{
177179
return _frameworks.FirstOrDefault(f => f.Name == name);
@@ -199,6 +201,11 @@ public RuntimeConfig RemoveFramework(string name)
199201
return this;
200202
}
201203

204+
public Framework GetIncludedFramework(string name)
205+
{
206+
return _includedFrameworks.FirstOrDefault(f => f.Name == name);
207+
}
208+
202209
public RuntimeConfig WithIncludedFramework(Framework framework)
203210
{
204211
_includedFrameworks.Add(framework);

src/installer/tests/TestUtils/TestApp.cs

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,11 +50,20 @@ public static TestApp CreateEmpty(string name)
5050
};
5151
}
5252

53-
public static TestApp CreateFromBuiltAssets(string appName)
53+
/// <summary>
54+
/// Create a test app from pre-built output of <paramref name="appName"/>.
55+
/// </summary>
56+
/// <param name="appName">Name of pre-built app</param>
57+
/// <param name="assetRelativePath">Path to asset - relative to the directory containing all pre-built assets</param>
58+
/// <returns>
59+
/// If <paramref name="assetRelativePath"/> is <c>null</c>, <paramref name="appName"/> is used as the relative path.
60+
/// </returns>
61+
public static TestApp CreateFromBuiltAssets(string appName, string assetRelativePath = null)
5462
{
63+
assetRelativePath = assetRelativePath ?? appName;
5564
TestApp app = CreateEmpty(appName);
5665
TestArtifact.CopyRecursive(
57-
Path.Combine(RepoDirectoriesProvider.Default.TestAssetsOutput, appName),
66+
Path.Combine(RepoDirectoriesProvider.Default.TestAssetsOutput, assetRelativePath),
5867
app.Location);
5968
return app;
6069
}

0 commit comments

Comments
 (0)