Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 25 additions & 3 deletions test/dotnet.Tests/CommandTests/Run/RunFileTestBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,35 @@
using Microsoft.Build.Logging.StructuredLogger;
using Microsoft.DotNet.Cli.Commands;
using Microsoft.DotNet.Cli.Commands.Run;
using Microsoft.DotNet.Cli.Utils;
using Microsoft.DotNet.FileBasedPrograms;
using Microsoft.DotNet.ProjectTools;
using Xunit.Sdk;

namespace Microsoft.DotNet.Cli.Run.Tests;

public abstract class RunFileTestBase(ITestOutputHelper log) : SdkTest(log)
public sealed class RunFileTestFixture(IMessageSink sink) : IAsyncLifetime
{
public ValueTask InitializeAsync()
{
RunFileTestBase.CopyNuGetConfigToRunfileDirectory();

// Ensure a simple app runs fully with MSBuild before running other csc-only tests
// so we have packages like ILLink.Tasks restored and csc-only optimization can kick in.
new DotnetCommand(new SharedTestOutputHelper(sink), "run", "-")
.WithStandardInput("""
Console.WriteLine("Hello");
""")
.Execute()
.Should().Pass()
.And.HaveStdOut("Hello");

return default;
}

public ValueTask DisposeAsync() => default;
}

public abstract class RunFileTestBase(ITestOutputHelper log) : SdkTest(log), IClassFixture<RunFileTestFixture>
{
internal static string s_includeExcludeDefaultKnownExtensions
=> field ??= string.Join(", ", CSharpDirective.IncludeOrExclude.DefaultMapping.Select(static e => e.Extension));
Expand Down Expand Up @@ -140,7 +162,7 @@ private static string PrepareOutOfTreeBaseDirectory()
/// is created under this directory, and NuGet walks up from the project location to
/// find config files.
/// </summary>
protected static void CopyNuGetConfigToRunfileDirectory()
internal static void CopyNuGetConfigToRunfileDirectory()
{
var sourceNuGetConfig = Path.Join(SdkTestContext.Current.TestExecutionDirectory, "NuGet.config");
var runfileDir = VirtualProjectBuilder.GetTempSubdirectory();
Expand Down
Loading