Skip to content

Commit

Permalink
Merge pull request #53590 from sharwell/nrt-utils
Browse files Browse the repository at this point in the history
Enable nullable reference types integration test harness
  • Loading branch information
sharwell authored May 28, 2021
2 parents 0d79d5d + 6f0b111 commit dfd5b87
Show file tree
Hide file tree
Showing 102 changed files with 248 additions and 374 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,14 @@
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.

#nullable disable

using System;
using System.Diagnostics;

namespace Microsoft.CodeAnalysis.ErrorReporting
{
internal class WatsonTraceListener : TraceListener
{
public override void Fail(string message, string detailMessage)
public override void Fail(string? message, string? detailMessage)
{
if (string.IsNullOrEmpty(message))
{
Expand All @@ -27,71 +25,71 @@ public override void Fail(string message, string detailMessage)
}
}

public override void Write(object o)
public override void Write(object? o)
{
if (Debugger.IsLogging())
{
Debugger.Log(0, null, o?.ToString());
}
}

public override void Write(object o, string category)
public override void Write(object? o, string? category)
{
if (Debugger.IsLogging())
{
Debugger.Log(0, category, o?.ToString());
}
}

public override void Write(string message)
public override void Write(string? message)
{
if (Debugger.IsLogging())
{
Debugger.Log(0, null, message);
}
}

public override void Write(string message, string category)
public override void Write(string? message, string? category)
{
if (Debugger.IsLogging())
{
Debugger.Log(0, category, message);
}
}

public override void WriteLine(object o)
public override void WriteLine(object? o)
{
if (Debugger.IsLogging())
{
Debugger.Log(0, null, o?.ToString() + Environment.NewLine);
}
}

public override void WriteLine(object o, string category)
public override void WriteLine(object? o, string? category)
{
if (Debugger.IsLogging())
{
Debugger.Log(0, category, o?.ToString() + Environment.NewLine);
}
}

public override void WriteLine(string message)
public override void WriteLine(string? message)
{
if (Debugger.IsLogging())
{
Debugger.Log(0, null, message + Environment.NewLine);
}
}

public override void WriteLine(string message, string category)
public override void WriteLine(string? message, string? category)
{
if (Debugger.IsLogging())
{
Debugger.Log(0, category, message + Environment.NewLine);
}
}

private static void Exit(string message)
private static void Exit(string? message)
{
FatalError.ReportAndPropagate(new Exception(message));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.

#nullable disable

using System;
using System.Collections.Concurrent;
using System.Diagnostics;
Expand Down Expand Up @@ -49,7 +47,7 @@ public static IntegrationService GetInstanceFromHostProcess(Process hostProcess)
return (IntegrationService)Activator.GetObject(typeof(IntegrationService), uri);
}

public string Execute(string assemblyFilePath, string typeFullName, string methodName)
public string? Execute(string assemblyFilePath, string typeFullName, string methodName)
{
var assembly = Assembly.LoadFrom(assemblyFilePath);
var type = assembly.GetType(typeFullName);
Expand All @@ -76,7 +74,7 @@ public string Execute(string assemblyFilePath, string typeFullName, string metho
}

// Ensure InProcComponents live forever
public override object InitializeLifetimeService()
public override object? InitializeLifetimeService()
=> null;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.

#nullable disable

using System;
using System.Composition;
using System.Threading;
Expand Down Expand Up @@ -56,7 +54,7 @@ private void HandleAsyncCompletionTriggered(object sender, CompletionTriggeredEv

// Local function
void ReleaseToken(object sender, EventArgs e)
=> Interlocked.Exchange(ref token, null)?.Dispose();
=> Interlocked.Exchange<IAsyncToken?>(ref token, null)?.Dispose();
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.

#nullable disable

using Microsoft.VisualStudio.Utilities;

namespace Microsoft.VisualStudio.IntegrationTest.Setup
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.

#nullable disable

using System;
using System.ComponentModel.Design;
using System.Diagnostics;
Expand Down Expand Up @@ -44,38 +42,39 @@ internal sealed class IntegrationTestServiceCommands : IDisposable
private readonly MenuCommand _startMenuCmd;
private readonly MenuCommand _stopMenuCmd;

private IntegrationService _service;
private IpcServerChannel _serviceChannel;
private IntegrationService? _service;
private IpcServerChannel? _serviceChannel;

#pragma warning disable IDE0052 // Remove unread private members - used to hold the marshalled integration test service
private ObjRef _marshalledService;
private ObjRef? _marshalledService;
#pragma warning restore IDE0052 // Remove unread private members

private IntegrationTestServiceCommands(Package package)
{
_package = package ?? throw new ArgumentNullException(nameof(package));

var startMenuCmdId = new CommandID(guidTestWindowCmdSet, cmdidStartIntegrationTestService);
_startMenuCmd = new MenuCommand(StartServiceCallback, startMenuCmdId)
{
Enabled = true,
Visible = true
};

var stopMenuCmdId = new CommandID(guidTestWindowCmdSet, cmdidStopIntegrationTestService);
_stopMenuCmd = new MenuCommand(StopServiceCallback, stopMenuCmdId)
{
Enabled = false,
Visible = false
};

if (ServiceProvider.GetService(typeof(IMenuCommandService)) is OleMenuCommandService menuCommandService)
{
var startMenuCmdId = new CommandID(guidTestWindowCmdSet, cmdidStartIntegrationTestService);
_startMenuCmd = new MenuCommand(StartServiceCallback, startMenuCmdId)
{
Enabled = true,
Visible = true
};
menuCommandService.AddCommand(_startMenuCmd);

var stopMenuCmdId = new CommandID(guidTestWindowCmdSet, cmdidStopIntegrationTestService);
_stopMenuCmd = new MenuCommand(StopServiceCallback, stopMenuCmdId)
{
Enabled = false,
Visible = false
};
menuCommandService.AddCommand(_stopMenuCmd);
}
}

public static IntegrationTestServiceCommands Instance { get; private set; }
public static IntegrationTestServiceCommands? Instance { get; private set; }

private IServiceProvider ServiceProvider => _package;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.

#nullable disable

using System;
using System.Runtime.InteropServices;
using System.Threading;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.

#nullable disable

using System;
using System.Composition;
using System.Threading.Tasks;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.

#nullable disable

using System;
using System.Composition;
using Microsoft.CodeAnalysis.Extensions;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,9 @@
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.

#nullable disable

using System;
using System.Collections.Generic;
using System.Diagnostics.CodeAnalysis;
using System.Runtime.InteropServices;
using System.Threading;
using UIAutomationClient;
Expand Down Expand Up @@ -275,10 +274,11 @@ public static IUIAutomationElement FindDescendantByPath(this IUIAutomationElemen
return item;
}

[DoesNotReturn]
private static void ThrowUnableToFindChildException(string path, IUIAutomationElement item)
{
// if not found, build a list of available children for debugging purposes
var validChildren = new List<string>();
var validChildren = new List<string?>();

try
{
Expand All @@ -298,7 +298,7 @@ private static void ThrowUnableToFindChildException(string path, IUIAutomationEl
string.Join(", ", validChildren)));
}

private static string SimpleControlTypeName(IUIAutomationElement element)
private static string? SimpleControlTypeName(IUIAutomationElement element)
{
var type = ControlType.LookupById((int)element.GetCurrentPropertyValue(AutomationElementIdentifiers.ControlTypeProperty.Id));
return type?.LocalizedControlType;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,9 @@
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.

#nullable disable

using System;
using System.Threading.Tasks;
using Roslyn.Utilities;
using UIAutomationClient;
using AutomationElementIdentifiers = System.Windows.Automation.AutomationElementIdentifiers;

Expand All @@ -23,14 +22,14 @@ public static async Task ClickAutomationElementAsync(string elementName, bool re

if (element != null)
{
var tcs = new TaskCompletionSource<object>();
var tcs = new TaskCompletionSource<VoidResult>();

Helper.Automation.AddAutomationEventHandler(
UIA_EventIds.UIA_Invoke_InvokedEventId,
element,
TreeScope.TreeScope_Element,
cacheRequest: null,
new AutomationEventHandler((src, e) => tcs.SetResult(null)));
new AutomationEventHandler((src, e) => tcs.SetResult(default)));

element.Invoke();
await tcs.Task;
Expand All @@ -45,7 +44,7 @@ public static async Task ClickAutomationElementAsync(string elementName, bool re

public static async Task<IUIAutomationElement> FindAutomationElementAsync(string elementName, bool recursive = false)
{
IUIAutomationElement element = null;
IUIAutomationElement? element = null;
var scope = recursive ? TreeScope.TreeScope_Descendants : TreeScope.TreeScope_Children;
var condition = Helper.Automation.CreatePropertyCondition(AutomationElementIdentifiers.NameProperty.Id, elementName);

Expand All @@ -55,6 +54,7 @@ await IntegrationHelper.WaitForResultAsync(
() => (element = Helper.Automation.GetRootElement().FindFirst(scope, condition)) != null, expectedResult: true
).ConfigureAwait(false);

Contract.ThrowIfNull(element);
return element;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.

#nullable disable

using System.Reflection;
using Xunit.Sdk;

Expand All @@ -20,7 +18,7 @@ public class CaptureTestNameAttribute : BeforeAfterTestAttribute
/// The name of the currently running test, or null if no test is running.
/// The format is test_class_name.method_name.
/// </summary>
public static string CurrentName { get; set; }
public static string? CurrentName { get; set; }

public override void Before(MethodInfo methodUnderTest)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,11 @@
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.

#nullable disable

using System;
using System.Runtime.Serialization;

namespace Microsoft.VisualStudio.IntegrationTest.Utilities.Common
{
[System.Serializable]
[Serializable]
public struct ClassifiedToken
{
public ClassifiedToken(string text, string classification)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,20 +2,24 @@
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.

#nullable disable

using System;
using System.Collections.Generic;

namespace Microsoft.VisualStudio.IntegrationTest.Utilities.Common
{
internal static class Comparison
{
public static bool AreStringValuesEqual(string str1, string str2)
public static bool AreStringValuesEqual(string? str1, string? str2)
=> (str1 ?? "") == (str2 ?? "");

public static bool AreArraysEqual<T>(T[] array1, T[] array2) where T : IEquatable<T>
public static bool AreArraysEqual<T>(T[]? array1, T[]? array2) where T : IEquatable<T>
{
if (array1 is null || array2 is null)
{
// both must be null
return array1 == array2;
}

if (array1.Length != array2.Length)
{
return false;
Expand Down
Loading

0 comments on commit dfd5b87

Please sign in to comment.