Assertions: Difference between revisions

Content added Content deleted
(→‎{{header|Perl}}: rearrangements)
No edit summary
Line 134:
MODULE Assertions;
VAR
x: INTEGER;
PROCEDURE DoIt*;
BEGIN
x := 41;
ASSERT(x = 42);
END DoIt;
END Assertions.
Line 150:
Assertions.DoIt [0000001DH]
Kernel.Call [00001A7CH]
.adr INTEGER 1685454913
.kind INTEGER 0
.n INTEGER 0
.p INTEGER 0
.par ARRAY 256 OF INTEGER elements
.r REAL 8.70603013185328E+175
.sig POINTER [64760018H]
.size INTEGER 2287288
.sp INTEGER 256
.typ POINTER NIL
Meta.Item.ParamCallVal [00002B5EH]
.adr INTEGER 1685454913
.data ARRAY 256 OF INTEGER elements
</pre>
=={{header|D}}==
Line 429:
before 'Hello Universe'...
java.lang.AssertionError: This: Hello Universe is not the answer!. Expression: (it == 42). Values: it = Hello Universe
at ConsoleScript80$_run_closure1.doCall(ConsoleScript80:2)
at ConsoleScript80.run(ConsoleScript80:8)</pre>
 
=={{header|Haskell}}==
Line 495:
julia> x::String
ERROR: type: typeassert: expected String, got Int32</lang>
 
=={{header|Lasso}}==
<lang lasso>local(a) = 8
fail_if(
#a != 42,
error_code_runtimeAssertion,
error_msg_runtimeAssertion + ": #a is not 42"
)</lang>
{{out}}
<pre>-9945 Runtime assertion: #a is not 42</pre>
 
=={{header|Lisaac}}==
<lang Lisaac>? { n = 42 };</lang>
Line 566 ⟶ 577:
class SampleClass
{
public SomeMethod (input : list[int]) : int
requires input.Length > 0 // requires keyword indicates precondition,
// there can be more than one condition per method
{ ... }
 
public AnotherMethod (input : string) : list[char]
ensures value.Length > 0 // ensures keyword indicates postcondition
{ ... } // value is a special symbol that indicates the method's return value
}</lang>
The design by contract macros throw <tt>Nemerle.AssertionException</tt>'s unless another Exception is specified using the <tt>otherwise</tt> keyword after the <tt>requires/ensures</tt> statement.
Line 588 ⟶ 599:
MODULE Assertions;
VAR
a: INTEGER;
BEGIN
a := 40;
ASSERT(a = 42);
END Assertions.
</lang>
Line 990 ⟶ 1,001:
====Definition====
<lang vb>sub Assert( boolExpr, strOnFail )
if not boolExpr then
Err.Raise vbObjectError + 99999, , strOnFail
end if
end sub
</lang>