Skip to content
Merged
Show file tree
Hide file tree
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
13 changes: 12 additions & 1 deletion src/Microsoft.TestPlatform.Extensions.TrxLogger/TrxLogger.cs
Original file line number Diff line number Diff line change
Expand Up @@ -536,7 +536,18 @@ private string SetDefaultTrxFilePath()
TPDebug.Assert(LoggerTestRun != null, "LoggerTestRun is null");
TPDebug.Assert(LoggerTestRun.RunConfiguration != null, "LoggerTestRun.RunConfiguration is null");
TPDebug.Assert(IsInitialized, "Logger is not initialized");
var defaultTrxFileName = LoggerTestRun.RunConfiguration.RunDeploymentRootDirectory + ".trx";

var baseName = LoggerTestRun.RunConfiguration.RunDeploymentRootDirectory;

if (_parametersDictionary is not null
&& _parametersDictionary.TryGetValue(DefaultLoggerParameterNames.TargetFramework, out var framework)
&& !framework.IsNullOrWhiteSpace())
{
Comment thread
nohwnd marked this conversation as resolved.
var shortName = Framework.FromString(framework)?.ShortName ?? framework;
baseName = baseName + "_" + shortName;
}
Comment thread
nohwnd marked this conversation as resolved.
Comment thread
nohwnd marked this conversation as resolved.
Comment thread
nohwnd marked this conversation as resolved.

var defaultTrxFileName = baseName + ".trx";

return TrxFileHelper.GetNextIterationFileName(_testResultsDirPath, defaultTrxFileName, false);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,8 @@ public void PassingNoArgumentsToVsTestConsoleShouldPrintHelpMessage(RunnerInfo r
{
SetTestEnvironment(_testEnvironment, runnerInfo);

InvokeVsTest(null);
// Don't add --diag, it changes the output and prevents help from showing.
InvokeVsTest(null, collectDiagnostics: false);

//Check for help usage, description and arguments text.
StdOutputContains("Usage: vstest.console.exe");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -630,6 +630,49 @@ public void DefaultTrxFileShouldCreateIfLogFileNameParameterNotPassed()
Assert.IsFalse(string.IsNullOrWhiteSpace(_testableTrxLogger.TrxFile));
}

[TestMethod]
public void DefaultTrxFileNameShouldIncludeFrameworkWhenAvailable()
{
_parameters.Remove(TrxLoggerConstants.LogFileNameKey);
_parameters[DefaultLoggerParameterNames.TargetFramework] = ".NETCoreApp,Version=v10.0";
_testableTrxLogger.Initialize(_events.Object, _parameters);

MakeTestRunComplete();

var fileName = Path.GetFileName(_testableTrxLogger.TrxFile);
Assert.IsNotNull(fileName);
Assert.Contains("_net10.0", fileName, $"Expected TFM 'net10.0' in filename but got: {fileName}");
Assert.EndsWith(".trx", fileName, $"Expected .trx extension but got: {fileName}");
}

[TestMethod]
public void DefaultTrxFileNameShouldWorkWithoutFramework()
{
_parameters.Remove(TrxLoggerConstants.LogFileNameKey);
Copy link

Copilot AI Mar 25, 2026

Choose a reason for hiding this comment

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

This test is intended to verify behavior when no framework is available, but it doesn’t explicitly clear DefaultLoggerParameterNames.TargetFramework. If _parameters is reused across tests (or pre-populated in setup), the test may not actually exercise the no-framework path. Consider removing DefaultLoggerParameterNames.TargetFramework (and/or asserting the filename does NOT contain a _<tfm> suffix) to make the scenario deterministic.

Suggested change
_parameters.Remove(TrxLoggerConstants.LogFileNameKey);
_parameters.Remove(TrxLoggerConstants.LogFileNameKey);
_parameters.Remove(DefaultLoggerParameterNames.TargetFramework);

Copilot uses AI. Check for mistakes.
_testableTrxLogger.Initialize(_events.Object, _parameters);

MakeTestRunComplete();

var fileName = Path.GetFileName(_testableTrxLogger.TrxFile);
Assert.IsNotNull(fileName);
Assert.EndsWith(".trx", fileName, $"Expected .trx extension but got: {fileName}");
}

[TestMethod]
public void DefaultTrxFileNameShouldUseRawStringWhenFrameworkCannotBeParsed()
{
_parameters.Remove(TrxLoggerConstants.LogFileNameKey);
_parameters[DefaultLoggerParameterNames.TargetFramework] = "SomeCustomFramework";
_testableTrxLogger.Initialize(_events.Object, _parameters);
Comment on lines +662 to +666
Copy link

Copilot AI Mar 24, 2026

Choose a reason for hiding this comment

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

New behavior uses the raw TargetFramework string when parsing fails, but there’s no test coverage for raw values containing characters that are invalid in filenames or path separators (e.g., Some/Framework, ..\\x, net10.0:custom). Adding a unit test for sanitization (or expected failure behavior) would prevent regressions and validate safe filename handling.

Copilot uses AI. Check for mistakes.

MakeTestRunComplete();

var fileName = Path.GetFileName(_testableTrxLogger.TrxFile);
Assert.IsNotNull(fileName);
Assert.Contains("_SomeCustomFramework", fileName, $"Expected raw framework string in filename but got: {fileName}");
Assert.EndsWith(".trx", fileName, $"Expected .trx extension but got: {fileName}");
}

[TestMethod]
public void DefaultTrxFileNameVerification()
{
Expand Down
Loading