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;
16 DateTime start
, end
= DateTime
.Now
;
18 if (args
!= null && args
.Length
> 0) {
19 for (j
= 0; j
< args
.Length
; j
++) {
21 if (args
[j
] == "--time") {
25 if ((args
[j
] == "-v") || (args
[j
] == "--verbose")) {
31 string[] new_args
= new string [args
.Length
- 1];
32 for (i
= 0; i
< j
; ++i
)
33 new_args
[i
] = args
[i
];
35 for (; j
< args
.Length
; ++i
, ++j
)
36 new_args
[i
] = args
[j
];
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_"))
47 if (args
!= null && args
.Length
> 0) {
49 for (j
= 0; j
< args
.Length
; j
++) {
50 if (name
.EndsWith (args
[j
])) {
58 for (j
= 5; j
< name
.Length
; ++j
)
59 if (!Char
.IsDigit (name
[j
]))
62 Console
.WriteLine ("Running '{0}' ...", name
);
63 expected
= Int32
.Parse (name
.Substring (5, j
- 5));
65 result
= (int)methods
[i
].Invoke (null, null);
68 long tdiff
= end
.Ticks
- start
.Ticks
;
69 int mdiff
= (int)tdiff
/10000;
71 Console
.WriteLine ("{0} took {1} ms", name
, mdiff
);
74 if (result
!= expected
) {
76 Console
.WriteLine ("{0} failed: got {1}, expected {2}", name
, result
, expected
);
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);
87 static public int RunTests (Type type
) {
88 return RunTests (type
, null);