Skip to content
This repository has been archived by the owner on Oct 12, 2022. It is now read-only.

Commit

Permalink
Improves log messages and changes default hive to default rather than…
Browse files Browse the repository at this point in the history
… Exp.
  • Loading branch information
zooba committed Oct 1, 2015
1 parent 161561e commit ed7a8f9
Show file tree
Hide file tree
Showing 5 changed files with 61 additions and 18 deletions.
20 changes: 19 additions & 1 deletion VSTestHost/Resources.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions VSTestHost/Resources.resx
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,13 @@
<value>Failed to launch {1} ({0}, {2}{3})</value>
<comment>application, executable, version, hive</comment>
</data>
<data name="VSLaunchMessage" xml:space="preserve">
<value>Launching {0}: "...\Microsoft Visual Studio {2}\Common7\IDE\{1}{3}"</value>
</data>
<data name="VSLaunchTimeout" xml:space="preserve">
<value>Visual Studio failed to start within {0} seconds.</value>
</data>
<data name="VSReuseMessage" xml:space="preserve">
<value>Reusing {0}: "...\Microsoft Visual Studio {2}\Common7\IDE\{1}{3}"</value>
</data>
</root>
50 changes: 35 additions & 15 deletions VSTestHost/TesterTestAdapter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -48,19 +48,38 @@ private async Task Connect(
string executable,
Version version,
string hive,
IRunContext runContext,
ITestElement currentTest,
CancellationToken cancel
) {
var hiveOption = string.IsNullOrEmpty(hive) ? "" : (" /rootSuffix " + hive);

if (_ide != null &&
_remote != null &&
application == _currentApplication &&
executable == _currentExecutable &&
version == _currentVersion &&
hive == _currentHive) {
if (runContext != null) {
SendMessage(
runContext,
string.Format(Resources.VSReuseMessage, application, executable, version, hiveOption),
currentTest
);
}
return;
}

Close();

if (runContext != null) {
SendMessage(
runContext,
string.Format(Resources.VSLaunchMessage, application, executable, version, hiveOption),
currentTest
);
}

Internal.VisualStudio ide = null;
try {
ide = await Internal.VisualStudio.LaunchAsync(application, executable, version, hive, cancel);
Expand Down Expand Up @@ -141,7 +160,11 @@ private bool IsClientAlive() {
/// <param name="runContext">
/// The context for the current test run.
/// </param>
private async Task InitializeWorker(TestProperties vars) {
private async Task InitializeWorker(
TestProperties vars,
IRunContext runContext,
ITestElement currentTest = null
) {
string application, executable, versionString, hive;
Version version;
string launchTimeoutInSecondsString;
Expand All @@ -165,7 +188,7 @@ private async Task InitializeWorker(TestProperties vars) {
}

// VSHive is the optional hive like 'Exp'
hive = vars[VSTestProperties.VSHive.Key] ?? VSTestProperties.VSHive.Exp;
hive = vars[VSTestProperties.VSHive.Key];

if (!vars.TryGetValue(VSTestProperties.VSLaunchTimeoutInSeconds.Key, out launchTimeoutInSecondsString) ||
!int.TryParse(launchTimeoutInSecondsString, out launchTimeoutInSeconds)) {
Expand All @@ -178,7 +201,7 @@ private async Task InitializeWorker(TestProperties vars) {
application ?? "(null)",
executable ?? "(null)",
version != null ? version.ToString() : "(null)",
hive ?? "(null)"
hive ?? "(default)"
));
}

Expand All @@ -205,7 +228,7 @@ private async Task InitializeWorker(TestProperties vars) {

var cts = new CancellationTokenSource(TimeSpan.FromSeconds(launchTimeoutInSeconds));
try {
await Connect(application, executable, version, hive, cts.Token);
await Connect(application, executable, version, hive, runContext, currentTest, cts.Token);
} catch (OperationCanceledException ex) {
throw new TimeoutException(string.Format(Resources.VSLaunchTimeout, launchTimeoutInSeconds), ex);
} catch (Exception ex) {
Expand All @@ -216,8 +239,8 @@ private async Task InitializeWorker(TestProperties vars) {
}
}

private static TestRunTextResultMessage GetFailure(Exception ex, Guid runId) {
var res = new TestRunTextResultMessage(runId, ex.Message);
private static TextTestResultMessage GetFailure(Exception ex, Guid runId, ITestElement currentTest) {
var res = new TextTestResultMessage(runId, currentTest, ex.Message);
#if DEBUG
if (ex.InnerException != null) {
res.SystemException = ex.InnerException;
Expand All @@ -228,25 +251,22 @@ private static TestRunTextResultMessage GetFailure(Exception ex, Guid runId) {

private bool InitializeForTest(ITestElement testElement, IRunContext runContext) {
var runId = runContext.RunConfig.TestRun.Id;
TestRunTextResultMessage failure = null;
TestResultMessage failure = null;

try {
var vars = new TestProperties(testElement, runContext.RunConfig.TestRun.RunConfiguration);
InitializeWorker(vars).GetAwaiter().GetResult();
InitializeWorker(vars, runContext, testElement).GetAwaiter().GetResult();
_remote.Initialize(_runContext);

AttachDebuggerIfNeeded(runContext, _ide, vars);
} catch (ArgumentException ex) {
failure = GetFailure(ex, runId);
failure = GetFailure(ex, runId, testElement);
} catch (TimeoutException ex) {
failure = GetFailure(ex, runId);
failure = GetFailure(ex, runId, testElement);
} catch (InvalidOperationException ex) {
failure = GetFailure(ex, runId);
failure = GetFailure(ex, runId, testElement);
} catch (Exception ex) {
failure = new TestRunTextResultMessage(
runId,
string.Format("{0}: {1}{2}{3}", ex.GetType().Name, ex.Message, Environment.NewLine, ex)
);
failure = GetFailure(ex, runId, testElement);
failure.SystemException = ex;
}

Expand Down
1 change: 0 additions & 1 deletion VSTestHost/VSTestProperties.cs
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,6 @@ public static class VSVersion {

public static class VSHive {
public const string Key = "VSHive";
public const string Default = "Default";
public const string Exp = "Exp";
}

Expand Down
2 changes: 1 addition & 1 deletion VSTestHost/VisualStudio.cs
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ CancellationToken cancel
}

var psi = new ProcessStartInfo(devenv);
if (!string.IsNullOrEmpty(hive) && hive != VSTestProperties.VSHive.Default) {
if (!string.IsNullOrEmpty(hive)) {
psi.Arguments = "/rootSuffix " + hive;
}

Expand Down

0 comments on commit ed7a8f9

Please sign in to comment.