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;
13 bool do_timings = false;
15 DateTime start, end = DateTime.Now;
17 if (args != null && args.Length > 0) {
18 for (j = 0; j < args.Length; j++) {
19 if (args [j] == "--time") {
21 string[] new_args = new string [args.Length - 1];
22 for (i = 0; i < j; ++i)
23 new_args [i] = args [i];
25 for (; j < args.Length; ++i, ++j)
26 new_args [i] = args [j];
32 methods = type.GetMethods (BindingFlags.Public|BindingFlags.NonPublic|BindingFlags.Static);
33 for (i = 0; i < methods.Length; ++i) {
34 name = methods [i].Name;
35 if (!name.StartsWith ("test_"))
37 if (args != null && args.Length > 0) {
39 for (j = 0; j < args.Length; j++) {
40 if (name.EndsWith (args [j])) {
48 for (j = 5; j < name.Length; ++j)
49 if (!Char.IsDigit (name [j]))
51 expected = Int32.Parse (name.Substring (5, j - 5));
53 result = (int)methods [i].Invoke (null, null);
56 long tdiff = end.Ticks - start.Ticks;
57 int mdiff = (int)tdiff/10000;
59 Console.WriteLine ("{0} took {1} ms", name, mdiff);
62 if (result != expected) {
64 Console.WriteLine ("{0} failed: got {1}, expected {2}", name, result, expected);
69 Console.WriteLine ("Total ms: {0}", tms);
71 Console.WriteLine ("Regression tests: {0} ran, {1} failed in {2}", ran, failed, type);
72 //Console.WriteLine ("Regression tests: {0} ran, {1} failed in [{2}]{3}", ran, failed, type.Assembly.GetName().Name, type);
75 static public int RunTests (Type type) {
76 return RunTests (type, null);