Skip to content

Commit 9d08b24

Browse files
authored
Make BundlerConsistencyTests stop building/copying self-contained project unnecessarily (#91829)
`BundlerConsistencyTests` were building a self-contained project and copying it for each test case. They are targeting the `Bundler` API and don't actual need a full app - just validation of how things get bundled and added to the manifest. - Add a `HelloWorld` project for as a pre-built test asset for host tests - Make `BundlerConsistencyTests` use a pre-built app and shared framework files instead of building/copying a self-contained project - Move the one test `TestWithAdditionalContentAfterBundleMetadata` that actually runs the bundled app into `BundleAndRun`
1 parent 9a68b7e commit 9d08b24

File tree

8 files changed

+251
-247
lines changed

8 files changed

+251
-247
lines changed

eng/Subsets.props

+1
Original file line numberDiff line numberDiff line change
@@ -489,6 +489,7 @@
489489
<!-- Host.pretest subset (consumes live built libraries assets so needs to come after libraries) -->
490490
<ItemGroup Condition="$(_subset.Contains('+host.pretest+'))">
491491
<ProjectToBuild Include="$(InstallerProjectRoot)tests\Assets\Projects\AppWithSubDirs\AppWithSubDirs.csproj" Category="host" />
492+
<ProjectToBuild Include="$(InstallerProjectRoot)tests\Assets\Projects\HelloWorld\HelloWorld.csproj" Category="host" />
492493
</ItemGroup>
493494

494495
<!-- Host.tests subset (consumes live built libraries assets so needs to come after libraries) -->
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
<Project Sdk="Microsoft.NET.Sdk">
2+
3+
<PropertyGroup>
4+
<TargetFramework>$(NetCoreAppCurrent)</TargetFramework>
5+
<OutputType>Exe</OutputType>
6+
</PropertyGroup>
7+
8+
</Project>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
// Licensed to the .NET Foundation under one or more agreements.
2+
// The .NET Foundation licenses this file to you under the MIT license.
3+
4+
using System;
5+
using System.Runtime.InteropServices;
6+
7+
namespace HelloWorld
8+
{
9+
public static class Program
10+
{
11+
public static void Main(string[] args)
12+
{
13+
Console.WriteLine("Hello World!");
14+
Console.WriteLine(string.Join(Environment.NewLine, args));
15+
Console.WriteLine(RuntimeInformation.FrameworkDescription);
16+
}
17+
}
18+
}

src/installer/tests/Microsoft.NET.HostModel.Tests/Microsoft.NET.HostModel.Bundle.Tests/BundleAndRun.cs

+22
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
using Microsoft.DotNet.CoreSetup.Test;
99
using BundleTests.Helpers;
1010
using System.Runtime.InteropServices;
11+
using System.Text;
1112

1213
namespace Microsoft.NET.HostModel.Tests
1314
{
@@ -120,6 +121,27 @@ public void TestWithRelativePathsDirSeparator()
120121
BundleRun(fixture, publishDir);
121122
}
122123

124+
[Fact]
125+
public void TestWithAdditionalContentAfterBundleMetadata()
126+
{
127+
var fixture = sharedTestState.TestFixture.Copy();
128+
string singleFile = BundleHelper.BundleApp(fixture);
129+
130+
using (var file = File.OpenWrite(singleFile))
131+
{
132+
file.Position = file.Length;
133+
var blob = Encoding.UTF8.GetBytes("Mock signature at the end of the bundle");
134+
file.Write(blob, 0, blob.Length);
135+
}
136+
137+
Command.Create(singleFile)
138+
.CaptureStdErr()
139+
.CaptureStdOut()
140+
.Execute()
141+
.Should().Pass()
142+
.And.HaveStdOutContaining("Hello World!");
143+
}
144+
123145
public class SharedTestState : IDisposable
124146
{
125147
public TestProjectFixture TestFixture { get; set; }

src/installer/tests/Microsoft.NET.HostModel.Tests/Microsoft.NET.HostModel.Bundle.Tests/BundlerConsistencyTests.cs

+178-241
Large diffs are not rendered by default.

src/installer/tests/TestUtils/Binaries.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ public static class AppHost
4242
public static class CoreClr
4343
{
4444
public static string FileName = GetSharedLibraryFileNameForCurrentPlatform("coreclr");
45-
public static string FilePath = Path.Combine(RepoDirectoriesProvider.Default.HostArtifacts, FileName);
45+
public static string FilePath = Path.Combine(new DotNetCli(RepoDirectoriesProvider.Default.BuiltDotnet).GreatestVersionSharedFxPath, FileName);
4646

4747
public static string MockName = GetSharedLibraryFileNameForCurrentPlatform("mockcoreclr");
4848
public static string MockPath = Path.Combine(RepoDirectoriesProvider.Default.HostTestArtifacts, MockName);

src/installer/tests/TestUtils/SingleFileTestApp.cs

+14-5
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,19 @@ private static SingleFileTestApp Create(string appName, bool selfContained)
6060
};
6161
}
6262

63+
public static IReadOnlyList<FileSpec> GetRuntimeFilesToBundle()
64+
{
65+
var runtimeAssemblies = Binaries.GetRuntimeFiles().Assemblies;
66+
List<FileSpec> fileSpecs = new List<FileSpec>();
67+
foreach (var asset in runtimeAssemblies)
68+
{
69+
fileSpecs.Add(new FileSpec(asset, Path.GetFileName(asset)));
70+
}
71+
72+
fileSpecs.Sort((a, b) => string.CompareOrdinal(a.BundleRelativePath, b.BundleRelativePath));
73+
return fileSpecs;
74+
}
75+
6376
public string Bundle(BundleOptions options, Version? bundleVersion = null)
6477
{
6578
string bundleDirectory = SharedFramework.CalculateUniqueTestDirectory(Path.Combine(Location, "bundle"));
@@ -81,11 +94,7 @@ public string Bundle(BundleOptions options, Version? bundleVersion = null)
8194
// If this is a self-contained app, add the runtime assemblies to the bundle
8295
if (selfContained)
8396
{
84-
var runtimeAssemblies = Binaries.GetRuntimeFiles().Assemblies;
85-
foreach (var asset in runtimeAssemblies)
86-
{
87-
fileSpecs.Add(new FileSpec(asset, Path.GetFileName(asset)));
88-
}
97+
fileSpecs.AddRange(GetRuntimeFilesToBundle());
8998
}
9099

91100
// Sort the file specs to keep the bundle construction deterministic.

src/installer/tests/TestUtils/TestApp.cs

+9
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,15 @@ public static TestApp CreateEmpty(string name)
5050
};
5151
}
5252

53+
public static TestApp CreateFromBuiltAssets(string appName)
54+
{
55+
TestApp app = CreateEmpty(appName);
56+
TestArtifact.CopyRecursive(
57+
Path.Combine(RepoDirectoriesProvider.Default.TestAssetsOutput, appName),
58+
app.Location);
59+
return app;
60+
}
61+
5362
public void PopulateFrameworkDependent(string fxName, string fxVersion, Action<NetCoreAppBuilder> customizer = null)
5463
{
5564
var builder = NetCoreAppBuilder.PortableForNETCoreApp(this);

0 commit comments

Comments
 (0)