Serene Runtime 1.0.0-dev
C runtime for the Serene programming language
Loading...
Searching...
No Matches
acutest.h File Reference
#include <stdlib.h>
#include <ctype.h>
#include <setjmp.h>
#include <stdarg.h>
#include <stdio.h>
#include <string.h>
Include dependency graph for acutest.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Data Structures

struct  acutest_test_
struct  acutest_test_data_

Macros

#define TEST_LIST   const struct acutest_test_ acutest_list_[]
#define TEST_CHECK_(cond, ...)
#define TEST_CHECK(cond)
#define TEST_ASSERT_(cond, ...)
#define TEST_ASSERT(cond)
#define TEST_CASE_(...)
#define TEST_CASE(name)
#define TEST_CASE_MAXSIZE   64
#define TEST_MSG(...)
#define TEST_MSG_MAXSIZE   1024
#define TEST_DUMP(title, addr, size)
#define TEST_DUMP_MAXSIZE   1024
#define TEST_SKIP(...)
#define ACUTEST_ATTRIBUTE_(attr)
#define ACUTEST_COLOR_DEFAULT_   0
#define ACUTEST_COLOR_RED_   1
#define ACUTEST_COLOR_GREEN_   2
#define ACUTEST_COLOR_YELLOW_   3
#define ACUTEST_COLOR_DEFAULT_INTENSIVE_   10
#define ACUTEST_COLOR_RED_INTENSIVE_   11
#define ACUTEST_COLOR_GREEN_INTENSIVE_   12
#define ACUTEST_COLOR_YELLOW_INTENSIVE_   13
#define ACUTEST_CMDLINE_OPTFLAG_OPTIONALARG_   0x0001
#define ACUTEST_CMDLINE_OPTFLAG_REQUIREDARG_   0x0002
#define ACUTEST_CMDLINE_OPTID_NONE_   0
#define ACUTEST_CMDLINE_OPTID_UNKNOWN_   (-0x7fffffff + 0)
#define ACUTEST_CMDLINE_OPTID_MISSINGARG_   (-0x7fffffff + 1)
#define ACUTEST_CMDLINE_OPTID_BOGUSARG_   (-0x7fffffff + 2)
#define ACUTEST_CMDLINE_AUXBUF_SIZE_   32

Typedefs

typedef int acutest_timer_type_

Enumerations

enum  acutest_state_ {
  ACUTEST_STATE_INITIAL = -4 , ACUTEST_STATE_SELECTED = -3 , ACUTEST_STATE_NEEDTORUN = -2 , ACUTEST_STATE_EXCLUDED = -1 ,
  ACUTEST_STATE_SUCCESS = 0 , ACUTEST_STATE_FAILED = 1 , ACUTEST_STATE_SKIPPED = 2
}

Functions

int acutest_check_ (int cond, const char *file, int line, const char *fmt,...)
void acutest_case_ (const char *fmt,...)
void acutest_message_ (const char *fmt,...)
void acutest_dump_ (const char *title, const void *addr, size_t size)
void acutest_abort_ (void) ACUTEST_ATTRIBUTE_(noreturn)
static int acutest_count_ (enum acutest_state_ state)
static void acutest_cleanup_ (void)
static void ACUTEST_ATTRIBUTE_ (noreturn) acutest_exit_(int exit_code)
void acutest_timer_init_ (void)
static void acutest_timer_get_time_ (int *ts)
static double acutest_timer_diff_ (int start, int end)
static void acutest_timer_print_diff_ (void)
static int ACUTEST_ATTRIBUTE_ (format(printf, 2, 3)) acutest_colored_printf_(int color
 va_start (args, fmt)
 vsnprintf (buffer, sizeof(buffer), fmt, args)
 va_end (args)
 if (!acutest_colorize_)
static const char * acutest_basename_ (const char *path)
static void acutest_begin_test_line_ (const struct acutest_test_ *test)
static void acutest_finish_test_line_ (enum acutest_state_ state)
static void acutest_line_indent_ (int level)
void ACUTEST_ATTRIBUTE_ (format(printf, 3, 4)) acutest_skip_(const char *file
 vsnprintf (acutest_test_skip_reason_, sizeof(acutest_test_skip_reason_), fmt, args)
 if (acutest_test_skip_reason_[reason_len - 1]=='.')
 if (acutest_test_check_count_ > 0)
 if (acutest_verbose_level_ >=2)
int ACUTEST_ATTRIBUTE_ (format(printf, 4, 5)) acutest_check_(int cond
 if (acutest_test_skip_count_)
 if (cond)
void ACUTEST_ATTRIBUTE_ (format(printf, 1, 2)) acutest_case_(const char *fmt
void if (acutest_verbose_level_< 2)
 if (acutest_case_name_[0])
 if (fmt==NULL)
 vsnprintf (acutest_case_name_, sizeof(acutest_case_name_) - 1, fmt, args)
 if (acutest_current_test_==NULL||!acutest_cond_failed_)
 vsnprintf (buffer, TEST_MSG_MAXSIZE, fmt, args)
 while (1)
 if (line_beg[0] !='\0')
static void acutest_init_ (const char *test_name)
static void acutest_fini_ (const char *test_name)
static void acutest_list_names_ (void)
static int acutest_name_contains_word_ (const char *name, const char *pattern)
static int acutest_select_ (const char *pattern)
static void static int acutest_cmdline_handle_short_opt_group_ (const ACUTEST_CMDLINE_OPTION_ *options, const char *arggroup, int(*callback)(int, const char *))
static int acutest_cmdline_read_ (const ACUTEST_CMDLINE_OPTION_ *options, int argc, char **argv, int(*callback)(int, const char *))
static void acutest_help_ (void)
static int acutest_cmdline_callback_ (int id, const char *arg)
static int acutest_under_debugger_ (void)
int main (int argc, char **argv)

Variables

const struct acutest_test_ acutest_list_ []
static char * acutest_argv0_ = NULL
static int acutest_list_size_ = 0
static struct acutest_test_data_ * acutest_test_data_ = NULL
static int acutest_no_exec_ = -1
static int acutest_no_summary_ = 0
static int acutest_tap_ = 0
static int acutest_exclude_mode_ = 0
static int acutest_worker_ = 0
static int acutest_worker_index_ = 0
static int acutest_cond_failed_ = 0
static FILE * acutest_xml_output_ = NULL
static const struct acutest_test_acutest_current_test_ = NULL
static int acutest_current_index_ = 0
static char acutest_case_name_ [TEST_CASE_MAXSIZE] = ""
static int acutest_test_check_count_ = 0
static int acutest_test_skip_count_ = 0
static char acutest_test_skip_reason_ [256] = ""
static int acutest_test_already_logged_ = 0
static int acutest_case_already_logged_ = 0
static int acutest_verbose_level_ = 2
static int acutest_test_failures_ = 0
static int acutest_colorize_ = 0
static int acutest_timer_ = 0
static int acutest_abort_has_jmp_buf_ = 0
static jmp_buf acutest_abort_jmp_buf_
static acutest_timer_type_ acutest_timer_start_
static acutest_timer_type_ acutest_timer_end_
static int const char * fmt
static int const char char buffer [256]
int n = printf("%s", buffer)
void int line
void int const char size_t reason_len
int const char * file
int const char int const char int result_color
int verbose_level = 2
 else
 result_str = "failed"
skip_check __pad0__
return !acutest_cond_failed_
void char * line_beg
char * line_end
va_list args
static const ACUTEST_CMDLINE_OPTION_ acutest_cmdline_options_ []

Macro Definition Documentation

◆ ACUTEST_ATTRIBUTE_

#define ACUTEST_ATTRIBUTE_ ( attr)

Definition at line 294 of file acutest.h.

◆ ACUTEST_CMDLINE_AUXBUF_SIZE_

#define ACUTEST_CMDLINE_AUXBUF_SIZE_   32

Definition at line 1416 of file acutest.h.

◆ ACUTEST_CMDLINE_OPTFLAG_OPTIONALARG_

#define ACUTEST_CMDLINE_OPTFLAG_OPTIONALARG_   0x0001

◆ ACUTEST_CMDLINE_OPTFLAG_REQUIREDARG_

#define ACUTEST_CMDLINE_OPTFLAG_REQUIREDARG_   0x0002

◆ ACUTEST_CMDLINE_OPTID_BOGUSARG_

#define ACUTEST_CMDLINE_OPTID_BOGUSARG_   (-0x7fffffff + 2)

◆ ACUTEST_CMDLINE_OPTID_MISSINGARG_

#define ACUTEST_CMDLINE_OPTID_MISSINGARG_   (-0x7fffffff + 1)

◆ ACUTEST_CMDLINE_OPTID_NONE_

#define ACUTEST_CMDLINE_OPTID_NONE_   0

◆ ACUTEST_CMDLINE_OPTID_UNKNOWN_

#define ACUTEST_CMDLINE_OPTID_UNKNOWN_   (-0x7fffffff + 0)

◆ ACUTEST_COLOR_DEFAULT_

#define ACUTEST_COLOR_DEFAULT_   0

Definition at line 512 of file acutest.h.

◆ ACUTEST_COLOR_DEFAULT_INTENSIVE_

#define ACUTEST_COLOR_DEFAULT_INTENSIVE_   10

Definition at line 516 of file acutest.h.

◆ ACUTEST_COLOR_GREEN_

#define ACUTEST_COLOR_GREEN_   2

Definition at line 514 of file acutest.h.

◆ ACUTEST_COLOR_GREEN_INTENSIVE_

#define ACUTEST_COLOR_GREEN_INTENSIVE_   12

Definition at line 518 of file acutest.h.

◆ ACUTEST_COLOR_RED_

#define ACUTEST_COLOR_RED_   1

Definition at line 513 of file acutest.h.

◆ ACUTEST_COLOR_RED_INTENSIVE_

#define ACUTEST_COLOR_RED_INTENSIVE_   11

Definition at line 517 of file acutest.h.

◆ ACUTEST_COLOR_YELLOW_

#define ACUTEST_COLOR_YELLOW_   3

Definition at line 515 of file acutest.h.

◆ ACUTEST_COLOR_YELLOW_INTENSIVE_

#define ACUTEST_COLOR_YELLOW_INTENSIVE_   13

Definition at line 519 of file acutest.h.

◆ TEST_ASSERT

#define TEST_ASSERT ( cond)
Value:
do { \
if (!acutest_check_(!!(cond), __FILE__, __LINE__, "%s", #cond)) \
acutest_abort_(); \
} while (0)
int acutest_check_(int cond, const char *file, int line, const char *fmt,...)

Definition at line 117 of file acutest.h.

117#define TEST_ASSERT(cond) \
118 do { \
119 if (!acutest_check_(!!(cond), __FILE__, __LINE__, "%s", #cond)) \
120 acutest_abort_(); \
121 } while (0)

◆ TEST_ASSERT_

#define TEST_ASSERT_ ( cond,
... )
Value:
do { \
if (!acutest_check_(!!(cond), __FILE__, __LINE__, __VA_ARGS__)) \
acutest_abort_(); \
} while (0)

Definition at line 112 of file acutest.h.

112#define TEST_ASSERT_(cond, ...) \
113 do { \
114 if (!acutest_check_(!!(cond), __FILE__, __LINE__, __VA_ARGS__)) \
115 acutest_abort_(); \
116 } while (0)

◆ TEST_CASE

#define TEST_CASE ( name)
Value:
acutest_case_("%s", name)
void acutest_case_(const char *fmt,...)

Definition at line 193 of file acutest.h.

◆ TEST_CASE_

#define TEST_CASE_ ( ...)
Value:
acutest_case_(__VA_ARGS__)

Definition at line 192 of file acutest.h.

◆ TEST_CASE_MAXSIZE

#define TEST_CASE_MAXSIZE   64

Definition at line 199 of file acutest.h.

◆ TEST_CHECK

#define TEST_CHECK ( cond)
Value:
acutest_check_(!!(cond), __FILE__, __LINE__, "%s", #cond)

Definition at line 95 of file acutest.h.

◆ TEST_CHECK_

#define TEST_CHECK_ ( cond,
... )
Value:
acutest_check_(!!(cond), __FILE__, __LINE__, __VA_ARGS__)

Definition at line 94 of file acutest.h.

◆ TEST_DUMP

#define TEST_DUMP ( title,
addr,
size )
Value:
acutest_dump_(title, addr, size)
void acutest_dump_(const char *title, const void *addr, size_t size)
Definition acutest.h:909

Definition at line 243 of file acutest.h.

◆ TEST_DUMP_MAXSIZE

#define TEST_DUMP_MAXSIZE   1024

Definition at line 249 of file acutest.h.

◆ TEST_LIST

#define TEST_LIST   const struct acutest_test_ acutest_list_[]

Definition at line 73 of file acutest.h.

◆ TEST_MSG

#define TEST_MSG ( ...)
Value:
acutest_message_(__VA_ARGS__)
void acutest_message_(const char *fmt,...)

Definition at line 223 of file acutest.h.

◆ TEST_MSG_MAXSIZE

#define TEST_MSG_MAXSIZE   1024

Definition at line 229 of file acutest.h.

◆ TEST_SKIP

#define TEST_SKIP ( ...)
Value:
acutest_skip_(__FILE__, __LINE__, __VA_ARGS__)

Definition at line 259 of file acutest.h.

Typedef Documentation

◆ acutest_timer_type_

typedef int acutest_timer_type_

Definition at line 495 of file acutest.h.

Enumeration Type Documentation

◆ acutest_state_

Enumerator
ACUTEST_STATE_INITIAL 
ACUTEST_STATE_SELECTED 
ACUTEST_STATE_NEEDTORUN 
ACUTEST_STATE_EXCLUDED 
ACUTEST_STATE_SUCCESS 
ACUTEST_STATE_FAILED 
ACUTEST_STATE_SKIPPED 

Definition at line 301 of file acutest.h.

301 {
305
306 /* By the end all tests should be in one of the following: */
311};
@ ACUTEST_STATE_SKIPPED
Definition acutest.h:310
@ ACUTEST_STATE_FAILED
Definition acutest.h:309
@ ACUTEST_STATE_SUCCESS
Definition acutest.h:308
@ ACUTEST_STATE_SELECTED
Definition acutest.h:303
@ ACUTEST_STATE_INITIAL
Definition acutest.h:302
@ ACUTEST_STATE_NEEDTORUN
Definition acutest.h:304
@ ACUTEST_STATE_EXCLUDED
Definition acutest.h:307

Function Documentation

◆ acutest_abort_()

void acutest_abort_ ( void )

Definition at line 985 of file acutest.h.

985 {
987 longjmp(acutest_abort_jmp_buf_, 1);
988 } else {
989 if (acutest_current_test_ != NULL) {
991 }
992 fflush(stdout);
993 fflush(stderr);
994 acutest_exit_(ACUTEST_STATE_FAILED);
995 }
996}
static const struct acutest_test_ * acutest_current_test_
Definition acutest.h:417
static void acutest_fini_(const char *test_name)
Definition acutest.h:976
static int acutest_abort_has_jmp_buf_
Definition acutest.h:430
static jmp_buf acutest_abort_jmp_buf_
Definition acutest.h:431
Here is the call graph for this function:

◆ ACUTEST_ATTRIBUTE_() [1/5]

void ACUTEST_ATTRIBUTE_ ( format(printf, 1, 2) ) const
Here is the call graph for this function:

◆ ACUTEST_ATTRIBUTE_() [2/5]

int ACUTEST_ATTRIBUTE_ ( format(printf, 2, 3) )
static

◆ ACUTEST_ATTRIBUTE_() [3/5]

void ACUTEST_ATTRIBUTE_ ( format(printf, 3, 4) ) const

◆ ACUTEST_ATTRIBUTE_() [4/5]

int ACUTEST_ATTRIBUTE_ ( format(printf, 4, 5) )
Here is the call graph for this function:

◆ ACUTEST_ATTRIBUTE_() [5/5]

void ACUTEST_ATTRIBUTE_ ( noreturn )
static

Definition at line 447 of file acutest.h.

447 {
449 exit(exit_code);
450}
static void acutest_cleanup_(void)
Definition acutest.h:445
Here is the call graph for this function:

◆ acutest_basename_()

const char * acutest_basename_ ( const char * path)
static

Definition at line 618 of file acutest.h.

618 {
619 const char *name;
620
621 name = strrchr(path, '/');
622 if (name != NULL) {
623 name++;
624 } else {
625 name = path;
626 }
627
628# ifdef ACUTEST_WIN_
629 {
630 const char *alt_name;
631
632 alt_name = strrchr(path, '\\');
633 if (alt_name != NULL) {
634 alt_name++;
635 } else {
636 alt_name = path;
637 }
638
639 if (alt_name > name) {
640 name = alt_name;
641 }
642 }
643# endif
644
645 return name;
646}
Here is the caller graph for this function:

◆ acutest_begin_test_line_()

void acutest_begin_test_line_ ( const struct acutest_test_ * test)
static

Definition at line 648 of file acutest.h.

648 {
649 if (!acutest_tap_) {
650 if (acutest_verbose_level_ >= 3) {
651 acutest_colored_printf_(ACUTEST_COLOR_DEFAULT_INTENSIVE_, "Test %s:\n", test->name);
653 } else if (acutest_verbose_level_ >= 1) {
654 int n;
655 char spaces[48];
656
657 n = acutest_colored_printf_(ACUTEST_COLOR_DEFAULT_INTENSIVE_, "Test %s... ", test->name);
658 memset(spaces, ' ', sizeof(spaces));
659 if (n < (int)sizeof(spaces)) {
660 printf("%.*s", (int)sizeof(spaces) - n, spaces);
661 }
662 } else {
664 }
665 }
666}
#define ACUTEST_COLOR_DEFAULT_INTENSIVE_
Definition acutest.h:516
static int acutest_test_already_logged_
Definition acutest.h:423
int n
Definition acutest.h:525
static int acutest_verbose_level_
Definition acutest.h:425
static int acutest_tap_
Definition acutest.h:410
const char * name
Definition acutest.h:394

◆ acutest_case_()

void acutest_case_ ( const char * fmt,
... )
Here is the caller graph for this function:

◆ acutest_check_()

int acutest_check_ ( int cond,
const char * file,
int line,
const char * fmt,
... )
Here is the caller graph for this function:

◆ acutest_cleanup_()

void acutest_cleanup_ ( void )
static

Definition at line 445 of file acutest.h.

445{ free((void *)acutest_test_data_); }
Here is the caller graph for this function:

◆ acutest_cmdline_callback_()

int acutest_cmdline_callback_ ( int id,
const char * arg )
static

Definition at line 1618 of file acutest.h.

1618 {
1619 switch (id) {
1620 case 'X':
1622 break;
1623
1624 case 'e':
1625 if (arg == NULL || strcmp(arg, "always") == 0) {
1626 acutest_no_exec_ = 0;
1627 } else if (strcmp(arg, "never") == 0) {
1628 acutest_no_exec_ = 1;
1629 } else if (strcmp(arg, "auto") == 0) {
1630 /*noop*/
1631 } else {
1632 fprintf(stderr, "%s: Unrecognized argument '%s' for option --exec.\n", acutest_argv0_, arg);
1633 fprintf(stderr, "Try '%s --help' for more information.\n", acutest_argv0_);
1634 acutest_exit_(2);
1635 }
1636 break;
1637
1638 case 'E':
1639 acutest_no_exec_ = 1;
1640 break;
1641
1642 case 't':
1643# if defined ACUTEST_WIN_ || defined ACUTEST_HAS_POSIX_TIMER_
1644 if (arg == NULL || strcmp(arg, "real") == 0) {
1645 acutest_timer_ = 1;
1646# ifndef ACUTEST_WIN_
1647 } else if (strcmp(arg, "cpu") == 0) {
1648 acutest_timer_ = 2;
1649# endif
1650 } else {
1651 fprintf(stderr, "%s: Unrecognized argument '%s' for option --time.\n", acutest_argv0_, arg);
1652 fprintf(stderr, "Try '%s --help' for more information.\n", acutest_argv0_);
1653 acutest_exit_(2);
1654 }
1655# endif
1656 break;
1657
1658 case 'S':
1660 break;
1661
1662 case 'T':
1663 acutest_tap_ = 1;
1664 break;
1665
1666 case 'l':
1668 acutest_exit_(0);
1669 break;
1670
1671 case 'v':
1672 acutest_verbose_level_ = (arg != NULL ? atoi(arg) : acutest_verbose_level_ + 1);
1673 break;
1674
1675 case 'q':
1677 break;
1678
1679 case 'c':
1680 if (arg == NULL || strcmp(arg, "always") == 0) {
1682 } else if (strcmp(arg, "never") == 0) {
1684 } else if (strcmp(arg, "auto") == 0) {
1685 /*noop*/
1686 } else {
1687 fprintf(stderr, "%s: Unrecognized argument '%s' for option --color.\n", acutest_argv0_, arg);
1688 fprintf(stderr, "Try '%s --help' for more information.\n", acutest_argv0_);
1689 acutest_exit_(2);
1690 }
1691 break;
1692
1693 case 'C':
1695 break;
1696
1697 case 'h':
1698 acutest_help_();
1699 acutest_exit_(0);
1700 break;
1701
1702 case 'w':
1703 acutest_worker_ = 1;
1704 acutest_worker_index_ = atoi(arg);
1705 break;
1706 case 'x':
1707 acutest_xml_output_ = fopen(arg, "w");
1708 if (!acutest_xml_output_) {
1709 fprintf(stderr, "Unable to open '%s': %s\n", arg, strerror(errno));
1710 acutest_exit_(2);
1711 }
1712 break;
1713
1714 case 0:
1715 if (acutest_select_(arg) == 0) {
1716 fprintf(stderr, "%s: Unrecognized unit test '%s'\n", acutest_argv0_, arg);
1717 fprintf(stderr, "Try '%s --list' for list of unit tests.\n", acutest_argv0_);
1718 acutest_exit_(2);
1719 }
1720 break;
1721
1723 fprintf(stderr, "Unrecognized command line option '%s'.\n", arg);
1724 fprintf(stderr, "Try '%s --help' for more information.\n", acutest_argv0_);
1725 acutest_exit_(2);
1726 break;
1727
1729 fprintf(stderr, "The command line option '%s' requires an argument.\n", arg);
1730 fprintf(stderr, "Try '%s --help' for more information.\n", acutest_argv0_);
1731 acutest_exit_(2);
1732 break;
1733
1735 fprintf(stderr, "The command line option '%s' does not expect an argument.\n", arg);
1736 fprintf(stderr, "Try '%s --help' for more information.\n", acutest_argv0_);
1737 acutest_exit_(2);
1738 break;
1739 }
1740
1741 return 0;
1742}
static int acutest_no_exec_
Definition acutest.h:408
static FILE * acutest_xml_output_
Definition acutest.h:415
static int acutest_worker_
Definition acutest.h:412
static int acutest_colorize_
Definition acutest.h:427
static void acutest_help_(void)
Definition acutest.h:1533
static int acutest_timer_
Definition acutest.h:428
#define ACUTEST_CMDLINE_OPTID_MISSINGARG_
#define ACUTEST_CMDLINE_OPTID_UNKNOWN_
#define ACUTEST_CMDLINE_OPTID_BOGUSARG_
static void acutest_list_names_(void)
Definition acutest.h:998
static int acutest_worker_index_
Definition acutest.h:413
static int acutest_select_(const char *pattern)
Definition acutest.h:1030
static int acutest_no_summary_
Definition acutest.h:409
static char * acutest_argv0_
Definition acutest.h:405
static int acutest_exclude_mode_
Definition acutest.h:411
Here is the call graph for this function:
Here is the caller graph for this function:

◆ acutest_cmdline_handle_short_opt_group_()

void static int acutest_cmdline_handle_short_opt_group_ ( const ACUTEST_CMDLINE_OPTION_ * options,
const char * arggroup,
int(* callback )(int, const char *) )
static

Definition at line 1379 of file acutest.h.

1382 {
1383 const ACUTEST_CMDLINE_OPTION_ *opt;
1384 int i;
1385 int ret = 0;
1386
1387 for (i = 0; arggroup[i] != '\0'; i++) {
1388 for (opt = options; opt->id != 0; opt++) {
1389 if (arggroup[i] == opt->shortname) {
1390 break;
1391 }
1392 }
1393
1394 if (opt->id != 0 && !(opt->flags & ACUTEST_CMDLINE_OPTFLAG_REQUIREDARG_)) {
1395 ret = callback(opt->id, NULL);
1396 } else {
1397 /* Unknown option. */
1398 char badoptname[3];
1399 badoptname[0] = '-';
1400 badoptname[1] = arggroup[i];
1401 badoptname[2] = '\0';
1402 ret = callback(
1404 badoptname
1405 );
1406 }
1407
1408 if (ret != 0) {
1409 break;
1410 }
1411 }
1412
1413 return ret;
1414}
#define ACUTEST_CMDLINE_OPTFLAG_REQUIREDARG_
Here is the caller graph for this function:

◆ acutest_cmdline_read_()

int acutest_cmdline_read_ ( const ACUTEST_CMDLINE_OPTION_ * options,
int argc,
char ** argv,
int(* callback )(int, const char *) )
static

Definition at line 1418 of file acutest.h.

1421 {
1422
1423 const ACUTEST_CMDLINE_OPTION_ *opt;
1424 char auxbuf[ACUTEST_CMDLINE_AUXBUF_SIZE_ + 1];
1425 int after_doubledash = 0;
1426 int i = 1;
1427 int ret = 0;
1428
1429 auxbuf[ACUTEST_CMDLINE_AUXBUF_SIZE_] = '\0';
1430
1431 while (i < argc) {
1432 if (after_doubledash || strcmp(argv[i], "-") == 0) {
1433 /* Non-option argument. */
1434 ret = callback(ACUTEST_CMDLINE_OPTID_NONE_, argv[i]);
1435 } else if (strcmp(argv[i], "--") == 0) {
1436 /* End of options. All the remaining members are non-option arguments. */
1437 after_doubledash = 1;
1438 } else if (argv[i][0] != '-') {
1439 /* Non-option argument. */
1440 ret = callback(ACUTEST_CMDLINE_OPTID_NONE_, argv[i]);
1441 } else {
1442 for (opt = options; opt->id != 0; opt++) {
1443 if (opt->longname != NULL && strncmp(argv[i], "--", 2) == 0) {
1444 size_t len = strlen(opt->longname);
1445 if (strncmp(argv[i] + 2, opt->longname, len) == 0) {
1446 /* Regular long option. */
1447 if (argv[i][2 + len] == '\0') {
1448 /* with no argument provided. */
1449 if (!(opt->flags & ACUTEST_CMDLINE_OPTFLAG_REQUIREDARG_)) {
1450 ret = callback(opt->id, NULL);
1451 } else {
1452 ret = callback(ACUTEST_CMDLINE_OPTID_MISSINGARG_, argv[i]);
1453 }
1454 break;
1455 } else if (argv[i][2 + len] == '=') {
1456 /* with an argument provided. */
1457 if (
1458 opt->flags &
1460 ) {
1461 ret = callback(opt->id, argv[i] + 2 + len + 1);
1462 } else {
1463 snprintf(auxbuf, sizeof(auxbuf), "--%s", opt->longname);
1464 ret = callback(ACUTEST_CMDLINE_OPTID_BOGUSARG_, auxbuf);
1465 }
1466 break;
1467 } else {
1468 continue;
1469 }
1470 }
1471 } else if (opt->shortname != '\0' && argv[i][0] == '-') {
1472 if (argv[i][1] == opt->shortname) {
1473 /* Regular short option. */
1474 if (opt->flags & ACUTEST_CMDLINE_OPTFLAG_REQUIREDARG_) {
1475 if (argv[i][2] != '\0') {
1476 ret = callback(opt->id, argv[i] + 2);
1477 } else if (i + 1 < argc) {
1478 ret = callback(opt->id, argv[++i]);
1479 } else {
1480 ret = callback(ACUTEST_CMDLINE_OPTID_MISSINGARG_, argv[i]);
1481 }
1482 break;
1483 } else {
1484 ret = callback(opt->id, NULL);
1485
1486 /* There might be more (argument-less) short options
1487 * grouped together. */
1488 if (ret == 0 && argv[i][2] != '\0') {
1489 ret = acutest_cmdline_handle_short_opt_group_(options, argv[i] + 2, callback);
1490 }
1491 break;
1492 }
1493 }
1494 }
1495 }
1496
1497 if (opt->id == 0) { /* still not handled? */
1498 if (argv[i][0] != '-') {
1499 /* Non-option argument. */
1500 ret = callback(ACUTEST_CMDLINE_OPTID_NONE_, argv[i]);
1501 } else {
1502 /* Unknown option. */
1503 char *badoptname = argv[i];
1504
1505 if (strncmp(badoptname, "--", 2) == 0) {
1506 /* Strip any argument from the long option. */
1507 char *assignment = strchr(badoptname, '=');
1508 if (assignment != NULL) {
1509 size_t len = (size_t)(assignment - badoptname);
1510 if (len > ACUTEST_CMDLINE_AUXBUF_SIZE_) {
1512 }
1513 strncpy(auxbuf, badoptname, len);
1514 auxbuf[len] = '\0';
1515 badoptname = auxbuf;
1516 }
1517 }
1518
1519 ret = callback(ACUTEST_CMDLINE_OPTID_UNKNOWN_, badoptname);
1520 }
1521 }
1522 }
1523
1524 if (ret != 0) {
1525 return ret;
1526 }
1527 i++;
1528 }
1529
1530 return ret;
1531}
#define ACUTEST_CMDLINE_OPTID_NONE_
static void static int acutest_cmdline_handle_short_opt_group_(const ACUTEST_CMDLINE_OPTION_ *options, const char *arggroup, int(*callback)(int, const char *))
Definition acutest.h:1379
#define ACUTEST_CMDLINE_AUXBUF_SIZE_
Definition acutest.h:1416
#define ACUTEST_CMDLINE_OPTFLAG_OPTIONALARG_
Here is the call graph for this function:
Here is the caller graph for this function:

◆ acutest_count_()

int acutest_count_ ( enum acutest_state_ state)
static

Definition at line 433 of file acutest.h.

433 {
434 int i, n;
435
436 for (i = 0, n = 0; i < acutest_list_size_; i++) {
437 if (acutest_test_data_[i].state == state) {
438 n++;
439 }
440 }
441
442 return n;
443}
static int acutest_list_size_
Definition acutest.h:406
Here is the caller graph for this function:

◆ acutest_dump_()

void acutest_dump_ ( const char * title,
const void * addr,
size_t size )

Definition at line 909 of file acutest.h.

909 {
910 static const size_t BYTES_PER_LINE = 16;
911 size_t line_beg;
912 size_t truncate = 0;
913
914 if (acutest_verbose_level_ < 2) {
915 return;
916 }
917
918 /* We allow extra message only when something is already wrong in the
919 * current test. */
921 return;
922 }
923
924 if (size > TEST_DUMP_MAXSIZE) {
925 truncate = size - TEST_DUMP_MAXSIZE;
926 size = TEST_DUMP_MAXSIZE;
927 }
928
930 printf((title[strlen(title) - 1] == ':') ? "%s\n" : "%s:\n", title);
931
932 for (line_beg = 0; line_beg < size; line_beg += BYTES_PER_LINE) {
933 size_t line_end = line_beg + BYTES_PER_LINE;
934 size_t off;
935
937 printf("%08lx: ", (unsigned long)line_beg);
938 for (off = line_beg; off < line_end; off++) {
939 if (off < size) {
940 printf(" %02x", ((const unsigned char *)addr)[off]);
941 } else {
942 printf(" ");
943 }
944 }
945
946 printf(" ");
947 for (off = line_beg; off < line_end; off++) {
948 unsigned char byte = ((const unsigned char *)addr)[off];
949 if (off < size) {
950 printf("%c", (iscntrl(byte) ? '.' : byte));
951 } else {
952 break;
953 }
954 }
955
956 printf("\n");
957 }
958
959 if (truncate > 0) {
961 printf(" ... (and more %u bytes)\n", (unsigned)truncate);
962 }
963}
static void acutest_line_indent_(int level)
Definition acutest.h:715
static char acutest_case_name_[TEST_CASE_MAXSIZE]
Definition acutest.h:419
static int acutest_cond_failed_
Definition acutest.h:414
void char * line_beg
Definition acutest.h:874
char * line_end
Definition acutest.h:875
#define TEST_DUMP_MAXSIZE
Definition acutest.h:249
Here is the call graph for this function:

◆ acutest_fini_()

void acutest_fini_ ( const char * test_name)
static

Definition at line 976 of file acutest.h.

976 {
977# ifdef TEST_FINI
978 TEST_FINI; /* Allow for a single unterminated function call */
979# endif
980
981 /* Suppress any warnings about unused variable. */
982 (void)test_name;
983}
Here is the caller graph for this function:

◆ acutest_finish_test_line_()

void acutest_finish_test_line_ ( enum acutest_state_ state)
static

Definition at line 668 of file acutest.h.

668 {
669 if (acutest_tap_) {
670 printf(
671 "%s %d - %s%s\n",
672 (state == ACUTEST_STATE_SUCCESS || state == ACUTEST_STATE_SKIPPED) ? "ok" : "not ok",
674 (state == ACUTEST_STATE_SKIPPED) ? " # SKIP" : ""
675 );
676
677 if (state == ACUTEST_STATE_SUCCESS && acutest_timer_) {
678 printf("# Duration: ");
680 printf("\n");
681 }
682 } else {
683 int color;
684 const char *str;
685
686 switch (state) {
689 str = "OK";
690 break;
693 str = "SKIPPED";
694 break;
695 case ACUTEST_STATE_FAILED: /* Fall through. */
696 default:
698 str = "FAILED";
699 break;
700 }
701
702 printf("[ ");
703 acutest_colored_printf_(color, "%s", str);
704 printf(" ]");
705
706 if (state == ACUTEST_STATE_SUCCESS && acutest_timer_) {
707 printf(" ");
709 }
710
711 printf("\n");
712 }
713}
#define ACUTEST_COLOR_GREEN_INTENSIVE_
Definition acutest.h:518
static void acutest_timer_print_diff_(void)
Definition acutest.h:509
#define ACUTEST_COLOR_RED_INTENSIVE_
Definition acutest.h:517
static int acutest_current_index_
Definition acutest.h:418
#define ACUTEST_COLOR_YELLOW_INTENSIVE_
Definition acutest.h:519
Here is the call graph for this function:
Here is the caller graph for this function:

◆ acutest_help_()

void acutest_help_ ( void )
static

Definition at line 1533 of file acutest.h.

1533 {
1534 printf("Usage: %s [options] [test...]\n", acutest_argv0_);
1535 printf("\n");
1536 printf(
1537 "Run the specified unit tests; or if the option '--exclude' is used, "
1538 "run all\n"
1539 );
1540 printf(
1541 "tests in the suite but those listed. By default, if no tests are "
1542 "specified\n"
1543 );
1544 printf("on the command line, all unit tests in the suite are run.\n");
1545 printf("\n");
1546 printf("Options:\n");
1547 printf(" -X, --exclude Execute all unit tests but the listed ones\n");
1548 printf(
1549 " --exec[=WHEN] If supported, execute unit tests as child "
1550 "processes\n"
1551 );
1552 printf(" (WHEN is one of 'auto', 'always', 'never')\n");
1553 printf(" -E, --no-exec Same as --exec=never\n");
1554# if defined ACUTEST_WIN_
1555 printf(" -t, --time Measure test duration\n");
1556# elif defined ACUTEST_HAS_POSIX_TIMER_
1557 printf(" -t, --time Measure test duration (real time)\n");
1558 printf(" --time=TIMER Measure test duration, using given timer\n");
1559 printf(" (TIMER is one of 'real', 'cpu')\n");
1560# endif
1561 printf(" --no-summary Suppress printing of test results summary\n");
1562 printf(" --tap Produce TAP-compliant output\n");
1563 printf(" (See https://testanything.org/)\n");
1564 printf(" -x, --xml-output=FILE Enable XUnit output to the given file\n");
1565 printf(" -l, --list List unit tests in the suite and exit\n");
1566 printf(" -v, --verbose Make output more verbose\n");
1567 printf(" --verbose=LEVEL Set verbose level to LEVEL:\n");
1568 printf(" 0 ... Be silent\n");
1569 printf(
1570 " 1 ... Output one line per test (and "
1571 "summary)\n"
1572 );
1573 printf(
1574 " 2 ... As 1 and failed conditions (this is "
1575 "default)\n"
1576 );
1577 printf(
1578 " 3 ... As 1 and all conditions (and "
1579 "extended summary)\n"
1580 );
1581 printf(" -q, --quiet Same as --verbose=0\n");
1582 printf(" --color[=WHEN] Enable colorized output\n");
1583 printf(" (WHEN is one of 'auto', 'always', 'never')\n");
1584 printf(" --no-color Same as --color=never\n");
1585 printf(" -h, --help Display this help and exit\n");
1586
1587 if (acutest_list_size_ < 16) {
1588 printf("\n");
1590 }
1591}
Here is the call graph for this function:
Here is the caller graph for this function:

◆ acutest_init_()

void acutest_init_ ( const char * test_name)
static

Definition at line 966 of file acutest.h.

966 {
967# ifdef TEST_INIT
968 TEST_INIT; /* Allow for a single unterminated function call */
969# endif
970
971 /* Suppress any warnings about unused variable. */
972 (void)test_name;
973}

◆ acutest_line_indent_()

void acutest_line_indent_ ( int level)
static

Definition at line 715 of file acutest.h.

715 {
716 static const char spaces[] = " ";
717 int n = level * 2;
718
719 if (acutest_tap_ && n > 0) {
720 n--;
721 printf("#");
722 }
723
724 while (n > 16) {
725 printf("%s", spaces);
726 n -= 16;
727 }
728 printf("%.*s", n, spaces);
729}
Here is the caller graph for this function:

◆ acutest_list_names_()

void acutest_list_names_ ( void )
static

Definition at line 998 of file acutest.h.

998 {
999 const struct acutest_test_ *test;
1000
1001 printf("Unit tests:\n");
1002 for (test = &acutest_list_[0]; test->func != NULL; test++) {
1003 printf(" %s\n", test->name);
1004 }
1005}
const struct acutest_test_ acutest_list_[]
void(* func)(void)
Definition acutest.h:395
Here is the caller graph for this function:

◆ acutest_message_()

void acutest_message_ ( const char * fmt,
... )

◆ acutest_name_contains_word_()

int acutest_name_contains_word_ ( const char * name,
const char * pattern )
static

Definition at line 1007 of file acutest.h.

1007 {
1008 static const char word_delim[] = " \t-_/.,:;";
1009 const char *substr;
1010 size_t pattern_len;
1011
1012 pattern_len = strlen(pattern);
1013
1014 substr = strstr(name, pattern);
1015 while (substr != NULL) {
1016 int starts_on_word_boundary = (substr == name || strchr(word_delim, substr[-1]) != NULL);
1017 int ends_on_word_boundary =
1018 (substr[pattern_len] == '\0' || strchr(word_delim, substr[pattern_len]) != NULL);
1019
1020 if (starts_on_word_boundary && ends_on_word_boundary) {
1021 return 1;
1022 }
1023
1024 substr = strstr(substr + 1, pattern);
1025 }
1026
1027 return 0;
1028}
Here is the caller graph for this function:

◆ acutest_select_()

int acutest_select_ ( const char * pattern)
static

Definition at line 1030 of file acutest.h.

1030 {
1031 int i;
1032 int n = 0;
1033
1034 /* Try exact match. */
1035 for (i = 0; i < acutest_list_size_; i++) {
1036 if (strcmp(acutest_list_[i].name, pattern) == 0) {
1038 n++;
1039 break;
1040 }
1041 }
1042 if (n > 0) {
1043 return n;
1044 }
1045
1046 /* Try word match. */
1047 for (i = 0; i < acutest_list_size_; i++) {
1048 if (acutest_name_contains_word_(acutest_list_[i].name, pattern)) {
1050 n++;
1051 }
1052 }
1053 if (n > 0) {
1054 return n;
1055 }
1056
1057 /* Try relaxed match. */
1058 for (i = 0; i < acutest_list_size_; i++) {
1059 if (strstr(acutest_list_[i].name, pattern) != NULL) {
1061 n++;
1062 }
1063 }
1064
1065 return n;
1066}
static int acutest_name_contains_word_(const char *name, const char *pattern)
Definition acutest.h:1007
enum acutest_state_ state
Definition acutest.h:399
Here is the call graph for this function:
Here is the caller graph for this function:

◆ acutest_timer_diff_()

double acutest_timer_diff_ ( int start,
int end )
static

Definition at line 503 of file acutest.h.

503 {
504 (void)start;
505 (void)end;
506 return 0.0;
507}

◆ acutest_timer_get_time_()

void acutest_timer_get_time_ ( int * ts)
static

Definition at line 501 of file acutest.h.

501{ (void)ts; }

◆ acutest_timer_init_()

void acutest_timer_init_ ( void )

Definition at line 499 of file acutest.h.

499{}
Here is the caller graph for this function:

◆ acutest_timer_print_diff_()

void acutest_timer_print_diff_ ( void )
static

Definition at line 509 of file acutest.h.

509{}
Here is the caller graph for this function:

◆ acutest_under_debugger_()

int acutest_under_debugger_ ( void )
static

Definition at line 1744 of file acutest.h.

1744 {
1745# ifdef ACUTEST_LINUX_
1746 /* Scan /proc/self/status for line "TracerPid: [PID]". If such line exists
1747 * and the PID is non-zero, we're being debugged. */
1748 {
1749 static const int OVERLAP = 32;
1750 int fd;
1751 char buf[512];
1752 size_t n_read;
1753 pid_t tracer_pid = 0;
1754
1755 /* Little trick so that we can treat the 1st line the same as any other
1756 * and detect line start easily. */
1757 buf[0] = '\n';
1758 n_read = 1;
1759
1760 fd = open("/proc/self/status", O_RDONLY);
1761 if (fd != -1) {
1762 while (1) {
1763 static const char pattern[] = "\nTracerPid:";
1764 const char *field;
1765
1766 while (n_read < sizeof(buf) - 1) {
1767 ssize_t n;
1768
1769 n = read(fd, buf + n_read, sizeof(buf) - 1 - n_read);
1770 if (n <= 0) {
1771 break;
1772 }
1773 n_read += (size_t)n;
1774 }
1775 buf[n_read] = '\0';
1776
1777 field = strstr(buf, pattern);
1778 if (field != NULL && field < buf + sizeof(buf) - OVERLAP) {
1779 tracer_pid = (pid_t)atoi(field + sizeof(pattern) - 1);
1780 break;
1781 }
1782
1783 if (n_read == sizeof(buf) - 1) {
1784 /* Move the tail with the potentially incomplete line we're
1785 * be looking for to the beginning of the buffer.
1786 * (The OVERLAP must be large enough so the searched line
1787 * can fit in completely.) */
1788 memmove(buf, buf + sizeof(buf) - 1 - OVERLAP, OVERLAP);
1789 n_read = OVERLAP;
1790 } else {
1791 break;
1792 }
1793 }
1794
1795 close(fd);
1796
1797 if (tracer_pid != 0) {
1798 return 1;
1799 }
1800 }
1801 }
1802# endif
1803
1804# ifdef ACUTEST_MACOS_
1805 /* See https://developer.apple.com/library/archive/qa/qa1361/_index.html */
1806 {
1807 int mib[4];
1808 struct kinfo_proc info;
1809 size_t size;
1810
1811 mib[0] = CTL_KERN;
1812 mib[1] = KERN_PROC;
1813 mib[2] = KERN_PROC_PID;
1814 mib[3] = getpid();
1815
1816 size = sizeof(info);
1817 info.kp_proc.p_flag = 0;
1818 sysctl(mib, sizeof(mib) / sizeof(*mib), &info, &size, NULL, 0);
1819
1820 if (info.kp_proc.p_flag & P_TRACED) {
1821 return 1;
1822 }
1823 }
1824# endif
1825
1826# ifdef ACUTEST_WIN_
1827 if (IsDebuggerPresent()) {
1828 return 1;
1829 }
1830# endif
1831
1832# ifdef RUNNING_ON_VALGRIND
1833 /* We treat Valgrind as a debugger of sorts.
1834 * (Macro RUNNING_ON_VALGRIND is provided by <valgrind.h>, if available.) */
1835 if (RUNNING_ON_VALGRIND) {
1836 return 1;
1837 }
1838# endif
1839
1840 return 0;
1841}
Here is the caller graph for this function:

◆ if() [1/11]

if ( ! acutest_colorize_)

Definition at line 532 of file acutest.h.

532 {
533 return printf("%s", buffer);
534 }
static int const char char buffer[256]
Definition acutest.h:524

◆ if() [2/11]

if ( acutest_case_name_ [0])

Definition at line 850 of file acutest.h.

850 {
852 acutest_case_name_[0] = '\0';
853 }
static int acutest_case_already_logged_
Definition acutest.h:424

◆ if() [3/11]

Definition at line 884 of file acutest.h.

884 {
885 return;
886 }

◆ if() [4/11]

Definition at line 748 of file acutest.h.

748 {
749 acutest_check_(0, file, line, "Cannot skip, already performed some checks");
750 return;
751 }
int const char * file
Definition acutest.h:779
void int line
Definition acutest.h:732
Here is the call graph for this function:

◆ if() [5/11]

Definition at line 785 of file acutest.h.

785 {
786 /* We've skipped the test. We shouldn't be here: The test implementation
787 * should have already return before. So lets suppress the following
788 * output. */
789 cond = 1;
790 goto skip_check;
791 }

◆ if() [6/11]

if ( acutest_test_skip_reason_ [reason_len - 1] = = '.')

Definition at line 744 of file acutest.h.

744 {
746 }
static char acutest_test_skip_reason_[256]
Definition acutest.h:422
void int const char size_t reason_len
Definition acutest.h:735

◆ if() [7/11]

Definition at line 753 of file acutest.h.

753 {
754 const char *result_str = "skipped";
756
759 }
761
763
764 if (file != NULL) {
766 printf("%s:%d: ", file, line);
767 }
768
769 printf("%s... ", acutest_test_skip_reason_);
770 acutest_colored_printf_(result_color, "%s", result_str);
771 printf("\n");
773 }
static void acutest_finish_test_line_(enum acutest_state_ state)
Definition acutest.h:668
int const char int const char int result_color
Definition acutest.h:782
#define ACUTEST_COLOR_YELLOW_
Definition acutest.h:515
result_str
Definition acutest.h:805
static const char * acutest_basename_(const char *path)
Definition acutest.h:618
Here is the call graph for this function:

◆ if() [8/11]

if ( )

Definition at line 846 of file acutest.h.

846 {
847 return;
848 }

◆ if() [9/11]

if ( cond )

Definition at line 793 of file acutest.h.

793 {
794 result_str = "ok";
796 verbose_level = 3;
797 } else {
int verbose_level
Definition acutest.h:783
#define ACUTEST_COLOR_GREEN_
Definition acutest.h:514

◆ if() [10/11]

if ( fmt = = NULL)

Definition at line 855 of file acutest.h.

855 {
856 return;
857 }

◆ if() [11/11]

if ( line_beg ! [0] = '\0')

Definition at line 903 of file acutest.h.

903 {
905 printf("%s\n", line_beg);
906 }
Here is the call graph for this function:

◆ main()

int main ( int argc,
char ** argv )

Definition at line 1843 of file acutest.h.

1843 {
1844 int i, index;
1845 int exit_code = 1;
1846
1847 acutest_argv0_ = argv[0];
1848
1849# if defined ACUTEST_UNIX_
1850 acutest_colorize_ = isatty(STDOUT_FILENO);
1851# elif defined ACUTEST_WIN_
1852# if defined _BORLANDC_
1853 acutest_colorize_ = isatty(_fileno(stdout));
1854# else
1855 acutest_colorize_ = _isatty(_fileno(stdout));
1856# endif
1857# else
1859# endif
1860
1861 /* Count all test units */
1863 for (i = 0; acutest_list_[i].func != NULL; i++) {
1865 }
1866
1868 (struct acutest_test_data_ *)calloc(acutest_list_size_, sizeof(struct acutest_test_data_));
1869 if (acutest_test_data_ == NULL) {
1870 fprintf(stderr, "Out of memory.\n");
1871 acutest_exit_(2);
1872 }
1873
1874 /* Parse options */
1876
1877 /* Initialize the proper timer. */
1879
1880# if defined(ACUTEST_WIN_)
1881 SetUnhandledExceptionFilter(acutest_seh_exception_filter_);
1882# ifdef _MSC_VER
1883 _set_abort_behavior(0, _WRITE_ABORT_MSG);
1884# endif
1885# endif
1886
1887 /* Determine what to run. */
1889 enum acutest_state_ if_selected;
1890 enum acutest_state_ if_unselected;
1891
1892 if (!acutest_exclude_mode_) {
1893 if_selected = ACUTEST_STATE_NEEDTORUN;
1894 if_unselected = ACUTEST_STATE_EXCLUDED;
1895 } else {
1896 if_selected = ACUTEST_STATE_EXCLUDED;
1897 if_unselected = ACUTEST_STATE_NEEDTORUN;
1898 }
1899
1900 for (i = 0; acutest_list_[i].func != NULL; i++) {
1902 acutest_test_data_[i].state = if_selected;
1903 } else {
1904 acutest_test_data_[i].state = if_unselected;
1905 }
1906 }
1907 } else {
1908 /* By default, we want to run all tests. */
1909 for (i = 0; acutest_list_[i].func != NULL; i++) {
1911 }
1912 }
1913
1914 /* By default, we want to suppress running tests as child processes if we
1915 * run just one test, or if we're under debugger: Debugging tests is then
1916 * so much easier. */
1917 if (acutest_no_exec_ < 0) {
1919 acutest_no_exec_ = 1;
1920 } else {
1921 acutest_no_exec_ = 0;
1922 }
1923 }
1924
1925 if (acutest_tap_) {
1926 /* TAP requires we know test result ("ok", "not ok") before we output
1927 * anything about the test, and this gets problematic for larger verbose
1928 * levels. */
1929 if (acutest_verbose_level_ > 2) {
1931 }
1932
1933 /* TAP harness should provide some summary. */
1935
1936 if (!acutest_worker_) {
1937 printf("1..%d\n", acutest_count_(ACUTEST_STATE_NEEDTORUN));
1938 }
1939 }
1940
1941 index = acutest_worker_index_;
1942 for (i = 0; acutest_list_[i].func != NULL; i++) {
1944 acutest_run_(&acutest_list_[i], index++, i);
1945 }
1946 }
1947
1948 /* Write a summary */
1950 int n_run, n_success, n_failed;
1951
1955
1956 if (acutest_verbose_level_ >= 3) {
1957 acutest_colored_printf_(ACUTEST_COLOR_DEFAULT_INTENSIVE_, "Summary:\n");
1958
1959 printf(" Count of run unit tests: %4d\n", n_run);
1960 printf(" Count of successful unit tests: %4d\n", n_success);
1961 printf(" Count of failed unit tests: %4d\n", n_failed);
1962 }
1963
1964 if (n_failed == 0) {
1965 acutest_colored_printf_(ACUTEST_COLOR_GREEN_INTENSIVE_, "SUCCESS:");
1966 printf(" No unit tests have failed.\n");
1967 } else {
1968 acutest_colored_printf_(ACUTEST_COLOR_RED_INTENSIVE_, "FAILED:");
1969 printf(
1970 " %d of %d unit tests %s failed.\n", n_failed, n_run, (n_failed == 1) ? "has" : "have"
1971 );
1972 }
1973
1974 if (acutest_verbose_level_ >= 3) {
1975 printf("\n");
1976 }
1977 }
1978
1979 if (acutest_xml_output_) {
1980 const char *suite_name = acutest_basename_(argv[0]);
1981 fprintf(acutest_xml_output_, "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n");
1982 fprintf(
1984 "<testsuite name=\"%s\" tests=\"%d\" errors=\"0\" failures=\"%d\" "
1985 "skip=\"%d\">\n",
1988 );
1989 for (i = 0; acutest_list_[i].func != NULL; i++) {
1990 struct acutest_test_data_ *details = &acutest_test_data_[i];
1991 const char *str_state;
1992 fprintf(
1993 acutest_xml_output_, " <testcase name=\"%s\" time=\"%.2f\">\n", acutest_list_[i].name,
1994 details->duration
1995 );
1996
1997 switch (details->state) {
1999 str_state = NULL;
2000 break;
2001 case ACUTEST_STATE_EXCLUDED: /* Fall through. */
2003 str_state = "<skipped />";
2004 break;
2005 case ACUTEST_STATE_FAILED: /* Fall through. */
2006 default:
2007 str_state = "<failure />";
2008 break;
2009 }
2010
2011 if (str_state != NULL) {
2012 fprintf(acutest_xml_output_, " %s\n", str_state);
2013 }
2014 fprintf(acutest_xml_output_, " </testcase>\n");
2015 }
2016 fprintf(acutest_xml_output_, "</testsuite>\n");
2017 fclose(acutest_xml_output_);
2018 }
2019
2021 /* If we are the child process, we need to propagate the test state
2022 * without any moderation. */
2023 for (i = 0; acutest_list_[i].func != NULL; i++) {
2025 exit_code = (int)acutest_test_data_[i].state;
2026 break;
2027 }
2028 }
2029 } else {
2031 exit_code = 1;
2032 } else {
2033 exit_code = 0;
2034 }
2035 }
2036
2038 return exit_code;
2039}
static const ACUTEST_CMDLINE_OPTION_ acutest_cmdline_options_[]
Definition acutest.h:1593
acutest_state_
Definition acutest.h:301
static int acutest_cmdline_read_(const ACUTEST_CMDLINE_OPTION_ *options, int argc, char **argv, int(*callback)(int, const char *))
Definition acutest.h:1418
void acutest_timer_init_(void)
Definition acutest.h:499
static int acutest_under_debugger_(void)
Definition acutest.h:1744
static int acutest_count_(enum acutest_state_ state)
Definition acutest.h:433
static int acutest_cmdline_callback_(int id, const char *arg)
Definition acutest.h:1618
Here is the call graph for this function:

◆ va_end()

va_end ( args )

◆ va_start()

va_start ( args ,
fmt  )

◆ vsnprintf() [1/4]

vsnprintf ( acutest_case_name_ ,
sizeof(acutest_case_name_) - 1,
fmt ,
args  )

◆ vsnprintf() [2/4]

◆ vsnprintf() [3/4]

vsnprintf ( buffer ,
sizeof(buffer) ,
fmt ,
args  )

◆ vsnprintf() [4/4]

vsnprintf ( buffer ,
TEST_MSG_MAXSIZE ,
fmt ,
args  )

◆ while()

while ( 1 )

Definition at line 894 of file acutest.h.

894 {
895 line_end = strchr(line_beg, '\n');
896 if (line_end == NULL) {
897 break;
898 }
900 printf("%.*s\n", (int)(line_end - line_beg), line_beg);
901 line_beg = line_end + 1;
902 }
Here is the call graph for this function:

Variable Documentation

◆ !acutest_cond_failed_

Definition at line 840 of file acutest.h.

◆ __pad0__

skip_check __pad0__

Definition at line 838 of file acutest.h.

◆ acutest_abort_has_jmp_buf_

int acutest_abort_has_jmp_buf_ = 0
static

Definition at line 430 of file acutest.h.

◆ acutest_abort_jmp_buf_

jmp_buf acutest_abort_jmp_buf_
static

Definition at line 431 of file acutest.h.

◆ acutest_argv0_

char* acutest_argv0_ = NULL
static

Definition at line 405 of file acutest.h.

◆ acutest_case_already_logged_

int acutest_case_already_logged_ = 0
static

Definition at line 424 of file acutest.h.

◆ acutest_case_name_

acutest_case_name_[sizeof(acutest_case_name_) - 1] = ""
static

Definition at line 419 of file acutest.h.

◆ acutest_cmdline_options_

const ACUTEST_CMDLINE_OPTION_ acutest_cmdline_options_[]
static
Initial value:
= {
{'X', "exclude", 'X', 0},
{'s', "skip", 'X', 0},
{'E', "no-exec", 'E', 0},
{0, "no-summary", 'S', 0},
{0, "tap", 'T', 0},
{'l', "list", 'l', 0},
{'v', "verbose", 'v', ACUTEST_CMDLINE_OPTFLAG_OPTIONALARG_},
{'q', "quiet", 'q', 0},
{0, "no-color", 'C', 0},
{'h', "help", 'h', 0},
{'x', "xml-output", 'x', ACUTEST_CMDLINE_OPTFLAG_REQUIREDARG_},
{0, NULL, 0, 0}
}

Definition at line 1593 of file acutest.h.

1593 {
1594 {'X', "exclude", 'X', 0},
1595 {'s', "skip", 'X', 0}, /* kept for compatibility, use --exclude instead */
1596 {0, "exec", 'e', ACUTEST_CMDLINE_OPTFLAG_OPTIONALARG_},
1597 {'E', "no-exec", 'E', 0},
1598# if defined ACUTEST_WIN_
1599 {'t', "time", 't', 0},
1600 {0, "timer", 't', 0}, /* kept for compatibility */
1601# elif defined ACUTEST_HAS_POSIX_TIMER_
1602 {'t', "time", 't', ACUTEST_CMDLINE_OPTFLAG_OPTIONALARG_},
1603 {0, "timer", 't', ACUTEST_CMDLINE_OPTFLAG_OPTIONALARG_}, /* kept for compatibility */
1604# endif
1605 {0, "no-summary", 'S', 0},
1606 {0, "tap", 'T', 0},
1607 {'l', "list", 'l', 0},
1608 {'v', "verbose", 'v', ACUTEST_CMDLINE_OPTFLAG_OPTIONALARG_},
1609 {'q', "quiet", 'q', 0},
1610 {0, "color", 'c', ACUTEST_CMDLINE_OPTFLAG_OPTIONALARG_},
1611 {0, "no-color", 'C', 0},
1612 {'h', "help", 'h', 0},
1613 {0, "worker", 'w', ACUTEST_CMDLINE_OPTFLAG_REQUIREDARG_}, /* internal */
1614 {'x', "xml-output", 'x', ACUTEST_CMDLINE_OPTFLAG_REQUIREDARG_},
1615 {0, NULL, 0, 0}
1616};

◆ acutest_colorize_

int acutest_colorize_ = 0
static

Definition at line 427 of file acutest.h.

◆ acutest_cond_failed_

int acutest_cond_failed_ = 0
static

Definition at line 414 of file acutest.h.

◆ acutest_current_index_

int acutest_current_index_ = 0
static

Definition at line 418 of file acutest.h.

◆ acutest_current_test_

const struct acutest_test_* acutest_current_test_ = NULL
static

Definition at line 417 of file acutest.h.

◆ acutest_exclude_mode_

int acutest_exclude_mode_ = 0
static

Definition at line 411 of file acutest.h.

◆ acutest_list_

const struct acutest_test_ acutest_list_[]
extern

◆ acutest_list_size_

int acutest_list_size_ = 0
static

Definition at line 406 of file acutest.h.

◆ acutest_no_exec_

int acutest_no_exec_ = -1
static

Definition at line 408 of file acutest.h.

◆ acutest_no_summary_

int acutest_no_summary_ = 0
static

Definition at line 409 of file acutest.h.

◆ acutest_tap_

int acutest_tap_ = 0
static

Definition at line 410 of file acutest.h.

◆ acutest_test_already_logged_

acutest_test_already_logged_ = 0
static

Definition at line 423 of file acutest.h.

◆ acutest_test_check_count_

acutest_test_check_count_ = 0
static

Definition at line 420 of file acutest.h.

◆ acutest_test_data_

struct acutest_test_data_* acutest_test_data_ = NULL
static

Definition at line 407 of file acutest.h.

◆ acutest_test_failures_

int acutest_test_failures_ = 0
static

Definition at line 426 of file acutest.h.

◆ acutest_test_skip_count_

acutest_test_skip_count_ = 0
static

Definition at line 421 of file acutest.h.

◆ acutest_test_skip_reason_

acutest_test_skip_reason_[sizeof(acutest_test_skip_reason_) - 1] = ""
static

Definition at line 422 of file acutest.h.

◆ acutest_timer_

int acutest_timer_ = 0
static

Definition at line 428 of file acutest.h.

◆ acutest_timer_end_

acutest_timer_type_ acutest_timer_end_
static

Definition at line 497 of file acutest.h.

◆ acutest_timer_start_

acutest_timer_type_ acutest_timer_start_
static

Definition at line 496 of file acutest.h.

◆ acutest_verbose_level_

int acutest_verbose_level_ = 2
static

Definition at line 425 of file acutest.h.

◆ acutest_worker_

int acutest_worker_ = 0
static

Definition at line 412 of file acutest.h.

◆ acutest_worker_index_

int acutest_worker_index_ = 0
static

Definition at line 413 of file acutest.h.

◆ acutest_xml_output_

FILE* acutest_xml_output_ = NULL
static

Definition at line 415 of file acutest.h.

◆ args

va_list args

Definition at line 876 of file acutest.h.

◆ buffer

buffer[TEST_MSG_MAXSIZE - 1]
Initial value:
{
va_list args
va_list args
Definition acutest.h:876

Definition at line 524 of file acutest.h.

◆ else

else

◆ file

int const char* file

Definition at line 779 of file acutest.h.

◆ fmt

int const char int const char * fmt

Definition at line 522 of file acutest.h.

◆ line

int const char int line

Definition at line 732 of file acutest.h.

◆ line_beg

line_beg
Initial value:
{
#define TEST_MSG_MAXSIZE
Definition acutest.h:229

Definition at line 874 of file acutest.h.

◆ line_end

char* line_end

Definition at line 875 of file acutest.h.

◆ n

return n = printf("%s", buffer)

Definition at line 525 of file acutest.h.

◆ reason_len

reason_len
Initial value:
{
va_list args

Definition at line 735 of file acutest.h.

◆ result_color

result_color
Initial value:
{
const char *result_str

Definition at line 782 of file acutest.h.

◆ result_str

result_str = "failed"

Definition at line 805 of file acutest.h.

◆ verbose_level

verbose_level = 2

Definition at line 783 of file acutest.h.