From 79ea3104bdf2bc2d75a7e57734aac3db3908d9f9 Mon Sep 17 00:00:00 2001 From: Christian Soltenborn Date: Mon, 25 Jun 2018 19:14:32 +0200 Subject: [PATCH] bugfix: WorkingDir returned placeholder if setting was empty (but not null) --- .../Settings/SettingsWrapperTests.cs | 52 +++++++++++++++++++ .../Core/Settings/SettingsWrapper.cs | 12 ++--- 2 files changed, 57 insertions(+), 7 deletions(-) diff --git a/GoogleTestAdapter/Core.Tests/Settings/SettingsWrapperTests.cs b/GoogleTestAdapter/Core.Tests/Settings/SettingsWrapperTests.cs index 644ea9093..daa590747 100644 --- a/GoogleTestAdapter/Core.Tests/Settings/SettingsWrapperTests.cs +++ b/GoogleTestAdapter/Core.Tests/Settings/SettingsWrapperTests.cs @@ -362,6 +362,58 @@ public void GetWorkingDir__EnvVarPlaceholderIsReplaced() } } + [TestMethod] + [TestCategory(Unit)] + public void GetWorkingDirForExecution_null_ExecutableDirIsReturned() + { + MockXmlOptions.Setup(o => o.WorkingDir).Returns((string)null); + + var result = TheOptions.GetWorkingDirForExecution(TestResources.Tests_DebugX86, "", 0); + + var expectedDir = new FileInfo(TestResources.Tests_DebugX86).Directory?.FullName; + result.Should().NotBeNullOrEmpty(); + result.Should().BeEquivalentTo(expectedDir); + } + + [TestMethod] + [TestCategory(Unit)] + public void GetWorkingDirForExecution_EmptyString_ExecutableDirIsReturned() + { + MockXmlOptions.Setup(o => o.WorkingDir).Returns(""); + + var result = TheOptions.GetWorkingDirForExecution(TestResources.Tests_DebugX86, "", 0); + + var expectedDir = new FileInfo(TestResources.Tests_DebugX86).Directory?.FullName; + result.Should().NotBeNullOrEmpty(); + result.Should().BeEquivalentTo(expectedDir); + } + + [TestMethod] + [TestCategory(Unit)] + public void GetWorkingDirForDiscovery_null_ExecutableDirIsReturned() + { + MockXmlOptions.Setup(o => o.WorkingDir).Returns((string) null); + + var result = TheOptions.GetWorkingDirForDiscovery(TestResources.Tests_DebugX86); + + var expectedDir = new FileInfo(TestResources.Tests_DebugX86).Directory?.FullName; + result.Should().NotBeNullOrEmpty(); + result.Should().BeEquivalentTo(expectedDir); + } + + [TestMethod] + [TestCategory(Unit)] + public void GetWorkingDirForDiscovery_EmptyString_ExecutableDirIsReturned() + { + MockXmlOptions.Setup(o => o.WorkingDir).Returns(""); + + var result = TheOptions.GetWorkingDirForDiscovery(TestResources.Tests_DebugX86); + + var expectedDir = new FileInfo(TestResources.Tests_DebugX86).Directory?.FullName; + result.Should().NotBeNullOrEmpty(); + result.Should().BeEquivalentTo(expectedDir); + } + [TestMethod] [TestCategory(Unit)] public void GetUserParams__EnvVarPlaceholderIsReplaced() diff --git a/GoogleTestAdapter/Core/Settings/SettingsWrapper.cs b/GoogleTestAdapter/Core/Settings/SettingsWrapper.cs index b041c367d..987675bb4 100644 --- a/GoogleTestAdapter/Core/Settings/SettingsWrapper.cs +++ b/GoogleTestAdapter/Core/Settings/SettingsWrapper.cs @@ -335,13 +335,13 @@ public virtual int TestDiscoveryTimeoutInSeconds { DescriptionOfThreadIdPlaceholder + DescriptionTestExecutionOnly + "\n" + DescriptionOfEnvVarPlaceholders; - public virtual string WorkingDir => _currentSettings.WorkingDir ?? OptionWorkingDirDefaultValue; + public virtual string WorkingDir => string.IsNullOrWhiteSpace(_currentSettings.WorkingDir) + ? OptionWorkingDirDefaultValue + : _currentSettings.WorkingDir; public string GetWorkingDirForExecution(string executable, string testDirectory, int threadId) { - return string.IsNullOrWhiteSpace(WorkingDir) - ? OptionWorkingDirDefaultValue - : ReplaceEnvironmentVariables( + return ReplaceEnvironmentVariables( ReplaceSolutionDirPlaceholder( ReplaceExecutablePlaceholders( ReplaceTestDirAndThreadIdPlaceholders(WorkingDir, testDirectory, threadId), executable))); @@ -349,9 +349,7 @@ public string GetWorkingDirForExecution(string executable, string testDirectory, public string GetWorkingDirForDiscovery(string executable) { - return string.IsNullOrWhiteSpace(WorkingDir) - ? new FileInfo(executable).DirectoryName - : ReplaceEnvironmentVariables( + return ReplaceEnvironmentVariables( ReplaceSolutionDirPlaceholder( RemoveTestDirAndThreadIdPlaceholders( ReplaceExecutablePlaceholders(WorkingDir, executable))));