Browse Source
Added parser unit tests for bugs discovered by the round-tripping test.newNRvisualizers
16 changed files with 730 additions and 68 deletions
@ -0,0 +1,170 @@
@@ -0,0 +1,170 @@
|
||||
// Copyright (c) AlphaSierraPapa for the SharpDevelop Team
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person obtaining a copy of this
|
||||
// software and associated documentation files (the "Software"), to deal in the Software
|
||||
// without restriction, including without limitation the rights to use, copy, modify, merge,
|
||||
// publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons
|
||||
// to whom the Software is furnished to do so, subject to the following conditions:
|
||||
//
|
||||
// The above copyright notice and this permission notice shall be included in all copies or
|
||||
// substantial portions of the Software.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
|
||||
// INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
|
||||
// PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE
|
||||
// FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
|
||||
// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
||||
// DEALINGS IN THE SOFTWARE.
|
||||
|
||||
using System; |
||||
using System.Collections.Generic; |
||||
using System.IO; |
||||
using System.Linq; |
||||
using ICSharpCode.NRefactory.CSharp; |
||||
using ICSharpCode.NRefactory.CSharp.TypeSystem; |
||||
using ICSharpCode.NRefactory.Editor; |
||||
using ICSharpCode.NRefactory.TypeSystem; |
||||
|
||||
namespace ICSharpCode.NRefactory.ConsistencyCheck |
||||
{ |
||||
public class CSharpProject |
||||
{ |
||||
public readonly Solution Solution; |
||||
public readonly string Title; |
||||
public readonly string AssemblyName; |
||||
public readonly string FileName; |
||||
|
||||
public readonly List<CSharpFile> Files = new List<CSharpFile>(); |
||||
|
||||
public readonly bool AllowUnsafeBlocks; |
||||
public readonly bool CheckForOverflowUnderflow; |
||||
public readonly string[] PreprocessorDefines; |
||||
|
||||
public IProjectContent ProjectContent; |
||||
|
||||
public ICompilation Compilation { |
||||
get { |
||||
return Solution.SolutionSnapshot.GetCompilation(ProjectContent); |
||||
} |
||||
} |
||||
|
||||
public CSharpProject(Solution solution, string title, string fileName) |
||||
{ |
||||
this.Solution = solution; |
||||
this.Title = title; |
||||
this.FileName = fileName; |
||||
|
||||
var p = new Microsoft.Build.Evaluation.Project(fileName); |
||||
this.AssemblyName = p.GetPropertyValue("AssemblyName"); |
||||
this.AllowUnsafeBlocks = GetBoolProperty(p, "AllowUnsafeBlocks") ?? false; |
||||
this.CheckForOverflowUnderflow = GetBoolProperty(p, "CheckForOverflowUnderflow") ?? false; |
||||
this.PreprocessorDefines = p.GetPropertyValue("DefineConstants").Split(new char[] { ';' }, StringSplitOptions.RemoveEmptyEntries); |
||||
foreach (var item in p.GetItems("Compile")) { |
||||
Files.Add(new CSharpFile(this, Path.Combine(p.DirectoryPath, item.EvaluatedInclude))); |
||||
} |
||||
List<IAssemblyReference> references = new List<IAssemblyReference>(); |
||||
foreach (var item in p.GetItems("Reference")) { |
||||
string assemblyFileName = null; |
||||
if (item.HasMetadata("HintPath")) { |
||||
assemblyFileName = Path.Combine(p.DirectoryPath, item.GetMetadataValue("HintPath")); |
||||
if (!File.Exists(assemblyFileName)) |
||||
assemblyFileName = null; |
||||
} |
||||
if (assemblyFileName == null) { |
||||
assemblyFileName = FindAssembly(Program.AssemblySearchPaths, item.EvaluatedInclude); |
||||
} |
||||
if (assemblyFileName != null) { |
||||
references.Add(Program.LoadAssembly(assemblyFileName)); |
||||
} else { |
||||
Console.WriteLine("Could not find referenced assembly " + item.EvaluatedInclude); |
||||
} |
||||
} |
||||
foreach (var item in p.GetItems("ProjectReference")) { |
||||
references.Add(new ProjectReference(solution, item.GetMetadataValue("Name"))); |
||||
} |
||||
this.ProjectContent = new CSharpProjectContent() |
||||
.SetAssemblyName(this.AssemblyName) |
||||
.AddAssemblyReferences(references) |
||||
.UpdateProjectContent(null, Files.Select(f => f.ParsedFile)); |
||||
} |
||||
|
||||
string FindAssembly(IEnumerable<string> assemblySearchPaths, string evaluatedInclude) |
||||
{ |
||||
if (evaluatedInclude.IndexOf(',') >= 0) |
||||
evaluatedInclude = evaluatedInclude.Substring(0, evaluatedInclude.IndexOf(',')); |
||||
foreach (string searchPath in assemblySearchPaths) { |
||||
string assemblyFile = Path.Combine(searchPath, evaluatedInclude + ".dll"); |
||||
if (File.Exists(assemblyFile)) |
||||
return assemblyFile; |
||||
} |
||||
return null; |
||||
} |
||||
|
||||
static bool? GetBoolProperty(Microsoft.Build.Evaluation.Project p, string propertyName) |
||||
{ |
||||
string val = p.GetPropertyValue(propertyName); |
||||
if (val.Equals("true", StringComparison.OrdinalIgnoreCase)) |
||||
return true; |
||||
if (val.Equals("false", StringComparison.OrdinalIgnoreCase)) |
||||
return false; |
||||
return null; |
||||
} |
||||
|
||||
public CSharpParser CreateParser() |
||||
{ |
||||
List<string> args = new List<string>(); |
||||
if (AllowUnsafeBlocks) |
||||
args.Add("-unsafe"); |
||||
foreach (string define in PreprocessorDefines) |
||||
args.Add("-d:" + define); |
||||
return new CSharpParser(args.ToArray()); |
||||
} |
||||
} |
||||
|
||||
public class ProjectReference : IAssemblyReference |
||||
{ |
||||
readonly Solution solution; |
||||
readonly string projectTitle; |
||||
|
||||
public ProjectReference(Solution solution, string projectTitle) |
||||
{ |
||||
this.solution = solution; |
||||
this.projectTitle = projectTitle; |
||||
} |
||||
|
||||
public IAssembly Resolve(ITypeResolveContext context) |
||||
{ |
||||
var project = solution.Projects.Single(p => string.Equals(p.Title, projectTitle, StringComparison.OrdinalIgnoreCase)); |
||||
return project.ProjectContent.Resolve(context); |
||||
} |
||||
} |
||||
|
||||
public class CSharpFile |
||||
{ |
||||
public readonly CSharpProject Project; |
||||
public readonly string FileName; |
||||
|
||||
public readonly ITextSource Content; |
||||
public readonly int LinesOfCode; |
||||
public CompilationUnit CompilationUnit; |
||||
public CSharpParsedFile ParsedFile; |
||||
|
||||
public CSharpFile(CSharpProject project, string fileName) |
||||
{ |
||||
this.Project = project; |
||||
this.FileName = fileName; |
||||
this.Content = new StringTextSource(File.ReadAllText(FileName)); |
||||
this.LinesOfCode = 1 + this.Content.Text.Count(c => c == '\n'); |
||||
|
||||
CSharpParser p = project.CreateParser(); |
||||
this.CompilationUnit = p.Parse(Content.CreateReader(), fileName); |
||||
if (p.HasErrors) { |
||||
Console.WriteLine("Error parsing " + fileName + ":"); |
||||
foreach (var error in p.ErrorPrinter.Errors) { |
||||
Console.WriteLine(" " + error.Region + " " + error.Message); |
||||
} |
||||
} |
||||
this.ParsedFile = this.CompilationUnit.ToTypeSystem(); |
||||
} |
||||
} |
||||
} |
@ -0,0 +1,71 @@
@@ -0,0 +1,71 @@
|
||||
<?xml version="1.0" encoding="utf-8"?> |
||||
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003" DefaultTargets="Build"> |
||||
<PropertyGroup> |
||||
<ProjectGuid>{D81206EF-3DCA-4A30-897B-E262A2AD9EE3}</ProjectGuid> |
||||
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration> |
||||
<Platform Condition=" '$(Platform)' == '' ">x86</Platform> |
||||
<OutputType>Exe</OutputType> |
||||
<RootNamespace>ICSharpCode.NRefactory.ConsistencyCheck</RootNamespace> |
||||
<AssemblyName>ICSharpCode.NRefactory.ConsistencyCheck</AssemblyName> |
||||
<TargetFrameworkVersion>v4.0</TargetFrameworkVersion> |
||||
<TargetFrameworkProfile> |
||||
</TargetFrameworkProfile> |
||||
<AppDesignerFolder>Properties</AppDesignerFolder> |
||||
</PropertyGroup> |
||||
<PropertyGroup Condition=" '$(Platform)' == 'x86' "> |
||||
<PlatformTarget>x86</PlatformTarget> |
||||
</PropertyGroup> |
||||
<PropertyGroup Condition=" '$(Configuration)' == 'Debug' "> |
||||
<OutputPath>bin\Debug\</OutputPath> |
||||
<DebugSymbols>True</DebugSymbols> |
||||
<DebugType>Full</DebugType> |
||||
<Optimize>False</Optimize> |
||||
<CheckForOverflowUnderflow>True</CheckForOverflowUnderflow> |
||||
<DefineConstants>DEBUG;TRACE</DefineConstants> |
||||
</PropertyGroup> |
||||
<PropertyGroup Condition=" '$(Configuration)' == 'Release' "> |
||||
<OutputPath>bin\Release\</OutputPath> |
||||
<DebugSymbols>False</DebugSymbols> |
||||
<DebugType>None</DebugType> |
||||
<Optimize>True</Optimize> |
||||
<CheckForOverflowUnderflow>False</CheckForOverflowUnderflow> |
||||
<DefineConstants>TRACE</DefineConstants> |
||||
</PropertyGroup> |
||||
<ItemGroup> |
||||
<Reference Include="Microsoft.Build" /> |
||||
<Reference Include="System" /> |
||||
<Reference Include="System.Core"> |
||||
<RequiredTargetFramework>3.5</RequiredTargetFramework> |
||||
</Reference> |
||||
<Reference Include="System.Data" /> |
||||
<Reference Include="System.Data.DataSetExtensions"> |
||||
<RequiredTargetFramework>3.5</RequiredTargetFramework> |
||||
</Reference> |
||||
<Reference Include="System.Xml" /> |
||||
<Reference Include="System.Xml.Linq"> |
||||
<RequiredTargetFramework>3.5</RequiredTargetFramework> |
||||
</Reference> |
||||
</ItemGroup> |
||||
<ItemGroup> |
||||
<Compile Include="CSharpProject.cs" /> |
||||
<Compile Include="Program.cs" /> |
||||
<Compile Include="Properties\AssemblyInfo.cs" /> |
||||
<Compile Include="RoundtripTest.cs" /> |
||||
<Compile Include="Solution.cs" /> |
||||
</ItemGroup> |
||||
<ItemGroup> |
||||
<None Include="app.config" /> |
||||
<None Include="Readme.txt" /> |
||||
</ItemGroup> |
||||
<ItemGroup> |
||||
<ProjectReference Include="..\ICSharpCode.NRefactory.CSharp\ICSharpCode.NRefactory.CSharp.csproj"> |
||||
<Project>{53DCA265-3C3C-42F9-B647-F72BA678122B}</Project> |
||||
<Name>ICSharpCode.NRefactory.CSharp</Name> |
||||
</ProjectReference> |
||||
<ProjectReference Include="..\ICSharpCode.NRefactory\ICSharpCode.NRefactory.csproj"> |
||||
<Project>{3B2A5653-EC97-4001-BB9B-D90F1AF2C371}</Project> |
||||
<Name>ICSharpCode.NRefactory</Name> |
||||
</ProjectReference> |
||||
</ItemGroup> |
||||
<Import Project="$(MSBuildBinPath)\Microsoft.CSharp.Targets" /> |
||||
</Project> |
@ -0,0 +1,84 @@
@@ -0,0 +1,84 @@
|
||||
// Copyright (c) AlphaSierraPapa for the SharpDevelop Team
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person obtaining a copy of this
|
||||
// software and associated documentation files (the "Software"), to deal in the Software
|
||||
// without restriction, including without limitation the rights to use, copy, modify, merge,
|
||||
// publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons
|
||||
// to whom the Software is furnished to do so, subject to the following conditions:
|
||||
//
|
||||
// The above copyright notice and this permission notice shall be included in all copies or
|
||||
// substantial portions of the Software.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
|
||||
// INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
|
||||
// PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE
|
||||
// FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
|
||||
// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
||||
// DEALINGS IN THE SOFTWARE.
|
||||
|
||||
using System; |
||||
using System.Collections.Concurrent; |
||||
using System.Diagnostics; |
||||
using System.IO; |
||||
using System.Linq; |
||||
using ICSharpCode.NRefactory.TypeSystem; |
||||
using ICSharpCode.NRefactory.Utils; |
||||
|
||||
namespace ICSharpCode.NRefactory.ConsistencyCheck |
||||
{ |
||||
class Program |
||||
{ |
||||
public static readonly string[] AssemblySearchPaths = { |
||||
@"C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETFramework\v4.0", |
||||
@"C:\Program Files (x86)\GtkSharp\2.12\lib\gtk-sharp-2.0", |
||||
@"C:\Program Files (x86)\GtkSharp\2.12\lib\Mono.Posix", |
||||
}; |
||||
|
||||
public const string TempPath = @"C:\temp"; |
||||
|
||||
public static void Main(string[] args) |
||||
{ |
||||
Solution sln; |
||||
using (new Timer("Loading solution... ")) { |
||||
sln = new Solution(Path.GetFullPath("../../../NRefactory.sln")); |
||||
} |
||||
|
||||
Console.WriteLine("Loaded {0} lines of code ({1:f1} MB) in {2} files in {3} projects.", |
||||
sln.AllFiles.Sum(f => f.LinesOfCode), |
||||
sln.AllFiles.Sum(f => f.Content.TextLength) / 1024.0 / 1024.0, |
||||
sln.AllFiles.Count(), |
||||
sln.Projects.Count); |
||||
|
||||
using (new Timer("Roundtripping tests... ")) { |
||||
foreach (var file in sln.AllFiles) { |
||||
RoundtripTest.RunTest(file); |
||||
} |
||||
} |
||||
|
||||
Console.Write("Press any key to continue . . . "); |
||||
Console.ReadKey(true); |
||||
} |
||||
|
||||
static ConcurrentDictionary<string, IUnresolvedAssembly> assemblyDict = new ConcurrentDictionary<string, IUnresolvedAssembly>(Platform.FileNameComparer); |
||||
|
||||
public static IUnresolvedAssembly LoadAssembly(string assemblyFileName) |
||||
{ |
||||
return assemblyDict.GetOrAdd(assemblyFileName, file => new CecilLoader().LoadAssemblyFile(file)); |
||||
} |
||||
|
||||
sealed class Timer : IDisposable |
||||
{ |
||||
Stopwatch w = Stopwatch.StartNew(); |
||||
|
||||
public Timer(string title) |
||||
{ |
||||
Console.Write(title); |
||||
} |
||||
|
||||
public void Dispose() |
||||
{ |
||||
Console.WriteLine(w.Elapsed); |
||||
} |
||||
} |
||||
} |
||||
} |
@ -0,0 +1,31 @@
@@ -0,0 +1,31 @@
|
||||
#region Using directives
|
||||
|
||||
using System; |
||||
using System.Reflection; |
||||
using System.Runtime.InteropServices; |
||||
|
||||
#endregion
|
||||
|
||||
// General Information about an assembly is controlled through the following
|
||||
// set of attributes. Change these attribute values to modify the information
|
||||
// associated with an assembly.
|
||||
[assembly: AssemblyTitle("ICSharpCode.NRefactory.ConsistencyCheck")] |
||||
[assembly: AssemblyDescription("")] |
||||
[assembly: AssemblyConfiguration("")] |
||||
[assembly: AssemblyCompany("")] |
||||
[assembly: AssemblyProduct("ICSharpCode.NRefactory.ConsistencyCheck")] |
||||
[assembly: AssemblyCopyright("Copyright 2011")] |
||||
[assembly: AssemblyTrademark("")] |
||||
[assembly: AssemblyCulture("")] |
||||
|
||||
// This sets the default COM visibility of types in the assembly to invisible.
|
||||
// If you need to expose a type to COM, use [ComVisible(true)] on that type.
|
||||
[assembly: ComVisible(false)] |
||||
|
||||
// The assembly version has following format :
|
||||
//
|
||||
// Major.Minor.Build.Revision
|
||||
//
|
||||
// You can specify all the values or you can use the default the Revision and
|
||||
// Build Numbers by using the '*' as shown below:
|
||||
[assembly: AssemblyVersion("1.0.*")] |
@ -0,0 +1,8 @@
@@ -0,0 +1,8 @@
|
||||
This is an automatic consistency check for NRefactory. |
||||
It loads a solution file and parses all the source code and referenced libraries, |
||||
and then performs a set of consistency checks. |
||||
These checks assume that the code is valid C# without any compilation errors, |
||||
so make sure to only pass in compilable source code. |
||||
|
||||
Checks currently being performed: |
||||
- |
@ -0,0 +1,104 @@
@@ -0,0 +1,104 @@
|
||||
// Copyright (c) AlphaSierraPapa for the SharpDevelop Team
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person obtaining a copy of this
|
||||
// software and associated documentation files (the "Software"), to deal in the Software
|
||||
// without restriction, including without limitation the rights to use, copy, modify, merge,
|
||||
// publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons
|
||||
// to whom the Software is furnished to do so, subject to the following conditions:
|
||||
//
|
||||
// The above copyright notice and this permission notice shall be included in all copies or
|
||||
// substantial portions of the Software.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
|
||||
// INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
|
||||
// PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE
|
||||
// FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
|
||||
// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
||||
// DEALINGS IN THE SOFTWARE.
|
||||
|
||||
using System; |
||||
using System.IO; |
||||
using System.Text; |
||||
using ICSharpCode.NRefactory.CSharp; |
||||
using ICSharpCode.NRefactory.Editor; |
||||
using ICSharpCode.NRefactory.PatternMatching; |
||||
|
||||
namespace ICSharpCode.NRefactory.ConsistencyCheck |
||||
{ |
||||
public class RoundtripTest |
||||
{ |
||||
public static void RunTest(CSharpFile file) |
||||
{ |
||||
// TODO: also try Windows-style newlines once the parser bug with integer literals followed by \r is fixed
|
||||
string code = file.Content.Text.Replace("\r\n", "\n"); |
||||
if (code.Contains("#pragma")) |
||||
return; // skip code with preprocessor directives
|
||||
if (code.Contains("enum VarianceModifier") || file.FileName.EndsWith("ecore.cs") || file.FileName.EndsWith("method.cs")) |
||||
return; // skip enum with ; at end (see TypeDeclarationTests.EnumWithSemicolonAtEnd)
|
||||
if (file.FileName.EndsWith("KnownTypeReference.cs") || file.FileName.EndsWith("typemanager.cs") || file.FileName.EndsWith("GetAllBaseTypesTest.cs") || file.FileName.EndsWith("Tokens.cs") || file.FileName.EndsWith("OpCode.cs") || file.FileName.EndsWith("MainWindow.cs")) |
||||
return; // skip due to optional , at end of array initializer (see ArrayCreateExpressionTests.ArrayInitializerWithCommaAtEnd)
|
||||
if (file.FileName.EndsWith("cs-parser.cs")) |
||||
return; // skip due to completely messed up comment locations
|
||||
if (file.FileName.EndsWith("PrimitiveExpressionTests.cs")) |
||||
return; // skip due to PrimitiveExpressionTests.*WithLeadingDot
|
||||
if (file.FileName.Contains("FormattingTests") || file.FileName.Contains("ContextAction") || file.FileName.Contains("CodeCompletion")) |
||||
return; // skip due to AttributeSectionTests.AttributeWithEmptyParenthesis
|
||||
if (file.FileName.EndsWith("TypeSystemTests.TestCase.cs")) |
||||
return; // skip due to AttributeSectionTests.AssemblyAttributeBeforeNamespace
|
||||
if (file.FileName.EndsWith("dynamic.cs") || file.FileName.EndsWith("expression.cs")) |
||||
return; // skip due to PreprocessorDirectiveTests.NestedInactiveIf
|
||||
if (file.FileName.EndsWith("property.cs")) |
||||
return; // skip due to PreprocessorDirectiveTests.CommentOnEndOfIfDirective
|
||||
|
||||
Roundtrip(file.Project.CreateParser(), file.FileName, code); |
||||
} |
||||
|
||||
public static void Roundtrip(CSharpParser parser, string fileName, string code) |
||||
{ |
||||
// 1. Parse
|
||||
CompilationUnit cu = parser.Parse(code, fileName); |
||||
if (parser.HasErrors) |
||||
throw new InvalidOperationException("There were parse errors."); |
||||
|
||||
// 2. Output
|
||||
StringWriter w = new StringWriter(); |
||||
cu.AcceptVisitor(new CSharpOutputVisitor(w, new CSharpFormattingOptions())); |
||||
string generatedCode = w.ToString().TrimEnd(); |
||||
|
||||
// 3. Compare output with original (modulo whitespaces)
|
||||
int pos2 = 0; |
||||
for (int pos1 = 0; pos1 < code.Length; pos1++) { |
||||
if (!char.IsWhiteSpace(code[pos1])) { |
||||
while (pos2 < generatedCode.Length && char.IsWhiteSpace(generatedCode[pos2])) |
||||
pos2++; |
||||
if (pos2 >= generatedCode.Length || code[pos1] != generatedCode[pos2]) { |
||||
ReadOnlyDocument doc = new ReadOnlyDocument(code); |
||||
File.WriteAllText(Path.Combine(Program.TempPath, "roundtrip-error.cs"), generatedCode); |
||||
throw new InvalidOperationException("Mismatch at " + doc.GetLocation(pos1) + " of file " + fileName); |
||||
} |
||||
pos2++; |
||||
} |
||||
} |
||||
if (pos2 != generatedCode.Length) |
||||
throw new InvalidOperationException("Mismatch at end of file " + fileName); |
||||
|
||||
// 4. Parse generated output
|
||||
CompilationUnit generatedCU; |
||||
try { |
||||
generatedCU = parser.Parse(generatedCode, fileName); |
||||
} catch { |
||||
File.WriteAllText(Path.Combine(Program.TempPath, "roundtrip-error.cs"), generatedCode, Encoding.Unicode); |
||||
throw; |
||||
} |
||||
|
||||
if (parser.HasErrors) { |
||||
File.WriteAllText(Path.Combine(Program.TempPath, "roundtrip-error.cs"), generatedCode); |
||||
throw new InvalidOperationException("There were parse errors in the roundtripped " + fileName); |
||||
} |
||||
|
||||
// 5. Compare AST1 with AST2
|
||||
if (!cu.IsMatch(generatedCU)) |
||||
throw new InvalidOperationException("AST match failed for " + fileName + "."); |
||||
} |
||||
} |
||||
} |
@ -0,0 +1,67 @@
@@ -0,0 +1,67 @@
|
||||
// Copyright (c) AlphaSierraPapa for the SharpDevelop Team
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person obtaining a copy of this
|
||||
// software and associated documentation files (the "Software"), to deal in the Software
|
||||
// without restriction, including without limitation the rights to use, copy, modify, merge,
|
||||
// publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons
|
||||
// to whom the Software is furnished to do so, subject to the following conditions:
|
||||
//
|
||||
// The above copyright notice and this permission notice shall be included in all copies or
|
||||
// substantial portions of the Software.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
|
||||
// INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
|
||||
// PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE
|
||||
// FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
|
||||
// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
||||
// DEALINGS IN THE SOFTWARE.
|
||||
|
||||
using System; |
||||
using System.Collections.Generic; |
||||
using System.IO; |
||||
using System.Linq; |
||||
using System.Text.RegularExpressions; |
||||
using ICSharpCode.NRefactory.TypeSystem; |
||||
using ICSharpCode.NRefactory.TypeSystem.Implementation; |
||||
|
||||
namespace ICSharpCode.NRefactory.ConsistencyCheck |
||||
{ |
||||
public class Solution |
||||
{ |
||||
public readonly string Directory; |
||||
public readonly List<CSharpProject> Projects = new List<CSharpProject>(); |
||||
public readonly ISolutionSnapshot SolutionSnapshot = new DefaultSolutionSnapshot(); |
||||
|
||||
public IEnumerable<CSharpFile> AllFiles { |
||||
get { |
||||
return Projects.SelectMany(p => p.Files); |
||||
} |
||||
} |
||||
|
||||
public Solution(string fileName) |
||||
{ |
||||
this.Directory = Path.GetDirectoryName(fileName); |
||||
var projectLinePattern = new Regex("Project\\(\"(?<TypeGuid>.*)\"\\)\\s+=\\s+\"(?<Title>.*)\",\\s*\"(?<Location>.*)\",\\s*\"(?<Guid>.*)\""); |
||||
foreach (string line in File.ReadLines(fileName)) { |
||||
Match match = projectLinePattern.Match(line); |
||||
if (match.Success) { |
||||
string typeGuid = match.Groups["TypeGuid"].Value; |
||||
string title = match.Groups["Title"].Value; |
||||
string location = match.Groups["Location"].Value; |
||||
string guid = match.Groups["Guid"].Value; |
||||
switch (typeGuid.ToUpperInvariant()) { |
||||
case "{2150E333-8FDC-42A3-9474-1A3956D46DE8}": // Solution Folder
|
||||
// ignore folders
|
||||
break; |
||||
case "{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}": // C# project
|
||||
Projects.Add(new CSharpProject(this, title, Path.Combine(Directory, location))); |
||||
break; |
||||
default: |
||||
Console.WriteLine("Project {0} has unsupported type {1}", location, typeGuid); |
||||
break; |
||||
} |
||||
} |
||||
} |
||||
} |
||||
} |
||||
} |
@ -0,0 +1,6 @@
@@ -0,0 +1,6 @@
|
||||
<?xml version="1.0" encoding="utf-8"?> |
||||
<configuration> |
||||
<startup> |
||||
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.0" /> |
||||
</startup> |
||||
</configuration> |
Loading…
Reference in new issue