Skip to content

Commit

Permalink
Merge pull request #862 from nunit/removewarnings
Browse files Browse the repository at this point in the history
Removewarnings
  • Loading branch information
OsirisTerje authored May 27, 2021
2 parents d37f809 + 353a96d commit 1e1feba
Show file tree
Hide file tree
Showing 27 changed files with 112 additions and 123 deletions.
4 changes: 2 additions & 2 deletions src/NUnit.TestAdapter.Tests.Acceptance/AcceptanceTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ public abstract class AcceptanceTests
"netcoreapp3.1"
};

private static readonly Lazy<(IsolatedWorkspaceManager manager, string nupkgVersion, bool keepWorkspaces)> Initialization = new Lazy<(IsolatedWorkspaceManager, string, bool)>(() =>
private static readonly Lazy<(IsolatedWorkspaceManager manager, string nupkgVersion, bool keepWorkspaces)> Initialization = new (() =>
{
var directory = TestContext.Parameters["ProjectWorkspaceDirectory"]
?? TryAutoDetectProjectWorkspaceDirectory()
Expand Down Expand Up @@ -69,7 +69,7 @@ private static void ClearCachedTestNupkgs(string packageCachePath)
Utils.DeleteDirectoryRobust(Path.Combine(packageCachePath, NuGetPackageId));
}

private static readonly Dictionary<string, List<IsolatedWorkspace>> WorkspacesByTestId = new Dictionary<string, List<IsolatedWorkspace>>();
private static readonly Dictionary<string, List<IsolatedWorkspace>> WorkspacesByTestId = new ();

protected static IsolatedWorkspace CreateWorkspace()
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ partial class IsolatedWorkspace
{
private sealed class RunSettings
{
private readonly List<string> arguments = new List<string>();
private readonly List<string> arguments = new ();

public string WorkingDirectory { get; }
public string FileName { get; }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ namespace NUnit.VisualStudio.TestAdapter.Tests.Acceptance.WorkspaceTools
[DebuggerDisplay("{Directory,nq}")]
public sealed partial class IsolatedWorkspace : IDisposable
{
private readonly List<string> projectPaths = new List<string>();
private readonly List<string> projectPaths = new ();
private readonly ToolResolver toolResolver;
private readonly DirectoryMutex directoryMutex;

Expand Down Expand Up @@ -111,6 +111,6 @@ public VSTestResult VSTest(string testAssemblyPath)
return VSTestResult.Load(result, tempTrxFile);
}

private RunSettings ConfigureRun(string filename) => new RunSettings(Directory, filename);
private RunSettings ConfigureRun(string filename) => new (Directory, filename);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ public void Dispose()

public IsolatedWorkspace CreateWorkspace(string name)
{
return new IsolatedWorkspace(
return new (
Utils.CreateMutexDirectory(workspaceDirectory.DirectoryPath, name),
toolResolver);
}
Expand Down
102 changes: 49 additions & 53 deletions src/NUnit.TestAdapter.Tests.Acceptance/WorkspaceTools/ProcessUtils.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ public static ProcessRunResult Run(string workingDirectory, string fileName, IEn

var escapedArguments = arguments is null ? null : EscapeProcessArguments(arguments, alwaysQuote: false);

using (var process = new Process
using var process = new Process
{
StartInfo =
{
Expand All @@ -29,51 +29,49 @@ public static ProcessRunResult Run(string workingDirectory, string fileName, IEn
RedirectStandardOutput = true,
RedirectStandardError = true
}
})
{
// This is inherited if the test runner was started by the Visual Studio process.
// It breaks MSBuild 15’s targets when it tries to build legacy csprojs and vbprojs.
process.StartInfo.EnvironmentVariables.Remove("VisualStudioVersion");
};
// This is inherited if the test runner was started by the Visual Studio process.
// It breaks MSBuild 15’s targets when it tries to build legacy csprojs and vbprojs.
process.StartInfo.EnvironmentVariables.Remove("VisualStudioVersion");

var stdout = (StringBuilder)null;
var stderr = (StringBuilder)null;
var stdout = (StringBuilder)null;
var stderr = (StringBuilder)null;

process.OutputDataReceived += (sender, e) =>
{
if (e.Data is null) return;
process.OutputDataReceived += (sender, e) =>
{
if (e.Data is null) return;
if (stdout is null)
stdout = new StringBuilder();
else
stdout.AppendLine();
if (stdout is null)
stdout = new StringBuilder();
else
stdout.AppendLine();
stdout.Append(e.Data);
};
stdout.Append(e.Data);
};

process.ErrorDataReceived += (sender, e) =>
{
if (e.Data is null) return;
if (stderr is null)
stderr = new StringBuilder();
else
stderr.AppendLine();
stderr.Append(e.Data);
};

process.Start();
process.BeginErrorReadLine();
process.BeginOutputReadLine();
process.WaitForExit();

return new ProcessRunResult(
fileName,
escapedArguments,
process.ExitCode,
stdout?.ToString(),
stderr?.ToString());
}
process.ErrorDataReceived += (sender, e) =>
{
if (e.Data is null) return;
if (stderr is null)
stderr = new StringBuilder();
else
stderr.AppendLine();
stderr.Append(e.Data);
};

process.Start();
process.BeginErrorReadLine();
process.BeginOutputReadLine();
process.WaitForExit();

return new ProcessRunResult(
fileName,
escapedArguments,
process.ExitCode,
stdout?.ToString(),
stderr?.ToString());
}

private static readonly char[] CharsThatRequireQuoting = { ' ', '"' };
Expand All @@ -87,21 +85,19 @@ public static string EscapeProcessArguments(IEnumerable<string> literalValues, b
{
if (literalValues is null) throw new ArgumentNullException(nameof(literalValues));

using (var en = literalValues.GetEnumerator())
{
if (!en.MoveNext()) return string.Empty;
using var en = literalValues.GetEnumerator();
if (!en.MoveNext()) return string.Empty;

var builder = new StringBuilder();
var builder = new StringBuilder();

while (true)
{
EscapeProcessArgument(builder, en.Current, alwaysQuote);
if (!en.MoveNext()) break;
builder.Append(' ');
}

return builder.ToString();
while (true)
{
EscapeProcessArgument(builder, en.Current, alwaysQuote);
if (!en.MoveNext()) break;
builder.Append(' ');
}

return builder.ToString();
}

private static void EscapeProcessArgument(StringBuilder builder, string literalValue, bool alwaysQuote)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,13 @@ public static void EscapeProcessArguments_null_alwaysQuote()
[Test]
public static void EscapeProcessArguments_empty()
{
Assert.That(ProcessUtils.EscapeProcessArguments(new string[] { string.Empty }), Is.EqualTo("\"\""));
Assert.That(ProcessUtils.EscapeProcessArguments(new[] { string.Empty }), Is.EqualTo("\"\""));
}

[Test]
public static void EscapeProcessArguments_empty_alwaysQuote()
{
Assert.That(ProcessUtils.EscapeProcessArguments(new string[] { string.Empty }, true), Is.EqualTo("\"\""));
Assert.That(ProcessUtils.EscapeProcessArguments(new[] { string.Empty }, true), Is.EqualTo("\"\""));
}

[Test]
Expand Down
2 changes: 1 addition & 1 deletion src/NUnitTestAdapter/CategoryList.cs
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ public IEnumerable<string> ProcessTestCaseProperties(INUnitTestCasePropertyInfo
/// <summary>
/// See https://github.com/nunit/nunit/blob/master/src/NUnitFramework/framework/Internal/PropertyNames.cs.
/// </summary>
private readonly HashSet<string> _internalProperties = new HashSet<string>(StringComparer.OrdinalIgnoreCase)
private readonly HashSet<string> _internalProperties = new (StringComparer.OrdinalIgnoreCase)
{ "Author", "ApartmentState", "Description", "IgnoreUntilDate", "LevelOfParallelism", "MaxTime", "Order", "ParallelScope", "Repeat", "RequiresThread", "SetCulture", "SetUICulture", "TestOf", "Timeout" };


Expand Down
2 changes: 1 addition & 1 deletion src/NUnitTestAdapter/Execution.cs
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ public virtual bool Run(TestFilter filter, DiscoveryConverter discovery, NUnit3T
public abstract TestFilter CheckFilterInCurrentMode(TestFilter filter, IDiscoveryConverter discovery);

protected NUnitTestFilterBuilder CreateTestFilterBuilder()
=> new NUnitTestFilterBuilder(NUnitEngineAdapter.GetService<ITestFilterService>(), Settings);
=> new (NUnitEngineAdapter.GetService<ITestFilterService>(), Settings);
protected ITestConverterCommon CreateConverter(DiscoveryConverter discovery) => Settings.DiscoveryMethod == DiscoveryMethod.Current ? discovery.TestConverter : discovery.TestConverterForXml;

protected TestFilter CheckFilter(IDiscoveryConverter discovery)
Expand Down
2 changes: 1 addition & 1 deletion src/NUnitTestAdapter/Metadata/AppDomainMetadataProvider.cs
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ public void Dispose()

private sealed class AppDomainHelper : MarshalByRefObject
{
private readonly DirectReflectionMetadataProvider provider = new DirectReflectionMetadataProvider();
private readonly DirectReflectionMetadataProvider provider = new ();

public TypeInfo? GetDeclaringType(string assemblyPath, string reflectedTypeName, string methodName)
{
Expand Down
2 changes: 1 addition & 1 deletion src/NUnitTestAdapter/NUnit3TestExecutor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -333,7 +333,7 @@ private void RestoreRandomSeed(string assemblyPath)

private NUnitTestFilterBuilder CreateTestFilterBuilder()
{
return new NUnitTestFilterBuilder(NUnitEngineAdapter.GetService<ITestFilterService>(), Settings);
return new (NUnitEngineAdapter.GetService<ITestFilterService>(), Settings);
}


Expand Down
4 changes: 2 additions & 2 deletions src/NUnitTestAdapter/NUnitEngine/DiscoveryConverter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ internal static class NUnitXmlAttributeNames

public bool IsExplicitRun => CurrentTestAssembly?.IsExplicit ?? false;

private readonly List<TestCase> loadedTestCases = new List<TestCase>();
private readonly List<TestCase> loadedTestCases = new ();
public IList<TestCase> LoadedTestCases => loadedTestCases;

public int NoOfLoadedTestCases => loadedTestCases.Count;
Expand Down Expand Up @@ -429,7 +429,7 @@ public BaseProperties(string dId, string dName, string dFullname, int dTestcasec
RunState = dRunstate;
}

public List<NUnitProperty> Properties { get; } = new List<NUnitProperty>();
public List<NUnitProperty> Properties { get; } = new ();

public string Id { get; }
public string Name { get; }
Expand Down
24 changes: 12 additions & 12 deletions src/NUnitTestAdapter/NUnitEngine/NUnitDiscoveryTestClasses.cs
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ protected NUnitDiscoverySuiteBase(BaseProperties other, INUnitDiscoverySuiteBase
Parent = parent;
}

public NUnitDiscoveryProperties NUnitDiscoveryProperties { get; } = new NUnitDiscoveryProperties();
public NUnitDiscoveryProperties NUnitDiscoveryProperties { get; } = new ();

public abstract bool IsExplicit { get; }
public virtual bool IsExplicitReverse => RunState == RunStateEnum.Explicit || (Parent?.IsExplicitReverse ?? RunState == RunStateEnum.Explicit);
Expand Down Expand Up @@ -109,7 +109,7 @@ public void AddTestAssembly(NUnitDiscoveryTestAssembly testAssembly)

public class NUnitDiscoveryProperties
{
private List<NUnitProperty> TheProperties { get; } = new List<NUnitProperty>();
private List<NUnitProperty> TheProperties { get; } = new ();
public IEnumerable<NUnitProperty> Properties => TheProperties;

public void Add(NUnitProperty p) => TheProperties.Add(p);
Expand All @@ -133,7 +133,7 @@ public sealed class NUnitDiscoveryTestAssembly : NUnitDiscoveryTestSuite
public NUnitDiscoveryTestAssembly(BaseProperties theBase, NUnitDiscoveryTestRun parent) : base(theBase, parent)
{ }

private readonly List<NUnitDiscoveryTestCase> allTestCases = new List<NUnitDiscoveryTestCase>();
private readonly List<NUnitDiscoveryTestCase> allTestCases = new ();

/// <summary>
/// If all testcases are Explicit, we can run this one.
Expand All @@ -158,12 +158,12 @@ public override void AddToAllTestCases(NUnitDiscoveryTestCase tc)

public sealed class NUnitDiscoveryTestFixture : NUnitDiscoveryCanHaveTestCases
{
private readonly List<NUnitDiscoveryParameterizedMethod> parameterizedMethods = new List<NUnitDiscoveryParameterizedMethod>();
private readonly List<NUnitDiscoveryParameterizedMethod> parameterizedMethods = new ();
public IEnumerable<NUnitDiscoveryParameterizedMethod> ParameterizedMethods => parameterizedMethods;

private readonly List<NUnitDiscoveryTheory> theories = new List<NUnitDiscoveryTheory>();
private readonly List<NUnitDiscoveryTheory> theories = new ();

private readonly List<NUnitDiscoveryGenericMethod> genericMethods = new List<NUnitDiscoveryGenericMethod>();
private readonly List<NUnitDiscoveryGenericMethod> genericMethods = new ();
public IEnumerable<NUnitDiscoveryTheory> Theories => theories;

public override int NoOfActualTestCases =>
Expand Down Expand Up @@ -266,7 +266,7 @@ public interface INUnitDiscoveryCanHaveTestCases : INUnitDiscoverySuiteBase

public abstract class NUnitDiscoveryCanHaveTestCases : NUnitDiscoverySuiteBase, INUnitDiscoveryCanHaveTestCases
{
private readonly List<NUnitDiscoveryTestCase> testCases = new List<NUnitDiscoveryTestCase>();
private readonly List<NUnitDiscoveryTestCase> testCases = new ();

public IEnumerable<NUnitDiscoveryTestCase> TestCases => testCases;
public virtual int NoOfActualTestCases => testCases.Count;
Expand Down Expand Up @@ -297,7 +297,7 @@ public interface INUnitDiscoveryCanHaveTestFixture : INUnitDiscoverySuiteBase

public abstract class NUnitDiscoveryCanHaveTestFixture : NUnitDiscoverySuiteBase, INUnitDiscoveryCanHaveTestFixture
{
private readonly List<NUnitDiscoveryTestFixture> testFixtures = new List<NUnitDiscoveryTestFixture>();
private readonly List<NUnitDiscoveryTestFixture> testFixtures = new ();

public IEnumerable<NUnitDiscoveryTestFixture> TestFixtures => testFixtures;

Expand All @@ -310,11 +310,11 @@ protected NUnitDiscoveryCanHaveTestFixture(BaseProperties theBase, INUnitDiscove
}


private readonly List<NUnitDiscoveryTestSuite> testSuites = new List<NUnitDiscoveryTestSuite>();
private readonly List<NUnitDiscoveryTestSuite> testSuites = new ();

private readonly List<NUnitDiscoveryGenericFixture> genericFixtures = new List<NUnitDiscoveryGenericFixture>();
private readonly List<NUnitDiscoverySetUpFixture> setUpFixtures = new List<NUnitDiscoverySetUpFixture>();
private readonly List<NUnitDiscoveryParameterizedTestFixture> parameterizedFixtures = new List<NUnitDiscoveryParameterizedTestFixture>();
private readonly List<NUnitDiscoveryGenericFixture> genericFixtures = new ();
private readonly List<NUnitDiscoverySetUpFixture> setUpFixtures = new ();
private readonly List<NUnitDiscoveryParameterizedTestFixture> parameterizedFixtures = new ();


public IEnumerable<NUnitDiscoveryTestSuite> TestSuites => testSuites;
Expand Down
2 changes: 1 addition & 1 deletion src/NUnitTestAdapter/NUnitEventListener.cs
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ public class NUnitEventListener :
private readonly ITestExecutionRecorder _recorder;
private readonly ITestConverterCommon _testConverter;
private readonly IAdapterSettings _settings;
private readonly Dictionary<string, ICollection<INUnitTestEventTestOutput>> _outputNodes = new Dictionary<string, ICollection<INUnitTestEventTestOutput>>();
private readonly Dictionary<string, ICollection<INUnitTestEventTestOutput>> _outputNodes = new ();

#if NET35
public override object InitializeLifetimeService()
Expand Down
2 changes: 1 addition & 1 deletion src/NUnitTestAdapter/NUnitTestFilterBuilder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ public class NUnitTestFilterBuilder
private readonly ITestFilterService _filterService;

// ReSharper disable once StringLiteralTypo
public static readonly TestFilter NoTestsFound = new TestFilter("<notestsfound/>");
public static readonly TestFilter NoTestsFound = new ("<notestsfound/>");
private readonly IAdapterSettings settings;

public NUnitTestFilterBuilder(ITestFilterService filterService, IAdapterSettings settings)
Expand Down
2 changes: 1 addition & 1 deletion src/NUnitTestAdapter/NavigationData.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ namespace NUnit.VisualStudio.TestAdapter
{
public class NavigationData
{
public static readonly NavigationData Invalid = new NavigationData(null, 0);
public static readonly NavigationData Invalid = new (null, 0);

public NavigationData(string filePath, int lineNumber)
{
Expand Down
4 changes: 2 additions & 2 deletions src/NUnitTestAdapter/NavigationDataProvider.cs
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ public sealed class NavigationDataProvider : IDisposable
private readonly string _assemblyPath;
private readonly IMetadataProvider _metadataProvider;
private readonly ITestLogger _logger;
private readonly Dictionary<string, DiaSession> _sessionsByAssemblyPath = new Dictionary<string, DiaSession>(StringComparer.OrdinalIgnoreCase);
private readonly Dictionary<string, DiaSession> _sessionsByAssemblyPath = new (StringComparer.OrdinalIgnoreCase);
private bool _disableMetadataLookup;

public NavigationDataProvider(string assemblyPath, ITestLogger logger)
Expand All @@ -49,7 +49,7 @@ public NavigationDataProvider(string assemblyPath, ITestLogger logger)
#if NET35
internal static AppDomainMetadataProvider CreateMetadataProvider(string assemblyPath)
{
return new AppDomainMetadataProvider(
return new (
applicationBase: Path.GetDirectoryName(assemblyPath),
configurationFile: assemblyPath + ".config");
}
Expand Down
Loading

0 comments on commit 1e1feba

Please sign in to comment.