3
./runtests --format=plain --suite=TTestCodetoolsCfgScript
4
./runtests --format=plain --suite=TestCfgScript
10
{$DEFINE VerboseTestCfgScript}
15
Classes, SysUtils, fpcunit, testglobals, FileProcs,
20
{ TTestCodetoolsCfgScript }
22
TTestCodetoolsCfgScript = class(TTestCase)
24
procedure TestResult(Script, ExpectedResult: string);
25
procedure TestSyntaxError(Script, ExpectedError: string);
27
procedure TestCfgScript;
32
{ TTestCodetoolsCfgScript }
34
procedure TTestCodetoolsCfgScript.TestResult(Script, ExpectedResult: string);
36
Engine: TCTConfigScriptEngine;
40
Engine:=TCTConfigScriptEngine.Create;
42
Engine.MaxErrorCount:=1;
43
if not Engine.Execute(Script) then begin
44
writeln('Script failed to run:');
45
for i:=0 to Engine.ErrorCount-1 do
46
writeln(Engine.GetErrorStr(i));
47
AssertEquals('Syntax error in script "'+Script+'"',true,false);
49
ScriptResult:=Engine.Variables['Result'];
50
if ScriptResult<>ExpectedResult then
51
Engine.Variables.WriteDebugReport('Variables');
52
AssertEquals(Script,ExpectedResult,ScriptResult);
59
procedure TTestCodetoolsCfgScript.TestSyntaxError(Script, ExpectedError: string
62
Engine: TCTConfigScriptEngine;
64
Engine:=TCTConfigScriptEngine.Create;
66
Engine.MaxErrorCount:=1;
67
if Engine.Execute(Script) then begin
68
AssertEquals('Syntax error in script not recognized: "'+Script+'"',true,false);
70
//writeln('TTestCodetoolsCfgScript.TestSyntaxError ',Engine.Errors[0].Msg);
71
AssertEquals(Script,ExpectedError,Engine.Errors[0].Msg);
78
procedure TTestCodetoolsCfgScript.TestCfgScript;
80
TestResult('Result:=2;','2');
81
TestResult('a:=2; b:=a; Result:=b;','2');
82
TestResult('Result:=1+2;','3');
83
TestResult('Result:=1=2;','0');
84
TestResult('Result:=1<>2;','1');
85
TestResult('Result:=2>1;','1');
86
TestResult('Result:=2>2;','0');
87
TestResult('Result:=2<2;','0');
88
TestResult('Result:=1<2;','1');
89
TestSyntaxError('{invalid operator * }Result:=2*3;','expected ; of statement, but found *');
93
AddToCodetoolsTestSuite(TTestCodetoolsCfgScript);