/ICSharpCode.Decompiler/Tests/TestRunner.cs

http://github.com/icsharpcode/ILSpy · C# · 205 lines · 158 code · 28 blank · 19 comment · 0 complexity · bd174c17305c186d3223e3cfe2c4e34d MD5 · raw file

  1. // Copyright (c) AlphaSierraPapa for the SharpDevelop Team
  2. //
  3. // Permission is hereby granted, free of charge, to any person obtaining a copy of this
  4. // software and associated documentation files (the "Software"), to deal in the Software
  5. // without restriction, including without limitation the rights to use, copy, modify, merge,
  6. // publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons
  7. // to whom the Software is furnished to do so, subject to the following conditions:
  8. //
  9. // The above copyright notice and this permission notice shall be included in all copies or
  10. // substantial portions of the Software.
  11. //
  12. // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
  13. // INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
  14. // PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE
  15. // FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
  16. // OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
  17. // DEALINGS IN THE SOFTWARE.
  18. using System;
  19. using System.CodeDom.Compiler;
  20. using System.Collections.Generic;
  21. using System.IO;
  22. using System.Linq;
  23. using System.Text;
  24. using DiffLib;
  25. using ICSharpCode.Decompiler.Ast;
  26. using ICSharpCode.Decompiler.Tests.Helpers;
  27. using Microsoft.CSharp;
  28. using Mono.Cecil;
  29. using NUnit.Framework;
  30. namespace ICSharpCode.Decompiler.Tests
  31. {
  32. [TestFixture]
  33. public class TestRunner : DecompilerTestBase
  34. {
  35. [Test]
  36. public void Async()
  37. {
  38. TestFile(@"..\..\Tests\Async.cs");
  39. }
  40. [Test, Ignore("disambiguating overloads is not yet implemented")]
  41. public void CallOverloadedMethod()
  42. {
  43. TestFile(@"..\..\Tests\CallOverloadedMethod.cs");
  44. }
  45. [Test, Ignore("unncessary primitive casts")]
  46. public void CheckedUnchecked()
  47. {
  48. TestFile(@"..\..\Tests\CheckedUnchecked.cs");
  49. }
  50. [Test, Ignore("Missing cast on null")]
  51. public void DelegateConstruction()
  52. {
  53. TestFile(@"..\..\Tests\DelegateConstruction.cs");
  54. }
  55. [Test, Ignore("Not yet implemented")]
  56. public void ExpressionTrees()
  57. {
  58. TestFile(@"..\..\Tests\ExpressionTrees.cs");
  59. }
  60. [Test]
  61. public void ExceptionHandling()
  62. {
  63. AssertRoundtripCode(@"..\..\Tests\ExceptionHandling.cs", optimize: false);
  64. AssertRoundtripCode(@"..\..\Tests\ExceptionHandling.cs", optimize: false);
  65. }
  66. [Test]
  67. public void Generics()
  68. {
  69. TestFile(@"..\..\Tests\Generics.cs");
  70. }
  71. [Test]
  72. public void CustomShortCircuitOperators()
  73. {
  74. TestFile(@"..\..\Tests\CustomShortCircuitOperators.cs");
  75. }
  76. [Test]
  77. public void ControlFlowWithDebug()
  78. {
  79. AssertRoundtripCode(@"..\..\Tests\ControlFlow.cs", optimize: false, useDebug: true);
  80. AssertRoundtripCode(@"..\..\Tests\ControlFlow.cs", optimize: false, useDebug: true);
  81. }
  82. [Test]
  83. public void DoubleConstants()
  84. {
  85. TestFile(@"..\..\Tests\DoubleConstants.cs");
  86. }
  87. [Test]
  88. public void IncrementDecrement()
  89. {
  90. TestFile(@"..\..\Tests\IncrementDecrement.cs");
  91. }
  92. [Test]
  93. public void InitializerTests()
  94. {
  95. TestFile(@"..\..\Tests\InitializerTests.cs");
  96. }
  97. [Test]
  98. public void LiftedOperators()
  99. {
  100. TestFile(@"..\..\Tests\LiftedOperators.cs");
  101. }
  102. [Test]
  103. public void Lock()
  104. {
  105. //TestFile(@"..\..\Tests\Lock.cs", compilerVersion: 2);
  106. TestFile(@"..\..\Tests\Lock.cs", compilerVersion: 4);
  107. }
  108. [Test]
  109. public void Loops()
  110. {
  111. TestFile(@"..\..\Tests\Loops.cs");
  112. }
  113. [Test]
  114. public void MultidimensionalArray()
  115. {
  116. TestFile(@"..\..\Tests\MultidimensionalArray.cs");
  117. }
  118. [Test]
  119. public void PInvoke()
  120. {
  121. TestFile(@"..\..\Tests\PInvoke.cs");
  122. }
  123. [Test]
  124. public void PropertiesAndEvents()
  125. {
  126. TestFile(@"..\..\Tests\PropertiesAndEvents.cs");
  127. }
  128. [Test]
  129. public void QueryExpressions()
  130. {
  131. TestFile(@"..\..\Tests\QueryExpressions.cs");
  132. }
  133. [Test, Ignore("switch transform doesn't recreate the exact original switch")]
  134. public void Switch()
  135. {
  136. TestFile(@"..\..\Tests\Switch.cs");
  137. }
  138. [Test]
  139. public void UndocumentedExpressions()
  140. {
  141. TestFile(@"..\..\Tests\UndocumentedExpressions.cs");
  142. }
  143. [Test, Ignore("has incorrect casts to IntPtr")]
  144. public void UnsafeCode()
  145. {
  146. TestFile(@"..\..\Tests\UnsafeCode.cs");
  147. }
  148. [Test]
  149. public void ValueTypes()
  150. {
  151. TestFile(@"..\..\Tests\ValueTypes.cs");
  152. }
  153. [Test, Ignore("Redundant yield break; not removed")]
  154. public void YieldReturn()
  155. {
  156. TestFile(@"..\..\Tests\YieldReturn.cs");
  157. }
  158. [Test]
  159. public void TypeAnalysis()
  160. {
  161. TestFile(@"..\..\Tests\TypeAnalysisTests.cs");
  162. }
  163. // see https://github.com/icsharpcode/ILSpy/pull/671
  164. [Test]
  165. public void NotUsingBlock()
  166. {
  167. TestFile(@"..\..\Tests\NotUsingBlock.cs");
  168. }
  169. static void TestFile(string fileName, bool useDebug = false, int compilerVersion = 4)
  170. {
  171. AssertRoundtripCode(fileName, optimize: false, useDebug: useDebug, compilerVersion: compilerVersion);
  172. AssertRoundtripCode(fileName, optimize: true, useDebug: useDebug, compilerVersion: compilerVersion);
  173. AssertRoundtripCode(fileName, optimize: false, useDebug: useDebug, compilerVersion: compilerVersion);
  174. AssertRoundtripCode(fileName, optimize: true, useDebug: useDebug, compilerVersion: compilerVersion);
  175. }
  176. }
  177. }