forked from fpc/Lazarus
-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathCompilerTestBase.pas
More file actions
141 lines (114 loc) · 3.37 KB
/
Copy pathCompilerTestBase.pas
File metadata and controls
141 lines (114 loc) · 3.37 KB
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
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
unit CompilerTestBase;
interface
uses Classes, uPSComponent, uPSCompiler, uPSRuntime, fpcunit, uPSC_std, uPSC_classes,
uPSR_std, uPSR_classes;
//TestFramework,
{ Project Units }
//ifps3,
//ifpscomp,
//IFPS3CompExec;
type
{ TCompilerTestBase }
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);
procedure OnCompile(Sender: TPSScript); virtual;
procedure OnExecute(Sender: TPSScript); virtual;
procedure OnCompImport(Sender: TObject; x: TIFPSPascalCompiler); virtual;
procedure OnExecImport(Sender: TObject; se: TIFPSExec; x: TIFPSRuntimeClassImporter); virtual;
end;
implementation
uses StrUtils, SysUtils, Math,
Dialogs;//,
{ Project Units }
//ifpiir_std,
//ifpii_std,
//ifpiir_stdctrls,
//ifpii_stdctrls,
//ifpiir_forms,
//ifpii_forms,
//ifpii_graphics,
//ifpii_controls,
//ifpii_classes,
//ifpiir_graphics,
//ifpiir_controls,
//ifpiir_classes;
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);
CompExec.OnCompile := {$IFDEF FPC}@{$ENDIF}OnCompile;
CompExec.OnExecute := {$IFDEF FPC}@{$ENDIF}OnExecute;
CompExec.OnCompImport := {$IFDEF FPC}@{$ENDIF}OnCompImport;
CompExec.OnExecImport := {$IFDEF FPC}@{$ENDIF}OnExecImport;
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;
procedure TCompilerTestBase.OnCompile(Sender: TPSScript);
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;
procedure TCompilerTestBase.OnExecute(Sender: TPSScript);
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;
end.