Group Assertion and Check Macros
The assertion and check macros provided by SeqAn.
Grouped Macros Overview
Test that the given expression can be coerced to true. |
Test that two given expressions are equal, as defined by the matching call to the operator=(,). |
Test that the two given expressions are in the greater-than-or-equal
relation as defined by the matching call to operator>=(,). |
Test that the two given expressions are in the greather-than relation
as defined by the matching call to operator>(,). |
Test that a value y lies within an delta environment of a value x. |
Test that the two given expressions are in the less-than-or-equal
relation as defined by the matching call to operator<=(,). |
Test that the two given expressions are in the less-than relation as defined by the matching call to
operator<(,). |
Test that two given expressions are not equal, as defined by the matching call to the operator!=(,). |
Test that the given expression can be coerced to false. |
Force abortion of program if a condition is not met, regardless of debugging settings. |
Force abortion of program, regardless of debugging settings. |
Detailed Description
Assertions are checks performed at runtime when debugging is enabled. Debugging is enabled by defining the preprocessor symbol SEQAN_ENABLE_DEBUG as 1 (the default is to set it to 0 if the common C macro NDEBUG is defined and to set it to 1 otherwise. When using the SeqAn build system or the CMake FindSeqAn.cmake module, this is automatically set appropriately.
The SEQAN_CHECK and SEQAN_FAIL macro always lead to an exit of the program with a non-0 return value.
Grouped Macros Detail
AssertMacros#SEQAN_ASSERT
- Defined in
- <seqan/basic.h>
SEQAN_ASSERT(expression);
SEQAN_ASSERT_MSG(expression, message[, parameters]);
- Parameters
-
expression
(in) - An expression to check for being true. -
message
(in) - A format string. -
parameters
(in) - An optional list of parameters.
Remarks
The main advantage of this macro is that it prints the values of its argument on failures. Note that the operator<< to the type of std::cerr has to be defined for the type of both expression parameters. Otherwise, simply use the equivalent SEQAN_ASSERT @call.
See SEQAN_CHECK and SEQAN_FAIL for (conditionally) aborting your program regardless of debug settings.
Examples
SEQAN_ASSERT(0); // will fail SEQAN_ASSERT(1); // will run through SEQAN_ASSERT_MSG(0, "message %d", 2); // Will fail with message.
AssertMacros#SEQAN_ASSERT_EQ
- Defined in
- <seqan/basic.h>
SEQAN_ASSERT_EQ(expression1, expression2);
SEQAN_ASSERT_EQ_MSG(expression1, expression2, comment[, parameters]);
- Parameters
-
expression1
(in) - The first expression. -
expression2
(in) - The second expression. -
comment
(in) - A C-string (char const *) to use as a format string for printing a message on failure. -
parameters
(in) - An optional parameter that is put into printf() with format string comment.
The main advantage of this macro is that it prints the values of its argument on failures. Note that the operator<< to the type of std::cerr has to be defined for the type of both expression parameters. Otherwise, simply use the equivalent SEQAN_ASSERT call.
See SEQAN_CHECK and SEQAN_FAIL for (conditionally) aborting your program regardless of debug settings.
Examples
SEQAN_ASSERT_EQ(0, false); // will run through SEQAN_ASSERT_EQ(1, false); // will fail SEQAN_ASSERT_EQ(1, "foo"); // will not compile SEQAN_ASSERT_EQ_MSG(1, false, "msg"); // will fail with message
AssertMacros#SEQAN_ASSERT_GEQ
SEQAN_ASSERT_GEQ(expression1, expression2);
SEQAN_ASSERT_GEQ_MSG(expression1, expression2, comment[, parameters]);
- Parameters
-
expression1
(in) - The first expression. -
expression2
(in) - The second expression. -
comment
(in) - A C-string (char const *) to use as a format string for printing a message on failure. -
parameters
(in) - An optional parameter that is put into printf() with format string comment.
The main advantage of this macro is that it prints the values of its argument on failures. Note that the operator<< to the type of std::cerr has to be defined for the type of both expression parameters. Otherwise, simply use the equivalent SEQAN_ASSERT call.
See SEQAN_CHECK and SEQAN_FAIL for (conditionally) aborting your program regardless of debug settings.
Examples
SEQAN_ASSERT_GEQ(1, 1); // will run through SEQAN_ASSERT_GEQ(0, 1); // will not run through SEQAN_ASSERT_GEQ_MSG(0, 1, "msg"); // will fail with message
AssertMacros#SEQAN_ASSERT_GT
SEQAN_ASSERT_GT(expression1, expression2);
SEQAN_ASSERT_GT_MSG(expression1, expression2, comment[, parameters]);
- Parameters
-
expression1
(in) - The first expression. -
expression2
(in) - The second expression. -
comment
(in) - A C-string (char const *) to use as a format string for printing a message on failure. -
parameters
(in) - An optional parameter that is put into printf() with format string comment.
The main advantage of this macro is that it prints the values of its argument on failures. Note that the operator<< to the type of std::cerr has to be defined for the type of both expression parameters. Otherwise, simply use the equivalent SEQAN_ASSERT call.
See SEQAN_CHECK and SEQAN_FAIL for (conditionally) aborting your program regardless of debug settings.
Examples
SEQAN_ASSERT_GT(2, 1); // will run through SEQAN_ASSERT_GT(1, 1); // will not run through SEQAN_ASSERT_GT_MSG(1, 1, "msg"); // will fail with message
AssertMacros#SEQAN_ASSERT_IN_DELTA
SEQAN_ASSERT_IN_DELTA(x, y, delta);
SEQAN_ASSERT_IN_DELTA_MSG(x, y, delta, comment[, parameters]);
- Parameters
-
x
(in) - The value to center the environment in. -
y
(in) - The value to check whether it falls within the environment. -
delta
(in) - The environment size. -
comment
(in) - A C-string (char const *) to use as a format string for printing a message on failure. -
parameters
(in) - An optional parameter that is put into printf() with format string comment.
The main advantage of this macro is that it prints the values of its argument on failures. Note that the operator<< to the type of std::cerr has to be defined for the type of both expression parameters. Otherwise, simply use the equivalent SEQAN_ASSERT call.
See SEQAN_CHECK and SEQAN_FAIL for (conditionally) aborting your program regardless of debug settings.
Examples
SEQAN_ASSERT_IN_DELTA(0, 0, 0.1); // will run through SEQAN_ASSERT_IN_DELTA(1, -2, 1); // will fail SEQAN_ASSERT_IN_DELTA(1, "foo"); // will not compile SEQAN_ASSERT_IN_DELTA_MSG(1, 0, 0.1, "msg"); // will fail with message
AssertMacros#SEQAN_ASSERT_LEQ
SEQAN_ASSERT_LEQ(expression1, expression2)
SEQAN_ASSERT_LEQ_MSG(expression1, expression2, comment[,
parameters])
- Parameters
-
expression1
(in) - The first expression. -
expression2
(in) - The second expression. -
comment
(in) - A C-string (char const *) to use as a format string for printing a message on failure. -
parameters
(in) - An optional parameter that is put into printf() with format string comment.
The main advantage of this macro is that it prints the values of its argument on failures. Note that the operator<< to the type of std::cerr has to be defined for the type of both expression parameters. Otherwise, simply use the equivalent SEQAN_ASSERT call.
See SEQAN_CHECK and SEQAN_FAIL for (conditionally) aborting your program regardless of debug settings.
Examples
SEQAN_ASSERT_LEQ(1, 1); // will run through SEQAN_ASSERT_LEQ(1, 2); // will not run through SEQAN_ASSERT_LEQ_MSG(1, 2, "msg"); // will fail with message
AssertMacros#SEQAN_ASSERT_LT
- Defined in
- <seqan/basic.h>
SEQAN_ASSERT_LT(expression1, expression2);
SEQAN_ASSERT_LT(expression1, expression2, comment[, parameters]);
- Parameters
-
expression1
(in) - The first expression. -
expression2
(in) - The second expression. -
comment
(in) - A C-string (char const *) to use as a format string for printing a message on failure. -
parameters
(in) - An optional parameter that is put into printf() with format string comment.
The main advantage of this macro is that it prints the values of its argument on failures. Note that the operator<< to the type of std::cerr has to be defined for the type of both expression parameters. Otherwise, simply use the equivalent SEQAN_ASSERT call.
See SEQAN_CHECK and SEQAN_FAIL for (conditionally) aborting your program regardless of debug settings.
Examples
SEQAN_ASSERT_LT(0, 1); // will run through SEQAN_ASSERT_LT(1, 1); // will not run through SEQAN_ASSERT_LT_MSG(1, 1, "msg"); // will fail with message
AssertMacros#SEQAN_ASSERT_NEQ
- Defined in
- <seqan/basic.h>
SEQAN_ASSERT_NEQ(expression1, expression2);
SEQAN_ASSERT_NEQ_MSG(expression1, expression2, comment[, parameters]);
- Parameters
-
expression1
(in) - The first expression. -
expression2
(in) - The second expression. -
comment
(in) - A C-string (char const *) to use as a format string for printing a message on failure. -
parameters
(in) - An optional parameter that is put into printf() with format string comment.
The main advantage of this macro is that it prints the values of its argument on failures. Note that the operator<< to the type of std::cerr has to be defined for the type of both expression parameters. Otherwise, simply use the equivalent SEQAN_ASSERT call.
See SEQAN_CHECK and SEQAN_FAIL for (conditionally) aborting your program regardless of debug settings.
Examples
SEQAN_ASSERT_NEQ(0, false); // will fail SEQAN_ASSERT_NEQ(1, false); // will run through SEQAN_ASSERT_NEQ(1, "foo"); // will not compile SEQAN_ASSERT_NEQ_MSG(1, false, "msg"); // will fail with message
AssertMacros#SEQAN_ASSERT_NOT
- Defined in
- <seqan/basic.h>
SEQAN_ASSERT_NOT(expression)
SEQAN_ASSERT_NOT_MSG(expression, message[, parameters])
- Parameters
-
expression
(in) - An expression to check for being false. -
message
(in) - A format string. -
parameters
(in) - An optional list of parameters.
Remarks
The main advantage of this macro is that it prints the values of its argument on failures. Note that the operator<< to the type of std::cerr has to be defined for the type of both expression parameters. Otherwise, simply use the equivalent SEQAN_ASSERT call.
See SEQAN_CHECK and SEQAN_FAIL for (conditionally) aborting your program regardless of debug settings.
Examples
SEQAN_ASSERT_NOT(0); // will run through SEQAN_ASSERT_NOT(1); // will fail SEQAN_ASSERT_NOT_MSG(0, "msg %s", "test"); // will fail with message
AssertMacros#SEQAN_CHECK
- Defined in
- <seqan/basic.h>
SEQAN_CHECK(condition, msg[, args]);
- Parameters
-
condition
(in) - An expression that is checked. -
msg
(in) - A format string. -
args
(in) - An optional list of arguments.
Remarks
Use this if something really unexpected happens inside your functions and there is no way to report this through the API. A good example would be logic errors, e.g. invalid values.
Examples
In the following example, the SEQAN_CHECK stops program execution if a value is added to MyEnum but the function foo is not updated accordingly.
enum MyEnum { VALUE_ONE, VALUE_TWO }; bool foo(MyEnum x) { SEQAN_CHECK((x == VALUE_ONE || x == VALUE_TWO), "Invalid value for x == %d.", x); switch (x) { case VALUE_ONE: // do something return true; case VALUE_TWO: // do something return true; } return false; // Should never reach here, checked above with SEQAN_CHECK. }
AssertMacros#SEQAN_FAIL
- Defined in
- <seqan/basic.h>
SEQAN_FAIL(msg[, args]);
- Parameters
-
msg
(in) - A format string. -
args
(in) - An optional list of arguments that are used for filling msg.
Remarks
Use this if something really unexpected happens inside your functions and there is no way to report this through the API. A good example would be logic errors, e.g. invalid values.
Examples
In the following example, the SEQAN_FAIL is there if a possible value is added to MyEnum but the function foo is not updated accordingly.
enum MyEnum { VALUE_ONE, VALUE_TWO }; bool foo(MyEnum x) { switch (x) { case VALUE_ONE: // do something return true; case VALUE_TWO: // do something return true; } SEQAN_FAIL("Logic error. Should never reach here. x == %d.", x); return false; }