From 2e95e24d2fbeda4576a0c44aca55f7832d777d85 Mon Sep 17 00:00:00 2001 From: mattias Date: Tue, 8 May 2018 17:00:20 +0000 Subject: [PATCH] codetools: started parsing pas2js output git-svn-id: trunk@57845 - --- .gitattributes | 1 + .../codetools/tests/runtestscodetools.lpi | 7 +- .../codetools/tests/runtestscodetools.lpr | 2 +- components/codetools/tests/testctpas2js.pas | 102 ++++++++++++++++++ 4 files changed, 110 insertions(+), 2 deletions(-) create mode 100644 components/codetools/tests/testctpas2js.pas diff --git a/.gitattributes b/.gitattributes index 83b022e5b0..416bf7d30e 100644 --- a/.gitattributes +++ b/.gitattributes @@ -969,6 +969,7 @@ components/codetools/tests/testcodecompletion.pas svneol=native#text/plain components/codetools/tests/testcompleteblock.pas svneol=native#text/plain components/codetools/tests/testcompreaderwriterpas.pas svneol=native#text/plain components/codetools/tests/testcth2pas.pas svneol=native#text/pascal +components/codetools/tests/testctpas2js.pas svneol=native#text/plain components/codetools/tests/testctrangescan.pas svneol=native#text/plain components/codetools/tests/testctxmlfixfragments.pas svneol=native#text/pascal components/codetools/tests/testfinddeclaration.pas svneol=native#text/plain diff --git a/components/codetools/tests/runtestscodetools.lpi b/components/codetools/tests/runtestscodetools.lpi index 20ce51b278..a062e4cb98 100644 --- a/components/codetools/tests/runtestscodetools.lpi +++ b/components/codetools/tests/runtestscodetools.lpi @@ -38,7 +38,7 @@ - + @@ -105,6 +105,11 @@ + + + + + diff --git a/components/codetools/tests/runtestscodetools.lpr b/components/codetools/tests/runtestscodetools.lpr index 352d9d4d3f..dcca41c528 100644 --- a/components/codetools/tests/runtestscodetools.lpr +++ b/components/codetools/tests/runtestscodetools.lpr @@ -39,7 +39,7 @@ uses TestBasicCodetools, TestCTRangeScan, TestPascalParser, TestMethodJumpTool, TestStdCodetools, TestFindDeclaration, TestIdentCompletion, TestCompleteBlock, TestRefactoring, TestCodeCompletion, TestCompReaderWriterPas, - fdt_arrays; + fdt_arrays, TestCTPas2js; const ConfigFilename = 'codetools.config'; diff --git a/components/codetools/tests/testctpas2js.pas b/components/codetools/tests/testctpas2js.pas new file mode 100644 index 0000000000..aa1ebcb53a --- /dev/null +++ b/components/codetools/tests/testctpas2js.pas @@ -0,0 +1,102 @@ +{ + Test all with: + ./runtests --format=plain --suite=TTestPas2js + + Test specific with: + ./runtests --format=plain --suite=TestPas2js_ReadSettings +} +unit TestCTPas2js; + +{$mode objfpc}{$H+} + +interface + +uses + Classes, SysUtils, CodeToolManager, FileProcs, DefineTemplates, LinkScanner, + LazLogger, LazFileUtils, LazUTF8, fpcunit, testregistry; + +type + + { TCustomTestPas2js } + + TCustomTestPas2js = class(TTestCase) + private + FAutoSearchPas2js: boolean; + FPas2jsFilename: string; + protected + procedure SetUp; override; + procedure TearDown; override; + public + constructor Create; override; + function FindPas2js: string; + property AutoSearchPas2js: boolean read FAutoSearchPas2js write FAutoSearchPas2js; + property Pas2jsFilename: string read FPas2jsFilename write FPas2jsFilename; + end; + + { TTestPas2js } + + TTestPas2js = class(TCustomTestPas2js) + published + procedure TestPas2js_ReadSettings; + end; + +implementation + +{ TCustomTestPas2js } + +procedure TCustomTestPas2js.SetUp; +begin + inherited SetUp; + if (Pas2jsFilename='') and AutoSearchPas2js then begin + FPas2jsFilename:=FindPas2js; + AutoSearchPas2js:=false; + end; + //CodeToolBoss.CompilerDefinesCache; +end; + +procedure TCustomTestPas2js.TearDown; +begin + inherited TearDown; +end; + +constructor TCustomTestPas2js.Create; +begin + inherited Create; + FAutoSearchPas2js:=true; +end; + +function TCustomTestPas2js.FindPas2js: string; +var + ShortFilename: String; +begin + Result:=GetEnvironmentVariable('PAS2JS'); + if Result<>'' then begin + if not FileExistsUTF8(Result) then + Fail('Environment variable PAS2JS has non existing "'+Result+'"'); + exit; + end; + ShortFilename:='pas2js'+ExeExt; + Result:=SearchFileInPath(ShortFilename,'', + GetEnvironmentVariableUTF8('PATH'),PathSeparator,ctsfcDefault); +end; + +{ TTestPas2js } + +procedure TTestPas2js.TestPas2js_ReadSettings; +var + UnitSetCache: TFPCUnitSetCache; +begin + if Pas2jsFilename='' then exit; + + exit; + UnitSetCache:=CodeToolBoss.CompilerDefinesCache.FindUnitSet(Pas2jsFilename, + '','','','',true); + // parse compiler settings + UnitSetCache.Init; + AssertEquals('compiler kind',dbgs(pcPas2js),dbgs(UnitSetCache.GetCompilerKind)); +end; + +initialization + RegisterTest(TTestPas2js); +end. +