Skip to content
Closed
Show file tree
Hide file tree
Changes from 1 commit
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
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.

using System.Text.RegularExpressions;
using Microsoft.NET.Build.Containers.Resources;

namespace Microsoft.NET.Build.Containers;
Expand Down Expand Up @@ -32,10 +33,12 @@ public static string TempPath
}
}

private static readonly Regex s_sha256DigestRegex = new(@"^sha256:[0-9A-Fa-f]{64}$", RegexOptions.Compiled);
Comment thread
lbussell marked this conversation as resolved.
Outdated

public static string PathForDescriptor(Descriptor descriptor)
{
string digestString = descriptor.Digest;
if (!ReferenceParser.DigestRegexp.IsMatch(digestString))
if (!s_sha256DigestRegex.IsMatch(digestString))
{
throw new ArgumentException($"Invalid digest: {digestString}", nameof(descriptor.Digest));
}
Expand Down
18 changes: 10 additions & 8 deletions test/dotnet.Tests/CommandTests/Run/GivenDotnetRunBuildsCsProj.cs
Original file line number Diff line number Diff line change
Expand Up @@ -400,7 +400,9 @@ public void ItUsesLaunchProfileOfTheSpecifiedName()
cmd.Should().Pass()
.And.HaveStdOutContaining("Second");

cmd.StdErr.Should().BeEmpty();
cmd.StdErr.Should().Contain(
string.Format(CliCommandStrings.UsingLaunchSettingsFromMessage,
Path.Combine(testProjectDirectory, "Properties", "launchSettings.json")));
}

[Fact]
Expand Down Expand Up @@ -441,7 +443,8 @@ public void ItSetsTheDotnetLaunchProfileEnvironmentVariableToDefaultLaunchProfil
cmd.Should().Pass()
.And.HaveStdOutContaining("DOTNET_LAUNCH_PROFILE=<<<First>>>");

cmd.StdErr.Should().BeEmpty();
cmd.StdErr.Should().Contain(
string.Format(CliCommandStrings.UsingLaunchSettingsFromMessage, launchSettingsPath));
}

[Fact]
Expand All @@ -461,7 +464,8 @@ public void ItSetsTheDotnetLaunchProfileEnvironmentVariableToSuppliedLaunchProfi
cmd.Should().Pass()
.And.HaveStdOutContaining("DOTNET_LAUNCH_PROFILE=<<<Second>>>");

cmd.StdErr.Should().BeEmpty();
cmd.StdErr.Should().Contain(
string.Format(CliCommandStrings.UsingLaunchSettingsFromMessage, launchSettingsPath));
}

[Fact]
Expand Down Expand Up @@ -518,10 +522,8 @@ public void ItPrintsUsingLaunchSettingsMessageWhenNotQuiet()
.Execute("-v:m");

cmd.Should().Pass()
.And.HaveStdOutContaining(string.Format(CliCommandStrings.UsingLaunchSettingsFromMessage, launchSettingsPath))
.And.HaveStdErrContaining(string.Format(CliCommandStrings.UsingLaunchSettingsFromMessage, launchSettingsPath))
.And.HaveStdOutContaining("First");
Comment thread
marcpopMSFT marked this conversation as resolved.

cmd.StdErr.Should().BeEmpty();
}

[Fact]
Expand All @@ -540,7 +542,7 @@ public void ItPrefersTheValueOfAppUrlFromEnvVarOverTheProp()
cmd.Should().Pass()
.And.HaveStdOutContaining("http://localhost:12345/");

cmd.StdErr.Should().BeEmpty();
cmd.StdErr.Should().Contain("Using launch settings from");
}

[Fact]
Expand All @@ -559,7 +561,7 @@ public void ItUsesTheValueOfAppUrlIfTheEnvVarIsNotSet()
cmd.Should().Pass()
.And.HaveStdOutContaining("http://localhost:54321/");

cmd.StdErr.Should().BeEmpty();
cmd.StdErr.Should().Contain("Using launch settings from");
}

[Fact]
Expand Down
12 changes: 5 additions & 7 deletions test/dotnet.Tests/CommandTests/Run/GivenDotnetRunBuildsVbProj.cs
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ public void ItUsesLaunchProfileOfTheSpecifiedName(string launchProfileName)
.And
.HaveStdOutContaining("Second")
.And
.NotHaveStdErr();
.HaveStdErrContaining("Using launch settings from");
}

[Fact]
Expand All @@ -99,17 +99,17 @@ public void ItDefaultsToTheFirstUsableLaunchProfile()
.WithSource();

var testProjectDirectory = testInstance.Path;
var launchSettingsPath = Path.Combine(testProjectDirectory, "Properties", "launchSettings.json");
var launchSettingsPath = Path.Combine(testProjectDirectory, "My Project", "launchSettings.json");

var cmd = new DotnetCommand(Log, "run")
.WithWorkingDirectory(testProjectDirectory)
.Execute();

cmd.Should().Pass()
.And.NotHaveStdOutContaining(string.Format(CliCommandStrings.UsingLaunchSettingsFromMessage, launchSettingsPath))
.And.HaveStdOutContaining("First");

cmd.StdErr.Should().BeEmpty();
cmd.StdErr.Should().Contain(
string.Format(CliCommandStrings.UsingLaunchSettingsFromMessage, launchSettingsPath));
}
Comment on lines 110 to 113

Copilot AI Apr 15, 2026

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In this test the previous assertion that the "Using launch settings from..." message is not written to stdout was removed. Since the intent is specifically to validate the stream change, keep an explicit stdout-negative assertion to catch accidental duplication (stdout + stderr).

Copilot uses AI. Check for mistakes.

[Fact]
Expand All @@ -126,10 +126,8 @@ public void ItPrintsUsingLaunchSettingsMessageWhenNotQuiet()
.Execute("-v:m");

cmd.Should().Pass()
.And.HaveStdOutContaining(string.Format(CliCommandStrings.UsingLaunchSettingsFromMessage, launchSettingsPath))
.And.HaveStdErrContaining(string.Format(CliCommandStrings.UsingLaunchSettingsFromMessage, launchSettingsPath))
.And.HaveStdOutContaining("First");

cmd.StdErr.Should().BeEmpty();
}

[Fact]
Expand Down
2 changes: 1 addition & 1 deletion test/dotnet.Tests/CommandTests/Run/RunCommandTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ public void EnvironmentVariableExpansion_Project()
.And.HaveStdOutContaining("TEST_VAR1=<<<VALUE1>>>")
.And.HaveStdOutContaining("ARGS=arg1,arg2,arg3");

cmd.StdErr.Should().BeEmpty();
cmd.StdErr.Should().Contain("Using launch settings from");

Copilot AI Apr 15, 2026

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The test now only checks that stderr contains the substring "Using launch settings from". To make the assertion resilient and ensure the message moved streams (and isn’t duplicated), assert against the full formatted message using the known launchSettingsPath, and also assert it is not present on stdout.

Copilot uses AI. Check for mistakes.
}

[Fact]
Expand Down
Loading