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
2 changes: 1 addition & 1 deletion playground/TestPlatform.Playground/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ static void Main()
// var processStartInfo = new ProcessStartInfo
// {
// FileName = console,
// Arguments = $"{string.Join(" ", sources)} --settings:{settingsFile} --listtests",
// Arguments = $"{string.Join(" ", sources)} --settings:{settingsFile} --logger:trx;LogFileName=my.trx;WarnOnFileOverwrite=false",
// UseShellExecute = false,
// };
// EnvironmentVariables.Variables.ToList().ForEach(processStartInfo.Environment.Add);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
<ProjectReference Include="$(RepoRoot)src\AttachVS\AttachVS.csproj" />
<ProjectReference Include="$(RepoRoot)src\Microsoft.TestPlatform.Build\Microsoft.TestPlatform.Build.csproj" />
<ProjectReference Include="$(RepoRoot)src\Microsoft.TestPlatform.Extensions.HtmlLogger\Microsoft.TestPlatform.Extensions.HtmlLogger.csproj" />
<ProjectReference Include="..\..\src\Microsoft.TestPlatform.Extensions.TrxLogger\Microsoft.TestPlatform.Extensions.TrxLogger.csproj" />
</ItemGroup>
<ItemGroup Condition=" $(TargetFramework.StartsWith('net4')) AND '$(OS)' != 'Windows_NT' ">
<Reference Include="System" />
Expand Down Expand Up @@ -74,6 +75,7 @@

<!-- copy loggers -->
<FileToCopy Include="$(SourcePath)bin\Microsoft.TestPlatform.Extensions.HtmlLogger\$(Configuration)\$(NetFrameworkMinimum)\Microsoft.VisualStudio.TestPlatform.Extensions.Html.TestLogger*" SubFolder="netfx\Extensions\" />
<FileToCopy Include="$(SourcePath)bin\Microsoft.TestPlatform.Extensions.TrxLogger\$(Configuration)\$(NetFrameworkMinimum)\Microsoft.VisualStudio.TestPlatform.Extensions.Trx.TestLogger*" SubFolder="netfx\Extensions\" />

<!-- .NET console -->
<FileToCopy Include="$(SourcePath)bin\vstest.console\$(Configuration)\$(NetCoreAppMinimum)\**\*.*" SubFolder="net" />
Expand Down
17 changes: 14 additions & 3 deletions src/Microsoft.TestPlatform.Extensions.TrxLogger/TrxLogger.cs
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,7 @@ internal TrxLogger(IFileHelper fileHelper, TrxFileHelper trxFileHelper)
/// Gets the directory under which default trx file and test results attachments should be saved.
/// </summary>
private string? _testResultsDirPath;
private bool _warnOnFileOverwrite;


#region ITestLogger
Expand Down Expand Up @@ -135,6 +136,13 @@ public void Initialize(TestLoggerEvents events, Dictionary<string, string?> para

var isLogFilePrefixParameterExists = parameters.TryGetValue(TrxLoggerConstants.LogFilePrefixKey, out _);
var isLogFileNameParameterExists = parameters.TryGetValue(TrxLoggerConstants.LogFileNameKey, out _);
_warnOnFileOverwrite = parameters.TryGetValue(TrxLoggerConstants.WarnOnFileOverwrite, out string? warnOnOverwriteString)
? bool.TryParse(warnOnOverwriteString, out bool providedValue)
? providedValue
// We found the option but could not parse the value.
: true
// We did not find the option and want to fallback to warning on write, because that was the default before.
: true;

if (isLogFilePrefixParameterExists && isLogFileNameParameterExists)
{
Expand Down Expand Up @@ -450,9 +458,12 @@ private void ReserveTrxFilePath()

if (shouldOverwrite && File.Exists(filePath))
{
var overwriteWarningMsg = string.Format(CultureInfo.CurrentCulture, TrxLoggerResources.TrxLoggerResultsFileOverwriteWarning, filePath);
ConsoleOutput.Instance.Warning(false, overwriteWarningMsg);
EqtTrace.Warning(overwriteWarningMsg);
if (_warnOnFileOverwrite)
{
var overwriteWarningMsg = string.Format(CultureInfo.CurrentCulture, TrxLoggerResources.TrxLoggerResultsFileOverwriteWarning, filePath);
ConsoleOutput.Instance.Warning(false, overwriteWarningMsg);
EqtTrace.Warning(overwriteWarningMsg);
}
}
else
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,11 @@ internal static class Constants
/// </summary>
public const string TmiTestIdPropertyIdentifier = "MSTestDiscoverer.TmiTestId";

/// <summary>
/// Warn when overwriting the trx file.
/// </summary>
public static string WarnOnFileOverwrite = "WarnOnFileOverwrite";

/// <summary>
/// Mstest adapter string
/// </summary>
Expand Down