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 AlignAfterOpenBracket: BlockIndent
BinPackArguments: false BinPackArguments: false
BinPackParameters: false BinPackParameters: false
ColumnLimit: 80
ContinuationIndentWidth: 2 ContinuationIndentWidth: 2
IndentCaseLabels: false
IndentWidth: 2 IndentWidth: 2

View File

@ -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

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. @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 */

View File

@ -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 */

View File

@ -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;
@ -287,8 +288,9 @@ typedef struct {
/* 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;

View File

@ -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(

View File

@ -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;

View File

@ -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) {

View File

@ -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);

View File

@ -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);

View File

@ -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) {

View File

@ -33,22 +33,18 @@
* 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 * definitions
* =================================================================== */ * =================================================================== */
@ -63,26 +59,22 @@ extern "C" {
#define SPUT_INITIALIZED 0x06 /* ACK */ #define SPUT_INITIALIZED 0x06 /* ACK */
/* =================================================================== /* ===================================================================
* sput global variable * sput global variable
* =================================================================== */ * =================================================================== */
static struct sput static struct sput {
{
FILE *out; FILE *out;
char initialized; char initialized;
struct sput_overall struct sput_overall {
{
unsigned long checks; unsigned long checks;
unsigned long suites; unsigned long suites;
unsigned long ok; unsigned long ok;
unsigned long nok; unsigned long nok;
} overall; } overall;
struct sput_suite struct sput_suite {
{
const char *name; const char *name;
unsigned long nr; unsigned long nr;
unsigned long checks; unsigned long checks;
@ -90,86 +82,84 @@ extern "C" {
unsigned long nok; unsigned long nok;
} suite; } suite;
struct sput_test struct sput_test {
{
const char *name; const char *name;
unsigned long nr; unsigned long nr;
} test; } test;
struct sput_check struct sput_check {
{
const char *name; const char *name;
const char *cond; const char *cond;
const char *type; const char *type;
unsigned long line; unsigned long line;
} check; } check;
struct sput_time struct sput_time {
{
time_t start; time_t start;
time_t end; time_t end;
} time; } time;
} __sput; } __sput;
/* ================================================================== /* ==================================================================
* sput internal macros * sput internal macros
* ================================================================== */ * ================================================================== */
#define _sput_die_unless_initialized() \ #define _sput_die_unless_initialized() \
if (__sput.initialized != SPUT_INITIALIZED) \ if (__sput.initialized != SPUT_INITIALIZED) { \
{ \
fputs("sput_start_testing() omitted\n", stderr); \ fputs("sput_start_testing() omitted\n", stderr); \
exit(EXIT_FAILURE); \ exit(EXIT_FAILURE); \
} }
#define _sput_die_unless_suite_set() \ #define _sput_die_unless_suite_set() \
if (! __sput.suite.name) \ if (!__sput.suite.name) { \
{ \
fputs("sput_enter_suite() omitted\n", __sput.out); \ fputs("sput_enter_suite() omitted\n", __sput.out); \
exit(EXIT_FAILURE); \ exit(EXIT_FAILURE); \
} }
#define _sput_die_unless_test_set() \ #define _sput_die_unless_test_set() \
if (! __sput.test.name) \ if (!__sput.test.name) { \
{ \
fputs("sput_run_test() omitted\n", __sput.out); \ fputs("sput_run_test() omitted\n", __sput.out); \
exit(EXIT_FAILURE); \ exit(EXIT_FAILURE); \
} }
#define _sput_check_failed() \ #define _sput_check_failed() \
{ \ { \
_sput_die_unless_initialized(); \ _sput_die_unless_initialized(); \
_sput_die_unless_suite_set(); \ _sput_die_unless_suite_set(); \
__sput.suite.nok++; \ __sput.suite.nok++; \
fprintf(__sput.out, \ fprintf( \
__sput.out, \
"[%lu:%lu] %s:#%lu \"%s\" FAIL\n" \ "[%lu:%lu] %s:#%lu \"%s\" FAIL\n" \
"! Type: %s\n" \ "! Type: %s\n" \
"! Condition: %s\n" \ "! Condition: %s\n" \
"! Line: %lu\n", \ "! Line: %lu\n", \
__sput.suite.nr, __sput.suite.checks, __sput.test.name, \ __sput.suite.nr, \
__sput.test.nr, __sput.check.name, __sput.check.type, \ __sput.suite.checks, \
__sput.check.cond, __sput.check.line); \ __sput.test.name, \
__sput.test.nr, \
__sput.check.name, \
__sput.check.type, \
__sput.check.cond, \
__sput.check.line \
); \
} }
#define _sput_check_succeeded() \ #define _sput_check_succeeded() \
{ \ { \
_sput_die_unless_initialized(); \ _sput_die_unless_initialized(); \
_sput_die_unless_suite_set(); \ _sput_die_unless_suite_set(); \
__sput.suite.ok++; \ __sput.suite.ok++; \
fprintf(__sput.out, \ fprintf( \
__sput.out, \
"[%lu:%lu] %s:#%lu \"%s\" pass\n", \ "[%lu:%lu] %s:#%lu \"%s\" pass\n", \
__sput.suite.nr, __sput.suite.checks, \ __sput.suite.nr, \
__sput.suite.checks, \
__sput.test.name, \ __sput.test.name, \
__sput.test.nr, \ __sput.test.nr, \
__sput.check.name); \ __sput.check.name \
); \
} }
/* ================================================================== /* ==================================================================
* user macros * user macros
* ================================================================== */ * ================================================================== */
@ -182,122 +172,116 @@ extern "C" {
__sput.initialized = SPUT_INITIALIZED; \ __sput.initialized = SPUT_INITIALIZED; \
} while (0) } while (0)
#define sput_leave_suite() \ #define sput_leave_suite() \
do { \ do { \
float failpls = 0.0f; \ float failpls = 0.0f; \
_sput_die_unless_initialized(); \ _sput_die_unless_initialized(); \
_sput_die_unless_suite_set(); \ _sput_die_unless_suite_set(); \
failpls = __sput.suite.checks ? (float) \ failpls = __sput.suite.checks \
((__sput.suite.nok * 100.0) / __sput.suite.checks) : \ ? (float)((__sput.suite.nok * 100.0) / __sput.suite.checks) \
0.0f; \ : 0.0f; \
fprintf(__sput.out, \ fprintf( \
__sput.out, \
"\n--> %lu check(s), %lu ok, %lu failed (%.2f%%)\n", \ "\n--> %lu check(s), %lu ok, %lu failed (%.2f%%)\n", \
__sput.suite.checks, __sput.suite.ok, __sput.suite.nok, \ __sput.suite.checks, \
failpls); \ __sput.suite.ok, \
__sput.suite.nok, \
failpls \
); \
__sput.overall.checks += __sput.suite.checks; \ __sput.overall.checks += __sput.suite.checks; \
__sput.overall.ok += __sput.suite.ok; \ __sput.overall.ok += __sput.suite.ok; \
__sput.overall.nok += __sput.suite.nok; \ __sput.overall.nok += __sput.suite.nok; \
memset(&__sput.suite, 0, sizeof(__sput.suite)); \ memset(&__sput.suite, 0, sizeof(__sput.suite)); \
} while (0) } while (0)
#define sput_get_return_value() \ #define sput_get_return_value() \
(__sput.overall.nok > 0 ? EXIT_FAILURE : EXIT_SUCCESS) (__sput.overall.nok > 0 ? EXIT_FAILURE : EXIT_SUCCESS)
#define sput_enter_suite(_name) \ #define sput_enter_suite(_name) \
do { \ do { \
_sput_die_unless_initialized(); \ _sput_die_unless_initialized(); \
if (__sput.suite.name) \ if (__sput.suite.name) { \
{ \
sput_leave_suite(); \ sput_leave_suite(); \
} \ } \
__sput.suite.name = _name != NULL ? \ __sput.suite.name = _name != NULL ? _name : SPUT_DEFAULT_SUITE_NAME; \
_name : SPUT_DEFAULT_SUITE_NAME; \
__sput.suite.nr = ++__sput.overall.suites; \ __sput.suite.nr = ++__sput.overall.suites; \
fprintf(__sput.out, "\n== Entering suite #%lu, \"%s\" ==\n\n", \ fprintf( \
__sput.suite.nr, __sput.suite.name); \ __sput.out, \
"\n== Entering suite #%lu, \"%s\" ==\n\n", \
__sput.suite.nr, \
__sput.suite.name \
); \
} while (0) } while (0)
#define sput_finish_testing() \ #define sput_finish_testing() \
do { \ do { \
float failpft = 0.0f; \ float failpft = 0.0f; \
_sput_die_unless_initialized(); \ _sput_die_unless_initialized(); \
if (__sput.suite.name) \ if (__sput.suite.name) { \
{ \
sput_leave_suite(); \ sput_leave_suite(); \
} \ } \
failpft = __sput.overall.checks ? (float) \ failpft = \
((__sput.overall.nok * 100.0) / __sput.overall.checks) : \ __sput.overall.checks \
0.0f; \ ? (float)((__sput.overall.nok * 100.0) / __sput.overall.checks) \
: 0.0f; \
__sput.time.end = time(NULL); \ __sput.time.end = time(NULL); \
fprintf(__sput.out, \ fprintf( \
__sput.out, \
"\n==> %lu check(s) in %lu suite(s) finished after %.2f " \ "\n==> %lu check(s) in %lu suite(s) finished after %.2f " \
"second(s),\n" \ "second(s),\n" \
" %lu succeeded, %lu failed (%.2f%%)\n" \ " %lu succeeded, %lu failed (%.2f%%)\n" \
"\n[%s]\n", \ "\n[%s]\n", \
__sput.overall.checks, __sput.overall.suites, \ __sput.overall.checks, \
__sput.overall.suites, \
difftime(__sput.time.end, __sput.time.start), \ difftime(__sput.time.end, __sput.time.start), \
__sput.overall.ok, __sput.overall.nok, failpft, \ __sput.overall.ok, \
(sput_get_return_value() == EXIT_SUCCESS) ? \ __sput.overall.nok, \
"SUCCESS" : "FAILURE"); \ failpft, \
(sput_get_return_value() == EXIT_SUCCESS) ? "SUCCESS" : "FAILURE" \
); \
} while (0) } while (0)
#define sput_set_output_stream(_fp) \ #define sput_set_output_stream(_fp) \
do { \ do { \
__sput.out = _fp != NULL ? _fp : stdout; \ __sput.out = _fp != NULL ? _fp : stdout; \
} while (0) } while (0)
#define sput_fail_if(_cond, _name) \ #define sput_fail_if(_cond, _name) \
do { \ do { \
_sput_die_unless_initialized(); \ _sput_die_unless_initialized(); \
_sput_die_unless_suite_set(); \ _sput_die_unless_suite_set(); \
_sput_die_unless_test_set(); \ _sput_die_unless_test_set(); \
__sput.check.name = _name != NULL ? \ __sput.check.name = _name != NULL ? _name : SPUT_DEFAULT_CHECK_NAME; \
_name : SPUT_DEFAULT_CHECK_NAME; \
__sput.check.line = __LINE__; \ __sput.check.line = __LINE__; \
__sput.check.cond = #_cond; \ __sput.check.cond = #_cond; \
__sput.check.type = "fail-if"; \ __sput.check.type = "fail-if"; \
__sput.test.nr++; \ __sput.test.nr++; \
__sput.suite.checks++; \ __sput.suite.checks++; \
if ((_cond)) \ if ((_cond)) { \
{ \
_sput_check_failed(); \ _sput_check_failed(); \
} \ } else { \
else \
{ \
_sput_check_succeeded(); \ _sput_check_succeeded(); \
} \ } \
} while (0) } while (0)
#define sput_fail_unless(_cond, _name) \ #define sput_fail_unless(_cond, _name) \
do { \ do { \
_sput_die_unless_initialized(); \ _sput_die_unless_initialized(); \
_sput_die_unless_suite_set(); \ _sput_die_unless_suite_set(); \
_sput_die_unless_test_set(); \ _sput_die_unless_test_set(); \
__sput.check.name = _name != NULL ? \ __sput.check.name = _name != NULL ? _name : SPUT_DEFAULT_CHECK_NAME; \
_name : SPUT_DEFAULT_CHECK_NAME; \
__sput.check.line = __LINE__; \ __sput.check.line = __LINE__; \
__sput.check.cond = #_cond; \ __sput.check.cond = #_cond; \
__sput.check.type = "fail-unless"; \ __sput.check.type = "fail-unless"; \
__sput.test.nr++; \ __sput.test.nr++; \
__sput.suite.checks++; \ __sput.suite.checks++; \
if (! (_cond)) \ if (!(_cond)) { \
{ \
_sput_check_failed(); \ _sput_check_failed(); \
} \ } else { \
else \
{ \
_sput_check_succeeded(); \ _sput_check_succeeded(); \
} \ } \
} while (0) } while (0)
#define sput_run_test(_func) \ #define sput_run_test(_func) \
do { \ do { \
_sput_die_unless_initialized(); \ _sput_die_unless_initialized(); \
@ -307,13 +291,10 @@ extern "C" {
_func(); \ _func(); \
} while (0) } 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: */

View File

@ -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);
} }

View File

@ -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\": {" " \"key\": {"
" \"type\": 2" " \"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);