Ada Programming/Libraries/Ada.Assertions
This language feature is only available from Ada 2005 on.
Ada. is a unit of the Predefined Language Environment since Ada 2005.
The Assert procedures in this package raise the Assertion_Error exception if the Check parameter is False.
This is the same behavior as the pragma Assert when the pragma Assertion_Policy is Check. In fact, you could think of pragma Assert as a call to this package, conditioned to the value of the pragma Assertion_Policy.
Example
This will raise Assertion_Error with the provided message.
with Ada.Assertions;
procedure Failing_Assertion is
begin
Ada.Assertions.Assert (0 in Positive, "0 is not in the positive range");
end Failing_Assertion;
Specification
-- Standard Ada library specification -- Copyright (c) 2003-2018 Maxim Reznik <reznikmm@gmail.com> -- Copyright (c) 2004-2016 AXE Consultants -- Copyright (c) 2004, 2005, 2006 Ada-Europe -- Copyright (c) 2000 The MITRE Corporation, Inc. -- Copyright (c) 1992, 1993, 1994, 1995 Intermetrics, Inc. -- SPDX-License-Identifier: BSD-3-Clause and LicenseRef-AdaReferenceManual -- -------------------------------------------------------------------------packageAda.ispragmaPure (Assertions); Assertion_Error :exception;procedureAssert (Check :inBoolean);procedureAssert (Check :inBoolean; Message :inString);endAda.Assertions;
See also
Wikibook
External examples
- Search for examples of
Ada.Assertionsin: Rosetta Code, GitHub (gists), any Alire crate or this Wikibook. - Search for posts related to
Ada.Assertionsin: Stack Overflow, comp.lang.ada or any Ada related page.
Ada Reference Manual
Ada 2005
Ada 2012
Open-Source Implementations
FSF GNAT
- Specification: a-assert.ads
- Body: a-assert.adb
drake
- Specification: a-assert.ads
- Body: a-assert.adb