Skip to content

Commit

Permalink
Save checked testcases to inifile (#171)
Browse files Browse the repository at this point in the history
  • Loading branch information
hattorihanzo76 authored and vincentparrett committed Dec 1, 2016
1 parent b6b74d5 commit 05383f2
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 10 deletions.
1 change: 1 addition & 0 deletions DUnitX.Loggers.GUI.VCL.dfm
Expand Up @@ -15,6 +15,7 @@ object GUIVCLTestRunner: TGUIVCLTestRunner
Font.Style = []
OldCreateOrder = False
Position = poScreenCenter
OnClose = FormClose
OnCreate = FormCreate
OnDestroy = FormDestroy
OnShow = FormShow
Expand Down
47 changes: 37 additions & 10 deletions DUnitX.Loggers.GUI.VCL.pas
Expand Up @@ -62,6 +62,7 @@ interface
Vcl.ActnPopup,
System.Generics.Defaults,
System.Generics.Collections,
System.IniFiles,
System.Actions, //IDE keeps adding this at the end even if it's in the infdef'd section. make sure it's not there when committing!
{$ELSE}
Windows,
Expand All @@ -88,6 +89,7 @@ interface
ActnPopup,
Generics.Defaults,
Generics.Collections,
IniFiles,
{$ENDIF}
DUnitX.TestFrameWork,
DUnitX.Extensibility,
Expand Down Expand Up @@ -191,6 +193,7 @@ TGUIVCLTestRunner = class(TForm, ITestLogger)
procedure tvwTestsMouseDown(Sender: TObject; Button: TMouseButton; Shift: TShiftState; X, Y: Integer);
procedure tvwResultsChange(Sender: TObject; Node: TTreeNode);
procedure tvwResultsCreateNodeClass(Sender: TCustomTreeView; var NodeClass: TTreeNodeClass);
procedure FormClose(Sender: TObject; var Action: TCloseAction);
private
type
TTestNodeStateOp = (tnsSelect, tnsUnselect, tnsInvert);
Expand Down Expand Up @@ -284,6 +287,8 @@ implementation

cRootNodeStrings : array[TTestResultType] of string = (STestsPassed,STestsFailed,STestsErrored,STestsIgnored,STestsWithLeak,STestsWarning);

cTestSetup = 'TestSetup';

type
//can't return "array of string" on function (at least in XE)
TStringArray = array of string;
Expand Down Expand Up @@ -539,6 +544,23 @@ procedure TGUIVCLTestRunner.actTestsSelectAllExecute(Sender: TObject);
SelectAll;
end;

procedure TGUIVCLTestRunner.FormClose(Sender: TObject; var Action: TCloseAction);
var
IniFile: TIniFile;
begin
IniFile := TIniFile.Create(ChangeFileExt(ParamStr(0), '.ini'));
try
tvwTests.IterateAll(
procedure(const Node: TTreeNode; var Stop: boolean)
begin
IniFile.WriteBool(cTestSetup, Node.Text, Node.StateIndex = cTestNodeStateChecked);
end
);
finally
IniFile.Free;
end;
end;

procedure TGUIVCLTestRunner.FormCreate(Sender: TObject);
begin
Width := Screen.WorkAreaWidth;
Expand Down Expand Up @@ -832,21 +854,26 @@ procedure TGUIVCLTestRunner.BuildTestTreeNode(const FixtureList: ITestFixtureLis
Fixture: ITestFixture;
Test: ITest;
TestNode: TTreeNode;

IniFile: TIniFile;
begin
for Fixture in FixtureList do
begin
for Test in Fixture.Tests do
IniFile := TIniFile.Create(ChangeFileExt(ParamStr(0), '.ini'));
try
for Fixture in FixtureList do
begin
if (edtFilter.Text = '') or ContainsText(Test.FullName, edtFilter.Text) then
for Test in Fixture.Tests do
begin
TestNode := tvwTests.Items.AddChild(nil, Test.FullName);
TestNode.StateIndex := cTestNodeStateChecked;
if (edtFilter.Text = '') or ContainsText(Test.FullName, edtFilter.Text) then
begin
TestNode := tvwTests.Items.AddChild(nil, Test.FullName);
TestNode.StateIndex := IfThen(IniFile.ReadBool(cTestSetup, Test.FullName, True), cTestNodeStateChecked, cTestNodeStateUnchecked);
end;
end;
end;

if Fixture.HasChildFixtures then
BuildTestTreeNode(Fixture.Children);
if Fixture.HasChildFixtures then
BuildTestTreeNode(Fixture.Children);
end;
finally
IniFile.Free;
end;
end;

Expand Down

0 comments on commit 05383f2

Please sign in to comment.