cleanup, code style
This commit is contained in:
parent
d163648a4d
commit
083892db7a
|
@ -4,6 +4,7 @@ target_link_libraries(tested-code xtest-assert)
|
||||||
function(xtest_define_example NAME)
|
function(xtest_define_example NAME)
|
||||||
set(TARGET_NAME "example-${NAME}")
|
set(TARGET_NAME "example-${NAME}")
|
||||||
add_executable(${TARGET_NAME} ${NAME}.c ${ARGN})
|
add_executable(${TARGET_NAME} ${NAME}.c ${ARGN})
|
||||||
|
target_compile_options(${TARGET_NAME} PRIVATE -Wall -Wextra -pedantic)
|
||||||
if (NAME STREQUAL "all")
|
if (NAME STREQUAL "all")
|
||||||
target_compile_definitions(${TARGET_NAME} PRIVATE XTEST_ALL_EXAMPLES)
|
target_compile_definitions(${TARGET_NAME} PRIVATE XTEST_ALL_EXAMPLES)
|
||||||
endif ()
|
endif ()
|
||||||
|
|
|
@ -1,15 +1,5 @@
|
||||||
#include "xtest.h"
|
#include "xtest.h"
|
||||||
|
#include "examples.h"
|
||||||
|
|
||||||
void example_assertions();
|
|
||||||
void example_expect_assertions();
|
|
||||||
void example_fail();
|
|
||||||
void example_float();
|
|
||||||
void example_groups();
|
|
||||||
void example_parameterized();
|
|
||||||
void example_skip();
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
XTEST_MAIN {
|
XTEST_MAIN {
|
||||||
xtest_run_group(example_assertions);
|
xtest_run_group(example_assertions);
|
||||||
|
@ -18,5 +8,6 @@ XTEST_MAIN {
|
||||||
xtest_run_group(example_float);
|
xtest_run_group(example_float);
|
||||||
xtest_run_group(example_groups);
|
xtest_run_group(example_groups);
|
||||||
xtest_run_group(example_parameterized);
|
xtest_run_group(example_parameterized);
|
||||||
|
xtest_run_group(example_prng);
|
||||||
xtest_run_group(example_skip);
|
xtest_run_group(example_skip);
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,8 +1,8 @@
|
||||||
#include <stddef.h>
|
|
||||||
#include "xtest.h"
|
#include "xtest.h"
|
||||||
#include "source.h"
|
#include "source.h"
|
||||||
|
#include "examples.h"
|
||||||
|
|
||||||
void test_assert() {
|
static void test_assert() {
|
||||||
int i1 = 1;
|
int i1 = 1;
|
||||||
int i2 = 1;
|
int i2 = 1;
|
||||||
int i3 = 2;
|
int i3 = 2;
|
||||||
|
@ -32,7 +32,7 @@ void test_assert() {
|
||||||
xtest_assert(ret_1());
|
xtest_assert(ret_1());
|
||||||
}
|
}
|
||||||
|
|
||||||
void test_assert_is() {
|
static void test_assert_is() {
|
||||||
int i1 = 1;
|
int i1 = 1;
|
||||||
int i2 = 1;
|
int i2 = 1;
|
||||||
int i3 = 2;
|
int i3 = 2;
|
||||||
|
@ -66,7 +66,7 @@ void test_assert_is() {
|
||||||
xtest_assert_is_not(b1, b3);
|
xtest_assert_is_not(b1, b3);
|
||||||
}
|
}
|
||||||
|
|
||||||
void test_assert_str_is() {
|
static void test_assert_str_is() {
|
||||||
const char *s1 = "ret_1";
|
const char *s1 = "ret_1";
|
||||||
const char *s2 = "ret_1";
|
const char *s2 = "ret_1";
|
||||||
const char *s3 = "bar";
|
const char *s3 = "bar";
|
||||||
|
@ -75,7 +75,7 @@ void test_assert_str_is() {
|
||||||
xtest_assert_str_is_not(s1, s3);
|
xtest_assert_str_is_not(s1, s3);
|
||||||
}
|
}
|
||||||
|
|
||||||
void test_assert_mem_is() {
|
static void test_assert_mem_is() {
|
||||||
char m1[100];
|
char m1[100];
|
||||||
char m2[100];
|
char m2[100];
|
||||||
for (int i = 0; i < 100; ++i) {
|
for (int i = 0; i < 100; ++i) {
|
||||||
|
@ -91,7 +91,7 @@ void test_assert_mem_is() {
|
||||||
xtest_assert_mem_is_not(m1, m2, 100);
|
xtest_assert_mem_is_not(m1, m2, 100);
|
||||||
}
|
}
|
||||||
|
|
||||||
void example_assertions() {
|
void example_assertions(void) {
|
||||||
xtest_run(test_assert);
|
xtest_run(test_assert);
|
||||||
xtest_run(test_assert_is);
|
xtest_run(test_assert_is);
|
||||||
xtest_run(test_assert_str_is);
|
xtest_run(test_assert_str_is);
|
||||||
|
|
11
examples/examples.h
Normal file
11
examples/examples.h
Normal file
|
@ -0,0 +1,11 @@
|
||||||
|
#ifndef XTEST_EXAMPLES_H
|
||||||
|
#define XTEST_EXAMPLES_H
|
||||||
|
void example_assertions(void);
|
||||||
|
void example_expect_assertions(void);
|
||||||
|
void example_fail(void);
|
||||||
|
void example_float(void);
|
||||||
|
void example_groups(void);
|
||||||
|
void example_parameterized(void);
|
||||||
|
void example_prng(void);
|
||||||
|
void example_skip(void);
|
||||||
|
#endif //XTEST_EXAMPLES_H
|
|
@ -1,29 +1,30 @@
|
||||||
#include "xtest.h"
|
#include "xtest.h"
|
||||||
#include "source.h"
|
#include "source.h"
|
||||||
|
#include "examples.h"
|
||||||
|
|
||||||
void test_simple() {
|
static void test_simple() {
|
||||||
xtest_expect_assertion_failure();
|
xtest_expect_assertion_failure();
|
||||||
div(10, 0);
|
div(10, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
void test_no_failure() {
|
static void test_no_failure() {
|
||||||
div(10, 1);
|
div(10, 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
void test_no_failure_2() {
|
static void test_no_failure_2() {
|
||||||
div(10, 2);
|
div(10, 2);
|
||||||
}
|
}
|
||||||
|
|
||||||
void test_will_fail() {
|
static void test_will_fail() {
|
||||||
xtest_expect_assertion_failure();
|
xtest_expect_assertion_failure();
|
||||||
div(10, 1);
|
div(10, 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
void test_will_fail_2() {
|
static void test_will_fail_2() {
|
||||||
div(10, 0);
|
div(10, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
void test_other_failure() {
|
static void test_other_failure() {
|
||||||
xtest_expect_assertion_failure();
|
xtest_expect_assertion_failure();
|
||||||
xtest_assert(0);
|
xtest_assert(0);
|
||||||
div(10, 0);
|
div(10, 0);
|
||||||
|
|
|
@ -1,136 +1,136 @@
|
||||||
#include <stddef.h>
|
|
||||||
#include "xtest.h"
|
#include "xtest.h"
|
||||||
|
#include "examples.h"
|
||||||
|
|
||||||
void fail_assert() {
|
static void fail_assert() {
|
||||||
xtest_assert(0);
|
xtest_assert(0);
|
||||||
}
|
}
|
||||||
|
|
||||||
void fail_assert_is_char() {
|
static void fail_assert_is_char() {
|
||||||
xtest_assert_is((char) 'a', (char) 'b');
|
xtest_assert_is((char) 'a', (char) 'b');
|
||||||
}
|
}
|
||||||
|
|
||||||
void fail_assert_is_not_char() {
|
static void fail_assert_is_not_char() {
|
||||||
xtest_assert_is_not((char) 'a', (char) 'a');
|
xtest_assert_is_not((char) 'a', (char) 'a');
|
||||||
}
|
}
|
||||||
|
|
||||||
void fail_assert_is_signed_char() {
|
static void fail_assert_is_signed_char() {
|
||||||
xtest_assert_is((signed char) 'a', (signed char) 'b');
|
xtest_assert_is((signed char) 'a', (signed char) 'b');
|
||||||
}
|
}
|
||||||
|
|
||||||
void fail_assert_is_not_signed_char() {
|
static void fail_assert_is_not_signed_char() {
|
||||||
xtest_assert_is_not((signed char) 'a', (signed char) 'a');
|
xtest_assert_is_not((signed char) 'a', (signed char) 'a');
|
||||||
}
|
}
|
||||||
|
|
||||||
void fail_assert_is_unsigned_char() {
|
static void fail_assert_is_unsigned_char() {
|
||||||
xtest_assert_is((unsigned char) 'a', (unsigned char) 'b');
|
xtest_assert_is((unsigned char) 'a', (unsigned char) 'b');
|
||||||
}
|
}
|
||||||
|
|
||||||
void fail_assert_is_not_unsigned_char() {
|
static void fail_assert_is_not_unsigned_char() {
|
||||||
xtest_assert_is_not((unsigned char) 'a', (unsigned char) 'a');
|
xtest_assert_is_not((unsigned char) 'a', (unsigned char) 'a');
|
||||||
}
|
}
|
||||||
|
|
||||||
void fail_assert_is_short() {
|
static void fail_assert_is_short() {
|
||||||
xtest_assert_is((short) 1, (short) 2);
|
xtest_assert_is((short) 1, (short) 2);
|
||||||
}
|
}
|
||||||
|
|
||||||
void fail_assert_is_not_short() {
|
static void fail_assert_is_not_short() {
|
||||||
xtest_assert_is_not((short) 1, (short) 1);
|
xtest_assert_is_not((short) 1, (short) 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
void fail_assert_is_ushort() {
|
static void fail_assert_is_ushort() {
|
||||||
xtest_assert_is((unsigned short) 1, (unsigned short) 2);
|
xtest_assert_is((unsigned short) 1, (unsigned short) 2);
|
||||||
}
|
}
|
||||||
|
|
||||||
void fail_assert_is_not_ushort() {
|
static void fail_assert_is_not_ushort() {
|
||||||
xtest_assert_is_not((unsigned short) 1, (unsigned short) 1);
|
xtest_assert_is_not((unsigned short) 1, (unsigned short) 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
void fail_assert_is_int() {
|
static void fail_assert_is_int() {
|
||||||
xtest_assert_is((int) 1, (int) 2);
|
xtest_assert_is((int) 1, (int) 2);
|
||||||
}
|
}
|
||||||
|
|
||||||
void fail_assert_is_not_int() {
|
static void fail_assert_is_not_int() {
|
||||||
xtest_assert_is_not((int) 1, (int) 1);
|
xtest_assert_is_not((int) 1, (int) 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
void fail_assert_is_uint() {
|
static void fail_assert_is_uint() {
|
||||||
xtest_assert_is((unsigned int) 1, (unsigned int) 2);
|
xtest_assert_is((unsigned int) 1, (unsigned int) 2);
|
||||||
}
|
}
|
||||||
|
|
||||||
void fail_assert_is_not_uint() {
|
static void fail_assert_is_not_uint() {
|
||||||
xtest_assert_is_not((unsigned int) 1, (unsigned int) 1);
|
xtest_assert_is_not((unsigned int) 1, (unsigned int) 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
void fail_assert_is_long() {
|
static void fail_assert_is_long() {
|
||||||
xtest_assert_is((short) 1, (short) 2);
|
xtest_assert_is((short) 1, (short) 2);
|
||||||
}
|
}
|
||||||
|
|
||||||
void fail_assert_is_not_long() {
|
static void fail_assert_is_not_long() {
|
||||||
xtest_assert_is_not((long) 1, (long) 1);
|
xtest_assert_is_not((long) 1, (long) 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
void fail_assert_is_ulong() {
|
static void fail_assert_is_ulong() {
|
||||||
xtest_assert_is((unsigned long) 1, (unsigned long) 2);
|
xtest_assert_is((unsigned long) 1, (unsigned long) 2);
|
||||||
}
|
}
|
||||||
|
|
||||||
void fail_assert_is_not_ulong() {
|
static void fail_assert_is_not_ulong() {
|
||||||
xtest_assert_is_not((unsigned long) 1, (unsigned long) 1);
|
xtest_assert_is_not((unsigned long) 1, (unsigned long) 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
void fail_assert_is_longlong() {
|
static void fail_assert_is_longlong() {
|
||||||
xtest_assert_is((long long) 1, (long long) 2);
|
xtest_assert_is((long long) 1, (long long) 2);
|
||||||
}
|
}
|
||||||
|
|
||||||
void fail_assert_is_not_longlong() {
|
static void fail_assert_is_not_longlong() {
|
||||||
xtest_assert_is_not((long long) 1, (long long) 1);
|
xtest_assert_is_not((long long) 1, (long long) 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
void fail_assert_is_ulonglong() {
|
static void fail_assert_is_ulonglong() {
|
||||||
xtest_assert_is((unsigned long long) 1, (unsigned long long) 2);
|
xtest_assert_is((unsigned long long) 1, (unsigned long long) 2);
|
||||||
}
|
}
|
||||||
|
|
||||||
void fail_assert_is_not_ulonglong() {
|
static void fail_assert_is_not_ulonglong() {
|
||||||
xtest_assert_is_not((unsigned long long) 1, (unsigned long long) 1);
|
xtest_assert_is_not((unsigned long long) 1, (unsigned long long) 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
void fail_assert_is_ptr() {
|
static void fail_assert_is_ptr() {
|
||||||
int i = 1;
|
int i = 1;
|
||||||
int j = 1;
|
int j = 1;
|
||||||
xtest_assert_is((void *) &i, (void *) &j);
|
xtest_assert_is((void *) &i, (void *) &j);
|
||||||
}
|
}
|
||||||
|
|
||||||
void fail_assert_is_not_ptr() {
|
static void fail_assert_is_not_ptr() {
|
||||||
int i = 1;
|
int i = 1;
|
||||||
xtest_assert_is_not((void *) &i, (void *) &i);
|
xtest_assert_is_not((void *) &i, (void *) &i);
|
||||||
}
|
}
|
||||||
|
|
||||||
void fail_assert_str_is() {
|
static void fail_assert_str_is() {
|
||||||
xtest_assert_str_is("foo", "bar");
|
xtest_assert_str_is("foo", "bar");
|
||||||
}
|
}
|
||||||
|
|
||||||
void fail_assert_str_is_not() {
|
static void fail_assert_str_is_not() {
|
||||||
xtest_assert_str_is_not("foo", "foo");
|
xtest_assert_str_is_not("foo", "foo");
|
||||||
}
|
}
|
||||||
|
|
||||||
void fail_assert_mem_is() {
|
static void fail_assert_mem_is() {
|
||||||
xtest_assert_mem_is("aaaaaaaaaaaaa", "aaaaaaaaaaaab", 13);
|
xtest_assert_mem_is("aaaaaaaaaaaaa", "aaaaaaaaaaaab", 13);
|
||||||
}
|
}
|
||||||
|
|
||||||
void fail_assert_mem_is_not() {
|
static void fail_assert_mem_is_not() {
|
||||||
xtest_assert_mem_is_not("aaaaaaaaaaaaa", "aaaaaaaaaaaab", 12);
|
xtest_assert_mem_is_not("aaaaaaaaaaaaa", "aaaaaaaaaaaab", 12);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void fail_assert_float_is() {
|
static void fail_assert_float_is() {
|
||||||
xtest_assert_float_is(1.2356, 1.2346, 3);
|
xtest_assert_float_is(1.2356, 1.2346, 3);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void fail_assert_float_is_not() {
|
static void fail_assert_float_is_not() {
|
||||||
xtest_assert_float_is_not(1.2356, 1.2346, 2);
|
xtest_assert_float_is_not(1.2356, 1.2346, 2);
|
||||||
}
|
}
|
||||||
|
|
||||||
void fail_assert_is() {
|
static void fail_assert_is(void) {
|
||||||
xtest_run(fail_assert_is_char);
|
xtest_run(fail_assert_is_char);
|
||||||
xtest_run(fail_assert_is_not_char);
|
xtest_run(fail_assert_is_not_char);
|
||||||
xtest_run(fail_assert_is_signed_char);
|
xtest_run(fail_assert_is_signed_char);
|
||||||
|
@ -157,22 +157,22 @@ void fail_assert_is() {
|
||||||
xtest_run(fail_assert_is_not_ptr);
|
xtest_run(fail_assert_is_not_ptr);
|
||||||
}
|
}
|
||||||
|
|
||||||
void fail_assert_str() {
|
static void fail_assert_str(void) {
|
||||||
xtest_run(fail_assert_str_is);
|
xtest_run(fail_assert_str_is);
|
||||||
xtest_run(fail_assert_str_is_not);
|
xtest_run(fail_assert_str_is_not);
|
||||||
}
|
}
|
||||||
|
|
||||||
void fail_assert_mem() {
|
static void fail_assert_mem(void) {
|
||||||
xtest_run(fail_assert_mem_is);
|
xtest_run(fail_assert_mem_is);
|
||||||
xtest_run(fail_assert_mem_is_not);
|
xtest_run(fail_assert_mem_is_not);
|
||||||
}
|
}
|
||||||
|
|
||||||
void fail_assert_float() {
|
static void fail_assert_float(void) {
|
||||||
xtest_run(fail_assert_float_is);
|
xtest_run(fail_assert_float_is);
|
||||||
xtest_run(fail_assert_float_is_not);
|
xtest_run(fail_assert_float_is_not);
|
||||||
}
|
}
|
||||||
|
|
||||||
void example_fail() {
|
void example_fail(void) {
|
||||||
xtest_run(fail_assert);
|
xtest_run(fail_assert);
|
||||||
xtest_run_group(fail_assert_is);
|
xtest_run_group(fail_assert_is);
|
||||||
xtest_run_group(fail_assert_str);
|
xtest_run_group(fail_assert_str);
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
#include <stddef.h>
|
|
||||||
#include "xtest.h"
|
#include "xtest.h"
|
||||||
|
#include "examples.h"
|
||||||
|
|
||||||
void test_float() {
|
void test_float() {
|
||||||
xtest_assert_float_is(1.0, 1.0, 0);
|
xtest_assert_float_is(1.0, 1.0, 0);
|
||||||
|
@ -34,7 +34,7 @@ void test_float() {
|
||||||
xtest_assert_float_is_not(0.001, 0.00100000000001, 16);
|
xtest_assert_float_is_not(0.001, 0.00100000000001, 16);
|
||||||
}
|
}
|
||||||
|
|
||||||
void example_float() {
|
void example_float(void) {
|
||||||
xtest_run(test_float);
|
xtest_run(test_float);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,18 +1,26 @@
|
||||||
#include <stddef.h>
|
|
||||||
#include "xtest.h"
|
#include "xtest.h"
|
||||||
|
#include "examples.h"
|
||||||
|
|
||||||
void test_1() {}
|
static void test_1() {}
|
||||||
void test_2() {}
|
|
||||||
void test_3() {}
|
static void test_2() {}
|
||||||
void test_4() {}
|
|
||||||
void test_5() {}
|
static void test_3() {}
|
||||||
void test_6() {}
|
|
||||||
void test_7() {}
|
static void test_4() {}
|
||||||
void test_8() {}
|
|
||||||
void test_9() {}
|
static void test_5() {}
|
||||||
|
|
||||||
|
static void test_6() {}
|
||||||
|
|
||||||
|
static void test_7() {}
|
||||||
|
|
||||||
|
static void test_8() {}
|
||||||
|
|
||||||
|
static void test_9() {}
|
||||||
|
|
||||||
|
|
||||||
void groups_manual() {
|
static void groups_manual(void) {
|
||||||
xtest_group(A);
|
xtest_group(A);
|
||||||
xtest_group(foo);
|
xtest_group(foo);
|
||||||
xtest_run(test_1);
|
xtest_run(test_1);
|
||||||
|
@ -42,55 +50,55 @@ void groups_manual() {
|
||||||
xtest_end_group();
|
xtest_end_group();
|
||||||
}
|
}
|
||||||
|
|
||||||
void bar() {
|
static void bar(void) {
|
||||||
xtest_run(test_2);
|
xtest_run(test_2);
|
||||||
xtest_run(test_3);
|
xtest_run(test_3);
|
||||||
}
|
}
|
||||||
|
|
||||||
void foo() {
|
static void foo(void) {
|
||||||
xtest_run(test_1);
|
xtest_run(test_1);
|
||||||
xtest_run_group(bar);
|
xtest_run_group(bar);
|
||||||
}
|
}
|
||||||
|
|
||||||
void A() {
|
static void A(void) {
|
||||||
xtest_run_group(foo);
|
xtest_run_group(foo);
|
||||||
xtest_run(test_4);
|
xtest_run(test_4);
|
||||||
}
|
}
|
||||||
|
|
||||||
void B() {
|
static void B(void) {
|
||||||
xtest_run(test_5);
|
xtest_run(test_5);
|
||||||
xtest_run(test_6);
|
xtest_run(test_6);
|
||||||
}
|
}
|
||||||
|
|
||||||
void Z() {
|
static void Z(void) {
|
||||||
xtest_run(test_7);
|
xtest_run(test_7);
|
||||||
}
|
}
|
||||||
|
|
||||||
void Y() {
|
static void Y(void) {
|
||||||
xtest_run_group(Z);
|
xtest_run_group(Z);
|
||||||
}
|
}
|
||||||
|
|
||||||
void X() {
|
static void X(void) {
|
||||||
xtest_run_group(Y);
|
xtest_run_group(Y);
|
||||||
}
|
}
|
||||||
|
|
||||||
void C() {
|
static void C(void) {
|
||||||
xtest_run_group(X);
|
xtest_run_group(X);
|
||||||
}
|
}
|
||||||
|
|
||||||
void D() {
|
static void D(void) {
|
||||||
xtest_run(test_8);
|
xtest_run(test_8);
|
||||||
xtest_run(test_9);
|
xtest_run(test_9);
|
||||||
}
|
}
|
||||||
|
|
||||||
void groups_convenient() {
|
static void groups_convenient(void) {
|
||||||
xtest_run_group(A);
|
xtest_run_group(A);
|
||||||
xtest_run_group(B);
|
xtest_run_group(B);
|
||||||
xtest_run_group(C);
|
xtest_run_group(C);
|
||||||
xtest_run_group(D);
|
xtest_run_group(D);
|
||||||
}
|
}
|
||||||
|
|
||||||
void example_groups() {
|
void example_groups(void) {
|
||||||
groups_manual();
|
groups_manual();
|
||||||
groups_convenient();
|
groups_convenient();
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
#include <stddef.h>
|
|
||||||
#include "xtest.h"
|
#include "xtest.h"
|
||||||
#include "source.h"
|
#include "source.h"
|
||||||
|
#include "examples.h"
|
||||||
|
|
||||||
void test_add(XTEST_UNUSED void *fixture, void **params) {
|
void test_add(XTEST_UNUSED void *fixture, void **params) {
|
||||||
int a = xtest_get_param(int, 0, params);
|
int a = xtest_get_param(int, 0, params);
|
||||||
|
@ -20,7 +20,6 @@ void test_str_equals(XTEST_UNUSED void *fixture, void **params) {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
xtest_param add_params[] = {
|
xtest_param add_params[] = {
|
||||||
{
|
{
|
||||||
.name = "A",
|
.name = "A",
|
||||||
|
@ -73,7 +72,7 @@ xtest_param str_params[] = {
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
void example_parameterized() {
|
void example_parameterized(void) {
|
||||||
xtest_run_parameterized(test_add, add_params);
|
xtest_run_parameterized(test_add, add_params);
|
||||||
xtest_run_parameterized(test_str_equals, str_params);
|
xtest_run_parameterized(test_str_equals, str_params);
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,5 +1,6 @@
|
||||||
#include "xtest.h"
|
#include "xtest.h"
|
||||||
#include "source.h"
|
#include "source.h"
|
||||||
|
#include "examples.h"
|
||||||
|
|
||||||
|
|
||||||
void rand_int() {
|
void rand_int() {
|
||||||
|
@ -9,9 +10,19 @@ void rand_int() {
|
||||||
xtest_assert_is(add(a, b), res);
|
xtest_assert_is(add(a, b), res);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void rand_double() {
|
||||||
|
double a = xtest_rand_double_range(0, 10);
|
||||||
|
double b = xtest_rand_double_range(0, 10);
|
||||||
|
double diff = a - b;
|
||||||
|
xtest_assert(diff < 10.0);
|
||||||
|
}
|
||||||
|
|
||||||
|
void example_prng(void) {
|
||||||
|
xtest_run(rand_int);
|
||||||
|
xtest_run(rand_double);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
#ifndef XTEST_ALL_EXAMPLES
|
#ifndef XTEST_ALL_EXAMPLES
|
||||||
XTEST_MAIN {
|
XTEST_RUN_MAIN(example_prng)
|
||||||
xtest_run(rand_int);
|
|
||||||
}
|
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -1,5 +1,6 @@
|
||||||
#include "xtest.h"
|
#include "xtest.h"
|
||||||
#include "source.h"
|
#include "source.h"
|
||||||
|
#include "examples.h"
|
||||||
|
|
||||||
void no_skip_1() {}
|
void no_skip_1() {}
|
||||||
|
|
||||||
|
@ -37,7 +38,7 @@ void skip_6() {
|
||||||
xtest_skip(NULL);
|
xtest_skip(NULL);
|
||||||
}
|
}
|
||||||
|
|
||||||
void example_skip() {
|
void example_skip(void) {
|
||||||
xtest_run(no_skip_1);
|
xtest_run(no_skip_1);
|
||||||
xtest_run(skip_1);
|
xtest_run(skip_1);
|
||||||
xtest_run(no_skip_2);
|
xtest_run(no_skip_2);
|
||||||
|
|
|
@ -2,7 +2,7 @@
|
||||||
#include "source.h"
|
#include "source.h"
|
||||||
#include "assert.h"
|
#include "assert.h"
|
||||||
|
|
||||||
int ret_1() {
|
int ret_1(void) {
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
#ifndef XTEST_SOURCE_H
|
#ifndef XTEST_SOURCE_H
|
||||||
#define XTEST_SOURCE_H
|
#define XTEST_SOURCE_H
|
||||||
|
|
||||||
int ret_1();
|
int ret_1(void);
|
||||||
|
|
||||||
double div(double a, double b);
|
double div(double a, double b);
|
||||||
|
|
||||||
|
|
|
@ -1,5 +1,7 @@
|
||||||
#if defined(__GNUC__) || defined(__clang__) || defined(XTEST_USE_INCLUDE_NEXT)
|
#if defined(__GNUC__) || defined(__clang__) || defined(XTEST_USE_INCLUDE_NEXT)
|
||||||
|
|
||||||
#include_next <assert.h>
|
#include_next <assert.h>
|
||||||
|
|
||||||
#else
|
#else
|
||||||
#include <assert.h>
|
#include <assert.h>
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -53,32 +53,34 @@ void xtest_init(int argc, char**argv);
|
||||||
void xtest_fail_assert(const char *expression, const char *file, int line, void *expected,
|
void xtest_fail_assert(const char *expression, const char *file, int line, void *expected,
|
||||||
void *actual, _Bool invert, enum xtest_type type);
|
void *actual, _Bool invert, enum xtest_type type);
|
||||||
void
|
void
|
||||||
xtest_assert_float(double expected, double actual, int precision, _Bool invert, const char *expression, const char *file,
|
xtest_assert_float(double expected, double actual, int precision, _Bool invert, const char *expression,
|
||||||
|
const char *file,
|
||||||
int line);
|
int line);
|
||||||
|
|
||||||
void xtest_assert_mem(const char *expected, const char *actual, size_t length, _Bool invert, const char *expression, const char *file,
|
void xtest_assert_mem(const char *expected, const char *actual, size_t length, _Bool invert, const char *expression,
|
||||||
|
const char *file,
|
||||||
int line);
|
int line);
|
||||||
|
|
||||||
void xtest_internal_run(xtest_test_fn fn, const char *name, xtest_param *params, xtest_setup_fn setup,
|
void xtest_internal_run(xtest_test_fn fn, const char *name, xtest_param *params, xtest_setup_fn setup,
|
||||||
xtest_teardown_fn teardown);
|
xtest_teardown_fn teardown);
|
||||||
|
|
||||||
void xtest_internal_start_group(const char *name);
|
void xtest_internal_start_group(const char *name);
|
||||||
void xtest_internal_end_group();
|
void xtest_internal_end_group(void);
|
||||||
|
|
||||||
void xtest_skip(const char *reason);
|
void xtest_skip(const char *reason);
|
||||||
void xtest_expect_assertion_failure();
|
void xtest_expect_assertion_failure(void);
|
||||||
int xtest_complete();
|
int xtest_complete(void);
|
||||||
|
|
||||||
#ifdef XTEST_PRNG
|
#ifdef XTEST_PRNG
|
||||||
void xtest_rand_fill(char *buf, size_t len);
|
void xtest_rand_fill(char *buf, size_t len);
|
||||||
double xtest_rand_double();
|
double xtest_rand_double(void);
|
||||||
double xtest_rand_double_range(double min, double max);
|
double xtest_rand_double_range(double min, double max);
|
||||||
int xtest_rand_int();
|
int xtest_rand_int(void);
|
||||||
int xtest_rand_int_range(int min, int max);
|
int xtest_rand_int_range(int min, int max);
|
||||||
uint8_t xtest_rand_8();
|
uint8_t xtest_rand_8(void);
|
||||||
uint16_t xtest_rand_16();
|
uint16_t xtest_rand_16(void);
|
||||||
uint32_t xtest_rand_32();
|
uint32_t xtest_rand_32(void);
|
||||||
uint64_t xtest_rand_64();
|
uint64_t xtest_rand_64(void);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -12,7 +12,7 @@ if(XTEST_ENABLE_PRNG)
|
||||||
endif ()
|
endif ()
|
||||||
|
|
||||||
add_library(xtest xtest.c)
|
add_library(xtest xtest.c)
|
||||||
target_compile_options(xtest PRIVATE -Wall -Wextra -pedantic)
|
target_compile_options(xtest PRIVATE -Wall -Wextra -pedantic -Wstrict-prototypes -Wmissing-prototypes -Wold-style-definition -Wold-style-declaration)
|
||||||
target_include_directories(xtest PRIVATE ${XTEST_SOURCE_DIR}/extern/pcg)
|
target_include_directories(xtest PRIVATE ${XTEST_SOURCE_DIR}/extern/pcg)
|
||||||
target_link_libraries(xtest PRIVATE ${XTEST_LINK_LIBRARIES})
|
target_link_libraries(xtest PRIVATE ${XTEST_LINK_LIBRARIES})
|
||||||
target_compile_definitions(xtest PUBLIC XTEST ${XTEST_ADDITIONAL_DEFINES})
|
target_compile_definitions(xtest PUBLIC XTEST ${XTEST_ADDITIONAL_DEFINES})
|
||||||
|
|
29
src/xtest.c
29
src/xtest.c
|
@ -76,6 +76,9 @@ int skipped_tests = 0;
|
||||||
_Bool list_tests = 0;
|
_Bool list_tests = 0;
|
||||||
|
|
||||||
|
|
||||||
|
void xtest_internal_assert(const char *file, int line, const char *func, const char *expr);
|
||||||
|
|
||||||
|
|
||||||
#define USAGE_BASE "[-?|--help] [-l|--list] [-m|--match filter] [-f|--output-format format]"
|
#define USAGE_BASE "[-?|--help] [-l|--list] [-m|--match filter] [-f|--output-format format]"
|
||||||
#define USAGE_PRNG "[-s|--seed prng-seed]"
|
#define USAGE_PRNG "[-s|--seed prng-seed]"
|
||||||
|
|
||||||
|
@ -206,7 +209,7 @@ void xtest_init(int argc, char **argv) {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
int xtest_complete() {
|
int xtest_complete(void) {
|
||||||
if (!list_tests) {
|
if (!list_tests) {
|
||||||
if (output_format == format_default) {
|
if (output_format == format_default) {
|
||||||
printf("============\nTotal: %d, Failed: %d, Skipped: %d\n", num_tests, failed_tests, skipped_tests);
|
printf("============\nTotal: %d, Failed: %d, Skipped: %d\n", num_tests, failed_tests, skipped_tests);
|
||||||
|
@ -218,7 +221,7 @@ int xtest_complete() {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void subunit_message(const char *name, const char *message, const char *details) {
|
static void subunit_message(const char *name, const char *message, const char *details) {
|
||||||
printf("%s: %s", message, name);
|
printf("%s: %s", message, name);
|
||||||
if (details == NULL) {
|
if (details == NULL) {
|
||||||
printf("\n");
|
printf("\n");
|
||||||
|
@ -467,7 +470,7 @@ xtest_assert_float(double expected, double actual, int precision, _Bool invert,
|
||||||
longjmp(xtest_jmp, 1);
|
longjmp(xtest_jmp, 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
size_t find_diff_offset(const char *a, const char *b, size_t length) {
|
static size_t find_diff_offset(const char *a, const char *b, size_t length) {
|
||||||
size_t offset = 0;
|
size_t offset = 0;
|
||||||
while (offset < length && *(a + offset) == *(b + offset)) offset++;
|
while (offset < length && *(a + offset) == *(b + offset)) offset++;
|
||||||
return offset;
|
return offset;
|
||||||
|
@ -510,13 +513,13 @@ void xtest_internal_start_group(const char *name) {
|
||||||
xtest_indent += XTEST_INDENT;
|
xtest_indent += XTEST_INDENT;
|
||||||
}
|
}
|
||||||
|
|
||||||
void xtest_internal_end_group() {
|
void xtest_internal_end_group(void) {
|
||||||
assert(group_nesting_pos > 0);
|
assert(group_nesting_pos > 0);
|
||||||
group_nesting_pos -= 1;
|
group_nesting_pos -= 1;
|
||||||
xtest_indent -= XTEST_INDENT;
|
xtest_indent -= XTEST_INDENT;
|
||||||
}
|
}
|
||||||
|
|
||||||
void xtest_expect_assertion_failure() {
|
void xtest_expect_assertion_failure(void) {
|
||||||
expecting_assertion = 1;
|
expecting_assertion = 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -537,7 +540,7 @@ union seed_encode_box {
|
||||||
uint8_t bytes[PRNG_SEED_LENGTH * 6 / 8 + 1];
|
uint8_t bytes[PRNG_SEED_LENGTH * 6 / 8 + 1];
|
||||||
};
|
};
|
||||||
|
|
||||||
void encode_seed(prng_seed seed, uint64_t state, uint64_t seq) {
|
static void encode_seed(prng_seed seed, uint64_t state, uint64_t seq) {
|
||||||
union seed_encode_box box;
|
union seed_encode_box box;
|
||||||
memset(&box, 0, sizeof(box));
|
memset(&box, 0, sizeof(box));
|
||||||
box.state = state;
|
box.state = state;
|
||||||
|
@ -571,7 +574,7 @@ void encode_seed(prng_seed seed, uint64_t state, uint64_t seq) {
|
||||||
seed[PRNG_SEED_LENGTH] = '\0';
|
seed[PRNG_SEED_LENGTH] = '\0';
|
||||||
}
|
}
|
||||||
|
|
||||||
void decode_seed(const prng_seed seed, uint64_t *state, uint64_t *seq) {
|
static void decode_seed(const prng_seed seed, uint64_t *state, uint64_t *seq) {
|
||||||
union seed_encode_box box;
|
union seed_encode_box box;
|
||||||
memset(&box, 0, sizeof(box));
|
memset(&box, 0, sizeof(box));
|
||||||
uint8_t cur;
|
uint8_t cur;
|
||||||
|
@ -638,7 +641,7 @@ void xtest_rand_fill(char *buf, size_t len) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
double xtest_rand_double() {
|
double xtest_rand_double(void) {
|
||||||
return ldexp((double) (xtest_rand_64() & 0xFFFFFFFFFFFFF), -52);
|
return ldexp((double) (xtest_rand_64() & 0xFFFFFFFFFFFFF), -52);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -647,7 +650,7 @@ double xtest_rand_double_range(double min, double max) {
|
||||||
return (max - min) * xtest_rand_double() + min;
|
return (max - min) * xtest_rand_double() + min;
|
||||||
}
|
}
|
||||||
|
|
||||||
int xtest_rand_int() {
|
int xtest_rand_int(void) {
|
||||||
uint32_t uval = pcg32_random_r(&rng);
|
uint32_t uval = pcg32_random_r(&rng);
|
||||||
int32_t *ival;
|
int32_t *ival;
|
||||||
ival = (int32_t *) &uval;
|
ival = (int32_t *) &uval;
|
||||||
|
@ -662,20 +665,20 @@ int xtest_rand_int_range(int min, int max) {
|
||||||
return (int) *ival + min;
|
return (int) *ival + min;
|
||||||
}
|
}
|
||||||
|
|
||||||
uint8_t xtest_rand_8() {
|
uint8_t xtest_rand_8(void) {
|
||||||
return (uint8_t) pcg32_random_r(&rng);
|
return (uint8_t) pcg32_random_r(&rng);
|
||||||
}
|
}
|
||||||
|
|
||||||
uint16_t xtest_rand_16() {
|
uint16_t xtest_rand_16(void) {
|
||||||
return (uint16_t) pcg32_random_r(&rng);
|
return (uint16_t) pcg32_random_r(&rng);
|
||||||
}
|
}
|
||||||
|
|
||||||
uint32_t xtest_rand_32() {
|
uint32_t xtest_rand_32(void) {
|
||||||
return pcg32_random_r(&rng);
|
return pcg32_random_r(&rng);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
uint64_t xtest_rand_64() {
|
uint64_t xtest_rand_64(void) {
|
||||||
uint32_t l = pcg32_random_r(&rng);
|
uint32_t l = pcg32_random_r(&rng);
|
||||||
uint32_t h = pcg32_random_r(&rng);
|
uint32_t h = pcg32_random_r(&rng);
|
||||||
return ((uint64_t) h) << 32 | l;
|
return ((uint64_t) h) << 32 | l;
|
||||||
|
|
Loading…
Reference in a new issue