diff --git a/src/Microsoft.TestPlatform.CoreUtilities/Helpers/FileHelper.cs b/src/Microsoft.TestPlatform.CoreUtilities/Helpers/FileHelper.cs
index 720334b291..0132d13167 100644
--- a/src/Microsoft.TestPlatform.CoreUtilities/Helpers/FileHelper.cs
+++ b/src/Microsoft.TestPlatform.CoreUtilities/Helpers/FileHelper.cs
@@ -22,6 +22,12 @@ public DirectoryInfo CreateDirectory(string path)
return Directory.CreateDirectory(path);
}
+ ///
+ public string GetCurrentDirectory()
+ {
+ return Directory.GetCurrentDirectory();
+ }
+
///
public bool Exists(string path)
{
@@ -52,5 +58,7 @@ public FileAttributes GetFileAttributes(string path)
{
return new FileInfo(path).Attributes;
}
+
+
}
}
diff --git a/src/Microsoft.TestPlatform.CoreUtilities/Helpers/Interfaces/IFileHelper.cs b/src/Microsoft.TestPlatform.CoreUtilities/Helpers/Interfaces/IFileHelper.cs
index 7e0af31121..cb7e972ee2 100644
--- a/src/Microsoft.TestPlatform.CoreUtilities/Helpers/Interfaces/IFileHelper.cs
+++ b/src/Microsoft.TestPlatform.CoreUtilities/Helpers/Interfaces/IFileHelper.cs
@@ -18,6 +18,12 @@ public interface IFileHelper
/// for the created directory.
DirectoryInfo CreateDirectory(string path);
+ ///
+ /// Gets the current directory
+ ///
+ /// Current directory
+ string GetCurrentDirectory();
+
///
/// Exists utility to check if file exists (case sensitive).
///
diff --git a/src/vstest.console/CommandLine/CommandLineOptions.cs b/src/vstest.console/CommandLine/CommandLineOptions.cs
index d14aeb4214..8f5e5eb619 100644
--- a/src/vstest.console/CommandLine/CommandLineOptions.cs
+++ b/src/vstest.console/CommandLine/CommandLineOptions.cs
@@ -14,6 +14,7 @@ namespace Microsoft.VisualStudio.TestPlatform.CommandLine
using Utilities.Helpers.Interfaces;
using CommandLineResources = Microsoft.VisualStudio.TestPlatform.CommandLine.Resources.Resources;
+ using System.IO;
///
/// Provides access to the command-line options.
@@ -253,6 +254,13 @@ public void AddSource(string source)
}
source = source.Trim();
+
+ // Convert the relative path to absolute path
+ if(!Path.IsPathRooted(source))
+ {
+ source = Path.Combine(FileHelper.GetCurrentDirectory(), source);
+ }
+
if (!FileHelper.Exists(source))
{
throw new CommandLineException(
diff --git a/test/vstest.console.UnitTests/CommandLine/CommandLineOptionsTests.cs b/test/vstest.console.UnitTests/CommandLine/CommandLineOptionsTests.cs
index 792c2f3661..4674e200df 100644
--- a/test/vstest.console.UnitTests/CommandLine/CommandLineOptionsTests.cs
+++ b/test/vstest.console.UnitTests/CommandLine/CommandLineOptionsTests.cs
@@ -10,17 +10,20 @@ namespace Microsoft.VisualStudio.TestPlatform.CommandLine.UnitTests.CommandLine
using Microsoft.VisualStudio.TestPlatform.Utilities.Helpers.Interfaces;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using Moq;
+ using System.IO;
[TestClass]
public class CommandLineOptionsTests
{
private readonly Mock fileHelper;
+ private readonly string currentDirectory = @"C:\\Temp";
public CommandLineOptionsTests()
{
this.fileHelper = new Mock();
CommandLineOptions.Instance.Reset();
CommandLineOptions.Instance.FileHelper = this.fileHelper.Object;
+ this.fileHelper.Setup(fh => fh.GetCurrentDirectory()).Returns(currentDirectory);
}
[TestMethod]
@@ -57,6 +60,18 @@ public void CommandLineOptionsAddSourceShouldThrowCommandLineExceptionForNullSou
{
Assert.ThrowsException(() => CommandLineOptions.Instance.AddSource(null));
}
+
+ [TestMethod]
+ public void CommandLineOptionsAddSourceShouldConvertRelativePathToAbsolutePath()
+ {
+ string relativeTestFilePath = "DummyTestFile.txt";
+ var absolutePath = Path.Combine(currentDirectory, relativeTestFilePath);
+ this.fileHelper.Setup(fh => fh.Exists(absolutePath)).Returns(true);
+
+ // Pass relative path
+ CommandLineOptions.Instance.AddSource(relativeTestFilePath);
+ Assert.IsTrue(CommandLineOptions.Instance.Sources.Contains(absolutePath));
+ }
[TestMethod]
public void CommandLineOptionsAddSourceShouldThrowCommandLineExceptionForInvalidSource()
@@ -67,7 +82,7 @@ public void CommandLineOptionsAddSourceShouldThrowCommandLineExceptionForInvalid
[TestMethod]
public void CommandLineOptionsAddSourceShouldAddSourceThrowExceptionIfDuplicateSource()
{
- var testFilePath = "DummyTestFile.txt";
+ var testFilePath = "C:\\DummyTestFile.txt";
this.fileHelper.Setup(fh => fh.Exists(testFilePath)).Returns(true);
CommandLineOptions.Instance.AddSource(testFilePath);
@@ -78,7 +93,7 @@ public void CommandLineOptionsAddSourceShouldAddSourceThrowExceptionIfDuplicateS
[TestMethod]
public void CommandLineOptionsAddSourceShouldAddSourceForValidSource()
{
- string testFilePath = "DummyTestFile.txt";
+ string testFilePath = "C:\\DummyTestFile.txt";
this.fileHelper.Setup(fh => fh.Exists(testFilePath)).Returns(true);
CommandLineOptions.Instance.AddSource(testFilePath);