Run formatting with additional rules.
parent
07f9853481
commit
a17d6eb3e3
|
@ -1,6 +1,8 @@
|
||||||
BasedOnStyle: LLVM
|
BasedOnStyle: Google
|
||||||
AlignAfterOpenBracket: BlockIndent
|
AlignAfterOpenBracket: BlockIndent
|
||||||
BinPackArguments: false
|
BinPackArguments: false
|
||||||
BinPackParameters: false
|
BinPackParameters: false
|
||||||
|
ColumnLimit: 80
|
||||||
ContinuationIndentWidth: 2
|
ContinuationIndentWidth: 2
|
||||||
|
IndentCaseLabels: false
|
||||||
IndentWidth: 2
|
IndentWidth: 2
|
||||||
|
|
|
@ -3,7 +3,7 @@ set -e
|
||||||
|
|
||||||
filesToFormat=$(
|
filesToFormat=$(
|
||||||
git --no-pager diff --name-status --no-color --cached | \
|
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
|
for path in $filesToFormat
|
||||||
|
|
|
@ -27,7 +27,7 @@
|
||||||
extern "C" {
|
extern "C" {
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#if !defined(__WINDOWS__) && \
|
#if !defined(__WINDOWS__) && \
|
||||||
(defined(WIN32) || defined(WIN64) || defined(_MSC_VER) || defined(_WIN32))
|
(defined(WIN32) || defined(WIN64) || defined(_MSC_VER) || defined(_WIN32))
|
||||||
#define __WINDOWS__
|
#define __WINDOWS__
|
||||||
#endif
|
#endif
|
||||||
|
@ -62,7 +62,7 @@ CJSON_EXPORT_SYMBOLS does
|
||||||
|
|
||||||
/* export symbols by default, this is necessary for copy pasting the C and
|
/* export symbols by default, this is necessary for copy pasting the C and
|
||||||
* header file */
|
* header file */
|
||||||
#if !defined(CJSON_HIDE_SYMBOLS) && !defined(CJSON_IMPORT_SYMBOLS) && \
|
#if !defined(CJSON_HIDE_SYMBOLS) && !defined(CJSON_IMPORT_SYMBOLS) && \
|
||||||
!defined(CJSON_EXPORT_SYMBOLS)
|
!defined(CJSON_EXPORT_SYMBOLS)
|
||||||
#define CJSON_EXPORT_SYMBOLS
|
#define CJSON_EXPORT_SYMBOLS
|
||||||
#endif
|
#endif
|
||||||
|
@ -78,7 +78,7 @@ CJSON_EXPORT_SYMBOLS does
|
||||||
#define CJSON_CDECL
|
#define CJSON_CDECL
|
||||||
#define CJSON_STDCALL
|
#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)
|
defined(CJSON_API_VISIBILITY)
|
||||||
#define CJSON_PUBLIC(type) __attribute__((visibility("default"))) type
|
#define CJSON_PUBLIC(type) __attribute__((visibility("default"))) type
|
||||||
#else
|
#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
|
/* When assigning an integer value, it needs to be propagated to valuedouble
|
||||||
* too. */
|
* too. */
|
||||||
#define cJSON_SetIntValue(object, number) \
|
#define cJSON_SetIntValue(object, number) \
|
||||||
((object) ? (object)->valueint = (object)->valuedouble = (number) : (number))
|
((object) ? (object)->valueint = (object)->valuedouble = (number) : (number))
|
||||||
/* helper for the cJSON_SetNumberValue macro */
|
/* helper for the cJSON_SetNumberValue macro */
|
||||||
CJSON_PUBLIC(double) cJSON_SetNumberHelper(cJSON *object, double number);
|
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))
|
((object != NULL) ? cJSON_SetNumberHelper(object, (double)number) : (number))
|
||||||
/* Change the valuestring of a cJSON_String object, only takes effect when type
|
/* Change the valuestring of a cJSON_String object, only takes effect when type
|
||||||
* of object is cJSON_String */
|
* 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
|
/* If the object is not a boolean type this does nothing and returns
|
||||||
* cJSON_Invalid else it returns the new type*/
|
* cJSON_Invalid else it returns the new type*/
|
||||||
#define cJSON_SetBoolValue(object, boolValue) \
|
#define cJSON_SetBoolValue(object, boolValue) \
|
||||||
((object != NULL && ((object)->type & (cJSON_False | cJSON_True))) \
|
((object != NULL && ((object)->type & (cJSON_False | cJSON_True))) \
|
||||||
? (object)->type = ((object)->type & (~(cJSON_False | cJSON_True))) | \
|
? (object)->type = ((object)->type & (~(cJSON_False | cJSON_True))) | \
|
||||||
((boolValue) ? cJSON_True : cJSON_False) \
|
((boolValue) ? cJSON_True : cJSON_False) \
|
||||||
: cJSON_Invalid)
|
: cJSON_Invalid)
|
||||||
|
|
||||||
/* Macro for iterating over an array or object */
|
/* Macro for iterating over an array or object */
|
||||||
#define cJSON_ArrayForEach(element, array) \
|
#define cJSON_ArrayForEach(element, array) \
|
||||||
for (element = (array != NULL) ? (array)->child : NULL; element != NULL; \
|
for (element = (array != NULL) ? (array)->child : NULL; element != NULL; \
|
||||||
element = element->next)
|
element = element->next)
|
||||||
|
|
||||||
/* malloc/free objects using the malloc/free functions that have been set with
|
/* malloc/free objects using the malloc/free functions that have been set with
|
||||||
|
|
|
@ -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.
|
@return: 0 on success and a @SpecParseError otherwise.
|
||||||
*/
|
*/
|
||||||
enum SpecParseError
|
enum SpecParseError parse_spec_json(
|
||||||
parse_spec_json(const struct Config *const config, cJSON **parsed);
|
const struct Config *const config, cJSON **parsed
|
||||||
|
);
|
||||||
|
|
||||||
#endif /* _BOOTSTRAP_PARSER_H */
|
#endif /* _BOOTSTRAP_PARSER_H */
|
||||||
|
|
|
@ -24,7 +24,8 @@ enum SpecValidationError {
|
||||||
SVE_FIELD_PROMPT_INVALID,
|
SVE_FIELD_PROMPT_INVALID,
|
||||||
};
|
};
|
||||||
|
|
||||||
enum SpecValidationError
|
enum SpecValidationError validate_spec_json(
|
||||||
validate_spec_json(const cJSON *const parsed, struct DynArray **fields);
|
const cJSON *const parsed, struct DynArray **fields
|
||||||
|
);
|
||||||
|
|
||||||
#endif /* _BOOTSTRAP_VALIDATOR_H */
|
#endif /* _BOOTSTRAP_VALIDATOR_H */
|
||||||
|
|
101
src/cJSON.c
101
src/cJSON.c
|
@ -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
|
/* This is a safeguard to prevent copy-pasters from using incompatible C and
|
||||||
* header files */
|
* header files */
|
||||||
#if (CJSON_VERSION_MAJOR != 1) || (CJSON_VERSION_MINOR != 7) || \
|
#if (CJSON_VERSION_MAJOR != 1) || (CJSON_VERSION_MINOR != 7) || \
|
||||||
(CJSON_VERSION_PATCH != 16)
|
(CJSON_VERSION_PATCH != 16)
|
||||||
#error cJSON.h and cJSON.c have different versions. Make sure that both have the same.
|
#error cJSON.h and cJSON.c have different versions. Make sure that both have the same.
|
||||||
#endif
|
#endif
|
||||||
|
@ -180,8 +180,9 @@ static void *CJSON_CDECL internal_realloc(void *pointer, size_t size) {
|
||||||
static internal_hooks global_hooks = {
|
static internal_hooks global_hooks = {
|
||||||
internal_malloc, internal_free, internal_realloc};
|
internal_malloc, internal_free, internal_realloc};
|
||||||
|
|
||||||
static unsigned char *
|
static unsigned char *cJSON_strdup(
|
||||||
cJSON_strdup(const unsigned char *string, const internal_hooks *const hooks) {
|
const unsigned char *string, const internal_hooks *const hooks
|
||||||
|
) {
|
||||||
size_t length = 0;
|
size_t length = 0;
|
||||||
unsigned char *copy = NULL;
|
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
|
/* check if the given size is left to read in a given parse buffer (starting
|
||||||
* with 1) */
|
* with 1) */
|
||||||
#define can_read(buffer, size) \
|
#define can_read(buffer, size) \
|
||||||
((buffer != NULL) && (((buffer)->offset + size) <= (buffer)->length))
|
((buffer != NULL) && (((buffer)->offset + size) <= (buffer)->length))
|
||||||
/* check if the buffer can be accessed at the given index (starting with 0) */
|
/* 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))
|
((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))
|
(!can_access_at_index(buffer, index))
|
||||||
/* get a pointer to the buffer at the position */
|
/* get a pointer to the buffer at the position */
|
||||||
#define buffer_at_offset(buffer) ((buffer)->content + (buffer)->offset)
|
#define buffer_at_offset(buffer) ((buffer)->content + (buffer)->offset)
|
||||||
|
|
||||||
/* Parse the input text to generate a number, and populate the result into item.
|
/* Parse the input text to generate a number, and populate the result into item.
|
||||||
*/
|
*/
|
||||||
static cJSON_bool
|
static cJSON_bool parse_number(
|
||||||
parse_number(cJSON *const item, parse_buffer *const input_buffer) {
|
cJSON *const item, parse_buffer *const input_buffer
|
||||||
|
) {
|
||||||
double number = 0;
|
double number = 0;
|
||||||
unsigned char *after_end = NULL;
|
unsigned char *after_end = NULL;
|
||||||
unsigned char number_c_string[64];
|
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. */
|
/* Render the number nicely from the given item into a string. */
|
||||||
static cJSON_bool
|
static cJSON_bool print_number(
|
||||||
print_number(const cJSON *const item, printbuffer *const output_buffer) {
|
const cJSON *const item, printbuffer *const output_buffer
|
||||||
|
) {
|
||||||
unsigned char *output_pointer = NULL;
|
unsigned char *output_pointer = NULL;
|
||||||
double d = item->valuedouble;
|
double d = item->valuedouble;
|
||||||
int length = 0;
|
int length = 0;
|
||||||
|
@ -689,8 +692,9 @@ fail:
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Parse the input text into an unescaped cinput, and populate item. */
|
/* Parse the input text into an unescaped cinput, and populate item. */
|
||||||
static cJSON_bool
|
static cJSON_bool parse_string(
|
||||||
parse_string(cJSON *const item, parse_buffer *const input_buffer) {
|
cJSON *const item, parse_buffer *const input_buffer
|
||||||
|
) {
|
||||||
const unsigned char *input_pointer = buffer_at_offset(input_buffer) + 1;
|
const unsigned char *input_pointer = buffer_at_offset(input_buffer) + 1;
|
||||||
const unsigned char *input_end = buffer_at_offset(input_buffer) + 1;
|
const unsigned char *input_end = buffer_at_offset(input_buffer) + 1;
|
||||||
unsigned char *output_pointer = NULL;
|
unsigned char *output_pointer = NULL;
|
||||||
|
@ -926,18 +930,24 @@ static cJSON_bool print_string(const cJSON *const item, printbuffer *const p) {
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Predeclare these prototypes. */
|
/* Predeclare these prototypes. */
|
||||||
static cJSON_bool
|
static cJSON_bool parse_value(
|
||||||
parse_value(cJSON *const item, parse_buffer *const input_buffer);
|
cJSON *const item, parse_buffer *const input_buffer
|
||||||
static cJSON_bool
|
);
|
||||||
print_value(const cJSON *const item, printbuffer *const output_buffer);
|
static cJSON_bool print_value(
|
||||||
static cJSON_bool
|
const cJSON *const item, printbuffer *const output_buffer
|
||||||
parse_array(cJSON *const item, parse_buffer *const input_buffer);
|
);
|
||||||
static cJSON_bool
|
static cJSON_bool parse_array(
|
||||||
print_array(const cJSON *const item, printbuffer *const output_buffer);
|
cJSON *const item, parse_buffer *const input_buffer
|
||||||
static cJSON_bool
|
);
|
||||||
parse_object(cJSON *const item, parse_buffer *const input_buffer);
|
static cJSON_bool print_array(
|
||||||
static cJSON_bool
|
const cJSON *const item, printbuffer *const output_buffer
|
||||||
print_object(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 */
|
/* Utility to jump whitespace and cr/lf */
|
||||||
static parse_buffer *buffer_skip_whitespace(parse_buffer *const buffer) {
|
static parse_buffer *buffer_skip_whitespace(parse_buffer *const buffer) {
|
||||||
|
@ -1199,8 +1209,9 @@ cJSON_PrintPreallocated(
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Parser core - when encountering text, process appropriately. */
|
/* Parser core - when encountering text, process appropriately. */
|
||||||
static cJSON_bool
|
static cJSON_bool parse_value(
|
||||||
parse_value(cJSON *const item, parse_buffer *const input_buffer) {
|
cJSON *const item, parse_buffer *const input_buffer
|
||||||
|
) {
|
||||||
if ((input_buffer == NULL) || (input_buffer->content == NULL)) {
|
if ((input_buffer == NULL) || (input_buffer->content == NULL)) {
|
||||||
return false; /* no input */
|
return false; /* no input */
|
||||||
}
|
}
|
||||||
|
@ -1246,8 +1257,9 @@ parse_value(cJSON *const item, parse_buffer *const input_buffer) {
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Render a value to text. */
|
/* Render a value to text. */
|
||||||
static cJSON_bool
|
static cJSON_bool print_value(
|
||||||
print_value(const cJSON *const item, printbuffer *const output_buffer) {
|
const cJSON *const item, printbuffer *const output_buffer
|
||||||
|
) {
|
||||||
unsigned char *output = NULL;
|
unsigned char *output = NULL;
|
||||||
|
|
||||||
if ((item == NULL) || (output_buffer == 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. */
|
/* Build an array from input text. */
|
||||||
static cJSON_bool
|
static cJSON_bool parse_array(
|
||||||
parse_array(cJSON *const item, parse_buffer *const input_buffer) {
|
cJSON *const item, parse_buffer *const input_buffer
|
||||||
|
) {
|
||||||
cJSON *head = NULL; /* head of the linked list */
|
cJSON *head = NULL; /* head of the linked list */
|
||||||
cJSON *current_item = NULL;
|
cJSON *current_item = NULL;
|
||||||
|
|
||||||
|
@ -1398,8 +1411,9 @@ fail:
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Render an array to text */
|
/* Render an array to text */
|
||||||
static cJSON_bool
|
static cJSON_bool print_array(
|
||||||
print_array(const cJSON *const item, printbuffer *const output_buffer) {
|
const cJSON *const item, printbuffer *const output_buffer
|
||||||
|
) {
|
||||||
unsigned char *output_pointer = NULL;
|
unsigned char *output_pointer = NULL;
|
||||||
size_t length = 0;
|
size_t length = 0;
|
||||||
cJSON *current_element = item->child;
|
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. */
|
/* Build an object from the text. */
|
||||||
static cJSON_bool
|
static cJSON_bool parse_object(
|
||||||
parse_object(cJSON *const item, parse_buffer *const input_buffer) {
|
cJSON *const item, parse_buffer *const input_buffer
|
||||||
|
) {
|
||||||
cJSON *head = NULL; /* linked list head */
|
cJSON *head = NULL; /* linked list head */
|
||||||
cJSON *current_item = NULL;
|
cJSON *current_item = NULL;
|
||||||
|
|
||||||
|
@ -1551,8 +1566,9 @@ fail:
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Render an object to text. */
|
/* Render an object to text. */
|
||||||
static cJSON_bool
|
static cJSON_bool print_object(
|
||||||
print_object(const cJSON *const item, printbuffer *const output_buffer) {
|
const cJSON *const item, printbuffer *const output_buffer
|
||||||
|
) {
|
||||||
unsigned char *output_pointer = NULL;
|
unsigned char *output_pointer = NULL;
|
||||||
size_t length = 0;
|
size_t length = 0;
|
||||||
cJSON *current_item = item->child;
|
cJSON *current_item = item->child;
|
||||||
|
@ -1756,8 +1772,9 @@ static void suffix_object(cJSON *prev, cJSON *item) {
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Utility for handling references. */
|
/* Utility for handling references. */
|
||||||
static cJSON *
|
static cJSON *create_reference(
|
||||||
create_reference(const cJSON *item, const internal_hooks *const hooks) {
|
const cJSON *item, const internal_hooks *const hooks
|
||||||
|
) {
|
||||||
cJSON *reference = NULL;
|
cJSON *reference = NULL;
|
||||||
if (item == NULL) {
|
if (item == NULL) {
|
||||||
return NULL;
|
return NULL;
|
||||||
|
@ -1807,8 +1824,8 @@ CJSON_PUBLIC(cJSON_bool) cJSON_AddItemToArray(cJSON *array, cJSON *item) {
|
||||||
return add_item_to_array(array, item);
|
return add_item_to_array(array, item);
|
||||||
}
|
}
|
||||||
|
|
||||||
#if defined(__clang__) || \
|
#if defined(__clang__) || \
|
||||||
(defined(__GNUC__) && \
|
(defined(__GNUC__) && \
|
||||||
((__GNUC__ > 4) || ((__GNUC__ == 4) && (__GNUC_MINOR__ > 5))))
|
((__GNUC__ > 4) || ((__GNUC__ == 4) && (__GNUC_MINOR__ > 5))))
|
||||||
#pragma GCC diagnostic push
|
#pragma GCC diagnostic push
|
||||||
#endif
|
#endif
|
||||||
|
@ -1817,8 +1834,8 @@ CJSON_PUBLIC(cJSON_bool) cJSON_AddItemToArray(cJSON *array, cJSON *item) {
|
||||||
#endif
|
#endif
|
||||||
/* helper function to cast away const */
|
/* helper function to cast away const */
|
||||||
static void *cast_away_const(const void *string) { return (void *)string; }
|
static void *cast_away_const(const void *string) { return (void *)string; }
|
||||||
#if defined(__clang__) || \
|
#if defined(__clang__) || \
|
||||||
(defined(__GNUC__) && \
|
(defined(__GNUC__) && \
|
||||||
((__GNUC__ > 4) || ((__GNUC__ == 4) && (__GNUC_MINOR__ > 5))))
|
((__GNUC__ > 4) || ((__GNUC__ == 4) && (__GNUC_MINOR__ > 5))))
|
||||||
#pragma GCC diagnostic pop
|
#pragma GCC diagnostic pop
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -1,9 +1,10 @@
|
||||||
|
#include "config.h"
|
||||||
|
|
||||||
#include <errno.h>
|
#include <errno.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include <sys/stat.h>
|
#include <sys/stat.h>
|
||||||
|
|
||||||
#include "config.h"
|
|
||||||
#include "path.h"
|
#include "path.h"
|
||||||
|
|
||||||
enum ConfigError config_load(
|
enum ConfigError config_load(
|
||||||
|
@ -22,7 +23,7 @@ enum ConfigError config_load(
|
||||||
return CE_TARGET_INVALID;
|
return CE_TARGET_INVALID;
|
||||||
}
|
}
|
||||||
|
|
||||||
{ // Check if the specified directory exists.
|
{ // Check if the specified directory exists.
|
||||||
struct stat sb;
|
struct stat sb;
|
||||||
|
|
||||||
const char *segments[] = {root_dir, target};
|
const char *segments[] = {root_dir, target};
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
#include <assert.h>
|
|
||||||
|
|
||||||
#include "dyn_array.h"
|
#include "dyn_array.h"
|
||||||
|
|
||||||
|
#include <assert.h>
|
||||||
|
|
||||||
struct DynArray *dyn_array_new(size_t capacity) {
|
struct DynArray *dyn_array_new(size_t capacity) {
|
||||||
struct DynArray *a = malloc(sizeof(struct DynArray));
|
struct DynArray *a = malloc(sizeof(struct DynArray));
|
||||||
size_t new_capacity = capacity ? capacity : 1;
|
size_t new_capacity = capacity ? capacity : 1;
|
||||||
|
|
|
@ -1,7 +1,8 @@
|
||||||
|
#include "evaluator.h"
|
||||||
|
|
||||||
#include <errno.h>
|
#include <errno.h>
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
|
|
||||||
#include "evaluator.h"
|
|
||||||
#include "path.h"
|
#include "path.h"
|
||||||
|
|
||||||
static int find_run_sh(const struct Config *const config, FILE **handle) {
|
static int find_run_sh(const struct Config *const config, FILE **handle) {
|
||||||
|
|
|
@ -1,9 +1,10 @@
|
||||||
|
#include "parser.h"
|
||||||
|
|
||||||
#include <assert.h>
|
#include <assert.h>
|
||||||
#include <errno.h>
|
#include <errno.h>
|
||||||
#include <stdbool.h>
|
#include <stdbool.h>
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
|
|
||||||
#include "parser.h"
|
|
||||||
#include "path.h"
|
#include "path.h"
|
||||||
|
|
||||||
static int find_spec_json(const struct Config *const config, FILE **handle) {
|
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;
|
return retval;
|
||||||
}
|
}
|
||||||
|
|
||||||
enum SpecParseError
|
enum SpecParseError parse_spec_json(
|
||||||
parse_spec_json(const struct Config *const config, cJSON **parsed) {
|
const struct Config *const config, cJSON **parsed
|
||||||
|
) {
|
||||||
FILE *handle = 0;
|
FILE *handle = 0;
|
||||||
int retval = find_spec_json(config, &handle);
|
int retval = find_spec_json(config, &handle);
|
||||||
|
|
||||||
|
|
|
@ -1,8 +1,8 @@
|
||||||
|
#include "path.h"
|
||||||
|
|
||||||
#include <assert.h>
|
#include <assert.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
|
||||||
#include "path.h"
|
|
||||||
|
|
||||||
char *join_path_segments(size_t n, const char *segments[static n]) {
|
char *join_path_segments(size_t n, const char *segments[static n]) {
|
||||||
assert(n > 0);
|
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) {
|
for (int i = 0; i < n; ++i) {
|
||||||
length += strlen(segments[i]);
|
length += strlen(segments[i]);
|
||||||
}
|
}
|
||||||
length += n - 1; // Path separators.
|
length += n - 1; // Path separators.
|
||||||
|
|
||||||
size_t offset = 0;
|
size_t offset = 0;
|
||||||
char *joined = calloc(1, length + 1);
|
char *joined = calloc(1, length + 1);
|
||||||
|
|
|
@ -1,9 +1,10 @@
|
||||||
#include <string.h>
|
|
||||||
|
|
||||||
#include "validator.h"
|
#include "validator.h"
|
||||||
|
|
||||||
static enum SpecValidationError
|
#include <string.h>
|
||||||
read_field(const cJSON *const field, struct Field **out) {
|
|
||||||
|
static enum SpecValidationError read_field(
|
||||||
|
const cJSON *const field, struct Field **out
|
||||||
|
) {
|
||||||
if (!cJSON_IsObject(field)) {
|
if (!cJSON_IsObject(field)) {
|
||||||
return SVE_FIELD_NOT_OBJECT;
|
return SVE_FIELD_NOT_OBJECT;
|
||||||
}
|
}
|
||||||
|
@ -40,8 +41,9 @@ cleanup:
|
||||||
return retval;
|
return retval;
|
||||||
}
|
}
|
||||||
|
|
||||||
enum SpecValidationError
|
enum SpecValidationError validate_spec_json(
|
||||||
validate_spec_json(const cJSON *const parsed, struct DynArray **fields) {
|
const cJSON *const parsed, struct DynArray **fields
|
||||||
|
) {
|
||||||
*fields = 0;
|
*fields = 0;
|
||||||
|
|
||||||
if (!parsed) {
|
if (!parsed) {
|
||||||
|
|
453
test/sput.h
453
test/sput.h
|
@ -33,287 +33,268 @@
|
||||||
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
|
||||||
#ifndef HAVE_SPUT_H
|
#ifndef HAVE_SPUT_H
|
||||||
#define HAVE_SPUT_H
|
#define HAVE_SPUT_H
|
||||||
|
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
extern "C" {
|
extern "C" {
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include <time.h>
|
#include <time.h>
|
||||||
|
|
||||||
|
/* ===================================================================
|
||||||
|
* definitions
|
||||||
|
* =================================================================== */
|
||||||
|
|
||||||
/* ===================================================================
|
#define SPUT_VERSION_MAJOR 1
|
||||||
* definitions
|
#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_SUITE_NAME "Unlabeled Suite"
|
||||||
#define SPUT_DEFAULT_CHECK_NAME "Unlabeled Check"
|
#define SPUT_DEFAULT_CHECK_NAME "Unlabeled Check"
|
||||||
|
|
||||||
#define SPUT_INITIALIZED 0x06 /* ACK */
|
#define SPUT_INITIALIZED 0x06 /* ACK */
|
||||||
|
|
||||||
|
/* ===================================================================
|
||||||
|
* sput global variable
|
||||||
|
* =================================================================== */
|
||||||
|
|
||||||
/* ===================================================================
|
static struct sput {
|
||||||
* sput global variable
|
FILE *out;
|
||||||
* =================================================================== */
|
char initialized;
|
||||||
|
|
||||||
static struct sput
|
struct sput_overall {
|
||||||
{
|
unsigned long checks;
|
||||||
FILE *out;
|
unsigned long suites;
|
||||||
char initialized;
|
unsigned long ok;
|
||||||
|
unsigned long nok;
|
||||||
|
} overall;
|
||||||
|
|
||||||
struct sput_overall
|
struct sput_suite {
|
||||||
{
|
const char *name;
|
||||||
unsigned long checks;
|
unsigned long nr;
|
||||||
unsigned long suites;
|
unsigned long checks;
|
||||||
unsigned long ok;
|
unsigned long ok;
|
||||||
unsigned long nok;
|
unsigned long nok;
|
||||||
} overall;
|
} suite;
|
||||||
|
|
||||||
struct sput_suite
|
struct sput_test {
|
||||||
{
|
const char *name;
|
||||||
const char *name;
|
unsigned long nr;
|
||||||
unsigned long nr;
|
} test;
|
||||||
unsigned long checks;
|
|
||||||
unsigned long ok;
|
|
||||||
unsigned long nok;
|
|
||||||
} suite;
|
|
||||||
|
|
||||||
struct sput_test
|
struct sput_check {
|
||||||
{
|
const char *name;
|
||||||
const char *name;
|
const char *cond;
|
||||||
unsigned long nr;
|
const char *type;
|
||||||
} test;
|
unsigned long line;
|
||||||
|
} check;
|
||||||
|
|
||||||
struct sput_check
|
struct sput_time {
|
||||||
{
|
time_t start;
|
||||||
const char *name;
|
time_t end;
|
||||||
const char *cond;
|
} time;
|
||||||
const char *type;
|
} __sput;
|
||||||
unsigned long line;
|
|
||||||
} check;
|
|
||||||
|
|
||||||
struct sput_time
|
/* ==================================================================
|
||||||
{
|
* sput internal macros
|
||||||
time_t start;
|
* ================================================================== */
|
||||||
time_t end;
|
|
||||||
} time;
|
|
||||||
} __sput;
|
|
||||||
|
|
||||||
|
#define _sput_die_unless_initialized() \
|
||||||
|
if (__sput.initialized != SPUT_INITIALIZED) { \
|
||||||
|
fputs("sput_start_testing() omitted\n", stderr); \
|
||||||
|
exit(EXIT_FAILURE); \
|
||||||
|
}
|
||||||
|
|
||||||
/* ==================================================================
|
#define _sput_die_unless_suite_set() \
|
||||||
* sput internal macros
|
if (!__sput.suite.name) { \
|
||||||
* ================================================================== */
|
fputs("sput_enter_suite() omitted\n", __sput.out); \
|
||||||
|
exit(EXIT_FAILURE); \
|
||||||
|
}
|
||||||
|
|
||||||
#define _sput_die_unless_initialized() \
|
#define _sput_die_unless_test_set() \
|
||||||
if (__sput.initialized != SPUT_INITIALIZED) \
|
if (!__sput.test.name) { \
|
||||||
{ \
|
fputs("sput_run_test() omitted\n", __sput.out); \
|
||||||
fputs("sput_start_testing() omitted\n", stderr); \
|
exit(EXIT_FAILURE); \
|
||||||
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() \
|
#define _sput_check_succeeded() \
|
||||||
if (! __sput.suite.name) \
|
{ \
|
||||||
{ \
|
_sput_die_unless_initialized(); \
|
||||||
fputs("sput_enter_suite() omitted\n", __sput.out); \
|
_sput_die_unless_suite_set(); \
|
||||||
exit(EXIT_FAILURE); \
|
__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() \
|
#define sput_start_testing() \
|
||||||
if (! __sput.test.name) \
|
do { \
|
||||||
{ \
|
memset(&__sput, 0, sizeof(__sput)); \
|
||||||
fputs("sput_run_test() omitted\n", __sput.out); \
|
__sput.out = stdout; \
|
||||||
exit(EXIT_FAILURE); \
|
__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() \
|
#define sput_get_return_value() \
|
||||||
{ \
|
(__sput.overall.nok > 0 ? EXIT_FAILURE : EXIT_SUCCESS)
|
||||||
_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_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() \
|
#define sput_finish_testing() \
|
||||||
{ \
|
do { \
|
||||||
_sput_die_unless_initialized(); \
|
float failpft = 0.0f; \
|
||||||
_sput_die_unless_suite_set(); \
|
_sput_die_unless_initialized(); \
|
||||||
__sput.suite.ok++; \
|
if (__sput.suite.name) { \
|
||||||
fprintf(__sput.out, \
|
sput_leave_suite(); \
|
||||||
"[%lu:%lu] %s:#%lu \"%s\" pass\n", \
|
} \
|
||||||
__sput.suite.nr, __sput.suite.checks, \
|
failpft = \
|
||||||
__sput.test.name, \
|
__sput.overall.checks \
|
||||||
__sput.test.nr, \
|
? (float)((__sput.overall.nok * 100.0) / __sput.overall.checks) \
|
||||||
__sput.check.name); \
|
: 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) \
|
||||||
* user macros
|
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() \
|
#define sput_fail_unless(_cond, _name) \
|
||||||
do { \
|
do { \
|
||||||
memset(&__sput, 0, sizeof(__sput)); \
|
_sput_die_unless_initialized(); \
|
||||||
__sput.out = stdout; \
|
_sput_die_unless_suite_set(); \
|
||||||
__sput.time.start = time(NULL); \
|
_sput_die_unless_test_set(); \
|
||||||
__sput.initialized = SPUT_INITIALIZED; \
|
__sput.check.name = _name != NULL ? _name : SPUT_DEFAULT_CHECK_NAME; \
|
||||||
} while (0)
|
__sput.check.line = __LINE__; \
|
||||||
|
__sput.check.cond = #_cond; \
|
||||||
|
__sput.check.type = "fail-unless"; \
|
||||||
#define sput_leave_suite() \
|
__sput.test.nr++; \
|
||||||
do { \
|
__sput.suite.checks++; \
|
||||||
float failpls = 0.0f; \
|
if (!(_cond)) { \
|
||||||
_sput_die_unless_initialized(); \
|
_sput_check_failed(); \
|
||||||
_sput_die_unless_suite_set(); \
|
} else { \
|
||||||
failpls = __sput.suite.checks ? (float) \
|
_sput_check_succeeded(); \
|
||||||
((__sput.suite.nok * 100.0) / __sput.suite.checks) : \
|
} \
|
||||||
0.0f; \
|
} while (0)
|
||||||
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_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
|
#ifdef __cplusplus
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
||||||
#endif /* HAVE_SPUT_H */
|
#endif /* HAVE_SPUT_H */
|
||||||
|
|
||||||
|
|
||||||
/* vim: set ft=c sts=4 sw=4 ts=4 ai et: */
|
/* vim: set ft=c sts=4 sw=4 ts=4 ai et: */
|
||||||
|
|
|
@ -6,14 +6,16 @@
|
||||||
|
|
||||||
static void test_join_path_single_segments() {
|
static void test_join_path_single_segments() {
|
||||||
const char *segments[] = {"abc"};
|
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");
|
sput_fail_unless(strcmp(joined, "abc") == 0, "abc");
|
||||||
free(joined);
|
free(joined);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void test_join_path_multiple_segments() {
|
static void test_join_path_multiple_segments() {
|
||||||
const char *segments[] = {"abc", "def", "ghi"};
|
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");
|
sput_fail_unless(strcmp(joined, "abc/def/ghi") == 0, "abc/def/ghi");
|
||||||
free(joined);
|
free(joined);
|
||||||
}
|
}
|
||||||
|
|
|
@ -49,11 +49,13 @@ static void test_validator_field_not_object() {
|
||||||
}
|
}
|
||||||
|
|
||||||
static void test_validator_field_type_invalid() {
|
static void test_validator_field_type_invalid() {
|
||||||
struct TestValidatorFixture *fixture = test_validator_setup("{"
|
struct TestValidatorFixture *fixture = test_validator_setup(
|
||||||
" \"key\": {"
|
"{"
|
||||||
" \"type\": 2"
|
" \"key\": {"
|
||||||
" }"
|
" \"type\": 2"
|
||||||
"}");
|
" }"
|
||||||
|
"}"
|
||||||
|
);
|
||||||
|
|
||||||
enum SpecValidationError retval =
|
enum SpecValidationError retval =
|
||||||
validate_spec_json(fixture->parsed, &fixture->prompts);
|
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() {
|
static void test_validator_field_type_unknown() {
|
||||||
struct TestValidatorFixture *fixture =
|
struct TestValidatorFixture *fixture = test_validator_setup(
|
||||||
test_validator_setup("{"
|
"{"
|
||||||
" \"key\": {"
|
" \"key\": {"
|
||||||
" \"type\": \"UNKNOWN\""
|
" \"type\": \"UNKNOWN\""
|
||||||
" }"
|
" }"
|
||||||
"}");
|
"}"
|
||||||
|
);
|
||||||
|
|
||||||
enum SpecValidationError retval =
|
enum SpecValidationError retval =
|
||||||
validate_spec_json(fixture->parsed, &fixture->prompts);
|
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() {
|
static void test_validator_field_prompt_invalid() {
|
||||||
struct TestValidatorFixture *fixture =
|
struct TestValidatorFixture *fixture = test_validator_setup(
|
||||||
test_validator_setup("{"
|
"{"
|
||||||
" \"key\": {"
|
" \"key\": {"
|
||||||
" \"type\": \"STRING\","
|
" \"type\": \"STRING\","
|
||||||
" \"prompt\": 2"
|
" \"prompt\": 2"
|
||||||
" }"
|
" }"
|
||||||
"}");
|
"}"
|
||||||
|
);
|
||||||
|
|
||||||
enum SpecValidationError retval =
|
enum SpecValidationError retval =
|
||||||
validate_spec_json(fixture->parsed, &fixture->prompts);
|
validate_spec_json(fixture->parsed, &fixture->prompts);
|
||||||
|
@ -94,13 +98,14 @@ static void test_validator_field_prompt_invalid() {
|
||||||
}
|
}
|
||||||
|
|
||||||
static void test_validator_valid() {
|
static void test_validator_valid() {
|
||||||
struct TestValidatorFixture *fixture =
|
struct TestValidatorFixture *fixture = test_validator_setup(
|
||||||
test_validator_setup("{"
|
"{"
|
||||||
" \"key\": {"
|
" \"key\": {"
|
||||||
" \"type\": \"STRING\","
|
" \"type\": \"STRING\","
|
||||||
" \"prompt\": \"What value for key?\""
|
" \"prompt\": \"What value for key?\""
|
||||||
" }"
|
" }"
|
||||||
"}");
|
"}"
|
||||||
|
);
|
||||||
|
|
||||||
enum SpecValidationError retval =
|
enum SpecValidationError retval =
|
||||||
validate_spec_json(fixture->parsed, &fixture->prompts);
|
validate_spec_json(fixture->parsed, &fixture->prompts);
|
||||||
|
|
Loading…
Reference in New Issue