git/t/unit-tests/clar/clar.c

/*
 * Copyright (c) Vicent Marti. All rights reserved.
 *
 * This file is part of clar, distributed under the ISC license.
 * For full terms see the included COPYING file.
 */

#define _BSD_SOURCE
#define _DARWIN_C_SOURCE
#define _DEFAULT_SOURCE

#include <errno.h>
#include <setjmp.h>
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <math.h>
#include <stdarg.h>
#include <wchar.h>
#include <time.h>
#include <inttypes.h>

/* required for sandboxing */
#include <sys/types.h>
#include <sys/stat.h>

#if defined(__UCLIBC__) && ! defined(__UCLIBC_HAS_WCHAR__)
	/*
	 * uClibc can optionally be built without wchar support, in which case
	 * the installed <wchar.h> is a stub that only defines the `whar_t`
	 * type but none of the functions typically declared by it.
	 */
#else
#define CLAR_HAVE_WCHAR
#endif

#ifdef _WIN32
#define WIN32_LEAN_AND_MEAN
#	include <windows.h>
#	include <io.h>
#	include <direct.h>

#define _MAIN_CC

#	ifndef stat
#define stat
		typedef struct _stat STAT_T;
#	else
		typedef struct stat STAT_T;
#	endif
#	ifndef mkdir
#define mkdir
#	endif
#	ifndef chdir
#define chdir
#	endif
#	ifndef access
#define access
#	endif
#	ifndef strdup
#define strdup
#	endif
#	ifndef strcasecmp
#define strcasecmp
#	endif

#	ifndef __MINGW32__
#		pragma comment(lib, "shell32")
#		ifndef strncpy
#define strncpy
#		endif
#		ifndef W_OK
#define W_OK
#		endif
#		ifndef S_ISDIR
#define S_ISDIR
#		endif
#define p_snprintf
#	else
#define p_snprintf
#	endif
#else
#	include <sys/wait.h> /* waitpid(2) */
#	include <unistd.h>
#define _MAIN_CC
#define p_snprintf
	STAT_T;
#endif

#define MAX(x, y)

#include "clar.h"

static void fs_rm(const char *_source);
static void fs_copy(const char *_source, const char *dest);

#ifdef CLAR_FIXTURE_PATH
static const char *
fixture_path(const char *base, const char *fixture_name);
#endif

struct clar_error {};

struct clar_explicit {};

struct clar_report {};

struct clar_summary {};

static struct {} _clar;

struct clar_func {};

struct clar_suite {};

/* From clar_print_*.c */
static void clar_print_init(int test_count, int suite_count, const char *suite_names);
static void clar_print_shutdown(int test_count, int suite_count, int error_count);
static void clar_print_error(int num, const struct clar_report *report, const struct clar_error *error);
static void clar_print_ontest(const char *suite_name, const char *test_name, int test_number, enum cl_test_status failed);
static void clar_print_onsuite(const char *suite_name, int suite_index);
static void clar_print_onabortv(const char *msg, va_list argp);
static void clar_print_onabort(const char *msg, ...);

/* From clar_sandbox.c */
static void clar_unsandbox(void);
static void clar_sandbox(void);

/* From summary.h */
static struct clar_summary *clar_summary_init(const char *filename);
static int clar_summary_shutdown(struct clar_summary *fp);

/* Load the declarations for the test suite */
#include "clar.suite"


#define CL_TRACE(ev)

static void clar_abort(const char *msg, ...)
{}

void cl_trace_register(cl_trace_cb *cb, void *payload)
{}


/* Core test functions */
static void
clar_report_errors(struct clar_report *report)
{}

static void
clar_report_all(void)
{}

#ifdef WIN32
#define clar_time

static void clar_time_now(clar_time *out)
{
	*out = GetTickCount();
}

static double clar_time_diff(clar_time *start, clar_time *end)
{
	return ((double)*end - (double)*start) / 1000;
}
#else
# include <sys/time.h>

#define clar_time

static void clar_time_now(clar_time *out)
{}

static double clar_time_diff(clar_time *start, clar_time *end)
{}
#endif

static void
clar_run_test(
	const struct clar_suite *suite,
	const struct clar_func *test,
	const struct clar_func *initialize,
	const struct clar_func *cleanup)
{}

static void
clar_run_suite(const struct clar_suite *suite, const char *filter)
{}

static void
clar_usage(const char *arg)
{}

static void
clar_parse_args(int argc, char **argv)
{}

void
clar_test_init(int argc, char **argv)
{}

int
clar_test_run(void)
{}

void
clar_test_shutdown(void)
{}

int
clar_test(int argc, char **argv)
{}

static void abort_test(void)
{}

void clar__skip(void)
{}

void clar__fail(
	const char *file,
	const char *function,
	size_t line,
	const char *error_msg,
	const char *description,
	int should_abort)
{}

void clar__assert(
	int condition,
	const char *file,
	const char *function,
	size_t line,
	const char *error_msg,
	const char *description,
	int should_abort)
{}

void clar__assert_equal(
	const char *file,
	const char *function,
	size_t line,
	const char *err,
	int should_abort,
	const char *fmt,
	...)
{}

void cl_set_cleanup(void (*cleanup)(void *), void *opaque)
{}

#include "clar/sandbox.h"
#include "clar/fixtures.h"
#include "clar/fs.h"
#include "clar/print.h"
#include "clar/summary.h"