Skip to content

Commit 41a45a9

Browse files
Merge pull request #1663 from nunit/version4_StyleCopAnalyzer
Add StyleCop.Analyzers
2 parents 924e545 + 7c1f723 commit 41a45a9

File tree

167 files changed

+1979
-1020
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

167 files changed

+1979
-1020
lines changed

.github/workflows/NUnitConsoleAndEngine.CI.yml

+2-1
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,8 @@ jobs:
3838
3.1.x
3939
6.0.x
4040
7.0.x
41-
8.0.100
41+
8.0.x
42+
9.0.x
4243
4344
- name: 🔧 Install dotnet tools
4445
run: dotnet tool restore

.gitignore

+3-3
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,8 @@ ClientBin/
123123
*.pfx
124124
*.publishsettings
125125

126+
!StyleCop.Analyzers.globalconfig
127+
126128
# RIA/Silverlight projects
127129
Generated_Code/
128130

@@ -166,10 +168,8 @@ $RECYCLE.BIN/
166168

167169
.~
168170
*.userprefs
169-
*.StyleCop
170171
*.sdf
171172
GeneratedAssemblyInfo.cs
172-
StyleCop.Cache
173173
local.settings.include
174174
InternalTrace.txt
175175
TestResult.xml
@@ -195,4 +195,4 @@ nunit3-netcore-console
195195
# Docker Mono build packages
196196
# =========================
197197

198-
*.deb
198+
*.deb

NUnitConsole.sln

+1
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution
2929
nunit.ico = nunit.ico
3030
package-tests.cake = package-tests.cake
3131
README.md = README.md
32+
src\StyleCop.Analyzers.globalconfig = src\StyleCop.Analyzers.globalconfig
3233
VERSIONING.md = VERSIONING.md
3334
EndProjectSection
3435
EndProject

global.json

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"sdk": {
33
"version": "9.0.100",
4-
"rollForward": "feature"
4+
"rollForward": "latestFeature"
55
}
6-
}
6+
}

src/Directory.Build.props

+6
Original file line numberDiff line numberDiff line change
@@ -39,4 +39,10 @@
3939
<Copyright>Copyright (c) 2022 Charlie Poole, Rob Prouse</Copyright>
4040
</PropertyGroup>
4141

42+
<!-- Code Style Analyzers -->
43+
<ItemGroup>
44+
<PackageReference Include="StyleCop.Analyzers.Unstable" Version="1.2.0.556" PrivateAssets="all" />
45+
<GlobalAnalyzerConfigFiles Include="$(MSBuildThisFileDirectory)/StyleCop.Analyzers.globalconfig" />
46+
</ItemGroup>
47+
4248
</Project>

src/NUnitCommon/nunit.agent.core.tests/AgentOptionTests.cs

+3-3
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ namespace NUnit.Agents
88
{
99
public class AgentOptionTests
1010
{
11-
static TestCaseData[] DefaultSettings = new[]
11+
private static TestCaseData[] DefaultSettings = new[]
1212
{
1313
new TestCaseData("AgentId", Guid.Empty),
1414
new TestCaseData("AgencyUrl", string.Empty),
@@ -28,8 +28,8 @@ public void DefaultOptionSettings<T>(string propertyName, T defaultValue)
2828
Assert.That(prop.GetValue(options, new object[0]), Is.EqualTo(defaultValue));
2929
}
3030

31-
static readonly Guid AGENT_GUID = Guid.NewGuid();
32-
static readonly TestCaseData[] ValidSettings = new[]
31+
private static readonly Guid AGENT_GUID = Guid.NewGuid();
32+
private static readonly TestCaseData[] ValidSettings = new[]
3333
{
3434
// Boolean options - no values provided
3535
new TestCaseData("--debug-agent", "DebugAgent", true),

src/NUnitCommon/nunit.agent.core.tests/Drivers/DriverServiceTests.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ public void CorrectDriverIsUsed(string fileName, bool skipNonTestAssemblies, Typ
2626
Assert.That(driver, Is.InstanceOf(expectedType));
2727
}
2828

29-
static TestCaseData[] DriverSelectionTestCases = new[]
29+
private static TestCaseData[] DriverSelectionTestCases = new[]
3030
{
3131
new TestCaseData("mock-assembly.dll", false, typeof(NUnitFrameworkDriver)),
3232
new TestCaseData("mock-assembly.dll", true, typeof(NUnitFrameworkDriver)),

src/NUnitCommon/nunit.agent.core.tests/Runners/DomainManagerStaticTests.cs

+5-5
Original file line numberDiff line numberDiff line change
@@ -12,16 +12,16 @@ namespace NUnit.Engine.Runners
1212
{
1313
public static class DomainManagerStaticTests
1414
{
15-
static string path1 = TestPath("/test/bin/debug/test1.dll");
16-
static string path2 = TestPath("/test/bin/debug/test2.dll");
17-
static string path3 = TestPath("/test/utils/test3.dll");
15+
private static string path1 = TestPath("/test/bin/debug/test1.dll");
16+
private static string path2 = TestPath("/test/bin/debug/test2.dll");
17+
private static string path3 = TestPath("/test/utils/test3.dll");
1818

1919
#if NETFRAMEWORK
20-
const string STANDARD_CONFIG_FILE = "nunit.engine.core.tests.exe.config";
20+
private const string STANDARD_CONFIG_FILE = "nunit.engine.core.tests.exe.config";
2121
#else
2222
const string STANDARD_CONFIG_FILE = "nunit.engine.core.tests.dll.config";
2323
#endif
24-
const string ALTERNATE_CONFIG_FILE = "alt.config";
24+
private const string ALTERNATE_CONFIG_FILE = "alt.config";
2525

2626
[Test]
2727
public static void GetPrivateBinPath()

src/NUnitCommon/nunit.agent.core.tests/Runners/TestAgentRunnerTests.cs

+3-2
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,8 @@ namespace NUnit.Engine.Runners
1616
#if NETFRAMEWORK
1717
[TestFixture(typeof(TestDomainRunner))]
1818
#endif
19-
public class TestAgentRunnerTests<TRunner> where TRunner : TestAgentRunner
19+
public class TestAgentRunnerTests<TRunner>
20+
where TRunner : TestAgentRunner
2021
{
2122
protected TestPackage _package;
2223
protected TRunner _runner;
@@ -37,7 +38,7 @@ public void Cleanup()
3738
if (_runner != null)
3839
_runner.Dispose();
3940
}
40-
41+
4142
[Test]
4243
public void Load()
4344
{

src/NUnitCommon/nunit.agent.core/AgentOptions.cs

+3-3
Original file line numberDiff line numberDiff line change
@@ -8,16 +8,16 @@
88
namespace NUnit.Agents
99
{
1010
/// <summary>
11-
/// All agents, either built-in or pluggable, must be able to
11+
/// All agents, either built-in or pluggable, must be able to
1212
/// handle the options defined in this class. In some cases,
1313
/// it may be permissible to ignore them but they should never
1414
/// give rise to an error.
1515
/// </summary>
1616
public class AgentOptions
1717
{
18-
static readonly char[] DELIMS = new[] { '=', ':' };
18+
private static readonly char[] DELIMS = new[] { '=', ':' };
1919
// Dictionary containing valid options with bool value true if a value is required.
20-
static readonly Dictionary<string, bool> VALID_OPTIONS = new Dictionary<string, bool>();
20+
private static readonly Dictionary<string, bool> VALID_OPTIONS = new Dictionary<string, bool>();
2121

2222
static AgentOptions()
2323
{

src/NUnitCommon/nunit.agent.core/Agents/RemoteTestAgent.cs

+3-1
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,9 @@ public class RemoteTestAgent : TestAgent
2222
/// The first argument is a temporary measure and will be removed
2323
/// once services are all moved from nunit.engine.core to nunit.engine.
2424
/// </remarks>
25-
public RemoteTestAgent(Guid agentId) : base(agentId) { }
25+
public RemoteTestAgent(Guid agentId) : base(agentId)
26+
{
27+
}
2628

2729
public ITestAgentTransport? Transport;
2830

src/NUnitCommon/nunit.agent.core/Communication/Transports/Remoting/TestAgentRemotingTransport.cs

-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@
99

1010
namespace NUnit.Engine.Communication.Transports.Remoting
1111
{
12-
1312
/// <summary>
1413
/// TestAgentRemotingTransport uses remoting to support
1514
/// a TestAgent in communicating with a TestAgency and

src/NUnitCommon/nunit.agent.core/Drivers/DriverService.cs

+4-4
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,9 @@ namespace NUnit.Engine.Drivers
1515
/// </summary>
1616
public class DriverService : IDriverService
1717
{
18-
static readonly Logger log = InternalTrace.GetLogger("DriverService");
18+
private static readonly Logger log = InternalTrace.GetLogger("DriverService");
1919

20-
readonly IList<IDriverFactory> _factories = new List<IDriverFactory>();
20+
private readonly IList<IDriverFactory> _factories = new List<IDriverFactory>();
2121

2222
public DriverService()
2323
{
@@ -69,7 +69,7 @@ public IFrameworkDriver GetDriver(AppDomain domain, TestPackage package, string
6969
if (skipNonTestAssemblies)
7070
return new SkippedAssemblyFrameworkDriver(assemblyPath, package.ID);
7171
else
72-
return new InvalidAssemblyFrameworkDriver(assemblyPath, package.ID, platform +
72+
return new InvalidAssemblyFrameworkDriver(assemblyPath, package.ID, platform +
7373
" test assemblies are not supported by this version of the engine");
7474
}
7575

@@ -111,7 +111,7 @@ public IFrameworkDriver GetDriver(AppDomain domain, TestPackage package, string
111111
if (skipNonTestAssemblies)
112112
return new SkippedAssemblyFrameworkDriver(assemblyPath, package.ID);
113113
else
114-
return new InvalidAssemblyFrameworkDriver(assemblyPath, package.ID,
114+
return new InvalidAssemblyFrameworkDriver(assemblyPath, package.ID,
115115
$"No suitable tests found in '{assemblyPath}'.\r\nEither assembly contains no tests or proper test driver has not been found.");
116116
}
117117
}

src/NUnitCommon/nunit.agent.core/Drivers/NUnit2DriverFactory.cs

+7-7
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ public class NUnit2DriverFactory : IDriverFactory
1616

1717
// TODO: This should be a central service but for now it's local
1818
private readonly ProvidedPathsAssemblyResolver _resolver;
19-
bool _resolverInstalled;
19+
private bool _resolverInstalled;
2020

2121
public NUnit2DriverFactory(IExtensionNode driverNode)
2222
{
@@ -55,13 +55,13 @@ public IFrameworkDriver GetDriver(AppDomain domain, string id, AssemblyName refe
5555
}
5656

5757
return (IFrameworkDriver)AppDomain.CurrentDomain.CreateInstanceFromAndUnwrap(
58-
_driverNode.AssemblyPath,
58+
_driverNode.AssemblyPath,
5959
_driverNode.TypeName,
60-
false,
61-
0,
62-
null,
63-
new object[] { domain, id, reference },
64-
null,
60+
false,
61+
0,
62+
null,
63+
new object[] { domain, id, reference },
64+
null,
6565
null).ShouldNotBeNull();
6666
}
6767
}

src/NUnitCommon/nunit.agent.core/Drivers/NUnit3DriverFactory.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ namespace NUnit.Engine.Drivers
99
public class NUnit3DriverFactory : IDriverFactory
1010
{
1111
internal const string NUNIT_FRAMEWORK = "nunit.framework";
12-
static readonly Logger log = InternalTrace.GetLogger(typeof(NUnit3DriverFactory));
12+
private static readonly Logger log = InternalTrace.GetLogger(typeof(NUnit3DriverFactory));
1313

1414
/// <summary>
1515
/// Gets a flag indicating whether a given assembly name and version

src/NUnitCommon/nunit.agent.core/Drivers/NUnitFrameworkApi2009.cs

+13-13
Original file line numberDiff line numberDiff line change
@@ -14,24 +14,24 @@ namespace NUnit.Engine.Drivers
1414
/// As far as I can discover, it first appeared in pre-release 2.9.1,
1515
/// on launchpad in 2009, hence the name.
1616
/// </summary>
17-
class NUnitFrameworkApi2009 : NUnitFrameworkApi
17+
internal class NUnitFrameworkApi2009 : NUnitFrameworkApi
1818
{
19-
static readonly Logger log = InternalTrace.GetLogger(nameof(NUnitFrameworkApi2009));
19+
private static readonly Logger log = InternalTrace.GetLogger(nameof(NUnitFrameworkApi2009));
2020

21-
const string LOAD_MESSAGE = "Method called without calling Load first. Possible error in runner.";
22-
const string INVALID_FRAMEWORK_MESSAGE = "Running tests against this version of the framework using this driver is not supported. Please update NUnit.Framework to the latest version.";
23-
const string FAILED_TO_LOAD_ASSEMBLY = "Failed to load assembly ";
24-
const string FAILED_TO_LOAD_NUNIT = "Failed to load the NUnit Framework in the test assembly";
21+
private const string LOAD_MESSAGE = "Method called without calling Load first. Possible error in runner.";
22+
private const string INVALID_FRAMEWORK_MESSAGE = "Running tests against this version of the framework using this driver is not supported. Please update NUnit.Framework to the latest version.";
23+
private const string FAILED_TO_LOAD_ASSEMBLY = "Failed to load assembly ";
24+
private const string FAILED_TO_LOAD_NUNIT = "Failed to load the NUnit Framework in the test assembly";
2525

26-
const string CONTROLLER_TYPE = "NUnit.Framework.Api.FrameworkController";
26+
private const string CONTROLLER_TYPE = "NUnit.Framework.Api.FrameworkController";
2727

2828
private readonly string _driverId;
2929

3030
private readonly AppDomain _testDomain;
3131
private readonly AssemblyName _nunitRef;
3232

3333
private string? _testAssemblyPath;
34-
34+
3535
private object? _frameworkController;
3636
private Type? _frameworkControllerType;
3737

@@ -118,7 +118,7 @@ private void CheckLoadWasCalled()
118118
}
119119

120120
// Actions with no extra arguments beyond controller and handler
121-
const string LOAD_ACTION = CONTROLLER_TYPE + "+LoadTestsAction";
121+
private const string LOAD_ACTION = CONTROLLER_TYPE + "+LoadTestsAction";
122122
private string ExecuteAction(string action)
123123
{
124124
CallbackHandler handler = new CallbackHandler();
@@ -127,9 +127,9 @@ private string ExecuteAction(string action)
127127
}
128128

129129
// Actions with one extra argument
130-
const string EXPLORE_ACTION = CONTROLLER_TYPE + "+ExploreTestsAction";
131-
const string COUNT_ACTION = CONTROLLER_TYPE + "+CountTestsAction";
132-
const string STOP_RUN_ACTION = CONTROLLER_TYPE + "+StopRunAction";
130+
private const string EXPLORE_ACTION = CONTROLLER_TYPE + "+ExploreTestsAction";
131+
private const string COUNT_ACTION = CONTROLLER_TYPE + "+CountTestsAction";
132+
private const string STOP_RUN_ACTION = CONTROLLER_TYPE + "+StopRunAction";
133133
private string ExecuteAction(string action, object arg1)
134134
{
135135
CallbackHandler handler = new CallbackHandler();
@@ -138,7 +138,7 @@ private string ExecuteAction(string action, object arg1)
138138
}
139139

140140
// Run action has two extra arguments and uses a special handler
141-
const string RUN_ACTION = CONTROLLER_TYPE + "+RunTestsAction";
141+
private const string RUN_ACTION = CONTROLLER_TYPE + "+RunTestsAction";
142142
private string ExecuteAction(string action, ITestEventListener? listener, string filter)
143143
{
144144
RunTestsCallbackHandler handler = new RunTestsCallbackHandler(listener);

src/NUnitCommon/nunit.agent.core/Drivers/NUnitFrameworkApi2018.cs

+6-6
Original file line numberDiff line numberDiff line change
@@ -23,14 +23,14 @@ public class NUnitFrameworkApi2018 : MarshalByRefObject, NUnitFrameworkApi
2323
public class NUnitFrameworkApi2018 : NUnitFrameworkApi
2424
#endif
2525
{
26-
static readonly Logger log = InternalTrace.GetLogger(nameof(NUnitFrameworkApi2018));
26+
private static readonly Logger log = InternalTrace.GetLogger(nameof(NUnitFrameworkApi2018));
2727

28-
const string LOAD_MESSAGE = "Method called without calling Load first. Possible error in runner.";
29-
const string INVALID_FRAMEWORK_MESSAGE = "Running tests against this version of the framework using this driver is not supported. Please update NUnit.Framework to the latest version.";
30-
const string FAILED_TO_LOAD_ASSEMBLY = "Failed to load assembly ";
31-
const string FAILED_TO_LOAD_NUNIT = "Failed to load the NUnit Framework in the test assembly";
28+
private const string LOAD_MESSAGE = "Method called without calling Load first. Possible error in runner.";
29+
private const string INVALID_FRAMEWORK_MESSAGE = "Running tests against this version of the framework using this driver is not supported. Please update NUnit.Framework to the latest version.";
30+
private const string FAILED_TO_LOAD_ASSEMBLY = "Failed to load assembly ";
31+
private const string FAILED_TO_LOAD_NUNIT = "Failed to load the NUnit Framework in the test assembly";
3232

33-
const string CONTROLLER_TYPE = "NUnit.Framework.Api.FrameworkController";
33+
private const string CONTROLLER_TYPE = "NUnit.Framework.Api.FrameworkController";
3434

3535
private readonly string _driverId;
3636

src/NUnitCommon/nunit.agent.core/Drivers/NUnitFrameworkDriver.cs

+11-11
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,10 @@ namespace NUnit.Engine.Drivers
1414
/// </summary>
1515
public class NUnitFrameworkDriver : IFrameworkDriver
1616
{
17-
static readonly Version MINIMUM_NUNIT_VERSION = new(3, 2, 0);
18-
static readonly Logger log = InternalTrace.GetLogger(nameof(NUnitFrameworkDriver));
17+
private static readonly Version MINIMUM_NUNIT_VERSION = new(3, 2, 0);
18+
private static readonly Logger log = InternalTrace.GetLogger(nameof(NUnitFrameworkDriver));
1919

20-
readonly NUnitFrameworkApi _api;
20+
private readonly NUnitFrameworkApi _api;
2121

2222
#if NETFRAMEWORK
2323
/// <summary>
@@ -164,17 +164,17 @@ public string Run(ITestEventListener? listener, string filter)
164164
/// <remarks>
165165
/// This class is absolutely needed when the 2018 NUnit API is used under
166166
/// the .NET Framework using Windows Remoting as a communication protocol.
167-
/// In particular, the MarshalByRef object implementing the listener must
167+
/// In particular, the MarshalByRef object implementing the listener must
168168
/// be convertible to ITestEventListener via the IConvertible interface.
169-
///
169+
///
170170
/// In other cases, the interceptor is not essential, but we use it anyway
171171
/// for several reasons:
172-
///
172+
///
173173
/// 1. We have no control over the implementation of runners using the engine.
174-
/// They may not implement IConvertible and may not even derive from
174+
/// They may not implement IConvertible and may not even derive from
175175
/// MarshaByRefObject.
176-
///
177-
/// 2. The interceptor provides a point of control for checking what events
176+
///
177+
/// 2. The interceptor provides a point of control for checking what events
178178
/// are received from the framework and for possible future modifications to
179179
/// the events before they are forwarded.
180180
/// </remarks>
@@ -215,9 +215,9 @@ object IConvertible.ToType(Type conversionType, IFormatProvider? provider) =>
215215
DateTime IConvertible.ToDateTime(IFormatProvider? provider) => InvalidCast<DateTime>();
216216
string IConvertible.ToString(IFormatProvider? provider) => InvalidCast<string>();
217217

218-
static T InvalidCast<T>() => (T)InvalidCast(typeof(T));
218+
private static T InvalidCast<T>() => (T)InvalidCast(typeof(T));
219219

220-
static object InvalidCast(Type type) =>
220+
private static object InvalidCast(Type type) =>
221221
throw new InvalidCastException($"{nameof(EventInterceptor)} is not convertible to {nameof(type)}");
222222

223223
#endregion

0 commit comments

Comments
 (0)