Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

--diag should take files with no extension #3048

Merged
merged 1 commit into from
Sep 10, 2021
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
7 changes: 0 additions & 7 deletions src/vstest.console/Processors/EnableDiagArgumentProcessor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -225,13 +225,6 @@ private string GetDiagFilePath(string diagFilePathArgument)
// Remove double quotes if present.
diagFilePathArgument = diagFilePathArgument.Replace("\"", "");

// Throw error in case diag file path is not a valid file path
var fileExtension = Path.GetExtension(diagFilePathArgument);
if (string.IsNullOrWhiteSpace(fileExtension))
{
throw new CommandLineException(string.Format(CultureInfo.CurrentCulture, CommandLineResources.InvalidDiagFilePath, diagFilePathArgument));
}

// Create base directory for diag file path (if doesn't exist)
CreateDirectoryIfNotExists(diagFilePathArgument);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -90,20 +90,11 @@ public void EnableDiagArgumentProcessorExecutorDoesNotThrowsIfFileDotOpenThrow()
this.diagProcessor.Executor.Value.Initialize(this.dummyFilePath);
}

[TestMethod]
[DataRow("abs;dfsdc.txt;verbosity=normal", "abs")] // ; in file path is not supported
[DataRow("\"abst;dfsdc.txt\";verbosity=normal", "abst")] // Even though in escaped double quotes, semi colon is not supported in file path
[DataRow("foo", "foo")]
public void EnableDiagArgumentProcessorExecutorShouldThrowIfDirectoryPathIsProvided(string argument, string filePath)
{
var exceptionMessage = string.Format(CultureInfo.CurrentCulture, CommandLineResources.InvalidDiagFilePath, filePath);

EnableDiagArgumentProcessorExecutorShouldThrowIfInvalidArgument(argument, exceptionMessage);
}

[TestMethod]
[DataRow("abc.txt;verbosity=normal=verbose")] // Multiple '=' in parameter
[DataRow("abc.txt;verbosity;key1=value1")] // No '=' in parameter
[DataRow("\"abst;dfsdc.txt\";verbosity=normal")] // Too many parameters
[DataRow("abs;dfsdc.txt;verbosity=normal")] // Too many parameters
public void EnableDiagArgumentProcessorExecutorShouldThrowIfInvalidArgument(string argument)
{
string exceptionMessage = string.Format(CultureInfo.CurrentCulture, CommandLineResources.InvalidDiagArgument, argument);
Expand All @@ -116,6 +107,15 @@ public void EnableDiagArgumentProcessorExecutorShouldThrowIfInvalidArgument(stri
[DataRow("abc.txt;tracelevel=info;newkey=newvalue")]
[DataRow("\"abc.txt\";verbosity=normal;newkey=newvalue")] //escaped double quotes are allowed for file path.
[DataRow(";;abc.txt;;;;verbosity=normal;;;;")]
// Files with no extension are totally valid files.
// When we delegate to host or datacollector we change the name in GetTimestampedLogFile
// Path.ChangeExtension replaces the curent extension with our new one that is timestamp and
// the name of the target (e.g. host). When there is no extension it just adds it, so we do either:
// log.txt -> log.host.21-09-10_12-25-41_68765_5.txt
// log.my.txt -> log.my.host.21-09-10_12-25-50_55183_5.txt
// log -> log.host.21-09-10_12-25-27_94286_5
[DataRow("log")]
[DataRow("log.log")]
public void EnableDiagArgumentProcessorExecutorShouldNotThrowIfValidArgument(string argument)
{
try
Expand Down Expand Up @@ -192,15 +192,8 @@ public TestableEnableDiagArgumentProcessor(IFileHelper fileHelper)

private void EnableDiagArgumentProcessorExecutorShouldThrowIfInvalidArgument(string argument, string exceptionMessage)
{
try
{
this.diagProcessor.Executor.Value.Initialize(argument);
}
catch (Exception e)
{
Assert.IsTrue(e.GetType().Equals(typeof(CommandLineException)));
Assert.IsTrue(e.Message.Contains(exceptionMessage));
}
var e = Assert.ThrowsException<CommandLineException>(() => this.diagProcessor.Executor.Value.Initialize(argument));
StringAssert.Contains(e.Message, exceptionMessage);
}
}
}