Skip to content

Commit

Permalink
Move StartupHooks tests and remaining uses of PortableApp project t…
Browse files Browse the repository at this point in the history
…o pre-built test assets (dotnet#95761)
  • Loading branch information
elinor-fung authored Dec 11, 2023
1 parent 5201ec3 commit 46bf1af
Show file tree
Hide file tree
Showing 17 changed files with 200 additions and 345 deletions.
18 changes: 18 additions & 0 deletions src/installer/tests/Assets/Projects/HelloWorld/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@
// The .NET Foundation licenses this file to you under the MIT license.

using System;
using System.Reflection;
using System.Runtime.InteropServices;
using System.Runtime.Loader;

namespace HelloWorld
{
Expand All @@ -13,6 +15,22 @@ public static void Main(string[] args)
Console.WriteLine("Hello World!");
Console.WriteLine(string.Join(Environment.NewLine, args));
Console.WriteLine(RuntimeInformation.FrameworkDescription);

if (args.Length == 0)
return;

switch (args[0])
{
case "load_shared_library":
var asm = AssemblyLoadContext.Default.LoadFromAssemblyName(new AssemblyName("SharedLibrary"));
PropertyInfo property = asm.GetType("SharedLibrary.SharedType").GetProperty("Value");
Console.WriteLine($"SharedLibrary.SharedType.Value = {property.GetValue(null)}");
break;
case "throw_exception":
throw new Exception("Goodbye World!");
default:
break;
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

<PropertyGroup>
<TargetFramework>$(NetCoreAppCurrent)</TargetFramework>
<RuntimeFrameworkVersion>$(MNAVersion)</RuntimeFrameworkVersion>
</PropertyGroup>

</Project>
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ public static void Initialize()
[MethodImpl(MethodImplOptions.NoInlining)]
private static void UseDependency()
{
Console.WriteLine($"SharedLibrary.Value: {SharedLibrary.SharedType.Value}");
Console.WriteLine($"SharedLibrary.SharedType.Value = {SharedLibrary.SharedType.Value}");
}

private static Assembly OnResolving(AssemblyLoadContext context, AssemblyName assemblyName)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>$(NetCoreAppCurrent)</TargetFramework>
</PropertyGroup>

<!-- Copy the preloaded base type to the startup hook's output
directory to make it easy to find. -->
<ItemGroup>
<ProjectReference Include="..\SharedLibrary\SharedLibrary.csproj" />
</ItemGroup>

</Project>

This file was deleted.

36 changes: 0 additions & 36 deletions src/installer/tests/Assets/TestProjects/PortableApp/Program.cs

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

73 changes: 73 additions & 0 deletions src/installer/tests/HostActivation.Tests/Breadcrumbs.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.

using Microsoft.DotNet.Cli.Build;
using System;
using System.Collections.Generic;
using System.IO;
using System.Runtime.InteropServices;
using Xunit;

namespace Microsoft.DotNet.CoreSetup.Test.HostActivation
{
public class Breadcrumbs : IClassFixture<Breadcrumbs.SharedTestState>
{
private SharedTestState sharedTestState;

public Breadcrumbs(SharedTestState fixture)
{
sharedTestState = fixture;
}

[Fact]
public void BreadcrumbThreadFinishes()
{
TestContext.BuiltDotNet.Exec(sharedTestState.App.AppDll)
.EnvironmentVariable(Constants.Breadcrumbs.EnvironmentVariable, sharedTestState.BreadcrumbLocation)
.EnableTracingAndCaptureOutputs()
.Execute()
.Should().Pass()
.And.HaveStdOutContaining("Hello World")
.And.HaveStdErrContaining("Done waiting for breadcrumb thread to exit...");
}

[Fact]
public void UnhandledException_BreadcrumbThreadDoesNotFinish()
{
TestContext.BuiltDotNet.Exec(sharedTestState.App.AppDll, "throw_exception")
.EnvironmentVariable(Constants.Breadcrumbs.EnvironmentVariable, sharedTestState.BreadcrumbLocation)
.EnableTracingAndCaptureOutputs()
.Execute(expectedToFail: true)
.Should().Fail()
.And.HaveStdErrContaining("Unhandled exception.")
.And.HaveStdErrContaining("System.Exception: Goodbye World")
.And.NotHaveStdErrContaining("Done waiting for breadcrumb thread to exit...");
}

public class SharedTestState : IDisposable
{
public TestApp App { get; }
public string BreadcrumbLocation { get; }

public SharedTestState()
{
App = TestApp.CreateFromBuiltAssets("HelloWorld");
if (!OperatingSystem.IsWindows())
{
// On non-Windows breadcrumbs are only written if the breadcrumb directory already exists,
// so we explicitly create a directory for breadcrumbs
BreadcrumbLocation = Path.Combine(
App.Location,
"opt",
"corebreadcrumbs");
Directory.CreateDirectory(BreadcrumbLocation);
}
}

public void Dispose()
{
App?.Dispose();
}
}
}
}
Loading

0 comments on commit 46bf1af

Please sign in to comment.