Skip to content

Commit 4246e62

Browse files
committed
2 parents d1f8bd0 + 29f0a02 commit 4246e62

File tree

3 files changed

+21
-0
lines changed

3 files changed

+21
-0
lines changed

Test.pas

+17
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
CustomFunctionWithSelfTest = 'a = [ func: add, value: 1 ] writeln(a.func(3).value)';
1717
YieldTest = 'i = 0 while i < 3 { i = i + 1 yield }';
1818
FibTest = 'fn fib(n) { if n < 2 result = n else result = fib(n-1) + fib(n-2) } writeln(fib(36))';
19+
AssertTest = 'assert(false, "Assert triggered")';
1920
ResultTest = 'result = 5';
2021

2122
type
@@ -120,6 +121,21 @@ procedure FibTestRun;
120121
Writeln(GetTickCount - S, 'ms');
121122
end;
122123

124+
procedure AssertTestRun;
125+
begin
126+
try
127+
Writeln('--- AssertTestRun ---');
128+
SE.OptimizeAsserts := False;
129+
SE.Source := AssertTest;
130+
SE.Exec;
131+
except
132+
on E: Exception do
133+
begin
134+
Writeln(E.Message);
135+
end;
136+
end;
137+
end;
138+
123139
procedure ResultTestRun;
124140
begin
125141
Writeln('--- ResultTestRun ---');
@@ -139,6 +155,7 @@ procedure ResultTestRun;
139155
CustomFunctionWithSelfTestRun;
140156
YieldTestRun;
141157
FibTestRun;
158+
AssertTestRun;
142159
ResultTestRun;
143160
SE.Free;
144161
end.

evil.pas

+1
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
Halt;
1818
end;
1919
SE := TScriptEngine.Create;
20+
SE.OptimizeAsserts := False;
2021
SL := TStringList.Create;
2122
try
2223
try

examples/assert.evil

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
writeln('Example on how to use assertions')
2+
writeln('You can enable assertions by setting OptimizeAsserts field to false')
3+
assert(false, 'Assert triggered')

0 commit comments

Comments
 (0)