Run formatting with additional rules.
parent
07f9853481
commit
a17d6eb3e3
|
@ -1,6 +1,8 @@
|
|||
BasedOnStyle: LLVM
|
||||
BasedOnStyle: Google
|
||||
AlignAfterOpenBracket: BlockIndent
|
||||
BinPackArguments: false
|
||||
BinPackParameters: false
|
||||
ColumnLimit: 80
|
||||
ContinuationIndentWidth: 2
|
||||
IndentCaseLabels: false
|
||||
IndentWidth: 2
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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 */
|
||||
|
|
|
@ -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 */
|
||||
|
|
85
src/cJSON.c
85
src/cJSON.c
|
@ -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;
|
||||
|
||||
|
@ -287,8 +288,9 @@ typedef struct {
|
|||
|
||||
/* 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;
|
||||
|
|
|
@ -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(
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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) {
|
||||
|
|
|
@ -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);
|
||||
|
||||
|
|
|
@ -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);
|
||||
|
||||
|
|
|
@ -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) {
|
||||
|
|
147
test/sput.h
147
test/sput.h
|
@ -33,22 +33,18 @@
|
|||
* 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
|
||||
* =================================================================== */
|
||||
|
@ -63,26 +59,22 @@ extern "C" {
|
|||
|
||||
#define SPUT_INITIALIZED 0x06 /* ACK */
|
||||
|
||||
|
||||
/* ===================================================================
|
||||
* sput global variable
|
||||
* =================================================================== */
|
||||
|
||||
static struct sput
|
||||
{
|
||||
static struct sput {
|
||||
FILE *out;
|
||||
char initialized;
|
||||
|
||||
struct sput_overall
|
||||
{
|
||||
struct sput_overall {
|
||||
unsigned long checks;
|
||||
unsigned long suites;
|
||||
unsigned long ok;
|
||||
unsigned long nok;
|
||||
} overall;
|
||||
|
||||
struct sput_suite
|
||||
{
|
||||
struct sput_suite {
|
||||
const char *name;
|
||||
unsigned long nr;
|
||||
unsigned long checks;
|
||||
|
@ -90,86 +82,84 @@ extern "C" {
|
|||
unsigned long nok;
|
||||
} suite;
|
||||
|
||||
struct sput_test
|
||||
{
|
||||
struct sput_test {
|
||||
const char *name;
|
||||
unsigned long nr;
|
||||
} test;
|
||||
|
||||
struct sput_check
|
||||
{
|
||||
struct sput_check {
|
||||
const char *name;
|
||||
const char *cond;
|
||||
const char *type;
|
||||
unsigned long line;
|
||||
} check;
|
||||
|
||||
struct sput_time
|
||||
{
|
||||
struct sput_time {
|
||||
time_t start;
|
||||
time_t end;
|
||||
} time;
|
||||
} __sput;
|
||||
|
||||
|
||||
/* ==================================================================
|
||||
* sput internal macros
|
||||
* ================================================================== */
|
||||
|
||||
#define _sput_die_unless_initialized() \
|
||||
if (__sput.initialized != SPUT_INITIALIZED) \
|
||||
{ \
|
||||
if (__sput.initialized != SPUT_INITIALIZED) { \
|
||||
fputs("sput_start_testing() omitted\n", stderr); \
|
||||
exit(EXIT_FAILURE); \
|
||||
}
|
||||
|
||||
|
||||
#define _sput_die_unless_suite_set() \
|
||||
if (! __sput.suite.name) \
|
||||
{ \
|
||||
if (!__sput.suite.name) { \
|
||||
fputs("sput_enter_suite() omitted\n", __sput.out); \
|
||||
exit(EXIT_FAILURE); \
|
||||
}
|
||||
|
||||
|
||||
#define _sput_die_unless_test_set() \
|
||||
if (! __sput.test.name) \
|
||||
{ \
|
||||
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, \
|
||||
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); \
|
||||
__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_check_succeeded() \
|
||||
{ \
|
||||
_sput_die_unless_initialized(); \
|
||||
_sput_die_unless_suite_set(); \
|
||||
__sput.suite.ok++; \
|
||||
fprintf(__sput.out, \
|
||||
fprintf( \
|
||||
__sput.out, \
|
||||
"[%lu:%lu] %s:#%lu \"%s\" pass\n", \
|
||||
__sput.suite.nr, __sput.suite.checks, \
|
||||
__sput.suite.nr, \
|
||||
__sput.suite.checks, \
|
||||
__sput.test.name, \
|
||||
__sput.test.nr, \
|
||||
__sput.check.name); \
|
||||
__sput.check.name \
|
||||
); \
|
||||
}
|
||||
|
||||
|
||||
/* ==================================================================
|
||||
* user macros
|
||||
* ================================================================== */
|
||||
|
@ -182,122 +172,116 @@ extern "C" {
|
|||
__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, \
|
||||
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.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) \
|
||||
{ \
|
||||
if (__sput.suite.name) { \
|
||||
sput_leave_suite(); \
|
||||
} \
|
||||
__sput.suite.name = _name != NULL ? \
|
||||
_name : SPUT_DEFAULT_SUITE_NAME; \
|
||||
__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); \
|
||||
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) \
|
||||
{ \
|
||||
if (__sput.suite.name) { \
|
||||
sput_leave_suite(); \
|
||||
} \
|
||||
failpft = __sput.overall.checks ? (float) \
|
||||
((__sput.overall.nok * 100.0) / __sput.overall.checks) : \
|
||||
0.0f; \
|
||||
failpft = \
|
||||
__sput.overall.checks \
|
||||
? (float)((__sput.overall.nok * 100.0) / __sput.overall.checks) \
|
||||
: 0.0f; \
|
||||
__sput.time.end = time(NULL); \
|
||||
fprintf(__sput.out, \
|
||||
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, \
|
||||
__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"); \
|
||||
__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.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)) \
|
||||
{ \
|
||||
if ((_cond)) { \
|
||||
_sput_check_failed(); \
|
||||
} \
|
||||
else \
|
||||
{ \
|
||||
} 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.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)) \
|
||||
{ \
|
||||
if (!(_cond)) { \
|
||||
_sput_check_failed(); \
|
||||
} \
|
||||
else \
|
||||
{ \
|
||||
} else { \
|
||||
_sput_check_succeeded(); \
|
||||
} \
|
||||
} while (0)
|
||||
|
||||
|
||||
#define sput_run_test(_func) \
|
||||
do { \
|
||||
_sput_die_unless_initialized(); \
|
||||
|
@ -307,13 +291,10 @@ extern "C" {
|
|||
_func(); \
|
||||
} while (0)
|
||||
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
#endif /* HAVE_SPUT_H */
|
||||
|
||||
|
||||
/* vim: set ft=c sts=4 sw=4 ts=4 ai et: */
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
|
|
|
@ -49,11 +49,13 @@ static void test_validator_field_not_object() {
|
|||
}
|
||||
|
||||
static void test_validator_field_type_invalid() {
|
||||
struct TestValidatorFixture *fixture = test_validator_setup("{"
|
||||
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("{"
|
||||
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("{"
|
||||
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("{"
|
||||
struct TestValidatorFixture *fixture = test_validator_setup(
|
||||
"{"
|
||||
" \"key\": {"
|
||||
" \"type\": \"STRING\","
|
||||
" \"prompt\": \"What value for key?\""
|
||||
" }"
|
||||
"}");
|
||||
"}"
|
||||
);
|
||||
|
||||
enum SpecValidationError retval =
|
||||
validate_spec_json(fixture->parsed, &fixture->prompts);
|
||||
|
|
Loading…
Reference in New Issue