diff options
author | Nick Drochak <nickd@mono-cvs.ximian.com> | 2002-01-19 22:55:23 +0300 |
---|---|---|
committer | Nick Drochak <nickd@mono-cvs.ximian.com> | 2002-01-19 22:55:23 +0300 |
commit | b3a9502b960559d7a6b6c9712be8dd052b2e0e19 (patch) | |
tree | da34a2b334adf9a39aacdd9432552db1bdd39999 /mcs/nunit/src/NUnitCore/ClassPathTestCollector.cs | |
parent | aa634bb0419989a60379efba25e04e149936158e (diff) |
* Added sources and makefile for NUnit
svn path=/trunk/mcs/; revision=2066
Diffstat (limited to 'mcs/nunit/src/NUnitCore/ClassPathTestCollector.cs')
-rw-r--r-- | mcs/nunit/src/NUnitCore/ClassPathTestCollector.cs | 76 |
1 files changed, 76 insertions, 0 deletions
diff --git a/mcs/nunit/src/NUnitCore/ClassPathTestCollector.cs b/mcs/nunit/src/NUnitCore/ClassPathTestCollector.cs new file mode 100644 index 00000000000..437cdaab977 --- /dev/null +++ b/mcs/nunit/src/NUnitCore/ClassPathTestCollector.cs @@ -0,0 +1,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;
+ }
+ }
+}
\ No newline at end of file |