Example
Assertion extensions are broken up into forwards, expectation setup, assertion definition, and output format.
testsuite.h
#ifndef AWRY_TESTSUITE_H
#define AWRY_TESTSUITE_H 1
#include "awry/extensions.h"
typedef struct ExpectExtStruct {
int value;
} ExpectExt;
AWRY_extension_forwards(
AWRY_expect_forward(extstruct, ExpectExt*)
AWRY_expect_array_forward(extstructarr, ExpectExt*)
)
#define AWRY_EXTENSIONS AWRY_setup_extensions( \
AWRY_extension(extstruct, ExpectExt*) \
AWRY_extension(extstructarr, ExpectExt**) \
)
#include "awry/awry.h"
#endif
Forwards
Forwards are defined in the header for defining AWRY_extension_forwards
. The AWRY_extension_forwards
macro is inserted into the _Generic
expectation call function if defined.
Expectation Setup
After defining forwards, the AWRY_EXTENSIONS
macro in your header file is to be defined with AWRY_setup_extensions
, space or newline delimited list containing AWRY_extension
definitions matching the forwards.
extension.c
Assertion definitions are created by the AWRY_expect_extension
,, AWRY_expect_extension_default
, and AWRY_expect_array_extension_default
macros. Any post-fixed macros with default
must take NULL
as the printf format to create a generic error message handler. Assertions can be a function call or C expression.
#include "testsuite.h"
int __format_extstruct(ExpectExt* extstruct) {
return extstruct->value;
}
int __assert_array_extstructarr(ExpectExt* arr_1[], ExpectExt* arr_2[], size_t s1, size_t s2) {
if (s1/sizeof(ExpectExt*) != s2/sizeof(ExpectExt*)) { return 0; }
return 1;
}
AWRY_expect_extension(extstruct, ExpectExt*, (actual->value == expected->value), "%i");
AWRY_expect_array_extension_default(extstructarr, ExpectExt*, __assert_array_extstructarr(expected, actual, actual_size, expected_size), NULL);
Output Format
Output formats, excluding those post fixed with default
are to return a value associated with the printf expression.
Full Example
testsuite.h
#ifndef AWRY_TESTSUITE_H
#define AWRY_TESTSUITE_H 1
#include "awry/extensions.h"
typedef struct ExpectExtStruct {
int value;
} ExpectExt;
AWRY_extension_forwards(
AWRY_expect_forward(extstruct, ExpectExt*)
AWRY_expect_array_forward(extstructarr, ExpectExt*)
)
#define AWRY_EXTENSIONS AWRY_setup_extensions( \
AWRY_extension(extstruct, ExpectExt*) \
AWRY_extension(extstructarr, ExpectExt**) \
)
#include "awry/awry.h"
#endif
extension.c
#include "testsuite.h"
int __format_extstruct(ExpectExt* extstruct) {
return extstruct->value;
}
int __assert_array_extstructarr(ExpectExt* arr_1[], ExpectExt* arr_2[], size_t s1, size_t s2) {
if (s1/sizeof(ExpectExt*) != s2/sizeof(ExpectExt*)) { return 0; }
return 1;
}
AWRY_expect_extension(extstruct, ExpectExt*, (actual->value == expected->value), "%i");
AWRY_expect_array_extension_default(extstructarr, ExpectExt*, __assert_array_extstructarr(expected, actual, actual_size, expected_size), NULL);
main.c
#include "testsuite.h"
describe("Awry", awry_extensions)
context("Extensions")
context("SINGLE")
ExpectExt subject = { .value = 1 };
it("creates the expectation for the extension")
ExpectExt comp = { .value = 1 };
expect(&subject) to equal(&comp)
comp.value = 2;
expect(&subject) to not equal(&comp)
end
end
context("ARRAY")
ExpectExt* subject[] = { NULL, NULL };
it("creates the expectation for the extension")
ExpectExt* comp[] = { NULL, NULL };
expect(subject) to equal(comp)
end
end
end
end
- Previous
- Next