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

github.com/mono/cecil.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJb Evain <jb@evain.net>2017-10-25 01:51:31 +0300
committerJb Evain <jb@evain.net>2017-10-25 01:51:31 +0300
commit8cb7ef78381ff8bd9a110faf4a4e84b7ab35ed1b (patch)
treef3f376a44a56a81e570045e46914e591340309f9 /Test/Mono.Cecil.Tests
parente292fc22b01ca386e7e6739cf8fe1f7cba9b321c (diff)
Style and patterns
Diffstat (limited to 'Test/Mono.Cecil.Tests')
-rw-r--r--Test/Mono.Cecil.Tests/AssemblyTests.cs6
-rw-r--r--Test/Mono.Cecil.Tests/CompilationService.cs46
-rw-r--r--Test/Mono.Cecil.Tests/ImportCecilTests.cs8
-rw-r--r--Test/Mono.Cecil.Tests/ImportReflectionTests.cs19
-rw-r--r--Test/Mono.Cecil.Tests/ModuleTests.cs6
-rw-r--r--Test/Mono.Cecil.Tests/TypeParserTests.cs3
6 files changed, 53 insertions, 35 deletions
diff --git a/Test/Mono.Cecil.Tests/AssemblyTests.cs b/Test/Mono.Cecil.Tests/AssemblyTests.cs
index 18251b6..bd7d6cd 100644
--- a/Test/Mono.Cecil.Tests/AssemblyTests.cs
+++ b/Test/Mono.Cecil.Tests/AssemblyTests.cs
@@ -59,7 +59,8 @@ namespace Mono.Cecil.Tests {
[Test]
public void Retargetable ()
{
- if (Platform.OnCoreClr) return;
+ if (Platform.OnCoreClr)
+ return;
TestModule ("RetargetableExample.dll", module => {
var type = module.Types [1];
@@ -78,7 +79,8 @@ namespace Mono.Cecil.Tests {
[Test]
public void SystemRuntime ()
{
- if (Platform.OnCoreClr) return;
+ if (Platform.OnCoreClr)
+ return;
TestModule("System.Runtime.dll", module => {
Assert.AreEqual ("System.Runtime", module.Assembly.Name.Name);
diff --git a/Test/Mono.Cecil.Tests/CompilationService.cs b/Test/Mono.Cecil.Tests/CompilationService.cs
index 8aea89a..5501d57 100644
--- a/Test/Mono.Cecil.Tests/CompilationService.cs
+++ b/Test/Mono.Cecil.Tests/CompilationService.cs
@@ -27,21 +27,22 @@ namespace Mono.Cecil.Tests {
}
}
- public static class Platform
- {
+ public static class Platform {
- public static bool OnMono { get { return TryGetType("Mono.Runtime") != null; } }
- public static bool OnCoreClr { get { return TryGetType("System.Runtime.Loader.AssemblyLoadContext, System.Runtime.Loader, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a") != null; } }
+ public static bool OnMono {
+ get { return TryGetType ("Mono.Runtime") != null; }
+ }
+
+ public static bool OnCoreClr {
+ get { return TryGetType ("System.Runtime.Loader.AssemblyLoadContext, System.Runtime.Loader, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a") != null; }
+ }
- private static Type TryGetType(string assemblyQualifiedName)
+ static Type TryGetType (string assemblyQualifiedName)
{
- try
- {
+ try {
// Note that throwOnError=false only suppresses some exceptions, not all.
return Type.GetType(assemblyQualifiedName, throwOnError: false);
- }
- catch
- {
+ } catch {
return null;
}
}
@@ -138,15 +139,17 @@ namespace Mono.Cecil.Tests {
Assert.Fail (output.ToString ());
}
}
+
#if NET_CORE
+
class RoslynCompilationService : CompilationService {
public static readonly RoslynCompilationService Instance = new RoslynCompilationService ();
protected override string CompileFile (string name)
{
- Compilation compilation = GetCompilation (name);
- string outputName = GetCompiledFilePath (name);
+ var compilation = GetCompilation (name);
+ var outputName = GetCompiledFilePath (name);
var result = compilation.Emit (outputName);
Assert.IsTrue (result.Success, GetErrorMessage (result));
@@ -154,10 +157,10 @@ namespace Mono.Cecil.Tests {
return outputName;
}
- private static Compilation GetCompilation (string name)
+ static Compilation GetCompilation (string name)
{
- string assemblyName = Path.GetFileNameWithoutExtension (name);
- string source = File.ReadAllText (name);
+ var assemblyName = Path.GetFileNameWithoutExtension (name);
+ var source = File.ReadAllText (name);
var tpa = BaseAssemblyResolver.TrustedPlatformAssemblies.Value;
@@ -176,14 +179,14 @@ namespace Mono.Cecil.Tests {
case ".cs":
return CS.CSharpCompilation.Create (
assemblyName,
- new [] { CS.SyntaxFactory.ParseSyntaxTree(source) },
+ new [] { CS.SyntaxFactory.ParseSyntaxTree (source) },
references,
- new CS.CSharpCompilationOptions(OutputKind.DynamicallyLinkedLibrary, optimizationLevel: OptimizationLevel.Release));
+ new CS.CSharpCompilationOptions (OutputKind.DynamicallyLinkedLibrary, optimizationLevel: OptimizationLevel.Release));
case ".vb":
return VB.VisualBasicCompilation.Create (
assemblyName,
- new [] { VB.SyntaxFactory.ParseSyntaxTree(source) },
+ new [] { VB.SyntaxFactory.ParseSyntaxTree (source) },
references,
new VB.VisualBasicCompilationOptions (OutputKind.DynamicallyLinkedLibrary, optimizationLevel: OptimizationLevel.Release));
@@ -198,12 +201,15 @@ namespace Mono.Cecil.Tests {
return string.Empty;
var builder = new StringBuilder ();
- foreach (Diagnostic diagnostic in result.Diagnostics)
+ foreach (var diagnostic in result.Diagnostics)
builder.AppendLine (diagnostic.ToString ());
+
return builder.ToString ();
}
}
+
#else
+
class CodeDomCompilationService : CompilationService {
public static readonly CodeDomCompilationService Instance = new CodeDomCompilationService ();
@@ -257,7 +263,9 @@ namespace Mono.Cecil.Tests {
CodeDomProvider.GetLanguageFromExtension (Path.GetExtension (name)));
}
}
+
#endif
+
class ShellService {
public class ProcessOutput {
diff --git a/Test/Mono.Cecil.Tests/ImportCecilTests.cs b/Test/Mono.Cecil.Tests/ImportCecilTests.cs
index dbcda5f..bc12f5e 100644
--- a/Test/Mono.Cecil.Tests/ImportCecilTests.cs
+++ b/Test/Mono.Cecil.Tests/ImportCecilTests.cs
@@ -1,7 +1,6 @@
#if !READ_ONLY
using System;
using System.Collections.Generic;
-using System.Diagnostics;
using System.IO;
using System.Linq;
using SR = System.Reflection;
@@ -255,7 +254,8 @@ namespace Mono.Cecil.Tests {
[Test]
public void ContextGenericTest ()
{
- if (Platform.OnCoreClr) return;
+ if (Platform.OnCoreClr)
+ return;
var module = ModuleDefinition.ReadModule (typeof (ContextGeneric1Method2<>).Module.FullyQualifiedName);
// by mixing open generics with 2 & 1 parameters, we make sure the right context is used (because otherwise, an exception will be thrown)
@@ -289,7 +289,7 @@ namespace Mono.Cecil.Tests {
delegate void Emitter (ModuleDefinition module, MethodBody body);
- static TDelegate Compile<TDelegate> (Emitter emitter, [CallerMemberName]string testMethodName = null)
+ static TDelegate Compile<TDelegate> (Emitter emitter, [CallerMemberName] string testMethodName = null)
where TDelegate : class
{
var name = "ImportCecil_" + testMethodName;
@@ -365,4 +365,4 @@ namespace Mono.Cecil.Tests {
}
}
}
-#endif \ No newline at end of file
+#endif
diff --git a/Test/Mono.Cecil.Tests/ImportReflectionTests.cs b/Test/Mono.Cecil.Tests/ImportReflectionTests.cs
index b4c11b7..c99ca4f 100644
--- a/Test/Mono.Cecil.Tests/ImportReflectionTests.cs
+++ b/Test/Mono.Cecil.Tests/ImportReflectionTests.cs
@@ -1,7 +1,6 @@
#if !READ_ONLY
using System;
using System.Collections.Generic;
-using System.Diagnostics;
using System.IO;
using SR = System.Reflection;
using System.Runtime.CompilerServices;
@@ -156,7 +155,8 @@ namespace Mono.Cecil.Tests {
[Test]
public void ImportGenericField ()
{
- if (Platform.OnCoreClr) return;
+ if (Platform.OnCoreClr)
+ return;
var get_field = Compile<Func<Generic<string>, string>> ((module, body) => {
var il = body.GetILProcessor ();
@@ -175,7 +175,8 @@ namespace Mono.Cecil.Tests {
[Test]
public void ImportGenericMethod ()
{
- if (Platform.OnCoreClr) return;
+ if (Platform.OnCoreClr)
+ return;
var generic_identity = Compile<Func<Generic<int>, int, int>> ((module, body) => {
var il = body.GetILProcessor ();
@@ -191,7 +192,8 @@ namespace Mono.Cecil.Tests {
[Test]
public void ImportGenericMethodSpec ()
{
- if (Platform.OnCoreClr) return;
+ if (Platform.OnCoreClr)
+ return;
var gen_spec_id = Compile<Func<Generic<string>, int, int>> ((module, body) => {
var il = body.GetILProcessor ();
@@ -208,7 +210,8 @@ namespace Mono.Cecil.Tests {
[Test]
public void ImportComplexGenericMethodSpec ()
{
- if (Platform.OnCoreClr) return;
+ if (Platform.OnCoreClr)
+ return;
var gen_spec_id = Compile<Func<Generic<string>, int, int>> ((module, body) => {
var il = body.GetILProcessor ();
@@ -287,7 +290,8 @@ namespace Mono.Cecil.Tests {
[Test]
public void ImportGenericFieldFromContext ()
{
- if (Platform.OnCoreClr) return;
+ if (Platform.OnCoreClr)
+ return;
var list_foo = typeof (Foo<>).GetField ("list").FieldType;
var generic_list_foo_open = typeof (Generic<>).MakeGenericType (list_foo);
@@ -305,7 +309,8 @@ namespace Mono.Cecil.Tests {
[Test]
public void ImportGenericMethodFromContext ()
{
- if (Platform.OnCoreClr) return;
+ if (Platform.OnCoreClr)
+ return;
var list_foo = typeof (Foo<>).GetField ("list").FieldType;
var generic_list_foo_open = typeof (Generic<>).MakeGenericType (list_foo);
diff --git a/Test/Mono.Cecil.Tests/ModuleTests.cs b/Test/Mono.Cecil.Tests/ModuleTests.cs
index 808fa07..2b8eda1 100644
--- a/Test/Mono.Cecil.Tests/ModuleTests.cs
+++ b/Test/Mono.Cecil.Tests/ModuleTests.cs
@@ -49,7 +49,8 @@ namespace Mono.Cecil.Tests {
[Test]
public void MultiModules ()
{
- if (Platform.OnCoreClr) return;
+ if (Platform.OnCoreClr)
+ return;
TestModule("mma.exe", module => {
var assembly = module.Assembly;
@@ -159,7 +160,8 @@ namespace Mono.Cecil.Tests {
[Test]
public void ExportedTypeFromNetModule ()
{
- if (Platform.OnCoreClr) return;
+ if (Platform.OnCoreClr)
+ return;
TestModule ("mma.exe", module => {
Assert.IsTrue (module.HasExportedTypes);
diff --git a/Test/Mono.Cecil.Tests/TypeParserTests.cs b/Test/Mono.Cecil.Tests/TypeParserTests.cs
index ac668e0..a838c07 100644
--- a/Test/Mono.Cecil.Tests/TypeParserTests.cs
+++ b/Test/Mono.Cecil.Tests/TypeParserTests.cs
@@ -233,7 +233,8 @@ namespace Mono.Cecil.Tests {
[Test]
public void GenericInstanceExternArguments ()
{
- if (Platform.OnCoreClr) return;
+ if (Platform.OnCoreClr)
+ return;
var module = GetCurrentModule ();