* TextControl.cs: Make PageUp and PageDown more like the
[mono-project.git] / mono / mini / TestDriver.cs
blob05facbab37795bd1845b656a50baceb3c5c57fc6
1 using System;
2 using System.Reflection;
5 public class TestDriver {
7 static public int RunTests (Type type, string[] args) {
8 int failed = 0, ran = 0;
9 int result, expected, elen;
10 int i, j;
11 string name;
12 MethodInfo[] methods;
13 bool do_timings = false;
14 bool verbose = false;
15 int tms = 0;
16 DateTime start, end = DateTime.Now;
18 if (args != null && args.Length > 0) {
19 for (j = 0; j < args.Length; j++) {
20 bool found = false;
21 if (args [j] == "--time") {
22 do_timings = true;
23 found = true;
25 if ((args [j] == "-v") || (args [j] == "--verbose")) {
26 verbose = true;
27 found = true;
30 if (found) {
31 string[] new_args = new string [args.Length - 1];
32 for (i = 0; i < j; ++i)
33 new_args [i] = args [i];
34 j++;
35 for (; j < args.Length; ++i, ++j)
36 new_args [i] = args [j];
37 args = new_args;
38 break;
42 methods = type.GetMethods (BindingFlags.Public|BindingFlags.NonPublic|BindingFlags.Static);
43 for (i = 0; i < methods.Length; ++i) {
44 name = methods [i].Name;
45 if (!name.StartsWith ("test_"))
46 continue;
47 if (args != null && args.Length > 0) {
48 bool found = false;
49 for (j = 0; j < args.Length; j++) {
50 if (name.EndsWith (args [j])) {
51 found = true;
52 break;
55 if (!found)
56 continue;
58 for (j = 5; j < name.Length; ++j)
59 if (!Char.IsDigit (name [j]))
60 break;
61 if (verbose)
62 Console.WriteLine ("Running '{0}' ...", name);
63 expected = Int32.Parse (name.Substring (5, j - 5));
64 start = DateTime.Now;
65 result = (int)methods [i].Invoke (null, null);
66 if (do_timings) {
67 end = DateTime.Now;
68 long tdiff = end.Ticks - start.Ticks;
69 int mdiff = (int)tdiff/10000;
70 tms += mdiff;
71 Console.WriteLine ("{0} took {1} ms", name, mdiff);
73 ran++;
74 if (result != expected) {
75 failed++;
76 Console.WriteLine ("{0} failed: got {1}, expected {2}", name, result, expected);
80 if (do_timings) {
81 Console.WriteLine ("Total ms: {0}", tms);
83 Console.WriteLine ("Regression tests: {0} ran, {1} failed in {2}", ran, failed, type);
84 //Console.WriteLine ("Regression tests: {0} ran, {1} failed in [{2}]{3}", ran, failed, type.Assembly.GetName().Name, type);
85 return failed;
87 static public int RunTests (Type type) {
88 return RunTests (type, null);