forked from VSoftTechnologies/DUnitX
-
Notifications
You must be signed in to change notification settings - Fork 0
/
DUnitX.FilterBuilder.pas
94 lines (78 loc) · 2.15 KB
/
DUnitX.FilterBuilder.pas
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
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
unit DUnitX.FilterBuilder;
interface
uses
DUnitX.TestFrameWork,
DUnitX.Filters;
type
TDUnitXFilterBuilder = class
class function BuildFilter(const options : TDUnitXOptions) : ITestFilter;
end;
implementation
uses
Classes,
SysUtils,
DUnitX.CategoryExpression,
DUnitX.TestNameParser;
{ TDUnitXFilterBuilder }
class function TDUnitXFilterBuilder.BuildFilter(const options: TDUnitXOptions): ITestFilter;
var
nameFilter : INameFilter;
includeFilter : ITestFilter;
excludeFilter : ITestFilter;
i : integer;
name : string;
sList : TStringList;
begin
result := TEmptyFilter.Create;
nameFilter := TNameFilter.Create;
if options.Run.Count > 0 then
begin
for i := 0 to options.Run.Count -1 do
begin
for name in TTestNameParser.Parse(options.Run[i]) do
nameFilter.Add(name);
end;
result := nameFilter;
end;
if options.RunListFile <> '' then
begin
if not FileExists(options.RunListFile) then
raise ECommandLineError.Create('RunList File does not exist : ' + options.RunListFile);
try
sList := TStringList.Create;
try
sList.LoadFromFile(options.RunListFile);
for i := 0 to sList.Count -1 do
begin
for name in TTestNameParser.Parse(sList[i]) do
nameFilter.Add(name);
end;
result := nameFilter;
finally
sList.Free;
end;
except
on e : Exception do
raise ECommandLineError.Create(e.Message);
end;
end;
if Trim(options.Include) <> '' then
begin
includeFilter := TCategoryExpression.CreateFilter(options.Include);
if result.IsEmpty then
result := includeFilter
else
result := TAndFilter.Create(TArray<ITestFilter>.Create(result,includeFilter));
end;
if Trim(options.Exclude) <> '' then
begin
excludeFilter := TNotFilter.Create(TCategoryExpression.CreateFilter(options.Exclude));
if result.IsEmpty then
result := excludeFilter
else
result := TAndFilter.Create(TArray<ITestFilter>.Create(result,excludeFilter));
end;
if Supports(result,INotFilter) then
(result as INotFilter).TopLevel := true;
end;
end.