blob: 0669a285c0739f4f7a4d5d16e35233dd59929b49 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
|
namespace NUnit.Runner
{
using System;
using System.Collections;
using System.Collections.Specialized;
using System.IO;
/// <summary>
/// A TestCollector that consults the
/// class path. It considers all classes on the class path
/// excluding classes in JARs. It leaves it up to subclasses
/// to decide whether a class is a runnable Test.
/// <see cref="ITestCollector"/>
/// </summary>
[Obsolete("Use StandardLoader or UnloadingLoader")]
public abstract class ClassPathTestCollector : ITestCollector
{
/// <summary>
///
/// </summary>
public ClassPathTestCollector() {}
/// <summary>
///
/// </summary>
/// <returns></returns>
public string[] CollectTestsClassNames()
{
string classPath = Environment.GetEnvironmentVariable("Path");
char separator= Path.PathSeparator;
ArrayList result = new ArrayList();
CollectFilesInRoots(classPath.Split(separator), result);
string[] retVal = new string[result.Count];
result.CopyTo(retVal);
return retVal;
}
/// <summary>
///
/// </summary>
/// <param name="classFileName"></param>
/// <returns></returns>
protected string ClassNameFromFile(string classFileName)
{
return classFileName;
}
private void CollectFilesInRoots(string[] roots, IList result)
{
foreach (string directory in roots)
{
DirectoryInfo dirInfo=new DirectoryInfo(directory);
if (dirInfo.Exists)
{
string[] files=Directory.GetFiles(dirInfo.FullName);
foreach (string file in files)
{
if (IsTestClass(file))
{
string className=ClassNameFromFile(file);
result.Add(className);
}
}
}
}
}
/// <summary>
///
/// </summary>
/// <param name="classFileName"></param>
/// <returns></returns>
protected virtual bool IsTestClass(string classFileName)
{
return
( classFileName.EndsWith(".dll")
|| classFileName.EndsWith(".exe"))
&& classFileName.IndexOf("Test") > 0;
}
}
}
|