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
|
--
-- Copyright (c) 2008 Tero Koskinen <tero.koskinen@iki.fi>
--
-- Permission to use, copy, modify, and distribute this software for any
-- purpose with or without fee is hereby granted, provided that the above
-- copyright notice and this permission notice appear in all copies.
--
-- THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
-- WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
-- MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
-- ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
-- WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
-- ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
-- OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
--
with Ahven;
use Ahven;
package body Assertion_Tests is
procedure Assert_Int_Equal is
new Assert_Equal (Data_Type => Integer, Image => Integer'Image);
procedure Initialize (T : in out Test) is
begin
Set_Name (T, "Ahven");
Framework.Add_Test_Routine
(T, Test_Assert_Equal'Access, "Assert_Equal");
Framework.Add_Test_Routine (T, Test_Assert'Access, "Assert");
Framework.Add_Test_Routine (T, Test_Fail'Access, "Fail");
end Initialize;
procedure Test_Assert_Equal is
Exception_Got : Boolean;
begin
begin
Exception_Got := False;
Assert_Int_Equal
(Expected => 1, Actual => 1, Message => "Assert_Equal");
exception
when Assertion_Error =>
Exception_Got := True;
end;
Assert (not Exception_Got, "exception for valid condition!");
begin
Exception_Got := False;
Assert_Int_Equal
(Expected => 1, Actual => 2, Message => "Assert_Equal");
exception
when Assertion_Error =>
Exception_Got := True;
end;
Assert (Exception_Got, "no exception for invalid condition!");
end Test_Assert_Equal;
procedure Test_Fail is
Exception_Got : Boolean;
begin
begin
Exception_Got := False;
Fail ("fail");
exception
when Assertion_Error =>
Exception_Got := True;
end;
Assert (Exception_Got, "Fail did not raise exception!");
end Test_Fail;
procedure Test_Assert is
Exception_Got : Boolean;
begin
Assert (True, "Assert (True)");
begin
Exception_Got := False;
Assert (False, "assertion");
exception
when Assertion_Error =>
Exception_Got := True;
end;
if not Exception_Got then
-- Raising Assertion_Error directly, since Assert apparently
-- does not work.
raise Assertion_Error;
end if;
end Test_Assert;
end Assertion_Tests;
|