提交 7d5d3a39 编写于 作者: T Tomáš Matoušek

Merge pull request #4454 from tmat/PortableTest2

Clean up CompilerTestUtilities2 - remove non-portable and unused code
......@@ -104,7 +104,7 @@ public void SyntaxNodeSyntaxTreeReturnsOriginalSyntaxTree()
private void CheckTree(SyntaxTree tree)
{
#if false
#if false // https://github.com/dotnet/roslyn/issues/4453
CheckAllMembers(
tree,
new Dictionary<Type, Func<object>>
......
// Copyright (c) Microsoft. All Rights Reserved. Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
using System;
using System.IO;
using System.Reflection;
using Microsoft.CodeAnalysis.Text;
namespace Microsoft.CodeAnalysis.Test.Utilities
{
public class CSReflectionBasedKindProvider : ISyntaxNodeKindProvider
{
private const string CS_DLL = "Microsoft.CodeAnalysis.CSharp.dll";
private const string CS_KIND_TYPE = "Roslyn.Compilers.CSharp.SyntaxKind";
private Type _CSKindType;
private readonly string _folder;
public CSReflectionBasedKindProvider(string folder)
{
_folder = Path.GetFullPath(folder);
GetKindTypes();
}
private void GetKindTypes()
{
if (_CSKindType == null)
{
var asm = Assembly.LoadFrom(Path.Combine(_folder, CS_DLL));
_CSKindType = asm.GetType(CS_KIND_TYPE);
}
}
private string GetKind(object o)
{
string kind = (string)o.GetType().GetProperty("Kind").GetValue(o, new object[] { });
return Enum.Parse(_CSKindType, kind).ToString();
}
public string Kind(object node)
{
return GetKind(node);
}
}
}
......@@ -103,13 +103,6 @@
<InternalsVisibleToTest Include="Roslyn.Test.Utilities" />
</ItemGroup>
<ItemGroup>
<Compile Include="..\..\..\Helpers\AbstractAnalyzerAssemblyLoader.cs">
<Link>AbstractAnalyzerAssemblyLoader.cs</Link>
</Compile>
<Compile Include="..\..\..\Helpers\SimpleAnalyzerAssemblyLoader.cs">
<Link>SimpleAnalyzerAssemblyLoader.cs</Link>
</Compile>
<Compile Include="CSReflectionBasedKindProvider.cs" />
<Compile Include="Diagnostics\DiagnosticsHelper.cs" />
<Compile Include="Diagnostics\OptionsDiagnosticAnalyzer.cs" />
<Compile Include="Diagnostics\TestDiagnosticAnalyzer.cs" />
......@@ -124,33 +117,12 @@
<Compile Include="NodeHelpers.cs" />
<Compile Include="NodeInfo.cs" />
<Compile Include="NodeInfo.FieldInfo.cs" />
<Compile Include="NodeRules.cs" />
<Compile Include="NonTerminalRuleAttribute.cs" />
<Compile Include="ParseHelpers.cs" />
<Compile Include="PEModuleTestHelpers.cs" />
<Compile Include="ProgressDialog.cs">
<SubType>Form</SubType>
</Compile>
<Compile Include="ProgressDialog.Designer.cs">
<DependentUpon>ProgressDialog.cs</DependentUpon>
</Compile>
<Compile Include="SourceCodeValidator.cs" />
<Compile Include="SpeculativeSemanticModelTestsBase.cs" />
<Compile Include="TestExceptionUtilities.cs" />
<Compile Include="TestReferences.cs" />
<Compile Include="TokenRuleAttribute.cs" />
<Compile Include="TreeRuleAttribute.cs" />
<Compile Include="TreeRules.cs" />
<Compile Include="TreeValidator.cs" />
<Compile Include="TriviaRuleAttribute.cs" />
<Compile Include="VBReflectionBasedKindProvider.cs" />
<Compile Include="XmlHelpers.cs" />
</ItemGroup>
<ItemGroup>
<EmbeddedResource Include="ProgressDialog.resx">
<DependentUpon>ProgressDialog.cs</DependentUpon>
</EmbeddedResource>
</ItemGroup>
<ItemGroup>
<None Include="packages.config" />
</ItemGroup>
......@@ -159,4 +131,4 @@
<Import Project="..\..\..\..\..\build\Targets\Roslyn.Toolsets.Xunit.targets" />
<Import Project="$(SolutionDir)\.nuget\NuGet.targets" Condition="Exists('$(SolutionDir)\.nuget\NuGet.targets')" />
</ImportGroup>
</Project>
</Project>
\ No newline at end of file
......@@ -27,12 +27,7 @@ public abstract class TestDiagnosticAnalyzer<TLanguageKindEnum> : DiagnosticAnal
private static ImmutableArray<T> GetAllEnumValues<T>()
{
return ImmutableArray<T>.Empty.AddRange(typeof(T).GetFields(BindingFlags.Public | BindingFlags.Static).Select(f => (T)f.GetRawConstantValue()));
}
protected static IEnumerable<string> GetAbstractMemberNames(Type abstractType)
{
return abstractType.GetMembers().Where(m => !(m is MethodInfo) || !((MethodInfo)m).IsSpecialName).Select(m => m.Name);
return ImmutableArray.CreateRange(Enum.GetValues(typeof(T)).Cast<T>());
}
protected abstract void OnAbstractMember(string abstractMemberName, SyntaxNode node = null, ISymbol symbol = null, [CallerMemberName]string callerName = null);
......
......@@ -144,7 +144,7 @@ public static NodeInfo GetNodeInfo(this SyntaxNode node)
{
var typeObject = node.GetType();
var nodeClassName = typeObject.Name;
var properties = typeObject.GetProperties(BindingFlags.Instance | BindingFlags.DeclaredOnly | BindingFlags.Public);
var properties = typeObject.GetTypeInfo().DeclaredProperties;
return new NodeInfo(typeObject.Name, (
from p in properties
where IsField(p)
......@@ -155,7 +155,7 @@ public static NodeInfo GetNodeInfo(this SyntaxToken token)
{
var typeObject = token.GetType();
var nodeClassName = typeObject.Name;
var properties = typeObject.GetProperties(BindingFlags.Instance | BindingFlags.DeclaredOnly | BindingFlags.Public);
var properties = typeObject.GetTypeInfo().DeclaredProperties;
return new NodeInfo(typeObject.Name, (
from p in properties
where IsField(p)
......@@ -166,7 +166,7 @@ public static NodeInfo GetNodeInfo(this SyntaxTrivia trivia)
{
var typeObject = trivia.GetType();
var nodeClassName = typeObject.Name;
var properties = typeObject.GetProperties(BindingFlags.Instance | BindingFlags.DeclaredOnly | BindingFlags.Public);
var properties = typeObject.GetTypeInfo().DeclaredProperties;
return new NodeInfo(typeObject.Name, (
from p in properties
where IsField(p)
......@@ -177,7 +177,18 @@ where IsField(p)
private static bool IsField(PropertyInfo prop)
{
var typeObject = prop.PropertyType;
if (typeObject == typeof(int) || typeObject == typeof(uint) || typeObject == typeof(long) || typeObject == typeof(ulong) || typeObject == typeof(bool) || typeObject == typeof(string) || typeObject == typeof(float) || typeObject == typeof(double) || typeObject == typeof(char) || typeObject == typeof(DateTime) || typeObject == typeof(decimal) || typeObject.IsEnum)
if (typeObject == typeof(int) ||
typeObject == typeof(uint) ||
typeObject == typeof(long) ||
typeObject == typeof(ulong) ||
typeObject == typeof(bool) ||
typeObject == typeof(string) ||
typeObject == typeof(float) ||
typeObject == typeof(double) ||
typeObject == typeof(char) ||
typeObject == typeof(DateTime) ||
typeObject == typeof(decimal) ||
typeObject.GetTypeInfo().IsEnum)
{
return true;
}
......
// Copyright (c) Microsoft. All Rights Reserved. Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
using System.Reflection;
using Microsoft.CodeAnalysis.Text;
using System;
namespace Microsoft.CodeAnalysis.Test.Utilities
{
......
// Copyright (c) Microsoft. All Rights Reserved. Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Reflection;
using Microsoft.CodeAnalysis.Text;
namespace Microsoft.CodeAnalysis.Test.Utilities
{
[AttributeUsage(AttributeTargets.Method, AllowMultiple = false, Inherited = false)]
public class NonTerminalRuleAttribute : Attribute
{
public string Name
{
get;
set;
}
public string Group
{
get;
set;
}
}
}
// Copyright (c) Microsoft. All Rights Reserved. Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
using System;
using System.IO;
using System.Reflection;
using Microsoft.CodeAnalysis.Text;
namespace Microsoft.CodeAnalysis.Test.Utilities
{
public class ParseHelpers
{
private const string CS_PARSER_DLL = "Microsoft.CodeAnalysis.CSharp.dll";
private const string VB_PARSER_DLL = "Microsoft.CodeAnalysis.VisualBasic.dll";
private const string CS_SYNTAX_TREE_TYPE = "Roslyn.Compilers.CSharp.CSharpSyntaxTree";
private const string VB_SYNTAX_TREE_TYPE = "Roslyn.Compilers.VisualBasic.VisualBasicSyntaxTree";
private const string CS_OPTIONS_TYPE = "Roslyn.Compilers.CSharp.ParseOptions";
private const string VB_OPTIONS_TYPE = "Roslyn.Compilers.VisualBasic.ParseOptions";
private const string SYNTAX_TREE_PARSE_METHOD = "ParseCompilationUnit";
private const string CS_LANG_VERSION_OPTION_TYPE = "Roslyn.Compilers.CSharp.LanguageVersion";
private const string CODE_KIND_OPTION = "Roslyn.Compilers.SourceCodeKind";
#if false
private Type m_CSParserType = null;
private Type m_VBParserType = null;
#endif
private Type _CSSyntaxTreeType;
private Type _visualBasicSyntaxTreeType;
private object _CSOptions;
private object _VBOptions;
private readonly string _CSFileName = "Default.cs";
private readonly string _VBFileName = "Default.vb";
private object _codeKind;
public SyntaxTree ParseCSTree(string code, string folder)
{
if (_CSSyntaxTreeType == null)
{
var asm = Assembly.LoadFrom(Path.Combine(folder, CS_PARSER_DLL));
_CSSyntaxTreeType = asm.GetType(CS_SYNTAX_TREE_TYPE);
var csLangVersionOption = Enum.Parse(asm.GetType(CS_LANG_VERSION_OPTION_TYPE), "CSharp4");
_codeKind = Enum.Parse(asm.GetType(CODE_KIND_OPTION), "Regular");
_CSOptions = Activator.CreateInstance(asm.GetType(CS_OPTIONS_TYPE), csLangVersionOption, null, false, _codeKind);
}
SyntaxTree syntaxTree = (SyntaxTree)_CSSyntaxTreeType.InvokeMember(SYNTAX_TREE_PARSE_METHOD, BindingFlags.InvokeMethod, null, null, new[]
{
code, _CSFileName, _CSOptions
}
);
return syntaxTree;
}
public SyntaxTree ParseVBTree(string code, string folder)
{
if (_visualBasicSyntaxTreeType == null)
{
var asm = Assembly.LoadFrom(Path.Combine(folder, VB_PARSER_DLL));
_visualBasicSyntaxTreeType = asm.GetType(VB_SYNTAX_TREE_TYPE);
_codeKind = Enum.Parse(asm.GetType(CODE_KIND_OPTION), "Regular");
_VBOptions = Activator.CreateInstance(asm.GetType(VB_OPTIONS_TYPE), null, false, _codeKind);
}
SyntaxTree syntaxTree = (SyntaxTree)_visualBasicSyntaxTreeType.InvokeMember(SYNTAX_TREE_PARSE_METHOD, BindingFlags.InvokeMethod, null, null, new[]
{
code, _VBFileName, _VBOptions
}
);
return syntaxTree;
}
}
}
using System.Diagnostics;
using System.Drawing;
using System.Windows.Forms;
using Microsoft.CodeAnalysis.Text;
namespace Microsoft.CodeAnalysis.Test.Utilities
{
partial class ProgressDialog : Form
{
[DebuggerNonUserCode()]
private void InitializeComponent()
{
this.Label1 = new Label();
this.Label2 = new Label();
this.ProgressBar1 = new ProgressBar();
this.SuspendLayout();
//
//Label1
//
this.Label1.AutoSize = true;
this.Label1.Location = new Point(12, 50);
this.Label1.Name = "Label1";
this.Label1.Size = new Size(60, 13);
this.Label1.TabIndex = 0;
this.Label1.Text = "Processed:";
//
//Label2
//
this.Label2.AutoSize = true;
this.Label2.Location = new Point(78, 50);
this.Label2.Name = "Label2";
this.Label2.Size = new Size(39, 13);
this.Label2.TabIndex = 1;
this.Label2.Text = "Label2";
//
//ProgressBar1
//
this.ProgressBar1.Location = new Point(12, 14);
this.ProgressBar1.Name = "ProgressBar1";
this.ProgressBar1.Size = new Size(211, 24);
this.ProgressBar1.TabIndex = 2;
//
//ProgressDialog
//
this.AutoScaleDimensions = new SizeF(6, 13);
this.AutoScaleMode = AutoScaleMode.Font;
this.ClientSize = new Size(235, 75);
this.Controls.Add(this.ProgressBar1);
this.Controls.Add(this.Label2);
this.Controls.Add(this.Label1);
this.Name = "ProgressDialog";
this.Text = "Progress...";
this.ResumeLayout(false);
this.PerformLayout();
}
internal Label Label1;
internal Label Label2;
internal ProgressBar ProgressBar1;
}
}
\ No newline at end of file
// Copyright (c) Microsoft. All Rights Reserved. Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
using System;
using System.Windows.Forms;
using Microsoft.CodeAnalysis.Text;
namespace Microsoft.CodeAnalysis.Test.Utilities
{
public partial class ProgressDialog
{
public ProgressDialog()
{
InitializeComponent();
}
public int Maximum
{
get;
set;
}
private void ProgressDialog_Load(object sender, EventArgs e)
{
Label2.Text = "0";
ProgressBar1.Maximum = Maximum;
}
public void Increment()
{
Label2.Text = "1";
ProgressBar1.Increment(1);
Application.DoEvents();
}
}
}
<?xml version="1.0" encoding="utf-8"?>
<!-- Copyright (c) Microsoft. All Rights Reserved. Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. -->
<root>
<!--
Microsoft ResX Schema
Version 2.0
The primary goals of this format is to allow a simple XML format
that is mostly human readable. The generation and parsing of the
various data types are done through the TypeConverter classes
associated with the data types.
Example:
... ado.net/XML headers & schema ...
<resheader name="resmimetype">text/microsoft-resx</resheader>
<resheader name="version">2.0</resheader>
<resheader name="reader">System.Resources.ResXResourceReader, System.Windows.Forms, ...</resheader>
<resheader name="writer">System.Resources.ResXResourceWriter, System.Windows.Forms, ...</resheader>
<data name="Name1"><value>this is my long string</value><comment>this is a comment</comment></data>
<data name="Color1" type="System.Drawing.Color, System.Drawing">Blue</data>
<data name="Bitmap1" mimetype="application/x-microsoft.net.object.binary.base64">
<value>[base64 mime encoded serialized .NET Framework object]</value>
</data>
<data name="Icon1" type="System.Drawing.Icon, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64">
<value>[base64 mime encoded string representing a byte array form of the .NET Framework object]</value>
<comment>This is a comment</comment>
</data>
There are any number of "resheader" rows that contain simple
name/value pairs.
Each data row contains a name, and value. The row also contains a
type or mimetype. Type corresponds to a .NET class that support
text/value conversion through the TypeConverter architecture.
Classes that don't support this are serialized and stored with the
mimetype set.
The mimetype is used for serialized objects, and tells the
ResXResourceReader how to depersist the object. This is currently not
extensible. For a given mimetype the value must be set accordingly:
Note - application/x-microsoft.net.object.binary.base64 is the format
that the ResXResourceWriter will generate, however the reader can
read any of the formats listed below.
mimetype: application/x-microsoft.net.object.binary.base64
value : The object must be serialized with
: System.Runtime.Serialization.Formatters.Binary.BinaryFormatter
: and then encoded with base64 encoding.
mimetype: application/x-microsoft.net.object.soap.base64
value : The object must be serialized with
: System.Runtime.Serialization.Formatters.Soap.SoapFormatter
: and then encoded with base64 encoding.
mimetype: application/x-microsoft.net.object.bytearray.base64
value : The object must be serialized into a byte array
: using a System.ComponentModel.TypeConverter
: and then encoded with base64 encoding.
-->
<xsd:schema id="root" xmlns="" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
<xsd:import namespace="http://www.w3.org/XML/1998/namespace" />
<xsd:element name="root" msdata:IsDataSet="true">
<xsd:complexType>
<xsd:choice maxOccurs="unbounded">
<xsd:element name="metadata">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" />
</xsd:sequence>
<xsd:attribute name="name" use="required" type="xsd:string" />
<xsd:attribute name="type" type="xsd:string" />
<xsd:attribute name="mimetype" type="xsd:string" />
<xsd:attribute ref="xml:space" />
</xsd:complexType>
</xsd:element>
<xsd:element name="assembly">
<xsd:complexType>
<xsd:attribute name="alias" type="xsd:string" />
<xsd:attribute name="name" type="xsd:string" />
</xsd:complexType>
</xsd:element>
<xsd:element name="data">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
<xsd:element name="comment" type="xsd:string" minOccurs="0" msdata:Ordinal="2" />
</xsd:sequence>
<xsd:attribute name="name" type="xsd:string" use="required" msdata:Ordinal="1" />
<xsd:attribute name="type" type="xsd:string" msdata:Ordinal="3" />
<xsd:attribute name="mimetype" type="xsd:string" msdata:Ordinal="4" />
<xsd:attribute ref="xml:space" />
</xsd:complexType>
</xsd:element>
<xsd:element name="resheader">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
</xsd:sequence>
<xsd:attribute name="name" type="xsd:string" use="required" />
</xsd:complexType>
</xsd:element>
</xsd:choice>
</xsd:complexType>
</xsd:element>
</xsd:schema>
<resheader name="resmimetype">
<value>text/microsoft-resx</value>
</resheader>
<resheader name="version">
<value>2.0</value>
</resheader>
<resheader name="reader">
<value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
<resheader name="writer">
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
</root>
// Copyright (c) Microsoft. All Rights Reserved. Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.IO;
using System.Text;
using System.Threading;
using Microsoft.CodeAnalysis.Text;
namespace Microsoft.CodeAnalysis.Test.Utilities
{
public class SourceCodeValidator
{
protected const int ParserTimeout = 1 * 600000;
protected const int TreeValidatorTimeout = 1 * 600000;
protected readonly Rule ExceptionRule = new Rule()
{
Name = "ExceptionThrown"
};
private readonly string[] _searchPatterns;
private readonly IParser _parser;
private readonly TreeValidator _treeValidator;
protected readonly List<Failure> m_failures;
public event Action<string> FileFound;
public event Action<StringBuilder> TransformCode;
public SourceCodeValidator(IParser parser, string[] searchPatterns, ISyntaxNodeKindProvider nodeKindProvider, bool enableAllRules)
{
_parser = parser;
_searchPatterns = searchPatterns;
_treeValidator = new TreeValidator(nodeKindProvider);
m_failures = new List<Failure>();
if (!enableAllRules)
{
_treeValidator.UnregisterAllRules();
}
}
public ReadOnlyCollection<Failure> Failures
{
get
{
return new ReadOnlyCollection<Failure>(m_failures);
}
}
public void RegisterRule(TreeRuleDelegate test, string name, string group)
{
_treeValidator.RegisterRule(test, name, group);
}
public void RegisterRule(NonTerminalRuleDelegate test, string name, string group)
{
_treeValidator.RegisterRule(test, name, group);
}
public void RegisterRule(TokenRuleDelegate test, string name, string group)
{
_treeValidator.RegisterRule(test, name, group);
}
public void RegisterRule(TriviaRuleDelegate test, string name, string group)
{
_treeValidator.RegisterRule(test, name, group);
}
public void UnRegisterRule(string name)
{
_treeValidator.UnregisterRule(name);
}
protected bool ValidateCode(string code, ref SyntaxTree outTree, string filePath = "")
{
var isValid = false;
ParameterizedThreadStart exceptionWrapper = (object obj) =>
{
ThreadStart wrapped = (ThreadStart)obj;
try
{
wrapped.Invoke();
}
catch (Exception ex)
{
isValid = false;
m_failures.Add(new Failure(filePath, ExceptionRule, null, ex.ToString(), null));
}
}
;
var codeBuilder = new StringBuilder(code);
TransformCode(codeBuilder);
code = codeBuilder.ToString();
SyntaxTree tree = null;
var parserThread = new Thread(exceptionWrapper);
parserThread.Start((ThreadStart)(() =>
{
tree = _parser.Parse(code);
}));
if (!parserThread.Join(ParserTimeout))
{
throw new TimeoutException("Parsing timed out. Current timeout is " + ParserTimeout / 1000 + " seconds.");
}
outTree = tree;
if (outTree != null)
{
var treeValidatorThread = new Thread(exceptionWrapper);
treeValidatorThread.Start((ThreadStart)(() =>
{
isValid = _treeValidator.Validate(tree, code, filePath, m_failures);
}));
if (!treeValidatorThread.Join(TreeValidatorTimeout))
{
throw new TimeoutException("Tree validation timed out. Current timeout is " + TreeValidatorTimeout / 1000 + " seconds.");
}
}
return isValid;
}
public virtual bool ValidateFile(string filePath)
{
SyntaxTree tree = null;
return ValidateCode(File.ReadAllText(filePath), ref tree, filePath);
}
public bool ValidateAllFiles(string dirPath)
{
var isValid = true;
var dirHelper = new DirectoryHelper(dirPath);
dirHelper.FileFound += (string filePath) =>
{
FileFound(filePath);
isValid = isValid & ValidateFile(filePath);
}
;
dirHelper.IterateFiles(_searchPatterns);
return isValid;
}
public bool ValidateAllFiles(IEnumerable<string> fileList)
{
var isValid = true;
foreach (var f in fileList)
{
FileFound(f);
isValid = isValid & ValidateFile(f);
}
return isValid;
}
}
}
......@@ -11,6 +11,7 @@ namespace Microsoft.CodeAnalysis.UnitTests
{
public class SpeculativeSemanticModelTestsBase
{
#if false // https://github.com/dotnet/roslyn/issues/4453
protected void CheckAllMembers<T>(T instance, IDictionary<Type, Func<object>> valueProviders, IDictionary<MemberInfo, Type> expectedExceptions)
{
foreach (var m in typeof(T).GetMembers())
......@@ -46,8 +47,10 @@ protected void CheckAllMembers<T>(T instance, IDictionary<Type, Func<object>> va
}
}
}
#endif
}
internal static class DictionaryExtensions
{
public static TValue GetValueOrDefault<TKey, TValue>(this IDictionary<TKey, TValue> dictionary, TKey key)
......
// Copyright (c) Microsoft. All Rights Reserved. Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Reflection;
using Microsoft.CodeAnalysis.Text;
namespace Microsoft.CodeAnalysis.Test.Utilities
{
[AttributeUsage(AttributeTargets.Method, AllowMultiple = false, Inherited = false)]
public class TokenRuleAttribute : Attribute
{
public string Name
{
get;
set;
}
public string Group
{
get;
set;
}
}
}
// Copyright (c) Microsoft. All Rights Reserved. Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Reflection;
using Microsoft.CodeAnalysis.Text;
namespace Microsoft.CodeAnalysis.Test.Utilities
{
[AttributeUsage(AttributeTargets.Method, AllowMultiple = false, Inherited = false)]
public class TreeRuleAttribute : Attribute
{
public string Name
{
get;
set;
}
public string Group
{
get;
set;
}
}
}
// Copyright (c) Microsoft. All Rights Reserved. Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
using System.Linq;
using Microsoft.CodeAnalysis.Text;
namespace Microsoft.CodeAnalysis.Test.Utilities
{
public class TreeRules
{
[TreeRule(Name = "RoundTrip", Group = "RoundTrip")]
private bool RoundTrip(SyntaxTree tree, string codeText, string filename, ref string errorText)
{
var retVal = true;
if (tree.GetRoot().ToFullString() != codeText)
{
retVal = false;
errorText = "FullText for tree parsed from '" + filename + "' does match actual text";
}
return retVal;
}
[TreeRule(Name = "TreeFullSpan", Group = "Span")]
private bool TreeFullSpan(SyntaxTree tree, string codeText, string filename, ref string errorText)
{
var retVal = true;
if (tree.GetRoot().FullSpan.Length != codeText.Length)
{
retVal = false;
errorText = "FullSpan width of tree (" + tree.GetRoot().FullSpan.Length + ") does not match length of the code (" + codeText.Length + ")";
}
return retVal;
}
[TreeRule(Name = "NullsAndCollections", Group = "RoundTrip")]
private bool NullsAndCollections(SyntaxTree tree, string codeText, string filename, ref string errorText)
{
var retVal = true;
if (tree.GetDiagnostics() == null)
{
retVal = false;
errorText = "Diagnostics collection for this tree is null";
}
else if ((
from e in tree.GetDiagnostics()
where e == null
select e).Any())
{
retVal = false;
errorText = "Diagnostics collection for this tree contains a null element";
}
else if (tree.GetRoot().DescendantTokens() == null)
{
retVal = false;
errorText = "Tokens collection for this tree is null";
}
return retVal;
}
}
}
// Copyright (c) Microsoft. All Rights Reserved. Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Reflection;
using Microsoft.CodeAnalysis.Text;
namespace Microsoft.CodeAnalysis.Test.Utilities
{
[AttributeUsage(AttributeTargets.Method, AllowMultiple = false, Inherited = false)]
public class TriviaRuleAttribute : Attribute
{
public string Name
{
get;
set;
}
public string Group
{
get;
set;
}
}
}
// Copyright (c) Microsoft. All Rights Reserved. Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
using System;
using System.IO;
using System.Reflection;
using Microsoft.CodeAnalysis.Text;
namespace Microsoft.CodeAnalysis.Test.Utilities
{
public class VBReflectionBasedKindProvider : ISyntaxNodeKindProvider
{
private const string VB_DLL = "Microsoft.CodeAnalysis.VisualBasic.dll";
private const string VB_KIND_TYPE = "Roslyn.Compilers.VisualBasic.SyntaxKind";
private Type _VBKindType;
private readonly string _folder;
public VBReflectionBasedKindProvider(string folder)
{
_folder = Path.GetFullPath(folder);
GetKindTypes();
}
private void GetKindTypes()
{
if (_VBKindType == null)
{
var asm = Assembly.LoadFrom(Path.Combine(_folder, VB_DLL));
_VBKindType = asm.GetType(VB_KIND_TYPE);
}
}
private string GetKind(object o)
{
string kind = (string)o.GetType().GetProperty("Kind").GetValue(o, new object[] { });
return Enum.Parse(_VBKindType, kind).ToString();
}
public string Kind(object node)
{
return GetKind(node);
}
}
}
......@@ -81,7 +81,7 @@ Namespace Microsoft.CodeAnalysis.VisualBasic.UnitTests.Semantics
End Sub
Private Sub CheckTree(tree As SyntaxTree)
#If False Then
#If False Then ' https://github.com/dotnet/roslyn/issues/4453
CheckAllMembers(
tree,
New Dictionary(Of Type, Func(Of Object)) From
......
......@@ -105,6 +105,12 @@
<Reference Include="System.Xml.Linq" />
</ItemGroup>
<ItemGroup>
<Compile Include="..\..\Compilers\Helpers\AbstractAnalyzerAssemblyLoader.cs">
<Link>AbstractAnalyzerAssemblyLoader.cs</Link>
</Compile>
<Compile Include="..\..\Compilers\Helpers\SimpleAnalyzerAssemblyLoader.cs">
<Link>SimpleAnalyzerAssemblyLoader.cs</Link>
</Compile>
<Compile Include="AssertEx.cs" />
<Compile Include="CLRHelpers.cs" />
<Compile Include="CommonDiagnosticAnalyzers.cs" />
......@@ -220,4 +226,4 @@
<Import Project="..\..\..\build\Targets\Roslyn.Toolsets.Xunit.targets" />
<Import Project="$(SolutionDir)\.nuget\NuGet.targets" Condition="Exists('$(SolutionDir)\.nuget\NuGet.targets')" />
</ImportGroup>
</Project>
</Project>
\ No newline at end of file
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册