Run formatting with additional rules.

pull/9/head
Joshua Potter 2023-11-24 19:35:22 -07:00
parent 07f9853481
commit a17d6eb3e3
15 changed files with 354 additions and 339 deletions

View File

@ -1,6 +1,8 @@
BasedOnStyle: LLVM
BasedOnStyle: Google
AlignAfterOpenBracket: BlockIndent
BinPackArguments: false
BinPackParameters: false
ColumnLimit: 80
ContinuationIndentWidth: 2
IndentCaseLabels: false
IndentWidth: 2

View File

@ -3,7 +3,7 @@ set -e
filesToFormat=$(
git --no-pager diff --name-status --no-color --cached | \
awk '$1 != "D" && $2 ~ /\.c|\.h/ {print $NF}'
awk '$1 != "D" && $2 ~ /\.c$|\.h$/ {print $NF}'
)
for path in $filesToFormat

View File

@ -27,7 +27,7 @@
extern "C" {
#endif
#if !defined(__WINDOWS__) && \
#if !defined(__WINDOWS__) && \
(defined(WIN32) || defined(WIN64) || defined(_MSC_VER) || defined(_WIN32))
#define __WINDOWS__
#endif
@ -62,7 +62,7 @@ CJSON_EXPORT_SYMBOLS does
/* export symbols by default, this is necessary for copy pasting the C and
* header file */
#if !defined(CJSON_HIDE_SYMBOLS) && !defined(CJSON_IMPORT_SYMBOLS) && \
#if !defined(CJSON_HIDE_SYMBOLS) && !defined(CJSON_IMPORT_SYMBOLS) && \
!defined(CJSON_EXPORT_SYMBOLS)
#define CJSON_EXPORT_SYMBOLS
#endif
@ -78,7 +78,7 @@ CJSON_EXPORT_SYMBOLS does
#define CJSON_CDECL
#define CJSON_STDCALL
#if (defined(__GNUC__) || defined(__SUNPRO_CC) || defined(__SUNPRO_C)) && \
#if (defined(__GNUC__) || defined(__SUNPRO_CC) || defined(__SUNPRO_C)) && \
defined(CJSON_API_VISIBILITY)
#define CJSON_PUBLIC(type) __attribute__((visibility("default"))) type
#else
@ -368,11 +368,11 @@ cJSON_AddArrayToObject(cJSON *const object, const char *const name);
/* When assigning an integer value, it needs to be propagated to valuedouble
* too. */
#define cJSON_SetIntValue(object, number) \
#define cJSON_SetIntValue(object, number) \
((object) ? (object)->valueint = (object)->valuedouble = (number) : (number))
/* helper for the cJSON_SetNumberValue macro */
CJSON_PUBLIC(double) cJSON_SetNumberHelper(cJSON *object, double number);
#define cJSON_SetNumberValue(object, number) \
#define cJSON_SetNumberValue(object, number) \
((object != NULL) ? cJSON_SetNumberHelper(object, (double)number) : (number))
/* Change the valuestring of a cJSON_String object, only takes effect when type
* of object is cJSON_String */
@ -381,15 +381,15 @@ cJSON_SetValuestring(cJSON *object, const char *valuestring);
/* If the object is not a boolean type this does nothing and returns
* cJSON_Invalid else it returns the new type*/
#define cJSON_SetBoolValue(object, boolValue) \
((object != NULL && ((object)->type & (cJSON_False | cJSON_True))) \
? (object)->type = ((object)->type & (~(cJSON_False | cJSON_True))) | \
((boolValue) ? cJSON_True : cJSON_False) \
#define cJSON_SetBoolValue(object, boolValue) \
((object != NULL && ((object)->type & (cJSON_False | cJSON_True))) \
? (object)->type = ((object)->type & (~(cJSON_False | cJSON_True))) | \
((boolValue) ? cJSON_True : cJSON_False) \
: cJSON_Invalid)
/* Macro for iterating over an array or object */
#define cJSON_ArrayForEach(element, array) \
for (element = (array != NULL) ? (array)->child : NULL; element != NULL; \
#define cJSON_ArrayForEach(element, array) \
for (element = (array != NULL) ? (array)->child : NULL; element != NULL; \
element = element->next)
/* malloc/free objects using the malloc/free functions that have been set with

View File

@ -19,7 +19,8 @@ cannot be found, the @parsed pointer is set to NULL with a success return code.
@return: 0 on success and a @SpecParseError otherwise.
*/
enum SpecParseError
parse_spec_json(const struct Config *const config, cJSON **parsed);
enum SpecParseError parse_spec_json(
const struct Config *const config, cJSON **parsed
);
#endif /* _BOOTSTRAP_PARSER_H */

View File

@ -24,7 +24,8 @@ enum SpecValidationError {
SVE_FIELD_PROMPT_INVALID,
};
enum SpecValidationError
validate_spec_json(const cJSON *const parsed, struct DynArray **fields);
enum SpecValidationError validate_spec_json(
const cJSON *const parsed, struct DynArray **fields
);
#endif /* _BOOTSTRAP_VALIDATOR_H */

View File

@ -114,7 +114,7 @@ CJSON_PUBLIC(double) cJSON_GetNumberValue(const cJSON *const item) {
/* This is a safeguard to prevent copy-pasters from using incompatible C and
* header files */
#if (CJSON_VERSION_MAJOR != 1) || (CJSON_VERSION_MINOR != 7) || \
#if (CJSON_VERSION_MAJOR != 1) || (CJSON_VERSION_MINOR != 7) || \
(CJSON_VERSION_PATCH != 16)
#error cJSON.h and cJSON.c have different versions. Make sure that both have the same.
#endif
@ -180,8 +180,9 @@ static void *CJSON_CDECL internal_realloc(void *pointer, size_t size) {
static internal_hooks global_hooks = {
internal_malloc, internal_free, internal_realloc};
static unsigned char *
cJSON_strdup(const unsigned char *string, const internal_hooks *const hooks) {
static unsigned char *cJSON_strdup(
const unsigned char *string, const internal_hooks *const hooks
) {
size_t length = 0;
unsigned char *copy = NULL;
@ -275,20 +276,21 @@ typedef struct {
/* check if the given size is left to read in a given parse buffer (starting
* with 1) */
#define can_read(buffer, size) \
#define can_read(buffer, size) \
((buffer != NULL) && (((buffer)->offset + size) <= (buffer)->length))
/* check if the buffer can be accessed at the given index (starting with 0) */
#define can_access_at_index(buffer, index) \
#define can_access_at_index(buffer, index) \
((buffer != NULL) && (((buffer)->offset + index) < (buffer)->length))
#define cannot_access_at_index(buffer, index) \
#define cannot_access_at_index(buffer, index) \
(!can_access_at_index(buffer, index))
/* get a pointer to the buffer at the position */
#define buffer_at_offset(buffer) ((buffer)->content + (buffer)->offset)
/* Parse the input text to generate a number, and populate the result into item.
*/
static cJSON_bool
parse_number(cJSON *const item, parse_buffer *const input_buffer) {
static cJSON_bool parse_number(
cJSON *const item, parse_buffer *const input_buffer
) {
double number = 0;
unsigned char *after_end = NULL;
unsigned char number_c_string[64];
@ -494,8 +496,9 @@ static cJSON_bool compare_double(double a, double b) {
}
/* Render the number nicely from the given item into a string. */
static cJSON_bool
print_number(const cJSON *const item, printbuffer *const output_buffer) {
static cJSON_bool print_number(
const cJSON *const item, printbuffer *const output_buffer
) {
unsigned char *output_pointer = NULL;
double d = item->valuedouble;
int length = 0;
@ -689,8 +692,9 @@ fail:
}
/* Parse the input text into an unescaped cinput, and populate item. */
static cJSON_bool
parse_string(cJSON *const item, parse_buffer *const input_buffer) {
static cJSON_bool parse_string(
cJSON *const item, parse_buffer *const input_buffer
) {
const unsigned char *input_pointer = buffer_at_offset(input_buffer) + 1;
const unsigned char *input_end = buffer_at_offset(input_buffer) + 1;
unsigned char *output_pointer = NULL;
@ -926,18 +930,24 @@ static cJSON_bool print_string(const cJSON *const item, printbuffer *const p) {
}
/* Predeclare these prototypes. */
static cJSON_bool
parse_value(cJSON *const item, parse_buffer *const input_buffer);
static cJSON_bool
print_value(const cJSON *const item, printbuffer *const output_buffer);
static cJSON_bool
parse_array(cJSON *const item, parse_buffer *const input_buffer);
static cJSON_bool
print_array(const cJSON *const item, printbuffer *const output_buffer);
static cJSON_bool
parse_object(cJSON *const item, parse_buffer *const input_buffer);
static cJSON_bool
print_object(const cJSON *const item, printbuffer *const output_buffer);
static cJSON_bool parse_value(
cJSON *const item, parse_buffer *const input_buffer
);
static cJSON_bool print_value(
const cJSON *const item, printbuffer *const output_buffer
);
static cJSON_bool parse_array(
cJSON *const item, parse_buffer *const input_buffer
);
static cJSON_bool print_array(
const cJSON *const item, printbuffer *const output_buffer
);
static cJSON_bool parse_object(
cJSON *const item, parse_buffer *const input_buffer
);
static cJSON_bool print_object(
const cJSON *const item, printbuffer *const output_buffer
);
/* Utility to jump whitespace and cr/lf */
static parse_buffer *buffer_skip_whitespace(parse_buffer *const buffer) {
@ -1199,8 +1209,9 @@ cJSON_PrintPreallocated(
}
/* Parser core - when encountering text, process appropriately. */
static cJSON_bool
parse_value(cJSON *const item, parse_buffer *const input_buffer) {
static cJSON_bool parse_value(
cJSON *const item, parse_buffer *const input_buffer
) {
if ((input_buffer == NULL) || (input_buffer->content == NULL)) {
return false; /* no input */
}
@ -1246,8 +1257,9 @@ parse_value(cJSON *const item, parse_buffer *const input_buffer) {
}
/* Render a value to text. */
static cJSON_bool
print_value(const cJSON *const item, printbuffer *const output_buffer) {
static cJSON_bool print_value(
const cJSON *const item, printbuffer *const output_buffer
) {
unsigned char *output = NULL;
if ((item == NULL) || (output_buffer == NULL)) {
@ -1312,8 +1324,9 @@ print_value(const cJSON *const item, printbuffer *const output_buffer) {
}
/* Build an array from input text. */
static cJSON_bool
parse_array(cJSON *const item, parse_buffer *const input_buffer) {
static cJSON_bool parse_array(
cJSON *const item, parse_buffer *const input_buffer
) {
cJSON *head = NULL; /* head of the linked list */
cJSON *current_item = NULL;
@ -1398,8 +1411,9 @@ fail:
}
/* Render an array to text */
static cJSON_bool
print_array(const cJSON *const item, printbuffer *const output_buffer) {
static cJSON_bool print_array(
const cJSON *const item, printbuffer *const output_buffer
) {
unsigned char *output_pointer = NULL;
size_t length = 0;
cJSON *current_element = item->child;
@ -1452,8 +1466,9 @@ print_array(const cJSON *const item, printbuffer *const output_buffer) {
}
/* Build an object from the text. */
static cJSON_bool
parse_object(cJSON *const item, parse_buffer *const input_buffer) {
static cJSON_bool parse_object(
cJSON *const item, parse_buffer *const input_buffer
) {
cJSON *head = NULL; /* linked list head */
cJSON *current_item = NULL;
@ -1551,8 +1566,9 @@ fail:
}
/* Render an object to text. */
static cJSON_bool
print_object(const cJSON *const item, printbuffer *const output_buffer) {
static cJSON_bool print_object(
const cJSON *const item, printbuffer *const output_buffer
) {
unsigned char *output_pointer = NULL;
size_t length = 0;
cJSON *current_item = item->child;
@ -1756,8 +1772,9 @@ static void suffix_object(cJSON *prev, cJSON *item) {
}
/* Utility for handling references. */
static cJSON *
create_reference(const cJSON *item, const internal_hooks *const hooks) {
static cJSON *create_reference(
const cJSON *item, const internal_hooks *const hooks
) {
cJSON *reference = NULL;
if (item == NULL) {
return NULL;
@ -1807,8 +1824,8 @@ CJSON_PUBLIC(cJSON_bool) cJSON_AddItemToArray(cJSON *array, cJSON *item) {
return add_item_to_array(array, item);
}
#if defined(__clang__) || \
(defined(__GNUC__) && \
#if defined(__clang__) || \
(defined(__GNUC__) && \
((__GNUC__ > 4) || ((__GNUC__ == 4) && (__GNUC_MINOR__ > 5))))
#pragma GCC diagnostic push
#endif
@ -1817,8 +1834,8 @@ CJSON_PUBLIC(cJSON_bool) cJSON_AddItemToArray(cJSON *array, cJSON *item) {
#endif
/* helper function to cast away const */
static void *cast_away_const(const void *string) { return (void *)string; }
#if defined(__clang__) || \
(defined(__GNUC__) && \
#if defined(__clang__) || \
(defined(__GNUC__) && \
((__GNUC__ > 4) || ((__GNUC__ == 4) && (__GNUC_MINOR__ > 5))))
#pragma GCC diagnostic pop
#endif

View File

@ -1,9 +1,10 @@
#include "config.h"
#include <errno.h>
#include <stdlib.h>
#include <string.h>
#include <sys/stat.h>
#include "config.h"
#include "path.h"
enum ConfigError config_load(
@ -22,7 +23,7 @@ enum ConfigError config_load(
return CE_TARGET_INVALID;
}
{ // Check if the specified directory exists.
{ // Check if the specified directory exists.
struct stat sb;
const char *segments[] = {root_dir, target};

View File

@ -1,7 +1,7 @@
#include <assert.h>
#include "dyn_array.h"
#include <assert.h>
struct DynArray *dyn_array_new(size_t capacity) {
struct DynArray *a = malloc(sizeof(struct DynArray));
size_t new_capacity = capacity ? capacity : 1;

View File

@ -1,7 +1,8 @@
#include "evaluator.h"
#include <errno.h>
#include <stdio.h>
#include "evaluator.h"
#include "path.h"
static int find_run_sh(const struct Config *const config, FILE **handle) {

View File

@ -1,9 +1,10 @@
#include "parser.h"
#include <assert.h>
#include <errno.h>
#include <stdbool.h>
#include <stdio.h>
#include "parser.h"
#include "path.h"
static int find_spec_json(const struct Config *const config, FILE **handle) {
@ -23,8 +24,9 @@ static int find_spec_json(const struct Config *const config, FILE **handle) {
return retval;
}
enum SpecParseError
parse_spec_json(const struct Config *const config, cJSON **parsed) {
enum SpecParseError parse_spec_json(
const struct Config *const config, cJSON **parsed
) {
FILE *handle = 0;
int retval = find_spec_json(config, &handle);

View File

@ -1,8 +1,8 @@
#include "path.h"
#include <assert.h>
#include <string.h>
#include "path.h"
char *join_path_segments(size_t n, const char *segments[static n]) {
assert(n > 0);
@ -10,7 +10,7 @@ char *join_path_segments(size_t n, const char *segments[static n]) {
for (int i = 0; i < n; ++i) {
length += strlen(segments[i]);
}
length += n - 1; // Path separators.
length += n - 1; // Path separators.
size_t offset = 0;
char *joined = calloc(1, length + 1);

View File

@ -1,9 +1,10 @@
#include <string.h>
#include "validator.h"
static enum SpecValidationError
read_field(const cJSON *const field, struct Field **out) {
#include <string.h>
static enum SpecValidationError read_field(
const cJSON *const field, struct Field **out
) {
if (!cJSON_IsObject(field)) {
return SVE_FIELD_NOT_OBJECT;
}
@ -40,8 +41,9 @@ cleanup:
return retval;
}
enum SpecValidationError
validate_spec_json(const cJSON *const parsed, struct DynArray **fields) {
enum SpecValidationError validate_spec_json(
const cJSON *const parsed, struct DynArray **fields
) {
*fields = 0;
if (!parsed) {

View File

@ -33,287 +33,268 @@
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#ifndef HAVE_SPUT_H
#define HAVE_SPUT_H
#ifdef __cplusplus
extern "C" {
#endif
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <time.h>
/* ===================================================================
* definitions
* =================================================================== */
/* ===================================================================
* definitions
* =================================================================== */
#define SPUT_VERSION_MAJOR 1
#define SPUT_VERSION_MINOR 4
#define SPUT_VERSION_PATCH 0
#define SPUT_VERSION_STRING "1.4.0"
#define SPUT_VERSION_MAJOR 1
#define SPUT_VERSION_MINOR 4
#define SPUT_VERSION_PATCH 0
#define SPUT_VERSION_STRING "1.4.0"
#define SPUT_DEFAULT_SUITE_NAME "Unlabeled Suite"
#define SPUT_DEFAULT_CHECK_NAME "Unlabeled Check"
#define SPUT_INITIALIZED 0x06 /* ACK */
#define SPUT_INITIALIZED 0x06 /* ACK */
/* ===================================================================
* sput global variable
* =================================================================== */
/* ===================================================================
* sput global variable
* =================================================================== */
static struct sput {
FILE *out;
char initialized;
static struct sput
{
FILE *out;
char initialized;
struct sput_overall {
unsigned long checks;
unsigned long suites;
unsigned long ok;
unsigned long nok;
} overall;
struct sput_overall
{
unsigned long checks;
unsigned long suites;
unsigned long ok;
unsigned long nok;
} overall;
struct sput_suite {
const char *name;
unsigned long nr;
unsigned long checks;
unsigned long ok;
unsigned long nok;
} suite;
struct sput_suite
{
const char *name;
unsigned long nr;
unsigned long checks;
unsigned long ok;
unsigned long nok;
} suite;
struct sput_test {
const char *name;
unsigned long nr;
} test;
struct sput_test
{
const char *name;
unsigned long nr;
} test;
struct sput_check {
const char *name;
const char *cond;
const char *type;
unsigned long line;
} check;
struct sput_check
{
const char *name;
const char *cond;
const char *type;
unsigned long line;
} check;
struct sput_time {
time_t start;
time_t end;
} time;
} __sput;
struct sput_time
{
time_t start;
time_t end;
} time;
} __sput;
/* ==================================================================
* sput internal macros
* ================================================================== */
#define _sput_die_unless_initialized() \
if (__sput.initialized != SPUT_INITIALIZED) { \
fputs("sput_start_testing() omitted\n", stderr); \
exit(EXIT_FAILURE); \
}
/* ==================================================================
* sput internal macros
* ================================================================== */
#define _sput_die_unless_suite_set() \
if (!__sput.suite.name) { \
fputs("sput_enter_suite() omitted\n", __sput.out); \
exit(EXIT_FAILURE); \
}
#define _sput_die_unless_initialized() \
if (__sput.initialized != SPUT_INITIALIZED) \
{ \
fputs("sput_start_testing() omitted\n", stderr); \
exit(EXIT_FAILURE); \
}
#define _sput_die_unless_test_set() \
if (!__sput.test.name) { \
fputs("sput_run_test() omitted\n", __sput.out); \
exit(EXIT_FAILURE); \
}
#define _sput_check_failed() \
{ \
_sput_die_unless_initialized(); \
_sput_die_unless_suite_set(); \
__sput.suite.nok++; \
fprintf( \
__sput.out, \
"[%lu:%lu] %s:#%lu \"%s\" FAIL\n" \
"! Type: %s\n" \
"! Condition: %s\n" \
"! Line: %lu\n", \
__sput.suite.nr, \
__sput.suite.checks, \
__sput.test.name, \
__sput.test.nr, \
__sput.check.name, \
__sput.check.type, \
__sput.check.cond, \
__sput.check.line \
); \
}
#define _sput_die_unless_suite_set() \
if (! __sput.suite.name) \
{ \
fputs("sput_enter_suite() omitted\n", __sput.out); \
exit(EXIT_FAILURE); \
}
#define _sput_check_succeeded() \
{ \
_sput_die_unless_initialized(); \
_sput_die_unless_suite_set(); \
__sput.suite.ok++; \
fprintf( \
__sput.out, \
"[%lu:%lu] %s:#%lu \"%s\" pass\n", \
__sput.suite.nr, \
__sput.suite.checks, \
__sput.test.name, \
__sput.test.nr, \
__sput.check.name \
); \
}
/* ==================================================================
* user macros
* ================================================================== */
#define _sput_die_unless_test_set() \
if (! __sput.test.name) \
{ \
fputs("sput_run_test() omitted\n", __sput.out); \
exit(EXIT_FAILURE); \
}
#define sput_start_testing() \
do { \
memset(&__sput, 0, sizeof(__sput)); \
__sput.out = stdout; \
__sput.time.start = time(NULL); \
__sput.initialized = SPUT_INITIALIZED; \
} while (0)
#define sput_leave_suite() \
do { \
float failpls = 0.0f; \
_sput_die_unless_initialized(); \
_sput_die_unless_suite_set(); \
failpls = __sput.suite.checks \
? (float)((__sput.suite.nok * 100.0) / __sput.suite.checks) \
: 0.0f; \
fprintf( \
__sput.out, \
"\n--> %lu check(s), %lu ok, %lu failed (%.2f%%)\n", \
__sput.suite.checks, \
__sput.suite.ok, \
__sput.suite.nok, \
failpls \
); \
__sput.overall.checks += __sput.suite.checks; \
__sput.overall.ok += __sput.suite.ok; \
__sput.overall.nok += __sput.suite.nok; \
memset(&__sput.suite, 0, sizeof(__sput.suite)); \
} while (0)
#define _sput_check_failed() \
{ \
_sput_die_unless_initialized(); \
_sput_die_unless_suite_set(); \
__sput.suite.nok++; \
fprintf(__sput.out, \
"[%lu:%lu] %s:#%lu \"%s\" FAIL\n" \
"! Type: %s\n" \
"! Condition: %s\n" \
"! Line: %lu\n", \
__sput.suite.nr, __sput.suite.checks, __sput.test.name, \
__sput.test.nr, __sput.check.name, __sput.check.type, \
__sput.check.cond, __sput.check.line); \
}
#define sput_get_return_value() \
(__sput.overall.nok > 0 ? EXIT_FAILURE : EXIT_SUCCESS)
#define sput_enter_suite(_name) \
do { \
_sput_die_unless_initialized(); \
if (__sput.suite.name) { \
sput_leave_suite(); \
} \
__sput.suite.name = _name != NULL ? _name : SPUT_DEFAULT_SUITE_NAME; \
__sput.suite.nr = ++__sput.overall.suites; \
fprintf( \
__sput.out, \
"\n== Entering suite #%lu, \"%s\" ==\n\n", \
__sput.suite.nr, \
__sput.suite.name \
); \
} while (0)
#define _sput_check_succeeded() \
{ \
_sput_die_unless_initialized(); \
_sput_die_unless_suite_set(); \
__sput.suite.ok++; \
fprintf(__sput.out, \
"[%lu:%lu] %s:#%lu \"%s\" pass\n", \
__sput.suite.nr, __sput.suite.checks, \
__sput.test.name, \
__sput.test.nr, \
__sput.check.name); \
}
#define sput_finish_testing() \
do { \
float failpft = 0.0f; \
_sput_die_unless_initialized(); \
if (__sput.suite.name) { \
sput_leave_suite(); \
} \
failpft = \
__sput.overall.checks \
? (float)((__sput.overall.nok * 100.0) / __sput.overall.checks) \
: 0.0f; \
__sput.time.end = time(NULL); \
fprintf( \
__sput.out, \
"\n==> %lu check(s) in %lu suite(s) finished after %.2f " \
"second(s),\n" \
" %lu succeeded, %lu failed (%.2f%%)\n" \
"\n[%s]\n", \
__sput.overall.checks, \
__sput.overall.suites, \
difftime(__sput.time.end, __sput.time.start), \
__sput.overall.ok, \
__sput.overall.nok, \
failpft, \
(sput_get_return_value() == EXIT_SUCCESS) ? "SUCCESS" : "FAILURE" \
); \
} while (0)
#define sput_set_output_stream(_fp) \
do { \
__sput.out = _fp != NULL ? _fp : stdout; \
} while (0)
/* ==================================================================
* user macros
* ================================================================== */
#define sput_fail_if(_cond, _name) \
do { \
_sput_die_unless_initialized(); \
_sput_die_unless_suite_set(); \
_sput_die_unless_test_set(); \
__sput.check.name = _name != NULL ? _name : SPUT_DEFAULT_CHECK_NAME; \
__sput.check.line = __LINE__; \
__sput.check.cond = #_cond; \
__sput.check.type = "fail-if"; \
__sput.test.nr++; \
__sput.suite.checks++; \
if ((_cond)) { \
_sput_check_failed(); \
} else { \
_sput_check_succeeded(); \
} \
} while (0)
#define sput_start_testing() \
do { \
memset(&__sput, 0, sizeof(__sput)); \
__sput.out = stdout; \
__sput.time.start = time(NULL); \
__sput.initialized = SPUT_INITIALIZED; \
} while (0)
#define sput_leave_suite() \
do { \
float failpls = 0.0f; \
_sput_die_unless_initialized(); \
_sput_die_unless_suite_set(); \
failpls = __sput.suite.checks ? (float) \
((__sput.suite.nok * 100.0) / __sput.suite.checks) : \
0.0f; \
fprintf(__sput.out, \
"\n--> %lu check(s), %lu ok, %lu failed (%.2f%%)\n", \
__sput.suite.checks, __sput.suite.ok, __sput.suite.nok, \
failpls); \
__sput.overall.checks += __sput.suite.checks; \
__sput.overall.ok += __sput.suite.ok; \
__sput.overall.nok += __sput.suite.nok; \
memset(&__sput.suite, 0, sizeof(__sput.suite)); \
} while (0)
#define sput_get_return_value() \
(__sput.overall.nok > 0 ? EXIT_FAILURE : EXIT_SUCCESS)
#define sput_enter_suite(_name) \
do { \
_sput_die_unless_initialized(); \
if (__sput.suite.name) \
{ \
sput_leave_suite(); \
} \
__sput.suite.name = _name != NULL ? \
_name : SPUT_DEFAULT_SUITE_NAME; \
__sput.suite.nr = ++__sput.overall.suites; \
fprintf(__sput.out, "\n== Entering suite #%lu, \"%s\" ==\n\n", \
__sput.suite.nr, __sput.suite.name); \
} while (0)
#define sput_finish_testing() \
do { \
float failpft = 0.0f; \
_sput_die_unless_initialized(); \
if (__sput.suite.name) \
{ \
sput_leave_suite(); \
} \
failpft = __sput.overall.checks ? (float) \
((__sput.overall.nok * 100.0) / __sput.overall.checks) : \
0.0f; \
__sput.time.end = time(NULL); \
fprintf(__sput.out, \
"\n==> %lu check(s) in %lu suite(s) finished after %.2f " \
"second(s),\n" \
" %lu succeeded, %lu failed (%.2f%%)\n" \
"\n[%s]\n", \
__sput.overall.checks, __sput.overall.suites, \
difftime(__sput.time.end, __sput.time.start), \
__sput.overall.ok, __sput.overall.nok, failpft, \
(sput_get_return_value() == EXIT_SUCCESS) ? \
"SUCCESS" : "FAILURE"); \
} while (0)
#define sput_set_output_stream(_fp) \
do { \
__sput.out = _fp != NULL ? _fp : stdout; \
} while (0)
#define sput_fail_if(_cond, _name) \
do { \
_sput_die_unless_initialized(); \
_sput_die_unless_suite_set(); \
_sput_die_unless_test_set(); \
__sput.check.name = _name != NULL ? \
_name : SPUT_DEFAULT_CHECK_NAME; \
__sput.check.line = __LINE__; \
__sput.check.cond = #_cond; \
__sput.check.type = "fail-if"; \
__sput.test.nr++; \
__sput.suite.checks++; \
if ((_cond)) \
{ \
_sput_check_failed(); \
} \
else \
{ \
_sput_check_succeeded(); \
} \
} while (0)
#define sput_fail_unless(_cond, _name) \
do { \
_sput_die_unless_initialized(); \
_sput_die_unless_suite_set(); \
_sput_die_unless_test_set(); \
__sput.check.name = _name != NULL ? \
_name : SPUT_DEFAULT_CHECK_NAME; \
__sput.check.line = __LINE__; \
__sput.check.cond = #_cond; \
__sput.check.type = "fail-unless"; \
__sput.test.nr++; \
__sput.suite.checks++; \
if (! (_cond)) \
{ \
_sput_check_failed(); \
} \
else \
{ \
_sput_check_succeeded(); \
} \
} while (0)
#define sput_run_test(_func) \
do { \
_sput_die_unless_initialized(); \
_sput_die_unless_suite_set(); \
memset(&__sput.test, 0, sizeof(__sput.test)); \
__sput.test.name = #_func; \
_func(); \
} while (0)
#define sput_fail_unless(_cond, _name) \
do { \
_sput_die_unless_initialized(); \
_sput_die_unless_suite_set(); \
_sput_die_unless_test_set(); \
__sput.check.name = _name != NULL ? _name : SPUT_DEFAULT_CHECK_NAME; \
__sput.check.line = __LINE__; \
__sput.check.cond = #_cond; \
__sput.check.type = "fail-unless"; \
__sput.test.nr++; \
__sput.suite.checks++; \
if (!(_cond)) { \
_sput_check_failed(); \
} else { \
_sput_check_succeeded(); \
} \
} while (0)
#define sput_run_test(_func) \
do { \
_sput_die_unless_initialized(); \
_sput_die_unless_suite_set(); \
memset(&__sput.test, 0, sizeof(__sput.test)); \
__sput.test.name = #_func; \
_func(); \
} while (0)
#ifdef __cplusplus
}
#endif
#endif /* HAVE_SPUT_H */
/* vim: set ft=c sts=4 sw=4 ts=4 ai et: */

View File

@ -6,14 +6,16 @@
static void test_join_path_single_segments() {
const char *segments[] = {"abc"};
char *joined = join_path_segments(sizeof(segments) / sizeof(char *), segments);
char *joined =
join_path_segments(sizeof(segments) / sizeof(char *), segments);
sput_fail_unless(strcmp(joined, "abc") == 0, "abc");
free(joined);
}
static void test_join_path_multiple_segments() {
const char *segments[] = {"abc", "def", "ghi"};
char *joined = join_path_segments(sizeof(segments) / sizeof(char *), segments);
char *joined =
join_path_segments(sizeof(segments) / sizeof(char *), segments);
sput_fail_unless(strcmp(joined, "abc/def/ghi") == 0, "abc/def/ghi");
free(joined);
}

View File

@ -49,11 +49,13 @@ static void test_validator_field_not_object() {
}
static void test_validator_field_type_invalid() {
struct TestValidatorFixture *fixture = test_validator_setup("{"
" \"key\": {"
" \"type\": 2"
" }"
"}");
struct TestValidatorFixture *fixture = test_validator_setup(
"{"
" \"key\": {"
" \"type\": 2"
" }"
"}"
);
enum SpecValidationError retval =
validate_spec_json(fixture->parsed, &fixture->prompts);
@ -63,12 +65,13 @@ static void test_validator_field_type_invalid() {
}
static void test_validator_field_type_unknown() {
struct TestValidatorFixture *fixture =
test_validator_setup("{"
" \"key\": {"
" \"type\": \"UNKNOWN\""
" }"
"}");
struct TestValidatorFixture *fixture = test_validator_setup(
"{"
" \"key\": {"
" \"type\": \"UNKNOWN\""
" }"
"}"
);
enum SpecValidationError retval =
validate_spec_json(fixture->parsed, &fixture->prompts);
@ -78,13 +81,14 @@ static void test_validator_field_type_unknown() {
}
static void test_validator_field_prompt_invalid() {
struct TestValidatorFixture *fixture =
test_validator_setup("{"
" \"key\": {"
" \"type\": \"STRING\","
" \"prompt\": 2"
" }"
"}");
struct TestValidatorFixture *fixture = test_validator_setup(
"{"
" \"key\": {"
" \"type\": \"STRING\","
" \"prompt\": 2"
" }"
"}"
);
enum SpecValidationError retval =
validate_spec_json(fixture->parsed, &fixture->prompts);
@ -94,13 +98,14 @@ static void test_validator_field_prompt_invalid() {
}
static void test_validator_valid() {
struct TestValidatorFixture *fixture =
test_validator_setup("{"
" \"key\": {"
" \"type\": \"STRING\","
" \"prompt\": \"What value for key?\""
" }"
"}");
struct TestValidatorFixture *fixture = test_validator_setup(
"{"
" \"key\": {"
" \"type\": \"STRING\","
" \"prompt\": \"What value for key?\""
" }"
"}"
);
enum SpecValidationError retval =
validate_spec_json(fixture->parsed, &fixture->prompts);