2006-05-30 16:23:25 +02:00
|
|
|
|
|
|
|
unit CompilerTestBase;
|
|
|
|
|
|
|
|
interface
|
|
|
|
|
2017-10-26 07:04:41 +02:00
|
|
|
uses Classes, uPSComponent, uPSCompiler, uPSRuntime, fpcunit, uPSC_std, uPSC_classes,
|
|
|
|
uPSR_std, uPSR_classes;
|
|
|
|
//TestFramework,
|
2006-05-30 16:23:25 +02:00
|
|
|
{ Project Units }
|
2017-10-26 07:04:41 +02:00
|
|
|
//ifps3,
|
|
|
|
//ifpscomp,
|
|
|
|
//IFPS3CompExec;
|
2006-05-30 16:23:25 +02:00
|
|
|
|
|
|
|
type
|
2017-10-26 07:04:41 +02:00
|
|
|
|
|
|
|
{ TCompilerTestBase }
|
|
|
|
|
2006-05-30 16:23:25 +02:00
|
|
|
TCompilerTestBase = class(TTestCase)
|
|
|
|
protected
|
|
|
|
procedure SetUp; override;
|
|
|
|
procedure TearDown; override;
|
|
|
|
protected
|
|
|
|
last_script : string;
|
|
|
|
CompExec: TIFPS3CompExec;
|
|
|
|
//Compiler: TIFPSPascalCompiler;
|
|
|
|
//Exec: TIFPSExec;
|
|
|
|
procedure Compile(script: string);
|
|
|
|
procedure CompileRun(Script: string);
|
|
|
|
|
2017-10-26 07:04:41 +02:00
|
|
|
procedure OnCompile(Sender: TPSScript); virtual;
|
|
|
|
procedure OnExecute(Sender: TPSScript); virtual;
|
2006-05-30 16:23:25 +02:00
|
|
|
procedure OnCompImport(Sender: TObject; x: TIFPSPascalCompiler); virtual;
|
|
|
|
procedure OnExecImport(Sender: TObject; se: TIFPSExec; x: TIFPSRuntimeClassImporter); virtual;
|
|
|
|
end;
|
|
|
|
|
|
|
|
implementation
|
|
|
|
|
|
|
|
uses StrUtils, SysUtils, Math,
|
2017-10-26 07:04:41 +02:00
|
|
|
Dialogs;//,
|
2006-05-30 16:23:25 +02:00
|
|
|
{ Project Units }
|
2017-10-26 07:04:41 +02:00
|
|
|
//ifpiir_std,
|
|
|
|
//ifpii_std,
|
|
|
|
//ifpiir_stdctrls,
|
|
|
|
//ifpii_stdctrls,
|
|
|
|
//ifpiir_forms,
|
|
|
|
//ifpii_forms,
|
|
|
|
//ifpii_graphics,
|
|
|
|
//ifpii_controls,
|
|
|
|
//ifpii_classes,
|
|
|
|
//ifpiir_graphics,
|
|
|
|
//ifpiir_controls,
|
|
|
|
//ifpiir_classes;
|
2006-05-30 16:23:25 +02:00
|
|
|
|
|
|
|
function MyFormat(const Format: string;
|
|
|
|
const Args: array of const): string;
|
|
|
|
begin
|
|
|
|
Result := SysUtils.Format(Format, Args);
|
|
|
|
end;
|
|
|
|
|
|
|
|
|
|
|
|
{ TCompilerTestBase }
|
|
|
|
|
|
|
|
procedure TCompilerTestBase.SetUp;
|
|
|
|
begin
|
|
|
|
inherited;
|
|
|
|
CompExec := TIFPS3CompExec.Create(nil);
|
2017-10-26 07:04:41 +02:00
|
|
|
CompExec.OnCompile := {$IFDEF FPC}@{$ENDIF}OnCompile;
|
|
|
|
CompExec.OnExecute := {$IFDEF FPC}@{$ENDIF}OnExecute;
|
|
|
|
CompExec.OnCompImport := {$IFDEF FPC}@{$ENDIF}OnCompImport;
|
|
|
|
CompExec.OnExecImport := {$IFDEF FPC}@{$ENDIF}OnExecImport;
|
2006-05-30 16:23:25 +02:00
|
|
|
end;
|
|
|
|
|
|
|
|
procedure TCompilerTestBase.TearDown;
|
|
|
|
begin
|
|
|
|
CompExec.Free;
|
|
|
|
//Compiler.Free;
|
|
|
|
//Exec.Free;
|
|
|
|
inherited;
|
|
|
|
end;
|
|
|
|
|
|
|
|
procedure TCompilerTestBase.CompileRun(Script: string);
|
|
|
|
var
|
|
|
|
ok: boolean;
|
|
|
|
begin
|
|
|
|
last_script := Script;
|
|
|
|
|
|
|
|
Compile(script);
|
|
|
|
|
|
|
|
ok := CompExec.Execute;
|
|
|
|
|
|
|
|
Check(ok, 'Exec Error:' + Script + #13#10 +
|
|
|
|
CompExec.ExecErrorToString + ' at ' +
|
|
|
|
Inttostr(CompExec.ExecErrorProcNo) + '.' +
|
|
|
|
Inttostr(CompExec.ExecErrorByteCodePosition));
|
|
|
|
end;
|
|
|
|
|
2017-10-26 07:04:41 +02:00
|
|
|
procedure TCompilerTestBase.OnCompile(Sender: TPSScript);
|
2006-05-30 16:23:25 +02:00
|
|
|
begin
|
|
|
|
Sender.AddFunction(@MyFormat, 'function Format(const Format: string; const Args: array of const): string;');
|
|
|
|
end;
|
|
|
|
|
|
|
|
procedure TCompilerTestBase.OnCompImport(Sender: TObject; x: TIFPSPascalCompiler);
|
|
|
|
begin
|
|
|
|
SIRegister_Std(x);
|
|
|
|
SIRegister_Classes(x, true);
|
|
|
|
end;
|
|
|
|
|
|
|
|
procedure TCompilerTestBase.OnExecImport(Sender: TObject; se: TIFPSExec; x: TIFPSRuntimeClassImporter);
|
|
|
|
begin
|
|
|
|
RIRegister_Std(x);
|
|
|
|
RIRegister_Classes(x, True);
|
|
|
|
end;
|
|
|
|
|
2017-10-26 07:04:41 +02:00
|
|
|
procedure TCompilerTestBase.OnExecute(Sender: TPSScript);
|
2006-05-30 16:23:25 +02:00
|
|
|
begin
|
|
|
|
//Sender.SetVarToInstance('SELF', Self);
|
|
|
|
end;
|
|
|
|
|
|
|
|
procedure TCompilerTestBase.Compile(script: string);
|
|
|
|
var
|
|
|
|
OutputMessages: string;
|
|
|
|
ok: Boolean;
|
|
|
|
i: Longint;
|
|
|
|
begin
|
|
|
|
|
|
|
|
CompExec.Script.Clear;
|
|
|
|
CompExec.Script.Add(Script);
|
|
|
|
|
|
|
|
OutputMessages := '';
|
|
|
|
ok := CompExec.Compile;
|
|
|
|
if (NOT ok) then
|
|
|
|
begin
|
|
|
|
//Get Compiler Messages now.
|
|
|
|
for i := 0 to CompExec.CompilerMessageCount - 1 do
|
|
|
|
OutputMessages := OutputMessages + CompExec.CompilerErrorToStr(i);
|
|
|
|
end;
|
|
|
|
Check(ok, 'Compiling failed:' + Script + #13#10 + OutputMessages);
|
|
|
|
|
|
|
|
end;
|
|
|
|
|
2017-10-26 07:04:41 +02:00
|
|
|
end.
|