Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/mono/linker.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSven Boemer <sbomer@gmail.com>2020-02-19 20:48:27 +0300
committerGitHub <noreply@github.com>2020-02-19 20:48:27 +0300
commit312f184c7da4728c447524be56307e58eb5d293e (patch)
treeca11b655f6258af5582ae644f05111aab32df5bd /test/Mono.Linker.Tests
parent72551f41d5925198262c1f3c2d06dfecd2596a4e (diff)
Code fixes (#955)
* Apply some code fixes * Apply code fixes for linker project * Apply code fixes to more projects * Apply more code fixes * Cleanup * Add missing LangVersion * Undo changes to shared file * Undo using changes
Diffstat (limited to 'test/Mono.Linker.Tests')
-rw-r--r--test/Mono.Linker.Tests/Extensions/NiceIO.cs19
-rw-r--r--test/Mono.Linker.Tests/Mono.Linker.Tests.csproj1
-rw-r--r--test/Mono.Linker.Tests/TestCases/IndividualTests.cs6
-rw-r--r--test/Mono.Linker.Tests/TestCases/TestDatabase.cs4
-rw-r--r--test/Mono.Linker.Tests/TestCasesRunner/AssemblyChecker.cs9
-rw-r--r--test/Mono.Linker.Tests/TestCasesRunner/LinkerDriver.cs2
-rw-r--r--test/Mono.Linker.Tests/TestCasesRunner/PeVerifier.cs7
-rw-r--r--test/Mono.Linker.Tests/TestCasesRunner/ResultChecker.cs12
-rw-r--r--test/Mono.Linker.Tests/TestCasesRunner/TestCaseCollector.cs9
-rw-r--r--test/Mono.Linker.Tests/TestCasesRunner/TestCaseMetadaProvider.cs3
-rw-r--r--test/Mono.Linker.Tests/TestCasesRunner/TestRunner.cs3
-rw-r--r--test/Mono.Linker.Tests/Tests/TypeNameParserTests.cs2
12 files changed, 29 insertions, 48 deletions
diff --git a/test/Mono.Linker.Tests/Extensions/NiceIO.cs b/test/Mono.Linker.Tests/Extensions/NiceIO.cs
index 69b6f30f4..32cf6c7e7 100644
--- a/test/Mono.Linker.Tests/Extensions/NiceIO.cs
+++ b/test/Mono.Linker.Tests/Extensions/NiceIO.cs
@@ -316,15 +316,11 @@ namespace Mono.Linker.Tests.Extensions
static char Slash(SlashMode slashMode)
{
- switch (slashMode)
- {
- case SlashMode.Backward:
- return '\\';
- case SlashMode.Forward:
- return '/';
- default:
- return Path.DirectorySeparatorChar;
- }
+ return slashMode switch {
+ SlashMode.Backward => '\\',
+ SlashMode.Forward => '/',
+ _ => Path.DirectorySeparatorChar,
+ };
}
public override bool Equals(Object obj)
@@ -333,8 +329,7 @@ namespace Mono.Linker.Tests.Extensions
return false;
// If parameter cannot be cast to Point return false.
- var p = obj as NPath;
- if ((Object)p == null)
+ if (!(obj is NPath p))
return false;
return Equals(p);
@@ -365,7 +360,7 @@ namespace Mono.Linker.Tests.Extensions
return true;
// If one is null, but not both, return false.
- if (((object)a == null) || ((object)b == null))
+ if ((a is null) || (b is null))
return false;
// Return true if the fields match:
diff --git a/test/Mono.Linker.Tests/Mono.Linker.Tests.csproj b/test/Mono.Linker.Tests/Mono.Linker.Tests.csproj
index 236ff33ab..794710197 100644
--- a/test/Mono.Linker.Tests/Mono.Linker.Tests.csproj
+++ b/test/Mono.Linker.Tests/Mono.Linker.Tests.csproj
@@ -3,6 +3,7 @@
<PropertyGroup>
<Configurations>Debug;Release</Configurations>
+ <LangVersion>latest</LangVersion>
</PropertyGroup>
<PropertyGroup Condition="'$(MonoBuild)' == ''">
diff --git a/test/Mono.Linker.Tests/TestCases/IndividualTests.cs b/test/Mono.Linker.Tests/TestCases/IndividualTests.cs
index 6a7ae9c56..439caf37e 100644
--- a/test/Mono.Linker.Tests/TestCases/IndividualTests.cs
+++ b/test/Mono.Linker.Tests/TestCases/IndividualTests.cs
@@ -151,8 +151,7 @@ namespace Mono.Linker.Tests.TestCases
protected Guid GetMvid (NPath assemblyPath)
{
- using (var assembly = AssemblyDefinition.ReadAssembly (assemblyPath))
- {
+ using (var assembly = AssemblyDefinition.ReadAssembly (assemblyPath)) {
return assembly.MainModule.Mvid;
}
}
@@ -164,8 +163,7 @@ namespace Mono.Linker.Tests.TestCases
protected LinkedTestCaseResult Run (TestCase testCase)
{
- TestRunner runner;
- return Run (testCase, out runner);
+ return Run (testCase, out _);
}
protected virtual LinkedTestCaseResult Run (TestCase testCase, out TestRunner runner)
diff --git a/test/Mono.Linker.Tests/TestCases/TestDatabase.cs b/test/Mono.Linker.Tests/TestCases/TestDatabase.cs
index fbb516153..41f37400a 100644
--- a/test/Mono.Linker.Tests/TestCases/TestDatabase.cs
+++ b/test/Mono.Linker.Tests/TestCases/TestDatabase.cs
@@ -158,9 +158,7 @@ namespace Mono.Linker.Tests.TestCases
public static TestCaseCollector CreateCollector ()
{
- string rootSourceDirectory;
- string testCaseAssemblyPath;
- GetDirectoryPaths (out rootSourceDirectory, out testCaseAssemblyPath);
+ GetDirectoryPaths (out string rootSourceDirectory, out string testCaseAssemblyPath);
return new TestCaseCollector (rootSourceDirectory, testCaseAssemblyPath);
}
diff --git a/test/Mono.Linker.Tests/TestCasesRunner/AssemblyChecker.cs b/test/Mono.Linker.Tests/TestCasesRunner/AssemblyChecker.cs
index 16f4a1d1d..887456b87 100644
--- a/test/Mono.Linker.Tests/TestCasesRunner/AssemblyChecker.cs
+++ b/test/Mono.Linker.Tests/TestCasesRunner/AssemblyChecker.cs
@@ -13,9 +13,9 @@ namespace Mono.Linker.Tests.TestCasesRunner {
readonly AssemblyDefinition originalAssembly, linkedAssembly;
HashSet<string> linkedMembers;
- HashSet<string> verifiedGeneratedFields = new HashSet<string> ();
- HashSet<string> verifiedEventMethods = new HashSet<string>();
- HashSet<string> verifiedGeneratedTypes = new HashSet<string> ();
+ readonly HashSet<string> verifiedGeneratedFields = new HashSet<string> ();
+ readonly HashSet<string> verifiedEventMethods = new HashSet<string>();
+ readonly HashSet<string> verifiedGeneratedTypes = new HashSet<string> ();
public AssemblyChecker (AssemblyDefinition original, AssemblyDefinition linked)
{
@@ -43,8 +43,7 @@ namespace Mono.Linker.Tests.TestCasesRunner {
var membersToAssert = originalAssembly.MainModule.Types;
foreach (var originalMember in membersToAssert) {
- var td = originalMember as TypeDefinition;
- if (td != null) {
+ if (originalMember is TypeDefinition td) {
if (td.Name == "<Module>") {
linkedMembers.Remove (td.Name);
continue;
diff --git a/test/Mono.Linker.Tests/TestCasesRunner/LinkerDriver.cs b/test/Mono.Linker.Tests/TestCasesRunner/LinkerDriver.cs
index 521094d8f..1589f5c6d 100644
--- a/test/Mono.Linker.Tests/TestCasesRunner/LinkerDriver.cs
+++ b/test/Mono.Linker.Tests/TestCasesRunner/LinkerDriver.cs
@@ -4,7 +4,7 @@
public class LinkerDriver {
protected class TestDriver : Driver
{
- LinkerCustomizations _customization;
+ readonly LinkerCustomizations _customization;
public TestDriver(Queue<string> args, LinkerCustomizations customizations) : base(args)
{
diff --git a/test/Mono.Linker.Tests/TestCasesRunner/PeVerifier.cs b/test/Mono.Linker.Tests/TestCasesRunner/PeVerifier.cs
index dd3d5e37c..fe980c78d 100644
--- a/test/Mono.Linker.Tests/TestCasesRunner/PeVerifier.cs
+++ b/test/Mono.Linker.Tests/TestCasesRunner/PeVerifier.cs
@@ -24,9 +24,7 @@ namespace Mono.Linker.Tests.TestCasesRunner {
public virtual void Check (LinkedTestCaseResult linkResult, AssemblyDefinition original)
{
- bool skipCheckEntirely;
- HashSet<string> assembliesToSkip;
- ProcessSkipAttributes (linkResult, original, out skipCheckEntirely, out assembliesToSkip);
+ ProcessSkipAttributes (linkResult, original, out bool skipCheckEntirely, out HashSet<string> assembliesToSkip);
if (skipCheckEntirely)
return;
@@ -109,8 +107,7 @@ namespace Mono.Linker.Tests.TestCasesRunner {
if (Environment.OSVersion.Platform != PlatformID.Win32NT)
throw new InvalidOperationException ("This method should only be called on windows");
- NPath result;
- if (TryFindPeExecutableFromRegustrySubfolder ("NETFXSDK", out result))
+ if (TryFindPeExecutableFromRegustrySubfolder ("NETFXSDK", out NPath result))
return result;
if (TryFindPeExecutableFromRegustrySubfolder ("Windows", out result))
return result;
diff --git a/test/Mono.Linker.Tests/TestCasesRunner/ResultChecker.cs b/test/Mono.Linker.Tests/TestCasesRunner/ResultChecker.cs
index df47260d7..7abff46b1 100644
--- a/test/Mono.Linker.Tests/TestCasesRunner/ResultChecker.cs
+++ b/test/Mono.Linker.Tests/TestCasesRunner/ResultChecker.cs
@@ -253,7 +253,7 @@ namespace Mono.Linker.Tests.TestCasesRunner {
case nameof (RemovedForwarderAttribute):
if (linkedAssembly.MainModule.ExportedTypes.Any (l => l.Name == expectedTypeName))
Assert.Fail ($"Forwarder `{expectedTypeName}' should have been removed");
-
+
break;
case nameof (KeptResourceInAssemblyAttribute):
VerifyKeptResourceInAssembly (checkAttrInAssembly);
@@ -651,7 +651,7 @@ namespace Mono.Linker.Tests.TestCasesRunner {
}
}
- string DependencyToString(TestDependencyRecorder.Dependency dependency)
+ static string DependencyToString(TestDependencyRecorder.Dependency dependency)
{
return $"{dependency.Source} -> {dependency.Target} Marked: {dependency.Marked}";
}
@@ -687,7 +687,7 @@ namespace Mono.Linker.Tests.TestCasesRunner {
.Select (p => "\t" + RecognizedReflectionAccessPatternToString (p)));
Assert.Fail (
- $"Expected to find recognized reflection access pattern '{expectedSourceMethod.ToString()}: Call to {expectedReflectionMethod} accessed {expectedAccessedItem}'{Environment.NewLine}" +
+ $"Expected to find recognized reflection access pattern '{expectedSourceMethod}: Call to {expectedReflectionMethod} accessed {expectedAccessedItem}'{Environment.NewLine}" +
$"Potential patterns matching the source method: {Environment.NewLine}{sourceMethodCandidates}{Environment.NewLine}" +
$"Potential patterns matching the reflection method: {Environment.NewLine}{reflectionMethodCandidates}{Environment.NewLine}" +
$"If there's no matches, try to specify just a part of the source method or reflection method name and rerun the test to get potential matches.");
@@ -813,8 +813,7 @@ namespace Mono.Linker.Tests.TestCasesRunner {
protected TypeDefinition GetOriginalTypeFromInAssemblyAttribute (string assemblyName, object typeOrTypeName)
{
- var attributeValueAsTypeReference = typeOrTypeName as TypeReference;
- if (attributeValueAsTypeReference != null)
+ if (typeOrTypeName is TypeReference attributeValueAsTypeReference)
return attributeValueAsTypeReference.Resolve ();
var assembly = ResolveOriginalsAssembly (assemblyName);
@@ -833,8 +832,7 @@ namespace Mono.Linker.Tests.TestCasesRunner {
foreach (var typeWithRemoveInAssembly in original.AllDefinedTypes ()) {
foreach (var attr in typeWithRemoveInAssembly.CustomAttributes.Where (IsTypeInOtherAssemblyAssertion)) {
var assemblyName = (string) attr.ConstructorArguments [0].Value;
- List<CustomAttribute> checksForAssembly;
- if (!checks.TryGetValue (assemblyName, out checksForAssembly))
+ if (!checks.TryGetValue (assemblyName, out List<CustomAttribute> checksForAssembly))
checks [assemblyName] = checksForAssembly = new List<CustomAttribute> ();
checksForAssembly.Add (attr);
diff --git a/test/Mono.Linker.Tests/TestCasesRunner/TestCaseCollector.cs b/test/Mono.Linker.Tests/TestCasesRunner/TestCaseCollector.cs
index 5c4f4dbc9..c48dd331e 100644
--- a/test/Mono.Linker.Tests/TestCasesRunner/TestCaseCollector.cs
+++ b/test/Mono.Linker.Tests/TestCasesRunner/TestCaseCollector.cs
@@ -39,8 +39,7 @@ namespace Mono.Linker.Tests.TestCasesRunner {
using (var caseAssemblyDefinition = AssemblyDefinition.ReadAssembly (_testCaseAssemblyPath.ToString ())) {
foreach (var file in sourceFiles) {
- TestCase testCase;
- if (CreateCase (caseAssemblyDefinition, file, out testCase))
+ if (CreateCase (caseAssemblyDefinition, file, out TestCase testCase))
yield return testCase;
}
}
@@ -85,10 +84,8 @@ namespace Mono.Linker.Tests.TestCasesRunner {
var pathRelativeToAssembly = $"{testCaseType.FullName.Substring (testCaseType.Module.Name.Length - 3).Replace ('.', '/')}.cs";
var fullSourcePath = _rootDirectory.Combine (pathRelativeToAssembly).FileMustExist ();
- using (var caseAssemblyDefinition = AssemblyDefinition.ReadAssembly (_testCaseAssemblyPath.ToString ()))
- {
- TestCase testCase;
- if (!CreateCase (caseAssemblyDefinition, fullSourcePath, out testCase))
+ using (var caseAssemblyDefinition = AssemblyDefinition.ReadAssembly (_testCaseAssemblyPath.ToString ())) {
+ if (!CreateCase (caseAssemblyDefinition, fullSourcePath, out TestCase testCase))
throw new ArgumentException ($"Could not create a test case for `{testCaseType}`. Ensure the namespace matches it's location on disk");
return testCase;
diff --git a/test/Mono.Linker.Tests/TestCasesRunner/TestCaseMetadaProvider.cs b/test/Mono.Linker.Tests/TestCasesRunner/TestCaseMetadaProvider.cs
index 589ed2ce1..cb0d855c8 100644
--- a/test/Mono.Linker.Tests/TestCasesRunner/TestCaseMetadaProvider.cs
+++ b/test/Mono.Linker.Tests/TestCasesRunner/TestCaseMetadaProvider.cs
@@ -307,8 +307,7 @@ namespace Mono.Linker.Tests.TestCasesRunner {
protected virtual NPath SourceFileForAttributeArgumentValue (object value)
{
- var valueAsTypeRef = value as TypeReference;
- if (valueAsTypeRef != null) {
+ if (value is TypeReference valueAsTypeRef) {
// Use the parent type for locating the source file
var parentType = ParentMostType (valueAsTypeRef);
var pathRelativeToAssembly = $"{parentType.FullName.Substring (parentType.Module.Name.Length - 3).Replace ('.', '/')}.cs".ToNPath ();
diff --git a/test/Mono.Linker.Tests/TestCasesRunner/TestRunner.cs b/test/Mono.Linker.Tests/TestCasesRunner/TestRunner.cs
index 4d16a83bf..f60398db0 100644
--- a/test/Mono.Linker.Tests/TestCasesRunner/TestRunner.cs
+++ b/test/Mono.Linker.Tests/TestCasesRunner/TestRunner.cs
@@ -20,8 +20,7 @@ namespace Mono.Linker.Tests.TestCasesRunner {
using (var fullTestCaseAssemblyDefinition = AssemblyDefinition.ReadAssembly (testCase.OriginalTestCaseAssemblyPath.ToString ())) {
var metadataProvider = _factory.CreateMetadataProvider (testCase, fullTestCaseAssemblyDefinition);
- string ignoreReason;
- if (metadataProvider.IsIgnored (out ignoreReason))
+ if (metadataProvider.IsIgnored (out string ignoreReason))
Assert.Ignore (ignoreReason);
var sandbox = Sandbox (testCase, metadataProvider);
diff --git a/test/Mono.Linker.Tests/Tests/TypeNameParserTests.cs b/test/Mono.Linker.Tests/Tests/TypeNameParserTests.cs
index b5d124619..177e83276 100644
--- a/test/Mono.Linker.Tests/Tests/TypeNameParserTests.cs
+++ b/test/Mono.Linker.Tests/Tests/TypeNameParserTests.cs
@@ -6,7 +6,7 @@ namespace Mono.Linker.Tests {
[Test]
public void TryParseTypeAssemblyQualifiedName_Null ()
{
- Assert.That (TypeNameParser.TryParseTypeAssemblyQualifiedName (null, out string typeName, out string assemblyName), Is.False);
+ Assert.That (TypeNameParser.TryParseTypeAssemblyQualifiedName (null, out _, out _), Is.False);
}
[Test]