From 116b91b184a1470e2bef25b31ec77579645f7344 Mon Sep 17 00:00:00 2001 From: mattias Date: Tue, 4 Feb 2025 16:45:03 +0100 Subject: [PATCH] codetools: directorycache: invalidate directory when a codebuffer is marked deleted --- components/codetools/codecache.pas | 29 ++ components/codetools/codetoolmanager.pas | 2 +- .../codetools/tests/testchangedeclaration.pas | 38 +- .../codetools/tests/testcodecompletion.pas | 46 +- .../codetools/tests/testcompleteblock.pas | 26 +- components/codetools/tests/testcth2pas.pas | 3 + components/codetools/tests/testctpas2js.pas | 1 - .../codetools/tests/testctrangescan.pas | 470 ++++++++++-------- .../codetools/tests/testdesignerformtools.pas | 2 + .../codetools/tests/testfinddeclaration.pas | 30 +- .../codetools/tests/testmethodjumptool.pas | 34 +- .../codetools/tests/testrefactoring.pas | 3 +- .../codetools/tests/teststdcodetools.pas | 123 +++-- 13 files changed, 459 insertions(+), 348 deletions(-) diff --git a/components/codetools/codecache.pas b/components/codetools/codecache.pas index 8d0b0876fe..a1a874aac9 100644 --- a/components/codetools/codecache.pas +++ b/components/codetools/codecache.pas @@ -53,6 +53,7 @@ type TCodeBuffer = class(TSourceLog) private FFilename: string; + FOnDeleted: TNotifyEvent; FReferenceCount: integer; FScanner: TLinkScanner; FOnSetScanner: TNotifyEvent; @@ -114,6 +115,7 @@ type property FileChangeStep: integer read FFileChangeStep; // last loaded/saved changestep, only valid if LoadDateValid=true property OnSetFilename: TNotifyEvent read FOnSetFilename write FOnSetFilename; property OnSetScanner: TNotifyEvent read FOnSetScanner write FOnSetScanner; + property OnDeleted: TNotifyEvent read FOnDeleted write FOnDeleted; property Scanner: TLinkScanner read FScanner write SetScanner; property ReferenceCount: integer read FReferenceCount; end; @@ -153,11 +155,13 @@ type fLastIncludeLinkFileValid: boolean; fLastIncludeLinkFileChangeStep: integer; fChangeStep: integer; + FOnCodeDeleted: TNotifyEvent; FOnDecodeLoaded: TOnCodeCacheDecodeLoaded; FOnEncodeSaving: TOnCodeCacheEncodeSaving; function FindIncludeLink(const IncludeFilename: string): string; function FindIncludeLinkNode(const IncludeFilename: string): TIncludedByLink; function FindIncludeLinkAVLNode(const IncludeFilename: string): TAVLTreeNode; + procedure OnCodeDeleted(Sender: TObject); function OnScannerCheckFileOnDisk(Code: TSourceLog): boolean; // true if code changed function OnScannerGetFileName(Sender: TObject; Code: TSourceLog): string; function OnScannerLoadSource(Sender: TObject; const AFilename: string; @@ -216,6 +220,7 @@ type write FOnDecodeLoaded; property OnEncodeSaving: TOnCodeCacheEncodeSaving read FOnEncodeSaving write FOnEncodeSaving; + property OnFileDeleted: TNotifyEvent read FOnCodeDeleted write FOnCodeDeleted; property DefaultEncoding: string read FDefaultEncoding write FDefaultEncoding; property ChangeStamp: int64 read FChangeStamp; property DirectoryCachePool: TCTDirectoryCachePool read FDirectoryCachePool @@ -760,6 +765,7 @@ begin FItems.Add(Result); Result.FCodeCache:=Self;// must be called after FileName:= Result.LastIncludedByFile:=FindIncludeLink(Result.Filename); + Result.OnDeleted:=@OnCodeDeleted; end; Result.DiskEncoding:=DefaultEncoding; Result.MemEncoding:=Result.DiskEncoding; @@ -998,6 +1004,27 @@ begin @CompareAnsiStringWithIncludedByLink); end; +procedure TCodeCache.OnCodeDeleted(Sender: TObject); +var + Code: TCodeBuffer; + Dir: String; + Cache: TCTDirectoryCache; +begin + if DirectoryCachePool<>nil then begin + Code:=TCodeBuffer(Sender); + if Code.IsVirtual then + Cache:=DirectoryCachePool.GetCache('',false,false) + else begin + Dir:=ExtractFilePath(Code.Filename); + Cache:=DirectoryCachePool.GetCache(Dir,false,false); + end; + if Cache<>nil then + Cache.Invalidate; + end; + if Assigned(OnFileDeleted) then + OnFileDeleted(Sender); +end; + function TCodeCache.FindIncludeLink(const IncludeFilename: string): string; var Link: TIncludedByLink; begin @@ -1391,6 +1418,8 @@ begin if FIsDeleted then begin Clear; FIsDeleted:=true; + if Assigned(OnDeleted) then + OnDeleted(Self); //DebugLn(['TCodeBuffer.SetIsDeleted ',Filename,' ',FileNeedsUpdate]); end; end; diff --git a/components/codetools/codetoolmanager.pas b/components/codetools/codetoolmanager.pas index 508ae381e8..41953ab154 100644 --- a/components/codetools/codetoolmanager.pas +++ b/components/codetools/codetoolmanager.pas @@ -6946,7 +6946,7 @@ begin if (Filename='') or (System.Pos(PathDelim,Filename)>0) then exit; Code:=FindFile(Filename); - if Code<>nil then + if (Code<>nil) and not Code.IsDeleted then Result:=Code.Filename; end; diff --git a/components/codetools/tests/testchangedeclaration.pas b/components/codetools/tests/testchangedeclaration.pas index 92b9afa5fa..7edd0223e9 100644 --- a/components/codetools/tests/testchangedeclaration.pas +++ b/components/codetools/tests/testchangedeclaration.pas @@ -43,24 +43,28 @@ procedure TTestChangeDeclaration.TestCTAddProcedureModifier; +'implementation'+sLineBreak +'end.'; Code:=CodeToolBoss.CreateFile(FDefFilename); - Code.Source:=Src; - if not CodeToolBoss.AddProcModifier(Code,3,3,aModifier) then - begin - Fail('AddProcModifier failed: '+CodeToolBoss.ErrorMessage); - end else begin - if not CodeToolBoss.ExtractProcedureHeader(Code,3,3, - [phpWithStart,phpWithResultType,phpWithOfObject,phpWithProcModifiers,phpWithComments,phpDoNotAddSemicolon], - ProcHead) - then - Fail('ExtractProcedureHeader failed: '+CodeToolBoss.ErrorMessage); - if ProcHead<>Expected then begin - writeln('Test ProcCode="',ProcCode,'"'); - Src:=Code.Source; - writeln('SrcSTART:======================'); - writeln(Src); - writeln('SrcEND:========================'); - AssertEquals('ProcHead',Expected,ProcHead); + try + Code.Source:=Src; + if not CodeToolBoss.AddProcModifier(Code,3,3,aModifier) then + begin + Fail('AddProcModifier failed: '+CodeToolBoss.ErrorMessage); + end else begin + if not CodeToolBoss.ExtractProcedureHeader(Code,3,3, + [phpWithStart,phpWithResultType,phpWithOfObject,phpWithProcModifiers,phpWithComments,phpDoNotAddSemicolon], + ProcHead) + then + Fail('ExtractProcedureHeader failed: '+CodeToolBoss.ErrorMessage); + if ProcHead<>Expected then begin + writeln('Test ProcCode="',ProcCode,'"'); + Src:=Code.Source; + writeln('SrcSTART:======================'); + writeln(Src); + writeln('SrcEND:========================'); + AssertEquals('ProcHead',Expected,ProcHead); + end; end; + finally + Code.IsDeleted:=true; end; end; diff --git a/components/codetools/tests/testcodecompletion.pas b/components/codetools/tests/testcodecompletion.pas index 87710e6ef0..5d9e5195a0 100644 --- a/components/codetools/tests/testcodecompletion.pas +++ b/components/codetools/tests/testcodecompletion.pas @@ -78,30 +78,34 @@ var NewCode, Code: TCodeBuffer; begin Code:=CodeToolBoss.CreateFile('test1.pas'); - s:=''; - for i:=Low(Src) to High(Src) do - s+=Src[i]+LineEnding; - Code.Source:=s; + try + s:=''; + for i:=Low(Src) to High(Src) do + s+=Src[i]+LineEnding; + Code.Source:=s; - if not CodeToolBoss.CompleteCode(Code,Col,Line,Line,NewCode,NewX,NewY,NewTopLine, - BlockTopLine,BlockBottomLine,false) - and (CodeToolBoss.ErrorDbgMsg<>'') then - begin - NewCode:=Code; - NewY:=Line; - NewX:=Col; - if (CodeToolBoss.ErrorCode<>nil) and (CodeToolBoss.ErrorLine>0) then begin - NewY:=CodeToolBoss.ErrorLine; - NewX:=CodeToolBoss.ErrorColumn; - NewCode:=CodeToolBoss.ErrorCode; + if not CodeToolBoss.CompleteCode(Code,Col,Line,Line,NewCode,NewX,NewY,NewTopLine, + BlockTopLine,BlockBottomLine,false) + and (CodeToolBoss.ErrorDbgMsg<>'') then + begin + NewCode:=Code; + NewY:=Line; + NewX:=Col; + if (CodeToolBoss.ErrorCode<>nil) and (CodeToolBoss.ErrorLine>0) then begin + NewY:=CodeToolBoss.ErrorLine; + NewX:=CodeToolBoss.ErrorColumn; + NewCode:=CodeToolBoss.ErrorCode; + end; + WriteSource(NewCode.Filename,NewY,NewX); + Fail(Title+': call CompleteCode failed: "'+CodeToolBoss.ErrorDbgMsg+'"'); end; - WriteSource(NewCode.Filename,NewY,NewX); - Fail(Title+': call CompleteCode failed: "'+CodeToolBoss.ErrorDbgMsg+'"'); + s:=''; + for i:=Low(Expected) to High(Expected) do + s+=Expected[i]+LineEnding; + CheckDiff(Title,s,Code.Source); + finally + Code.IsDeleted:=true; end; - s:=''; - for i:=Low(Expected) to High(Expected) do - s+=Expected[i]+LineEnding; - CheckDiff(Title,s,Code.Source); end; procedure TTestCodeCompletion.TestIntfProcUpdateArgName; diff --git a/components/codetools/tests/testcompleteblock.pas b/components/codetools/tests/testcompleteblock.pas index 13e1116fb3..302a113693 100644 --- a/components/codetools/tests/testcompleteblock.pas +++ b/components/codetools/tests/testcompleteblock.pas @@ -111,6 +111,7 @@ begin AssertEquals('Src is empty',Trim(Src)<>'',true); AssertEquals('ExpectedSrc is empty',Trim(ExpectedSrc)<>'',true); + Code:=nil; ExpectedCode:=TCodeBuffer.Create; try // replace cursor | marker in Src @@ -146,6 +147,7 @@ begin AssertEquals('CompleteBlock did no or the wrong completion: ',TrimExpected,TrimResult); finally + if Code<>nil then Code.IsDeleted:=true; ExpectedCode.Free; end; end; @@ -173,17 +175,21 @@ begin // replace cursor | marker in Src Code:=CodeToolBoss.CreateFile('TestCompleteBlock.pas'); - FullSrc:=CreateFullSrc(Src,p); - if p<1 then - AssertEquals('missing cursor | in test source: "'+dbgstr(Src)+'"',true,false); - Code.Source:=FullSrc; - Code.AbsoluteToLineCol(p,Y,X); + try + FullSrc:=CreateFullSrc(Src,p); + if p<1 then + AssertEquals('missing cursor | in test source: "'+dbgstr(Src)+'"',true,false); + Code.Source:=FullSrc; + Code.AbsoluteToLineCol(p,Y,X); - if CodeToolBoss.CompleteBlock(Code,X,Y,OnlyIfCursorBlockIndented, - NewCode,NewX,NewY,NewTopLine) - then begin - debugln(['TTestCodetoolsCompleteBlock.CompleteBlockFail completion: ',dbgstr(Code.Source)]); - AssertEquals('CodeToolBoss.CompleteBlock returned true for incompletable src="'+dbgstr(Src)+'"',true,false); + if CodeToolBoss.CompleteBlock(Code,X,Y,OnlyIfCursorBlockIndented, + NewCode,NewX,NewY,NewTopLine) + then begin + debugln(['TTestCodetoolsCompleteBlock.CompleteBlockFail completion: ',dbgstr(Code.Source)]); + AssertEquals('CodeToolBoss.CompleteBlock returned true for incompletable src="'+dbgstr(Src)+'"',true,false); + end; + finally + Code.IsDeleted:=true; end; end; diff --git a/components/codetools/tests/testcth2pas.pas b/components/codetools/tests/testcth2pas.pas index f69e9d944a..760e86bc95 100644 --- a/components/codetools/tests/testcth2pas.pas +++ b/components/codetools/tests/testcth2pas.pas @@ -119,6 +119,8 @@ begin AssertEquals('start comment header1.h in front of header2.h',true,Header1Startnil',true,RootNode<>nil); - //Tool.WriteDebugTreeReport; + // scan source + Code.Source:=GetSource([]); + {$IFDEF VerboseTestCTRangeScan} + debugln(['TTestCodetoolsRangeScan.TestCTScanRange INITIAL SCAN']); + {$ENDIF} + Tool.BuildTree(lsrEnd); + RootNode:=Tool.Tree.Root; + TreeChangeStep:=Tool.TreeChangeStep; + AssertEquals('Step1: RootNode<>nil',true,RootNode<>nil); + //Tool.WriteDebugTreeReport; - // append a comment at end and scan again => this should result in no tree change - Code.Source:=GetSource([crsfWithCommentAtEnd]); - {$IFDEF VerboseTestCTRangeScan} - debugln(['TTestCodetoolsRangeScan.TestCTScanRange SCAN with comment at end']); - {$ENDIF} - Tool.BuildTree(lsrEnd); - AssertEquals('Step2: RootNode=Tree.Root',true,RootNode=Tool.Tree.Root); - AssertEquals('Step2: TreeChangeStep=Tool.TreeChangeStep',true,TreeChangeStep=Tool.TreeChangeStep); - //Tool.WriteDebugTreeReport; + // append a comment at end and scan again => this should result in no tree change + Code.Source:=GetSource([crsfWithCommentAtEnd]); + {$IFDEF VerboseTestCTRangeScan} + debugln(['TTestCodetoolsRangeScan.TestCTScanRange SCAN with comment at end']); + {$ENDIF} + Tool.BuildTree(lsrEnd); + AssertEquals('Step2: RootNode=Tree.Root',true,RootNode=Tool.Tree.Root); + AssertEquals('Step2: TreeChangeStep=Tool.TreeChangeStep',true,TreeChangeStep=Tool.TreeChangeStep); + //Tool.WriteDebugTreeReport; - // insert a procedure in the implementation and scan again - // => this should result in a tree change, but the root node should be kept - Code.Source:=GetSource([crsfWithProc1]); - {$IFDEF VerboseTestCTRangeScan} - debugln(['TTestCodetoolsRangeScan.TestCTScanRange SCAN with new proc in implementation']); - {$ENDIF} - Tool.BuildTree(lsrEnd); - AssertEquals('Step3: RootNode=Tree.Root',true,RootNode=Tool.Tree.Root); - AssertEquals('Step3: TreeChangeStep<>Tool.TreeChangeStep',true,TreeChangeStep<>Tool.TreeChangeStep); - //Tool.WriteDebugTreeReport; + // insert a procedure in the implementation and scan again + // => this should result in a tree change, but the root node should be kept + Code.Source:=GetSource([crsfWithProc1]); + {$IFDEF VerboseTestCTRangeScan} + debugln(['TTestCodetoolsRangeScan.TestCTScanRange SCAN with new proc in implementation']); + {$ENDIF} + Tool.BuildTree(lsrEnd); + AssertEquals('Step3: RootNode=Tree.Root',true,RootNode=Tool.Tree.Root); + AssertEquals('Step3: TreeChangeStep<>Tool.TreeChangeStep',true,TreeChangeStep<>Tool.TreeChangeStep); + //Tool.WriteDebugTreeReport; + finally + Code.IsDeleted:=true; + end; end; procedure TTestCodetoolsRangeScan.TestCTScanRangeAscending; @@ -209,56 +213,60 @@ var MaxRange: TLinkScannerRange; begin Code:=CodeToolBoss.CreateFile('TestRangeScan.pas'); - Tool:=CodeToolBoss.GetCodeToolForSource(Code,false,true) as TCodeTool; + try + Tool:=CodeToolBoss.GetCodeToolForSource(Code,false,true) as TCodeTool; - // empty tool - Code.Source:=''; - Tool.BuildTree(lsrInit); + // empty tool + Code.Source:=''; + Tool.BuildTree(lsrInit); - // scan source - Code.Source:=GetSource([crsfWithInitialization,crsfWithFinalization]); - RootNode:=nil; - MinRange:=low(TLinkScannerRange); - MaxRange:=high(TLinkScannerRange); - for r:=MinRange to MaxRange do begin - {$IFDEF VerboseTestCTRangeScan} - debugln(['TTestCodetoolsRangeScan.TestCTScanRangeAscending Range=',dbgs(r)]); - {$ENDIF} - Tool.BuildTree(r); - if RootNode<>nil then begin - AssertEquals('RootNode must stay for ascending range '+dbgs(r),true,RootNode=Tool.Tree.Root); - end; - RootNode:=Tool.Tree.Root; - //Tool.WriteDebugTreeReport; - case r of - lsrNone: ; - lsrInit: ; - lsrSourceType: - AssertEquals('source type scanned',true,RootNode<>nil); - lsrSourceName: - begin - AssertEquals('source name scanned',true,RootNode.FirstChild<>nil); - AssertEquals('source name found',true,RootNode.FirstChild.Desc=ctnSrcName); + // scan source + Code.Source:=GetSource([crsfWithInitialization,crsfWithFinalization]); + RootNode:=nil; + MinRange:=low(TLinkScannerRange); + MaxRange:=high(TLinkScannerRange); + for r:=MinRange to MaxRange do begin + {$IFDEF VerboseTestCTRangeScan} + debugln(['TTestCodetoolsRangeScan.TestCTScanRangeAscending Range=',dbgs(r)]); + {$ENDIF} + Tool.BuildTree(r); + if RootNode<>nil then begin + AssertEquals('RootNode must stay for ascending range '+dbgs(r),true,RootNode=Tool.Tree.Root); + end; + RootNode:=Tool.Tree.Root; + //Tool.WriteDebugTreeReport; + case r of + lsrNone: ; + lsrInit: ; + lsrSourceType: + AssertEquals('source type scanned',true,RootNode<>nil); + lsrSourceName: + begin + AssertEquals('source name scanned',true,RootNode.FirstChild<>nil); + AssertEquals('source name found',true,RootNode.FirstChild.Desc=ctnSrcName); + end; + lsrInterfaceStart: + AssertEquals('interface start scanned',true,Tool.FindInterfaceNode<>nil); + lsrMainUsesSectionStart: + AssertEquals('main uses section start scanned',true,Tool.FindMainUsesNode<>nil); + lsrMainUsesSectionEnd: + AssertEquals('main uses section end scanned',true,Tool.FindMainUsesNode.FirstChild<>nil); + lsrImplementationStart: + AssertEquals('implementation start scanned',true,Tool.FindImplementationNode<>nil); + lsrImplementationUsesSectionStart: + AssertEquals('implementation uses section start scanned',true,Tool.FindImplementationUsesNode<>nil); + lsrImplementationUsesSectionEnd: + AssertEquals('implementation uses section end scanned',true,Tool.FindImplementationUsesNode.FirstChild<>nil); + lsrInitializationStart: + AssertEquals('initialization section start scanned',true,Tool.FindInitializationNode<>nil); + lsrFinalizationStart: + AssertEquals('finalization section start scanned',true,Tool.FindFinalizationNode<>nil); + lsrEnd: + AssertEquals('end. found',true,Tool.Tree.FindRootNode(ctnEndPoint)<>nil); end; - lsrInterfaceStart: - AssertEquals('interface start scanned',true,Tool.FindInterfaceNode<>nil); - lsrMainUsesSectionStart: - AssertEquals('main uses section start scanned',true,Tool.FindMainUsesNode<>nil); - lsrMainUsesSectionEnd: - AssertEquals('main uses section end scanned',true,Tool.FindMainUsesNode.FirstChild<>nil); - lsrImplementationStart: - AssertEquals('implementation start scanned',true,Tool.FindImplementationNode<>nil); - lsrImplementationUsesSectionStart: - AssertEquals('implementation uses section start scanned',true,Tool.FindImplementationUsesNode<>nil); - lsrImplementationUsesSectionEnd: - AssertEquals('implementation uses section end scanned',true,Tool.FindImplementationUsesNode.FirstChild<>nil); - lsrInitializationStart: - AssertEquals('initialization section start scanned',true,Tool.FindInitializationNode<>nil); - lsrFinalizationStart: - AssertEquals('finalization section start scanned',true,Tool.FindFinalizationNode<>nil); - lsrEnd: - AssertEquals('end. found',true,Tool.Tree.FindRootNode(ctnEndPoint)<>nil); end; + finally + Code.IsDeleted:=true; end; end; @@ -271,21 +279,25 @@ var r: TLinkScannerRange; begin Code:=CodeToolBoss.CreateFile('TestRangeScan.pas'); - Tool:=CodeToolBoss.GetCodeToolForSource(Code,false,true) as TCodeTool; + try + Tool:=CodeToolBoss.GetCodeToolForSource(Code,false,true) as TCodeTool; - // scan source - Code.Source:='begin end.'; - Tool.BuildTree(lsrEnd); - Code.Source:=GetSource([]); - MinRange:=low(TLinkScannerRange); - MaxRange:=high(TLinkScannerRange); - for r:=MaxRange downto MinRange do begin - {$IFDEF VerboseTestCTRangeScan} - debugln(['TTestCodetoolsRangeScan.TestCTScanRangeDescending Range=',dbgs(r)]); - {$ENDIF} - Tool.BuildTree(r); - AssertEquals('RootNode must stay for descending range '+dbgs(r),true,Tool.Tree.Root<>nil); - //Tool.WriteDebugTreeReport; + // scan source + Code.Source:='begin end.'; + Tool.BuildTree(lsrEnd); + Code.Source:=GetSource([]); + MinRange:=low(TLinkScannerRange); + MaxRange:=high(TLinkScannerRange); + for r:=MaxRange downto MinRange do begin + {$IFDEF VerboseTestCTRangeScan} + debugln(['TTestCodetoolsRangeScan.TestCTScanRangeDescending Range=',dbgs(r)]); + {$ENDIF} + Tool.BuildTree(r); + AssertEquals('RootNode must stay for descending range '+dbgs(r),true,Tool.Tree.Root<>nil); + //Tool.WriteDebugTreeReport; + end; + finally + Code.IsDeleted:=true; end; end; @@ -295,20 +307,24 @@ var Tool: TEventsCodeTool; begin Code:=CodeToolBoss.CreateFile('TestRangeScan.pas'); - Tool:=CodeToolBoss.GetCodeToolForSource(Code,false,true) as TCodeTool; + try + Tool:=CodeToolBoss.GetCodeToolForSource(Code,false,true) as TCodeTool; - // scan source - Code.Source:=GetSource([crsfWithProc1]); - Tool.BuildTree(lsrEnd); - //Tool.WriteDebugTreeReport; - AssertEquals('step1: end. found',true,Tool.Tree.FindRootNode(ctnEndPoint)<>nil); + // scan source + Code.Source:=GetSource([crsfWithProc1]); + Tool.BuildTree(lsrEnd); + //Tool.WriteDebugTreeReport; + AssertEquals('step1: end. found',true,Tool.Tree.FindRootNode(ctnEndPoint)<>nil); - Code.Source:=GetSource([crsfWithProc1Modified]); - Tool.BuildTree(lsrEnd); - //Tool.WriteDebugTreeReport; - AssertEquals('step2: end. found',true,Tool.Tree.FindRootNode(ctnEndPoint)<>nil); + Code.Source:=GetSource([crsfWithProc1Modified]); + Tool.BuildTree(lsrEnd); + //Tool.WriteDebugTreeReport; + AssertEquals('step2: end. found',true,Tool.Tree.FindRootNode(ctnEndPoint)<>nil); - CheckTree(Tool); + CheckTree(Tool); + finally + Code.IsDeleted:=true; + end; end; procedure TTestCodetoolsRangeScan.TestCTScanRangeImplementationToEnd; @@ -317,22 +333,26 @@ var Tool: TEventsCodeTool; begin Code:=CodeToolBoss.CreateFile('TestRangeScan.pas'); - Tool:=CodeToolBoss.GetCodeToolForSource(Code,false,true) as TCodeTool; + try + Tool:=CodeToolBoss.GetCodeToolForSource(Code,false,true) as TCodeTool; - Code.Source:=''; - Tool.BuildTree(lsrInit); + Code.Source:=''; + Tool.BuildTree(lsrInit); - // scan source - Code.Source:=GetSource([crsfWithProc1]); - Tool.BuildTree(lsrImplementationStart); - //Tool.WriteDebugTreeReport; - AssertEquals('step1: implementation found',true,Tool.FindImplementationNode<>nil); + // scan source + Code.Source:=GetSource([crsfWithProc1]); + Tool.BuildTree(lsrImplementationStart); + //Tool.WriteDebugTreeReport; + AssertEquals('step1: implementation found',true,Tool.FindImplementationNode<>nil); - Tool.BuildTree(lsrEnd); - //Tool.WriteDebugTreeReport; - AssertEquals('step2: end. found',true,Tool.Tree.FindRootNode(ctnEndPoint)<>nil); + Tool.BuildTree(lsrEnd); + //Tool.WriteDebugTreeReport; + AssertEquals('step2: end. found',true,Tool.Tree.FindRootNode(ctnEndPoint)<>nil); - CheckTree(Tool); + CheckTree(Tool); + finally + Code.IsDeleted:=true; + end; end; procedure TTestCodetoolsRangeScan.TestCTScanRangeInitializationModified; @@ -341,20 +361,24 @@ var Tool: TCodeTool; begin Code:=CodeToolBoss.CreateFile('TestRangeScan.pas'); - Tool:=CodeToolBoss.GetCodeToolForSource(Code,false,true) as TCodeTool; + try + Tool:=CodeToolBoss.GetCodeToolForSource(Code,false,true) as TCodeTool; - // scan source with initialization - Code.Source:=GetSource([crsfWithInitialization,crsfWithInitializationStatement1]); - Tool.BuildTree(lsrEnd); - AssertEquals('step1: end found',true,Tool.Tree.FindRootNode(ctnEndPoint)<>nil); + // scan source with initialization + Code.Source:=GetSource([crsfWithInitialization,crsfWithInitializationStatement1]); + Tool.BuildTree(lsrEnd); + AssertEquals('step1: end found',true,Tool.Tree.FindRootNode(ctnEndPoint)<>nil); - // scan source with a modified initialization - Code.Source:=GetSource([crsfWithInitialization,crsfWithInitializationStatement2]); - Tool.BuildTree(lsrEnd); - AssertEquals('step2: end found',true,Tool.Tree.FindRootNode(ctnEndPoint)<>nil); + // scan source with a modified initialization + Code.Source:=GetSource([crsfWithInitialization,crsfWithInitializationStatement2]); + Tool.BuildTree(lsrEnd); + AssertEquals('step2: end found',true,Tool.Tree.FindRootNode(ctnEndPoint)<>nil); - CheckTree(Tool); - //Tool.WriteDebugTreeReport; + CheckTree(Tool); + //Tool.WriteDebugTreeReport; + finally + Code.IsDeleted:=true; + end; end; procedure TTestCodetoolsRangeScan.TestCTScanRangeLibraryInitializationModified; @@ -363,20 +387,24 @@ var Tool: TCodeTool; begin Code:=CodeToolBoss.CreateFile('TestRangeScan.pas'); - Tool:=CodeToolBoss.GetCodeToolForSource(Code,false,true) as TCodeTool; + try + Tool:=CodeToolBoss.GetCodeToolForSource(Code,false,true) as TCodeTool; - // scan source with initialization - Code.Source:=GetSource([crsfLibrary,crsfWithInitialization,crsfWithInitializationStatement1]); - Tool.BuildTree(lsrEnd); - AssertEquals('step1: end found',true,Tool.Tree.FindRootNode(ctnEndPoint)<>nil); + // scan source with initialization + Code.Source:=GetSource([crsfLibrary,crsfWithInitialization,crsfWithInitializationStatement1]); + Tool.BuildTree(lsrEnd); + AssertEquals('step1: end found',true,Tool.Tree.FindRootNode(ctnEndPoint)<>nil); - // scan source with a modified initialization - Code.Source:=GetSource([crsfLibrary,crsfWithInitialization,crsfWithInitializationStatement2]); - Tool.BuildTree(lsrEnd); - AssertEquals('step2: end found',true,Tool.Tree.FindRootNode(ctnEndPoint)<>nil); + // scan source with a modified initialization + Code.Source:=GetSource([crsfLibrary,crsfWithInitialization,crsfWithInitializationStatement2]); + Tool.BuildTree(lsrEnd); + AssertEquals('step2: end found',true,Tool.Tree.FindRootNode(ctnEndPoint)<>nil); - CheckTree(Tool); - //Tool.WriteDebugTreeReport; + CheckTree(Tool); + //Tool.WriteDebugTreeReport; + finally + Code.IsDeleted:=true; + end; end; procedure TTestCodetoolsRangeScan.TestCTScanRangeScannerAtEnd; @@ -387,24 +415,28 @@ var CleanCursorPos: integer; begin Code:=CodeToolBoss.CreateFile('TestRangeScan.pas'); - Tool:=CodeToolBoss.GetCodeToolForSource(Code,false,true) as TCodeTool; + try + Tool:=CodeToolBoss.GetCodeToolForSource(Code,false,true) as TCodeTool; - // scan source til implementation uses end - Code.Source:=GetSource([crsfWithProc1Modified]); - Tool.BuildTree(lsrImplementationUsesSectionEnd); + // scan source til implementation uses end + Code.Source:=GetSource([crsfWithProc1Modified]); + Tool.BuildTree(lsrImplementationUsesSectionEnd); - // let LinkScanner scan til end - Tool.Scanner.Scan(lsrEnd,false); + // let LinkScanner scan til end + Tool.Scanner.Scan(lsrEnd,false); - AssertEquals('scanner at end, tool at impl uses end',true,Tool.ScannedRange=lsrImplementationUsesSectionEnd); - AssertEquals('scanner at end, tool at impl uses end',true,Tool.Scanner.ScannedRange=lsrEnd); - // test BuildTreeAndGetCleanPos in implementation section - CursorPos.Code:=Code; - FindPos(Code,ctrsCommentOfProc1,CursorPos.Y,CursorPos.X); - Tool.BuildTreeAndGetCleanPos(trTillCursor,lsrEnd,CursorPos,CleanCursorPos, - [btSetIgnoreErrorPos]); - AssertEquals('scanner and tool at end',true,Tool.ScannedRange=lsrEnd); - AssertEquals('scanner and tool at end',true,Tool.Scanner.ScannedRange=lsrEnd); + AssertEquals('scanner at end, tool at impl uses end',true,Tool.ScannedRange=lsrImplementationUsesSectionEnd); + AssertEquals('scanner at end, tool at impl uses end',true,Tool.Scanner.ScannedRange=lsrEnd); + // test BuildTreeAndGetCleanPos in implementation section + CursorPos.Code:=Code; + FindPos(Code,ctrsCommentOfProc1,CursorPos.Y,CursorPos.X); + Tool.BuildTreeAndGetCleanPos(trTillCursor,lsrEnd,CursorPos,CleanCursorPos, + [btSetIgnoreErrorPos]); + AssertEquals('scanner and tool at end',true,Tool.ScannedRange=lsrEnd); + AssertEquals('scanner and tool at end',true,Tool.Scanner.ScannedRange=lsrEnd); + finally + Code.IsDeleted:=true; + end; end; procedure TTestCodetoolsRangeScan.TestCTScanRangeProgramNoName; @@ -415,41 +447,45 @@ var RootNode: TCodeTreeNode; begin Code:=CodeToolBoss.CreateFile('TestRangeScan.pas'); - Tool:=CodeToolBoss.GetCodeToolForSource(Code,false,true) as TCodeTool; - Tool.BuildTree(lsrInit); - Code.Source:=GetSource([crsfProgram,crsfNoSrcName]); - Tool.BuildTree(lsrImplementationUsesSectionEnd); - RootNode:=nil; - for r in TLinkScannerRange do begin - {$IFDEF VerboseTestCTRangeScan} - debugln(['TTestCodetoolsRangeScan.TestCTScanRangeProgramNoName Range=',dbgs(r)]); - {$ENDIF} - Tool.BuildTree(r); - if RootNode<>nil then begin - AssertEquals('RootNode must stay for ascending range '+dbgs(r),true,RootNode=Tool.Tree.Root); - end; - RootNode:=Tool.Tree.Root; - //Tool.WriteDebugTreeReport; - case r of - lsrNone: ; - lsrInit: ; - lsrSourceType: - AssertEquals('source type scanned',true,RootNode<>nil); - lsrSourceName: - AssertEquals('source name scanned',true,RootNode<>nil); - lsrInterfaceStart: ; - lsrMainUsesSectionStart: - AssertEquals('main uses section start scanned',true,Tool.FindMainUsesNode<>nil); - lsrMainUsesSectionEnd: - AssertEquals('main uses section end scanned',true,Tool.FindMainUsesNode.FirstChild<>nil); - lsrImplementationStart: ; - lsrImplementationUsesSectionStart: ; - lsrImplementationUsesSectionEnd: ; - lsrInitializationStart: ; - lsrFinalizationStart: ; - lsrEnd: - AssertEquals('end. found',true,Tool.Tree.FindRootNode(ctnEndPoint)<>nil); + try + Tool:=CodeToolBoss.GetCodeToolForSource(Code,false,true) as TCodeTool; + Tool.BuildTree(lsrInit); + Code.Source:=GetSource([crsfProgram,crsfNoSrcName]); + Tool.BuildTree(lsrImplementationUsesSectionEnd); + RootNode:=nil; + for r in TLinkScannerRange do begin + {$IFDEF VerboseTestCTRangeScan} + debugln(['TTestCodetoolsRangeScan.TestCTScanRangeProgramNoName Range=',dbgs(r)]); + {$ENDIF} + Tool.BuildTree(r); + if RootNode<>nil then begin + AssertEquals('RootNode must stay for ascending range '+dbgs(r),true,RootNode=Tool.Tree.Root); + end; + RootNode:=Tool.Tree.Root; + //Tool.WriteDebugTreeReport; + case r of + lsrNone: ; + lsrInit: ; + lsrSourceType: + AssertEquals('source type scanned',true,RootNode<>nil); + lsrSourceName: + AssertEquals('source name scanned',true,RootNode<>nil); + lsrInterfaceStart: ; + lsrMainUsesSectionStart: + AssertEquals('main uses section start scanned',true,Tool.FindMainUsesNode<>nil); + lsrMainUsesSectionEnd: + AssertEquals('main uses section end scanned',true,Tool.FindMainUsesNode.FirstChild<>nil); + lsrImplementationStart: ; + lsrImplementationUsesSectionStart: ; + lsrImplementationUsesSectionEnd: ; + lsrInitializationStart: ; + lsrFinalizationStart: ; + lsrEnd: + AssertEquals('end. found',true,Tool.Tree.FindRootNode(ctnEndPoint)<>nil); + end; end; + finally + Code.IsDeleted:=true; end; end; @@ -463,40 +499,44 @@ var Src: String; begin Code:=CodeToolBoss.CreateFile('TestRangeScan.pas'); - Tool:=CodeToolBoss.GetCodeToolForSource(Code,false,true) as TCodeTool; + try + Tool:=CodeToolBoss.GetCodeToolForSource(Code,false,true) as TCodeTool; - Src:= - 'unit testrangescan;'+LineEnding - +'interface'+LineEnding - +'uses sysutils;'+LineEnding - +'implementation'+LineEnding - +'initialization'+LineEnding - +'write;'+LineEnding - +'finalization'+LineEnding - +'writeln;'+LineEnding - +'end.'+LineEnding; - Code.Source:=Src; - Tool.BuildTree(lsrEnd); - p:=1; - repeat - ReadRawNextPascalAtom(Src,p,AtomStart); - if p>=length(Src) then break; - if Src[AtomStart] in ['a'..'z'] then begin - try - {$IFDEF VerboseTestCTRangeScan} - debugln(['TTestCodetoolsRangeScan.TestCTScanRangeAscending Word="',GetIdentifier(@Src[AtomStart]),'"']); - {$ENDIF} - Src[AtomStart]:=upcase(Src[AtomStart]); - Code.Source:=Src; - Tool.BuildTree(lsrEnd); - except - on E: Exception do begin - debugln(['TTestCodetoolsRangeScan.TestCTScanRangeUnitModified word="'+GetIdentifier(@Src[AtomStart])+'" ',E.ClassName,' Msg=',E.Message]); - Fail(E.Message); + Src:= + 'unit testrangescan;'+LineEnding + +'interface'+LineEnding + +'uses sysutils;'+LineEnding + +'implementation'+LineEnding + +'initialization'+LineEnding + +'write;'+LineEnding + +'finalization'+LineEnding + +'writeln;'+LineEnding + +'end.'+LineEnding; + Code.Source:=Src; + Tool.BuildTree(lsrEnd); + p:=1; + repeat + ReadRawNextPascalAtom(Src,p,AtomStart); + if p>=length(Src) then break; + if Src[AtomStart] in ['a'..'z'] then begin + try + {$IFDEF VerboseTestCTRangeScan} + debugln(['TTestCodetoolsRangeScan.TestCTScanRangeAscending Word="',GetIdentifier(@Src[AtomStart]),'"']); + {$ENDIF} + Src[AtomStart]:=upcase(Src[AtomStart]); + Code.Source:=Src; + Tool.BuildTree(lsrEnd); + except + on E: Exception do begin + debugln(['TTestCodetoolsRangeScan.TestCTScanRangeUnitModified word="'+GetIdentifier(@Src[AtomStart])+'" ',E.ClassName,' Msg=',E.Message]); + Fail(E.Message); + end; end; end; - end; - until false; + until false; + finally + Code.IsDeleted:=true; + end; end; initialization diff --git a/components/codetools/tests/testdesignerformtools.pas b/components/codetools/tests/testdesignerformtools.pas index 3f42bad42e..2e33e9e0df 100644 --- a/components/codetools/tests/testdesignerformtools.pas +++ b/components/codetools/tests/testdesignerformtools.pas @@ -79,6 +79,7 @@ begin s+=Expected[i]+LineEnding; CheckDiff(Title,s,Code.Source); finally + Code.IsDeleted:=true; CodeToolBoss.DefineTree.RemoveDefineTemplate(DefTemp); end; end; @@ -135,6 +136,7 @@ begin Fail('VarNameToToType differ'); end; finally + Code.IsDeleted:=true; VarNameToToType.Free; CodeToolBoss.DefineTree.RemoveDefineTemplate(DefTemp); end; diff --git a/components/codetools/tests/testfinddeclaration.pas b/components/codetools/tests/testfinddeclaration.pas index 1c4d80cc1e..311a15edeb 100644 --- a/components/codetools/tests/testfinddeclaration.pas +++ b/components/codetools/tests/testfinddeclaration.pas @@ -1510,20 +1510,24 @@ var UnitType: TCodeBuffer; begin UnitType:=CodeToolBoss.CreateFile('type.pas'); - UnitType.Source:= - 'unit &Type;'+sLineBreak - +'interface'+sLineBreak - +'var r: word;'+sLineBreak - +'implementation'+sLineBreak - +'end.'; + try + UnitType.Source:= + 'unit &Type;'+sLineBreak + +'interface'+sLineBreak + +'var r: word;'+sLineBreak + +'implementation'+sLineBreak + +'end.'; - StartProgram; - Add([ - 'uses &Type;', - 'begin', - ' r{declaration:&type.r}:=3;', - 'end.']); - FindDeclarations(Code); + StartProgram; + Add([ + 'uses &Type;', + 'begin', + ' r{declaration:&type.r}:=3;', + 'end.']); + FindDeclarations(Code); + finally + UnitType.IsDeleted:=true; + end; end; procedure TTestFindDeclaration.TestFindDeclaration_AmpersandArray; diff --git a/components/codetools/tests/testmethodjumptool.pas b/components/codetools/tests/testmethodjumptool.pas index 8186dfac4e..8274465648 100644 --- a/components/codetools/tests/testmethodjumptool.pas +++ b/components/codetools/tests/testmethodjumptool.pas @@ -146,22 +146,26 @@ begin +'{$I TestMethodJumpTool2.inc}'+LineEnding +'end.'+LineEnding; IncCode:=CodeToolBoss.CreateFile('TestMethodJumpTool2.inc'); - IncCode.Source:='' - +'{%MainUnit test1.pas}'+LineEnding - +'{$IFDEF UseInterface}'+LineEnding - +'procedure {ProcHeader}DoSomething;'+LineEnding - +'{$ENDIF}'+LineEnding - +'{$IFDEF UseImplementation}'+LineEnding - +'procedure DoSomething;'+LineEnding - +'begin'+LineEnding - +' {ProcBody}writeln;'+LineEnding - +'end;'+LineEnding - +'{$ENDIF}'+LineEnding; + try + IncCode.Source:='' + +'{%MainUnit test1.pas}'+LineEnding + +'{$IFDEF UseInterface}'+LineEnding + +'procedure {ProcHeader}DoSomething;'+LineEnding + +'{$ENDIF}'+LineEnding + +'{$IFDEF UseImplementation}'+LineEnding + +'procedure DoSomething;'+LineEnding + +'begin'+LineEnding + +' {ProcBody}writeln;'+LineEnding + +'end;'+LineEnding + +'{$ENDIF}'+LineEnding; - Test('Method jump from interface to implementation in one include file', - IncCode,'ProcHeader',false,'ProcBody',true); - Test('Method jump from implementation to interface in one include file', - IncCode,'ProcBody',false,'ProcHeader',false); + Test('Method jump from interface to implementation in one include file', + IncCode,'ProcHeader',false,'ProcBody',true); + Test('Method jump from implementation to interface in one include file', + IncCode,'ProcBody',false,'ProcHeader',false); + finally + IncCode.IsDeleted:=true; + end; end; procedure TTestMethodJumpTool.TestMethodJump_IntfToImplSingleProc; diff --git a/components/codetools/tests/testrefactoring.pas b/components/codetools/tests/testrefactoring.pas index 8810c57fae..dabcfa8096 100644 --- a/components/codetools/tests/testrefactoring.pas +++ b/components/codetools/tests/testrefactoring.pas @@ -73,7 +73,6 @@ type procedure TestRenameUsedUnit_Impl; procedure TestRenameUsedUnit_FN_KeepShort; procedure TestRenameUsedUnit_InFilename; - // todo: rename uses Bar in 'bar.pas' end; implementation @@ -1486,7 +1485,7 @@ var begin UsedUnit:=nil; try - UsedUnit:=CodeToolBoss.CreateFile('type.pp'); + UsedUnit:=CodeToolBoss.CreateFile('type.pas'); UsedUnit.Source:='unit &Type;'+LineEnding +'interface'+LineEnding +'type'+LineEnding diff --git a/components/codetools/tests/teststdcodetools.pas b/components/codetools/tests/teststdcodetools.pas index b83d9a22b3..3d57f2fa21 100644 --- a/components/codetools/tests/teststdcodetools.pas +++ b/components/codetools/tests/teststdcodetools.pas @@ -223,21 +223,25 @@ var i: Integer; begin Code:=CodeToolBoss.CreateFile('test1.pas'); - s:=''; - for i:=Low(Src) to High(Src) do - s+=Src[i]+LineEnding; - Code.Source:=s; + try + s:=''; + for i:=Low(Src) to High(Src) do + s+=Src[i]+LineEnding; + Code.Source:=s; - if not CodeToolBoss.AddUnitWarnDirective(Code,WarnID,Comment,TurnOn) then begin - WriteSource(Code.Filename,1,1); - Fail(Title+'call AddUnitWarnDirective failed: '+CodeToolBoss.ErrorDbgMsg); + if not CodeToolBoss.AddUnitWarnDirective(Code,WarnID,Comment,TurnOn) then begin + WriteSource(Code.Filename,1,1); + Fail(Title+'call AddUnitWarnDirective failed: '+CodeToolBoss.ErrorDbgMsg); + end; + + //debugln(['TTestCTStdCodetools.DoTestAddUnitWarn NewSrc=',Code.Source]); + s:=''; + for i:=Low(Expected) to High(Expected) do + s+=Expected[i]+LineEnding; + CheckDiff(Title,s,Code.Source); + finally + Code.IsDeleted:=true; end; - - //debugln(['TTestCTStdCodetools.DoTestAddUnitWarn NewSrc=',Code.Source]); - s:=''; - for i:=Low(Expected) to High(Expected) do - s+=Expected[i]+LineEnding; - CheckDiff(Title,s,Code.Source); end; procedure TTestCTStdCodetools.DoTestAddUnitToMainUses(NewUnitName, NewUnitInFilename, UsesSrc, ExpectedUsesSrc: string; @@ -253,19 +257,23 @@ begin +'begin'+LineEnding +'end.'+LineEnding; Code:=CodeToolBoss.CreateFile('TestStdCodeTools.pas'); - Code.Source:=Header+UsesSrc+Footer; - if not CodeToolBoss.AddUnitToMainUsesSectionIfNeeded(Code,NewUnitName,NewUnitInFilename,Flags) then - begin - AssertEquals('AddUnitToMainUsesSectionIfNeeded failed: '+CodeToolBoss.ErrorMessage,true,false); - end else begin - Src:=Code.Source; - AssertEquals('AddUnitToMainUsesSectionIfNeeded altered header: ',Header,LeftStr(Src,length(Header))); - System.Delete(Src,1,length(Header)); - AssertEquals('AddUnitToMainUsesSectionIfNeeded altered footer: ',Footer,RightStr(Src,length(Footer))); - System.Delete(Src,length(Src)-length(Footer)+1,length(Footer)); - if ExpectedUsesSrc<>Src then - debugln(Code.Source); - AssertEquals('AddUnitToMainUsesSectionIfNeeded: ',ExpectedUsesSrc,Src); + try + Code.Source:=Header+UsesSrc+Footer; + if not CodeToolBoss.AddUnitToMainUsesSectionIfNeeded(Code,NewUnitName,NewUnitInFilename,Flags) then + begin + AssertEquals('AddUnitToMainUsesSectionIfNeeded failed: '+CodeToolBoss.ErrorMessage,true,false); + end else begin + Src:=Code.Source; + AssertEquals('AddUnitToMainUsesSectionIfNeeded altered header: ',Header,LeftStr(Src,length(Header))); + System.Delete(Src,1,length(Header)); + AssertEquals('AddUnitToMainUsesSectionIfNeeded altered footer: ',Footer,RightStr(Src,length(Footer))); + System.Delete(Src,length(Src)-length(Footer)+1,length(Footer)); + if ExpectedUsesSrc<>Src then + debugln(Code.Source); + AssertEquals('AddUnitToMainUsesSectionIfNeeded: ',ExpectedUsesSrc,Src); + end; + finally + Code.IsDeleted:=true; end; end; @@ -323,6 +331,7 @@ begin Test('begin,try,finally,end|end','begin1','begin1end'); Test('begin,try,finally,|end,end','try1finally','try1end'); Test('begin,try,finally,|end,end','try1','try1finally'); + Code.IsDeleted:=true; end; procedure TTestCTStdCodetools.TestCTUses_AddUses_Start; @@ -405,17 +414,21 @@ procedure TTestCTStdCodetools.TestCTUses_RemoveFromAllUsesSections; +'begin'+LineEnding +'end.'+LineEnding; Code:=CodeToolBoss.CreateFile('TestStdCodeTools.pas'); - Code.Source:=Header+UsesSrc+Footer; - if not CodeToolBoss.RemoveUnitFromAllUsesSections(Code,RemoveUnit) then - begin - AssertEquals('RemoveUnitFromAllUsesSections failed: '+CodeToolBoss.ErrorMessage,true,false); - end else begin - Src:=Code.Source; - AssertEquals('RemoveUnitFromAllUsesSections altered header: ',Header,LeftStr(Src,length(Header))); - System.Delete(Src,1,length(Header)); - AssertEquals('RemoveUnitFromAllUsesSections altered footer: ',Footer,RightStr(Src,length(Footer))); - System.Delete(Src,length(Src)-length(Footer)+1,length(Footer)); - AssertEquals('RemoveUnitFromAllUsesSections: ',ExpectedUsesSrc,Src); + try + Code.Source:=Header+UsesSrc+Footer; + if not CodeToolBoss.RemoveUnitFromAllUsesSections(Code,RemoveUnit) then + begin + AssertEquals('RemoveUnitFromAllUsesSections failed: '+CodeToolBoss.ErrorMessage,true,false); + end else begin + Src:=Code.Source; + AssertEquals('RemoveUnitFromAllUsesSections altered header: ',Header,LeftStr(Src,length(Header))); + System.Delete(Src,1,length(Header)); + AssertEquals('RemoveUnitFromAllUsesSections altered footer: ',Footer,RightStr(Src,length(Footer))); + System.Delete(Src,length(Src)-length(Footer)+1,length(Footer)); + AssertEquals('RemoveUnitFromAllUsesSections: ',ExpectedUsesSrc,Src); + end; + finally + Code.IsDeleted:=true; end; end; @@ -524,22 +537,26 @@ procedure TTestCTStdCodetools.TestCTSetApplicationTitleStatement; OldSrc:=Header+OldBeginEnd; ExpectedSrc:=Header+NewBeginEnd; Code:=CodeToolBoss.CreateFile('TestStdCodeTools.pas'); - Code.Source:=OldSrc; - if not CodeToolBoss.SetApplicationTitleStatement(Code,NewTitle) then - begin - writeln('Src=['); - writeln(OldSrc,']'); - AssertEquals('SetApplicationTitleStatement failed: '+CodeToolBoss.ErrorMessage,true,false); - end else begin - ActualSrc:=Code.Source; - if ActualSrc=ExpectedSrc then exit; - writeln('TTestCTStdCodetools.TestCTSetApplicationTitleStatement OldSrc:'); - writeln(OldSrc); - writeln('TTestCTStdCodetools.TestCTSetApplicationTitleStatement NewTitle="',NewTitle,'" ExpectedSrc:'); - writeln(ExpectedSrc); - writeln('TTestCTStdCodetools.TestCTSetApplicationTitleStatement But found NewSrc:'); - writeln(ActualSrc); - Fail('SetApplicationTitleStatement with Title="'+NewTitle+'"'); + try + Code.Source:=OldSrc; + if not CodeToolBoss.SetApplicationTitleStatement(Code,NewTitle) then + begin + writeln('Src=['); + writeln(OldSrc,']'); + AssertEquals('SetApplicationTitleStatement failed: '+CodeToolBoss.ErrorMessage,true,false); + end else begin + ActualSrc:=Code.Source; + if ActualSrc=ExpectedSrc then exit; + writeln('TTestCTStdCodetools.TestCTSetApplicationTitleStatement OldSrc:'); + writeln(OldSrc); + writeln('TTestCTStdCodetools.TestCTSetApplicationTitleStatement NewTitle="',NewTitle,'" ExpectedSrc:'); + writeln(ExpectedSrc); + writeln('TTestCTStdCodetools.TestCTSetApplicationTitleStatement But found NewSrc:'); + writeln(ActualSrc); + Fail('SetApplicationTitleStatement with Title="'+NewTitle+'"'); + end; + finally + Code.IsDeleted:=true; end; end;