Skip to content

Commit

Permalink
Merge pull request #226 from csoltenborn/#225_FixWorkingDirDefault
Browse files Browse the repository at this point in the history
bugfix: WorkingDir returned placeholder if setting was empty (but not null)
  • Loading branch information
csoltenborn authored Jun 26, 2018
2 parents 7b848ef + 79ea310 commit 2c2cdcb
Show file tree
Hide file tree
Showing 2 changed files with 57 additions and 7 deletions.
52 changes: 52 additions & 0 deletions GoogleTestAdapter/Core.Tests/Settings/SettingsWrapperTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
12 changes: 5 additions & 7 deletions GoogleTestAdapter/Core/Settings/SettingsWrapper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -335,23 +335,21 @@ 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)));
}

public string GetWorkingDirForDiscovery(string executable)
{
return string.IsNullOrWhiteSpace(WorkingDir)
? new FileInfo(executable).DirectoryName
: ReplaceEnvironmentVariables(
return ReplaceEnvironmentVariables(
ReplaceSolutionDirPlaceholder(
RemoveTestDirAndThreadIdPlaceholders(
ReplaceExecutablePlaceholders(WorkingDir, executable))));
Expand Down

0 comments on commit 2c2cdcb

Please sign in to comment.