2 using System
.Reflection
;
3 using System
.Collections
.Generic
;
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
;
20 List
<string> new_args
= new List
<string> ();
21 if (args
!= null && args
.Length
> 0) {
22 for (j
= 0; j
< args
.Length
; j
++) {
24 if (args
[j
] == "--time") {
28 } else if (args
[j
] == "--iter") {
29 iterations
= Int32
.Parse (args
[j
+ 1]);
32 } else if ((args
[j
] == "-v") || (args
[j
] == "--verbose")) {
36 new_args
.Add (args
[j
]);
40 methods
= type
.GetMethods (BindingFlags
.Public
|BindingFlags
.NonPublic
|BindingFlags
.Static
);
41 for (int iter
= 0; iter
< iterations
; ++iter
) {
42 for (i
= 0; i
< methods
.Length
; ++i
) {
43 name
= methods
[i
].Name
;
44 if (!name
.StartsWith ("test_"))
46 if (new_args
.Count
> 0) {
48 for (j
= 0; j
< new_args
.Count
; j
++) {
49 if (name
.EndsWith (new_args
[j
])) {
57 for (j
= 5; j
< name
.Length
; ++j
)
58 if (!Char
.IsDigit (name
[j
]))
61 Console
.WriteLine ("Running '{0}' ...", name
);
62 expected
= Int32
.Parse (name
.Substring (5, j
- 5));
64 result
= (int)methods
[i
].Invoke (null, null);
67 long tdiff
= end
.Ticks
- start
.Ticks
;
68 int mdiff
= (int)tdiff
/10000;
70 Console
.WriteLine ("{0} took {1} ms", name
, mdiff
);
73 if (result
!= expected
) {
75 Console
.WriteLine ("{0} failed: got {1}, expected {2}", name
, result
, expected
);
80 Console
.WriteLine ("Total ms: {0}", tms
);
82 Console
.WriteLine ("Regression tests: {0} ran, {1} failed in {2}", ran
, failed
, type
);
85 //Console.WriteLine ("Regression tests: {0} ran, {1} failed in [{2}]{3}", ran, failed, type.Assembly.GetName().Name, type);
88 static public int RunTests (Type type
) {
89 return RunTests (type
, null);