Skip to content

Commit

Permalink
Merge pull request #228 from csoltenborn/#227_FixForErrorReporting
Browse files Browse the repository at this point in the history
  • Loading branch information
csoltenborn authored Jun 26, 2018
2 parents 2c2cdcb + 60b30c1 commit ca04a30
Show file tree
Hide file tree
Showing 4 changed files with 64 additions and 16 deletions.
6 changes: 5 additions & 1 deletion GoogleTestAdapter/Core/Runners/SequentialTestRunner.cs
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,11 @@ private IEnumerable<TestResult> RunTests(string executable, string workingDir, b
public static void LogExecutionError(ILogger logger, string executable, string workingDir, string arguments, Exception exception, string threadName = "")
{
logger.LogError($"{threadName}Failed to run test executable '{executable}': {exception.Message}");
logger.DebugError($@"{threadName}Stacktrace:{Environment.NewLine}{exception.StackTrace}");
if (exception is AggregateException aggregateException)
{
exception = aggregateException.Flatten();
}
logger.DebugError($@"{threadName}Exception:{Environment.NewLine}{exception}");
logger.LogError(
$"{threadName}{Strings.Instance.TroubleShootingLink}");
logger.LogError(
Expand Down
16 changes: 6 additions & 10 deletions GoogleTestAdapter/Core/TestCases/TestCaseFactory.cs
Original file line number Diff line number Diff line change
Expand Up @@ -40,12 +40,11 @@ public IList<TestCase> CreateTestCases(Action<TestCase> reportTestCase = null)
return NewCreateTestcases(reportTestCase);
}

string workingDir = _settings.GetWorkingDirForDiscovery(_executable);
string finalParams = GetDiscoveryParams();
List<string> standardOutput = new List<string>();
try
{
string workingDir = _settings.GetWorkingDirForDiscovery(_executable);
string finalParams = GetDiscoveryParams();

int processExitCode = 0;
ProcessLauncher launcher = null;
var listTestsTask = new Task(() =>
Expand All @@ -68,8 +67,7 @@ public IList<TestCase> CreateTestCases(Action<TestCase> reportTestCase = null)
}
catch (Exception e)
{
SequentialTestRunner.LogExecutionError(_logger, _executable, Path.GetFullPath(""),
GoogleTestConstants.ListTestsOption, e);
SequentialTestRunner.LogExecutionError(_logger, _executable, workingDir, finalParams, e);
return new List<TestCase>();
}

Expand Down Expand Up @@ -152,11 +150,10 @@ private IList<TestCase> NewCreateTestcases(Action<TestCase> reportTestCase)
parser.ReportLine(s);
};

string workingDir = _settings.GetWorkingDirForDiscovery(_executable);
var finalParams = GetDiscoveryParams();
try
{
string workingDir = _settings.GetWorkingDirForDiscovery(_executable);
var finalParams = GetDiscoveryParams();

int processExitCode = ProcessExecutor.ExecutionFailed;
ProcessExecutor executor = null;
var listAndParseTestsTask = new Task(() =>
Expand Down Expand Up @@ -192,8 +189,7 @@ private IList<TestCase> NewCreateTestcases(Action<TestCase> reportTestCase)
}
catch (Exception e)
{
SequentialTestRunner.LogExecutionError(_logger, _executable, Path.GetFullPath(""),
GoogleTestConstants.ListTestsOption, e);
SequentialTestRunner.LogExecutionError(_logger, _executable, workingDir, finalParams, e);
return new List<TestCase>();
}
return testCases;
Expand Down
39 changes: 38 additions & 1 deletion GoogleTestAdapter/DiaResolver.Tests/PdbLocatorTests.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System.Diagnostics.CodeAnalysis;
using System;
using System.Diagnostics.CodeAnalysis;
using System.IO;
using FluentAssertions;
using GoogleTestAdapter.Tests.Common;
Expand Down Expand Up @@ -58,5 +59,41 @@ public void FindPdbFile_ExeWithoutPdb_AttemptsToFindPdbAreLogged()
.Should()
.Contain(msg => msg.Contains("Attempts to find pdb:"));
}

[TestMethod]
[TestCategory(Unit)]
[SuppressMessage("ReSharper", "AssignNullToNotNullAttribute")]
public void FindPdbFile_PATHcontainsInvalidChars_ErrorIsLogged()
{
TestResources.LoadTests_ReleaseX86.AsFileInfo().Should().Exist();
string pdb = Path.ChangeExtension(TestResources.LoadTests_ReleaseX86, ".pdb");
pdb.AsFileInfo().Should().Exist();
string renamedPdb = $"{pdb}.bak";
renamedPdb.AsFileInfo().Should().NotExist();

string pdbFound;
var fakeLogger = new FakeLogger(() => true);
var currentPath = Environment.GetEnvironmentVariable("PATH");
try
{
File.Move(pdb, renamedPdb);
pdb.AsFileInfo().Should().NotExist();

Environment.SetEnvironmentVariable("PATH", $"My<Invalid>Path;{currentPath}");
pdbFound = PdbLocator.FindPdbFile(TestResources.LoadTests_ReleaseX86, "", fakeLogger);
}
finally
{
Environment.SetEnvironmentVariable("PATH", currentPath);
File.Move(renamedPdb, pdb);
pdb.AsFileInfo().Should().Exist();
}

pdbFound.Should().BeNull();
fakeLogger.Warnings
.Should()
.Contain(msg => msg.Contains("invalid path"));
}

}
}
19 changes: 15 additions & 4 deletions GoogleTestAdapter/DiaResolver/PdbLocator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,21 @@ public static string FindPdbFile(string binary, string pathExtension, ILogger lo
{
foreach (string pathElement in pathElements)
{
string file = Path.Combine(pathElement, pdb);
if (File.Exists(file))
return file;
attempts.Add($"\"{file}\"");
try
{
string file = Path.Combine(pathElement, pdb);
if (File.Exists(file))
return file;
attempts.Add($"\"{file}\"");
}
catch (Exception e)
{
string message = $"Exception while searching for the PDB file of binary '{binary}'. ";
message += "Do you have some invalid path on your system's PATH environment variable? ";
message += $"The according path is '{pathElement}' and will be ignored.";
logger.LogWarning(message);
logger.DebugWarning($"Exception:{Environment.NewLine}{e}");
}
}
}

Expand Down

0 comments on commit ca04a30

Please sign in to comment.