Welcome to mirror list, hosted at ThFree Co, Russian Federation.

ClassPathTestCollector.cs « NUnitCore « src « nunit « mcs - github.com/mono/mono.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 437cdaab977e0eb1020f9a748dd4c5eafa8191bf (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
namespace NUnit.Runner 
{

	using System;
	using System.Collections;
	using System.IO;

	/// <summary>
	/// An implementation of 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>
	public abstract class ClassPathTestCollector: ITestCollector 
	{
		/// <summary>
		/// 
		/// </summary>
		public ClassPathTestCollector() 
		{
		}
		/// <summary>
		/// 
		/// </summary>
		/// <returns></returns>
		public Hashtable CollectTests() 
		{
			string classPath= Environment.GetEnvironmentVariable("Path");
			char separator= Path.PathSeparator;
			Hashtable result= new Hashtable(100);
			CollectFilesInRoots(classPath.Split(separator), result);
			return result;
		}
		/// <summary>
		/// 
		/// </summary>
		/// <param name="classFileName"></param>
		/// <returns></returns>
		protected string ClassNameFromFile(string classFileName) 
		{
			return classFileName;
		}
		void CollectFilesInRoots(string[] roots, Hashtable 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, 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;
		}
	}
}