Browse Source

Let's avoid switching to C# 6 for now.

pull/681/head
Daniel Grunwald 10 years ago
parent
commit
7265de118d
  1. 13
      ICSharpCode.Decompiler/Tests/FSharpPatterns/FSharpPatternTests.cs
  2. 11
      ICSharpCode.Decompiler/Tests/FSharpPatterns/TestHelpers.cs
  3. 32
      ICSharpCode.Decompiler/Tests/FSharpPatterns/ToolLocator.cs

13
ICSharpCode.Decompiler/Tests/FSharpPatterns/FSharpPatternTests.cs

@ -5,7 +5,6 @@ using System.Linq;
using System.Reflection; using System.Reflection;
using System.Text; using System.Text;
using System.Threading.Tasks; using System.Threading.Tasks;
using static ICSharpCode.Decompiler.Tests.FSharpPatterns.TestHelpers;
namespace ICSharpCode.Decompiler.Tests.FSharpPatterns namespace ICSharpCode.Decompiler.Tests.FSharpPatterns
{ {
@ -15,17 +14,17 @@ namespace ICSharpCode.Decompiler.Tests.FSharpPatterns
[Test] [Test]
public void FSharpUsingDecompilesToCSharpUsing_Debug() public void FSharpUsingDecompilesToCSharpUsing_Debug()
{ {
var ilCode = FuzzyReadResource("FSharpUsing.fs.Debug.il"); var ilCode = TestHelpers.FuzzyReadResource("FSharpUsing.fs.Debug.il");
var csharpCode = FuzzyReadResource("FSharpUsing.fs.Debug.cs"); var csharpCode = TestHelpers.FuzzyReadResource("FSharpUsing.fs.Debug.cs");
RunIL(ilCode, csharpCode); TestHelpers.RunIL(ilCode, csharpCode);
} }
[Test] [Test]
public void FSharpUsingDecompilesToCSharpUsing_Release() public void FSharpUsingDecompilesToCSharpUsing_Release()
{ {
var ilCode = FuzzyReadResource("FSharpUsing.fs.Release.il"); var ilCode = TestHelpers.FuzzyReadResource("FSharpUsing.fs.Release.il");
var csharpCode = FuzzyReadResource("FSharpUsing.fs.Release.cs"); var csharpCode = TestHelpers.FuzzyReadResource("FSharpUsing.fs.Release.cs");
RunIL(ilCode, csharpCode); TestHelpers.RunIL(ilCode, csharpCode);
} }
} }
} }

11
ICSharpCode.Decompiler/Tests/FSharpPatterns/TestHelpers.cs

@ -20,7 +20,7 @@ namespace ICSharpCode.Decompiler.Tests.FSharpPatterns
{ {
var asm = Assembly.GetExecutingAssembly(); var asm = Assembly.GetExecutingAssembly();
var allResources = asm.GetManifestResourceNames(); var allResources = asm.GetManifestResourceNames();
var fullResourceName = allResources.Single(r => r.ToLowerInvariant().EndsWith(resourceName.ToLowerInvariant())); var fullResourceName = allResources.Single(r => r.EndsWith(resourceName, StringComparison.OrdinalIgnoreCase));
return new StreamReader(asm.GetManifestResourceStream(fullResourceName)).ReadToEnd(); return new StreamReader(asm.GetManifestResourceStream(fullResourceName)).ReadToEnd();
} }
@ -33,7 +33,7 @@ namespace ICSharpCode.Decompiler.Tests.FSharpPatterns
File.WriteAllText(sourceFile, source); File.WriteAllText(sourceFile, source);
var asmFile = Path.ChangeExtension(sourceFile, ".dll"); var asmFile = Path.ChangeExtension(sourceFile, ".dll");
var sscs = new Microsoft.FSharp.Compiler.SimpleSourceCodeServices.SimpleSourceCodeServices(); var sscs = new Microsoft.FSharp.Compiler.SimpleSourceCodeServices.SimpleSourceCodeServices();
var result = sscs.Compile(new[] { "fsc.exe", "--debug:full", $"--optimize{(optimize ? "+" : "-")}", "--target:library", "-o", asmFile, sourceFile }); var result = sscs.Compile(new[] { "fsc.exe", "--debug:full", "--optimize" + (optimize ? "+" : "-"), "--target:library", "-o", asmFile, sourceFile });
File.Delete(sourceFile); File.Delete(sourceFile);
Assert.AreEqual(0, result.Item1.Length); Assert.AreEqual(0, result.Item1.Length);
Assert.AreEqual(0, result.Item2); Assert.AreEqual(0, result.Item2);
@ -54,7 +54,7 @@ namespace ICSharpCode.Decompiler.Tests.FSharpPatterns
File.WriteAllText(sourceFile, source); File.WriteAllText(sourceFile, source);
var asmFile = Path.ChangeExtension(sourceFile, ".dll"); var asmFile = Path.ChangeExtension(sourceFile, ".dll");
var args = $"{sourceFile} /dll /debug /output:{asmFile}"; var args = string.Format("{0} /dll /debug /output:{1}", sourceFile, asmFile);
using (var proc = Process.Start(new ProcessStartInfo(ilasm.Value, args) { UseShellExecute = false, })) using (var proc = Process.Start(new ProcessStartInfo(ilasm.Value, args) { UseShellExecute = false, }))
{ {
proc.WaitForExit(); proc.WaitForExit();
@ -91,8 +91,9 @@ namespace ICSharpCode.Decompiler.Tests.FSharpPatterns
// the F# assembly contains a namespace `<StartupCode$tmp6D55>` where the part after tmp is randomly generated. // the F# assembly contains a namespace `<StartupCode$tmp6D55>` where the part after tmp is randomly generated.
// remove this from the ast to simplify the diff // remove this from the ast to simplify the diff
var startupCodeNode = decompiler.SyntaxTree.Children.SingleOrDefault(d => (d as NamespaceDeclaration)?.Name?.StartsWith("<StartupCode$") ?? false); var startupCodeNode = decompiler.SyntaxTree.Children.OfType<NamespaceDeclaration>().SingleOrDefault(d => d.Name.StartsWith("<StartupCode$", StringComparison.Ordinal));
startupCodeNode?.Remove(); if (startupCodeNode != null)
startupCodeNode.Remove();
decompiler.GenerateCode(new PlainTextOutput(output)); decompiler.GenerateCode(new PlainTextOutput(output));
var fullCSharpCode = output.ToString(); var fullCSharpCode = output.ToString();

32
ICSharpCode.Decompiler/Tests/FSharpPatterns/ToolLocator.cs

@ -19,19 +19,19 @@ namespace ICSharpCode.Decompiler.Tests.FSharpPatterns
{ {
string[] windowsSdkPaths = new[] string[] windowsSdkPaths = new[]
{ {
@"Microsoft SDKs\Windows\v8.0A\bin\NETFX 4.0 Tools\", @"Microsoft SDKs\Windows\v8.0A\bin\NETFX 4.0 Tools\",
@"Microsoft SDKs\Windows\v8.0A\bin\", @"Microsoft SDKs\Windows\v8.0A\bin\",
@"Microsoft SDKs\Windows\v8.0\bin\NETFX 4.0 Tools\", @"Microsoft SDKs\Windows\v8.0\bin\NETFX 4.0 Tools\",
@"Microsoft SDKs\Windows\v8.0\bin\", @"Microsoft SDKs\Windows\v8.0\bin\",
@"Microsoft SDKs\Windows\v7.1A\bin\NETFX 4.0 Tools\", @"Microsoft SDKs\Windows\v7.1A\bin\NETFX 4.0 Tools\",
@"Microsoft SDKs\Windows\v7.1A\bin\", @"Microsoft SDKs\Windows\v7.1A\bin\",
@"Microsoft SDKs\Windows\v7.0A\bin\NETFX 4.0 Tools\", @"Microsoft SDKs\Windows\v7.0A\bin\NETFX 4.0 Tools\",
@"Microsoft SDKs\Windows\v7.0A\bin\", @"Microsoft SDKs\Windows\v7.0A\bin\",
@"Microsoft SDKs\Windows\v6.1A\bin\", @"Microsoft SDKs\Windows\v6.1A\bin\",
@"Microsoft SDKs\Windows\v6.0A\bin\", @"Microsoft SDKs\Windows\v6.0A\bin\",
@"Microsoft SDKs\Windows\v6.0\bin\", @"Microsoft SDKs\Windows\v6.0\bin\",
@"Microsoft.NET\FrameworkSDK\bin" @"Microsoft.NET\FrameworkSDK\bin"
}; };
foreach (var possiblePath in windowsSdkPaths) foreach (var possiblePath in windowsSdkPaths)
{ {
@ -71,9 +71,9 @@ namespace ICSharpCode.Decompiler.Tests.FSharpPatterns
{ {
string[] frameworkPaths = new[] string[] frameworkPaths = new[]
{ {
@"Microsoft.NET\Framework\v4.0.30319", @"Microsoft.NET\Framework\v4.0.30319",
@"Microsoft.NET\Framework\v2.0.50727" @"Microsoft.NET\Framework\v2.0.50727"
}; };
foreach (var possiblePath in frameworkPaths) foreach (var possiblePath in frameworkPaths)
{ {

Loading…
Cancel
Save