Apply changes from https://github.com/dotnet/runtime/commit/eb1756e97d23df13bc6fe798e...
[mono-project.git] / mono / tests / verbose.cs
blob2c609567dbf78723ff5b1edb949bfeee29ef0638
1 using System;
2 using System.Diagnostics;
3 using System.Linq;
4 using System.Reflection;
5 using System.Text.RegularExpressions;
7 public class MainClass
9 class TestCase
11 public string MethodSpec;
12 public string[] ExpectedMethods;
15 public static int Main (string[] args)
17 var testCase = new TestCase {
18 MethodSpec = "*:Method",
19 ExpectedMethods = new[] {
20 "N1.Test:Method ()",
21 "N2.Test:Method ()",
22 "N2.Test:Method (int)",
23 "N2.Test:Method (int,string[])",
26 if (!RunTest (testCase))
27 return 1;
29 testCase = new TestCase {
30 MethodSpec = "*:Method (int)",
31 ExpectedMethods = new[] {
32 "N2.Test:Method (int)",
35 if (!RunTest (testCase))
36 return 2;
38 testCase = new TestCase
40 MethodSpec = "N1.Test:Method",
41 ExpectedMethods = new[] {
42 "N1.Test:Method ()",
45 if (!RunTest (testCase))
46 return 3;
48 testCase = new TestCase {
49 MethodSpec = "Test:Method",
50 ExpectedMethods = new[] {
51 "N1.Test:Method ()",
52 "N2.Test:Method ()",
53 "N2.Test:Method (int)",
54 "N2.Test:Method (int,string[])",
57 if (!RunTest (testCase))
58 return 4;
60 testCase = new TestCase {
61 MethodSpec = "*:Method(int,string[])",
62 ExpectedMethods = new[] {
63 "N2.Test:Method (int,string[])",
66 if (!RunTest (testCase))
67 return 5;
69 testCase = new TestCase {
70 MethodSpec = "*:Method();N2.*:Method(int,string[])",
71 ExpectedMethods = new[] {
72 "N1.Test:Method ()",
73 "N2.Test:Method ()",
74 "N2.Test:Method (int,string[])",
77 if (!RunTest (testCase))
78 return 6;
80 return 0;
83 static bool RunTest (TestCase testCase)
85 var thisProcess = typeof (MainClass).Assembly.Location;
87 var process = StartCompileAssemblyProcess (thisProcess, testCase.MethodSpec);
88 var output = process.StandardOutput.ReadToEnd ();
89 process.WaitForExit ();
91 var lines = output.Split (new[] { Environment.NewLine }, StringSplitOptions.RemoveEmptyEntries);
92 foreach (var expectedMethod in testCase.ExpectedMethods) {
93 var sortedExpectedMethods = testCase.ExpectedMethods.OrderBy (x => x).ToArray ();
95 var regex = new Regex ("converting method void (?<methodName>.*)");
96 var matches = regex.Matches (output);
97 var sortedJittedMethods = matches.Cast<Match> ().Select (x => x.Groups["methodName"])
98 .SelectMany (x => x.Captures.Cast<Capture> ())
99 .Select (x => x.Value)
100 .OrderBy (x => x)
101 .ToArray ();
103 if (sortedJittedMethods.Length != sortedExpectedMethods.Length)
104 return false;
106 for (int i = 0; i < sortedJittedMethods.Length; ++i) {
107 if (sortedJittedMethods[i] != sortedExpectedMethods[i])
108 return false;
113 return true;
116 static Process StartCompileAssemblyProcess (string process, string methodSpec)
118 var psi = new ProcessStartInfo (process) {
119 UseShellExecute = false,
120 RedirectStandardOutput = true,
122 psi.EnvironmentVariables["MONO_ENV_OPTIONS"] = "--compile-all";
123 psi.EnvironmentVariables["MONO_VERBOSE_METHOD"] = methodSpec;
125 return Process.Start (psi);
129 namespace N1
131 public class Test
133 public static void Method ()
139 namespace N2
141 public class Test
143 public static void Method (int n)
147 public static void Method ()
151 public static void Method (int n, string[] args)