You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

132 lines
3.4 KiB

  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.IO;
  20. using System.Linq;
  21. using System.Runtime.CompilerServices;
  22. using ICSharpCode.Decompiler.Tests.Helpers;
  23. using NUnit.Framework;
  24. namespace ICSharpCode.Decompiler.Tests
  25. {
  26. [TestFixture, Parallelizable(ParallelScope.All)]
  27. public class ILPrettyTestRunner
  28. {
  29. static readonly string TestCasePath = DecompilerTestBase.TestCasePath + "/ILPretty";
  30. [Test]
  31. public void AllFilesHaveTests()
  32. {
  33. var testNames = typeof(ILPrettyTestRunner).GetMethods()
  34. .Where(m => m.GetCustomAttributes(typeof(TestAttribute), false).Any())
  35. .Select(m => m.Name)
  36. .ToArray();
  37. foreach (var file in new DirectoryInfo(TestCasePath).EnumerateFiles()) {
  38. if (file.Extension.Equals(".il", StringComparison.OrdinalIgnoreCase)) {
  39. var testName = file.Name.Split('.')[0];
  40. Assert.Contains(testName, testNames);
  41. Assert.IsTrue(File.Exists(Path.Combine(TestCasePath, testName + ".cs")));
  42. }
  43. }
  44. }
  45. [Test, Ignore("Need to decide how to represent virtual methods without 'newslot' flag")]
  46. public void Issue379()
  47. {
  48. Run();
  49. }
  50. [Test]
  51. public void Issue646()
  52. {
  53. Run();
  54. }
  55. [Test]
  56. public void Issue959()
  57. {
  58. Run();
  59. }
  60. [Test]
  61. public void Issue982()
  62. {
  63. Run();
  64. }
  65. [Test]
  66. public void Issue1038()
  67. {
  68. Run();
  69. }
  70. [Test]
  71. public void Issue1047()
  72. {
  73. Run();
  74. }
  75. [Test]
  76. public void FSharpUsing_Debug()
  77. {
  78. Run(settings: new DecompilerSettings { RemoveDeadCode = true });
  79. }
  80. [Test]
  81. public void FSharpUsing_Release()
  82. {
  83. Run(settings: new DecompilerSettings { RemoveDeadCode = true });
  84. }
  85. [Test]
  86. public void CS1xSwitch_Debug()
  87. {
  88. Run();
  89. }
  90. [Test]
  91. public void CS1xSwitch_Release()
  92. {
  93. Run();
  94. }
  95. [Test, Ignore("?")]
  96. public void FSharpLoops_Debug()
  97. {
  98. Run(settings: new DecompilerSettings { RemoveDeadCode = true });
  99. }
  100. [Test, Ignore("?")]
  101. public void FSharpLoops_Release()
  102. {
  103. Run(settings: new DecompilerSettings { RemoveDeadCode = true });
  104. }
  105. void Run([CallerMemberName] string testName = null, DecompilerSettings settings = null)
  106. {
  107. var ilFile = Path.Combine(TestCasePath, testName + ".il");
  108. var csFile = Path.Combine(TestCasePath, testName + ".cs");
  109. var executable = Tester.AssembleIL(ilFile, AssemblerOptions.Library);
  110. var decompiled = Tester.DecompileCSharp(executable, settings);
  111. CodeAssert.FilesAreEqual(csFile, decompiled);
  112. }
  113. }
  114. }