Skip to content

Commit

Permalink
Move off validate arg from VSTest ObjectModel (#4019)
Browse files Browse the repository at this point in the history
Co-authored-by: Amaury Levé <amauryleve@microsoft.com>
  • Loading branch information
SimonCropp and Evangelink authored Nov 8, 2024
1 parent ac9cc4c commit b17ba16
Show file tree
Hide file tree
Showing 16 changed files with 29 additions and 35 deletions.
2 changes: 1 addition & 1 deletion Directory.Packages.props
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@
<PackageVersion Include="Microsoft.TestPlatform.ObjectModel" Version="$(MicrosoftNETTestSdkVersion)" />
<PackageVersion Include="Microsoft.TestPlatform.TranslationLayer" Version="$(MicrosoftNETTestSdkVersion)" />
<PackageVersion Include="Microsoft.WindowsAppSDK" Version="1.0.0" />
<PackageVersion Include="Polyfill" Version="6.9.0" />
<PackageVersion Include="Polyfill" Version="7.4.0" />
<!-- CVE-2019-0820 -->
<PackageVersion Include="System.Diagnostics.TextWriterTraceListener" Version="4.3.0" />
<!-- CVE-2019-0981, CVE-2019-0980, CVE-2019-0657 -->
Expand Down
1 change: 0 additions & 1 deletion src/Adapter/MSTest.TestAdapter/MSTest.TestAdapter.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,6 @@

<ItemGroup>
<PackageReference Include="Microsoft.TestPlatform.AdapterUtilities" />
<PackageReference Include="Microsoft.TestPlatform.ObjectModel" />
</ItemGroup>

<ItemGroup>
Expand Down
3 changes: 1 addition & 2 deletions src/Adapter/MSTest.TestAdapter/MSTestSettings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
using Microsoft.Testing.Platform.Configurations;
using Microsoft.VisualStudio.TestPlatform.MSTest.TestAdapter.ObjectModel;
using Microsoft.VisualStudio.TestPlatform.MSTestAdapter.PlatformServices;
using Microsoft.VisualStudio.TestPlatform.ObjectModel;
using Microsoft.VisualStudio.TestPlatform.ObjectModel.Adapter;
using Microsoft.VisualStudio.TestPlatform.ObjectModel.Logging;
using Microsoft.VisualStudio.TestPlatform.ObjectModel.Utilities;
Expand Down Expand Up @@ -401,7 +400,7 @@ internal static void Reset()
/// <returns>An instance of the <see cref="MSTestSettings"/> class.</returns>
private static MSTestSettings ToSettings(XmlReader reader, IMessageLogger? logger)
{
ValidateArg.NotNull(reader, "reader");
Guard.NotNull(reader);

// Expected format of the xml is: -
//
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,9 @@ public class MSTestDiscoverer : ITestDiscoverer

internal static void DiscoverTests(IEnumerable<string> sources, IDiscoveryContext discoveryContext, IMessageLogger logger, ITestCaseDiscoverySink discoverySink, IConfiguration? configuration)
{
ValidateArg.NotNull(sources, "sources");
ValidateArg.NotNull(logger, "logger");
ValidateArg.NotNull(discoverySink, "discoverySink");
Guard.NotNull(sources);
Guard.NotNull(logger);
Guard.NotNull(discoverySink);

if (MSTestDiscovererHelpers.InitializeDiscovery(sources, discoveryContext, logger, configuration))
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,8 @@ internal MSTestExecutor(CancellationToken cancellationToken)
internal void RunTests(IEnumerable<TestCase>? tests, IRunContext? runContext, IFrameworkHandle? frameworkHandle, IConfiguration? configuration)
{
PlatformServiceProvider.Instance.AdapterTraceLogger.LogInfo("MSTestExecutor.RunTests: Running tests from testcases.");
ValidateArg.NotNull(frameworkHandle, "frameworkHandle");
ValidateArg.NotNullOrEmpty(tests, "tests");
Guard.NotNull(frameworkHandle);
Guard.NotNullOrEmpty(tests);

if (!MSTestDiscovererHelpers.InitializeDiscovery(from test in tests select test.Source, runContext, frameworkHandle, configuration))
{
Expand All @@ -65,8 +65,8 @@ internal void RunTests(IEnumerable<TestCase>? tests, IRunContext? runContext, IF
internal void RunTests(IEnumerable<string>? sources, IRunContext? runContext, IFrameworkHandle? frameworkHandle, IConfiguration? configuration)
{
PlatformServiceProvider.Instance.AdapterTraceLogger.LogInfo("MSTestExecutor.RunTests: Running tests from sources.");
ValidateArg.NotNull(frameworkHandle, "frameworkHandle");
ValidateArg.NotNullOrEmpty(sources, "sources");
Guard.NotNull(frameworkHandle);
Guard.NotNullOrEmpty(sources);
if (!MSTestDiscovererHelpers.InitializeDiscovery(sources, runContext, frameworkHandle, configuration))
{
return;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@
</ItemGroup>

<ItemGroup>
<PackageReference Include="Microsoft.TestPlatform.ObjectModel" />
<PackageReference Include="System.Diagnostics.TextWriterTraceListener" Condition=" '$(TargetFramework)' == '$(WinUiMinimum)' " />
</ItemGroup>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ public MSTestAdapterSettings()
/// <returns>An instance of the <see cref="MSTestAdapterSettings"/> class.</returns>
public static MSTestAdapterSettings ToSettings(XmlReader reader)
{
ValidateArg.NotNull(reader, "reader");
Guard.NotNull(reader);

// Expected format of the xml is: -
//
Expand Down Expand Up @@ -317,7 +317,7 @@ public List<RecursiveDirectoryPath> GetDirectoryListWithRecursiveProperty(string

private void ReadAssemblyResolutionPath(XmlReader reader)
{
ValidateArg.NotNull(reader, "reader");
Guard.NotNull(reader);

// Expected format of the xml is: -
//
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,6 @@

using Microsoft.Testing.Platform.Configurations;
using Microsoft.VisualStudio.TestPlatform.MSTestAdapter.PlatformServices.Interface;
#if !WINDOWS_UWP
using Microsoft.VisualStudio.TestPlatform.ObjectModel;
#endif

namespace Microsoft.VisualStudio.TestPlatform.MSTestAdapter.PlatformServices;

Expand Down Expand Up @@ -57,7 +54,7 @@ internal static void Load(IConfiguration configuration)
public void Load(XmlReader reader)
{
#if !WINDOWS_UWP
ValidateArg.NotNull(reader, "reader");
Guard.NotNull(reader);
s_settings = MSTestAdapterSettings.ToSettings(reader);
#endif
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ protected IEnumerable<string> Deploy(IList<DeploymentItem> deploymentItems, stri
// Copy the deployment items. (As deployment item can correspond to directories as well, so each deployment item may map to n files)
foreach (DeploymentItem deploymentItem in deploymentItems)
{
ValidateArg.NotNull(deploymentItem, "deploymentItem should not be null.");
Guard.NotNull(deploymentItem);

// Validate the output directory.
if (!IsOutputDirectoryValid(deploymentItem, deploymentDirectory, warnings))
Expand Down Expand Up @@ -399,7 +399,7 @@ private static void LogWarnings(ITestExecutionRecorder testExecutionRecorder, IE

private bool Deploy(string source, IRunContext? runContext, ITestExecutionRecorder testExecutionRecorder, IList<DeploymentItem> deploymentItems, TestRunDirectories runDirectories)
{
ValidateArg.NotNull(runDirectories, "runDirectories");
Guard.NotNull(runDirectories);
if (EqtTrace.IsInfoEnabled)
{
EqtTrace.Info("MSTestExecutor: Found that deployment items for source {0} are: ", source);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ internal Condition(string name, Operation operation, string value)
/// </summary>
internal bool Evaluate(Func<string, object?> propertyValueProvider)
{
ValidateArg.NotNull(propertyValueProvider, nameof(propertyValueProvider));
Guard.NotNull(propertyValueProvider);
bool result = false;
string[]? multiValue = GetPropertyValue(propertyValueProvider);
switch (Operation)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
using System.Text.RegularExpressions;

using Microsoft.Testing.Platform;
using Microsoft.VisualStudio.TestPlatform.ObjectModel;

namespace Microsoft.Testing.Extensions.VSTestBridge.ObjectModel;

Expand All @@ -17,7 +16,7 @@ internal sealed class FastFilter
{
internal FastFilter(ImmutableDictionary<string, ISet<string>> filterProperties, Operation filterOperation, Operator filterOperator)
{
ValidateArg.NotNullOrEmpty(filterProperties, nameof(filterProperties));
Guard.NotNullOrEmpty(filterProperties);

FilterProperties = filterProperties;

Expand Down Expand Up @@ -45,7 +44,7 @@ internal FastFilter(ImmutableDictionary<string, ISet<string>> filterProperties,

internal bool Evaluate(Func<string, object?> propertyValueProvider)
{
ValidateArg.NotNull(propertyValueProvider, nameof(propertyValueProvider));
Guard.NotNull(propertyValueProvider);

bool matched = false;
foreach (string name in FilterProperties.Keys)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@ private static void ProcessOperator(Stack<FilterExpression> filterStack, Operato
/// </summary>
internal static FilterExpression Parse(string filterString, out FastFilter? fastFilter)
{
ValidateArg.NotNull(filterString, nameof(filterString));
Guard.NotNull(filterString);

// Below parsing doesn't error out on pattern (), so explicitly search for that (empty parenthesis).
Match invalidInput = GetEmptyParenthesisPattern().Match(filterString);
Expand Down Expand Up @@ -318,7 +318,7 @@ private T IterateFilterExpression<T>(Func<FilterExpression, Stack<T>, T> getNode
/// <returns> True if evaluation is successful. </returns>
internal bool Evaluate(Func<string, object?> propertyValueProvider)
{
ValidateArg.NotNull(propertyValueProvider, nameof(propertyValueProvider));
Guard.NotNull(propertyValueProvider);

return IterateFilterExpression<bool>((current, result) =>
{
Expand All @@ -341,7 +341,7 @@ internal bool Evaluate(Func<string, object?> propertyValueProvider)

internal static IEnumerable<string> TokenizeFilterExpressionString(string str)
{
ValidateArg.NotNull(str, nameof(str));
Guard.NotNull(str);
return TokenizeFilterExpressionStringHelper(str);

static IEnumerable<string> TokenizeFilterExpressionStringHelper(string s)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ internal class FilterExpressionWrapper
/// </summary>
public FilterExpressionWrapper(string filterString, FilterOptions? options)
{
ValidateArg.NotNullOrEmpty(filterString, nameof(filterString));
Guard.NotNullOrEmpty(filterString);

FilterString = filterString;
FilterOptions = options;
Expand Down Expand Up @@ -112,7 +112,7 @@ public FilterExpressionWrapper(string filterString)
/// </summary>
public bool Evaluate(Func<string, object?> propertyValueProvider)
{
ValidateArg.NotNull(propertyValueProvider, nameof(propertyValueProvider));
Guard.NotNull(propertyValueProvider);

return UseFastFilter
? _fastFilter.Evaluate(propertyValueProvider)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,8 +56,8 @@ public TestCaseFilterExpression(FilterExpressionWrapper filterWrapper)
/// </summary>
public bool MatchTestCase(TestCase testCase, Func<string, object?> propertyValueProvider)
{
ValidateArg.NotNull(testCase, nameof(testCase));
ValidateArg.NotNull(propertyValueProvider, nameof(propertyValueProvider));
Guard.NotNull(testCase);
Guard.NotNull(propertyValueProvider);

return _validForMatch && _filterWrapper.Evaluate(propertyValueProvider);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@

<ItemGroup>
<PackageReference Include="FluentAssertions" />
<PackageReference Include="Polyfill" PrivateAssets="all" />
</ItemGroup>

<ItemGroup>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ internal static class TestCaseFilterFactory

public static ITestCaseFilterExpression ParseTestFilter(string filterString)
{
ValidateArg.NotNullOrEmpty(filterString, nameof(filterString));
Guard.NotNullOrEmpty(filterString);
if (Regex.IsMatch(filterString, @"\(\s*\)"))
{
throw new FormatException($"Invalid filter, empty parenthesis: {filterString}");
Expand Down Expand Up @@ -119,7 +119,7 @@ public TestFilterExpression(string filter, Func<Func<string, object>, bool> expr

private static void MergeExpression(Stack<Expression<Func<Func<string, object>, bool>>> exp, Operator op)
{
ValidateArg.NotNull(exp, nameof(exp));
Guard.NotNull(exp);
if (op is not Operator.And and not Operator.Or)
{
throw new ArgumentException($"Unexpected operator: {op}", nameof(op));
Expand Down Expand Up @@ -190,7 +190,7 @@ private static IEnumerable<string> TokenizeFilter(string filterString)

private static IEnumerable<string> TokenizeCondition(string conditionString)
{
ValidateArg.NotNullOrEmpty(conditionString, nameof(conditionString));
Guard.NotNullOrEmpty(conditionString);
var token = new StringBuilder(conditionString.Length);

for (int i = 0; i < conditionString.Length; i++)
Expand Down Expand Up @@ -286,7 +286,7 @@ private static bool ContainsComparer(string[] values, string value)

private static Expression<Func<Func<string, object>, bool>> ConditionExpression(string conditionString)
{
ValidateArg.NotNull(conditionString, nameof(conditionString));
Guard.NotNull(conditionString);

string[] condition = TokenizeCondition(conditionString).ToArray();

Expand Down

0 comments on commit b17ba16

Please sign in to comment.