diff --git a/include/loader.h b/include/parser.h similarity index 70% rename from include/loader.h rename to include/parser.h index d5dc82f..38f0dcf 100644 --- a/include/loader.h +++ b/include/parser.h @@ -1,14 +1,14 @@ -#ifndef _BOOTSTRAP_LOADER_H -#define _BOOTSTRAP_LOADER_H +#ifndef _BOOTSTRAP_PARSER_H +#define _BOOTSTRAP_PARSER_H #include "cJSON.h" #include "config.h" enum SpecParseError { // The `spec.json` file exists but cannot be open. - SPE_PARSE_CANNOT_OPEN = 1, - // The JSON of the corresponding file is not syntactically valid JSON. - SPE_PARSE_INVALID, + SPE_CANNOT_OPEN = 1, + // The JSON of the corresponding file is not syntactically valid. + SPE_INVALID_SYNTAX, }; /* @@ -20,6 +20,6 @@ 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 -read_spec_json(const struct Config *const config, cJSON **parsed); +parse_spec_json(const struct Config *const config, cJSON **parsed); -#endif /* _BOOTSTRAP_LOADER_H */ +#endif /* _BOOTSTRAP_PARSER_H */ diff --git a/main.c b/main.c index 99aef14..e48c21c 100644 --- a/main.c +++ b/main.c @@ -4,13 +4,11 @@ #include "cJSON.h" #include "config.h" -#include "loader.h" +#include "parser.h" const char *ENV_BOOTSTRAP_ROOT_DIR = "BOOTSTRAP_ROOT_DIR"; int main(int argc, char **argv) { - int num = 0; - if (argc != 2) { fprintf(stderr, "Usage: bootstrap \n"); exit(EXIT_FAILURE); @@ -42,12 +40,12 @@ int main(int argc, char **argv) { // `config` must be free'd. cJSON *parsed = 0; - switch (read_spec_json(config, &parsed)) { - case SPE_PARSE_CANNOT_OPEN: + switch (parse_spec_json(config, &parsed)) { + case SPE_CANNOT_OPEN: fprintf(stderr, "Found `spec.json` but could not open."); retval = EXIT_FAILURE; goto config_cleanup; - case SPE_PARSE_INVALID: + case SPE_INVALID_SYNTAX: fprintf(stderr, "`spec.json` does not conform to bootstrap format."); retval = EXIT_FAILURE; goto config_cleanup; diff --git a/src/loader.c b/src/parser.c similarity index 89% rename from src/loader.c rename to src/parser.c index 5e71481..106e83e 100644 --- a/src/loader.c +++ b/src/parser.c @@ -3,7 +3,7 @@ #include #include -#include "loader.h" +#include "parser.h" #include "path.h" /* @@ -28,12 +28,12 @@ static int find_spec_json(const struct Config *const config, FILE **handle) { } enum SpecParseError -read_spec_json(const struct Config *const config, cJSON **parsed) { +parse_spec_json(const struct Config *const config, cJSON **parsed) { FILE *handle = 0; int retval = find_spec_json(config, &handle); if (retval != 0) { - return SPE_PARSE_CANNOT_OPEN; + return SPE_CANNOT_OPEN; } // The `spec.json` file does not exist. @@ -57,7 +57,7 @@ read_spec_json(const struct Config *const config, cJSON **parsed) { // Can use `cJSON_GetErrorPtr()` to get the actual error message. if (!*parsed) { - return SPE_PARSE_INVALID; + return SPE_INVALID_SYNTAX; } return 0; diff --git a/test/runner.c b/test/runner.c index 1c95d6f..15bb7b7 100644 --- a/test/runner.c +++ b/test/runner.c @@ -1,7 +1,7 @@ #include "sput.h" #include "test_config.h" #include "test_dyn_array.h" -#include "test_loader.h" +#include "test_parser.h" #include "test_path.h" int main(int argc, char *argv[]) { @@ -20,10 +20,10 @@ int main(int argc, char *argv[]) { sput_run_test(test_join_path_single_segments); sput_run_test(test_join_path_multiple_segments); - sput_enter_suite("loader"); - sput_run_test(test_read_spec_json_missing); - sput_run_test(test_read_spec_json_minimal); - sput_run_test(test_read_spec_json_invalid); + sput_enter_suite("parser"); + sput_run_test(test_parse_spec_json_missing); + sput_run_test(test_parse_spec_json_minimal); + sput_run_test(test_parse_spec_json_invalid); sput_finish_testing(); diff --git a/test/test_loader.h b/test/test_parser.h similarity index 64% rename from test/test_loader.h rename to test/test_parser.h index 5300c2c..5771f4f 100644 --- a/test/test_loader.h +++ b/test/test_parser.h @@ -5,7 +5,7 @@ #include "cJSON.h" #include "config.h" -#include "loader.h" +#include "parser.h" #include "path.h" #include "sput.h" @@ -13,11 +13,12 @@ A missing `spec.json` file is not an error. Our parsed @cJSON instance should be set to NULL in this case. */ -static void test_read_spec_json_missing() { +static void test_parse_spec_json_missing() { char *cwd = getcwd(0, 0); const char *segments[] = {cwd, "test", "specs"}; - char *root_dir = join_path_segments(sizeof(segments) / sizeof(char *), segments); + char *root_dir = + join_path_segments(sizeof(segments) / sizeof(char *), segments); struct Config config = { cwd, @@ -26,7 +27,7 @@ static void test_read_spec_json_missing() { }; cJSON *parsed = 0; - enum SpecParseError retval = read_spec_json(&config, &parsed); + enum SpecParseError retval = parse_spec_json(&config, &parsed); sput_fail_unless(retval == 0, "no spec.json, success"); sput_fail_unless(parsed == 0, "no spec.json, no parsed"); @@ -34,11 +35,12 @@ static void test_read_spec_json_missing() { free(root_dir); } -static void test_read_spec_json_minimal() { +static void test_parse_spec_json_minimal() { char *cwd = getcwd(0, 0); const char *segments[] = {cwd, "test", "specs"}; - char *root_dir = join_path_segments(sizeof(segments) / sizeof(char *), segments); + char *root_dir = + join_path_segments(sizeof(segments) / sizeof(char *), segments); struct Config config = { cwd, @@ -47,7 +49,7 @@ static void test_read_spec_json_minimal() { }; cJSON *parsed = 0; - enum SpecParseError retval = read_spec_json(&config, &parsed); + enum SpecParseError retval = parse_spec_json(&config, &parsed); sput_fail_unless(retval == 0, "minimal spec.json, success"); sput_fail_unless(parsed != 0, "minimal spec.json, parsed"); @@ -55,11 +57,12 @@ static void test_read_spec_json_minimal() { free(root_dir); } -static void test_read_spec_json_invalid() { +static void test_parse_spec_json_invalid() { char *cwd = getcwd(0, 0); const char *segments[] = {cwd, "test", "specs"}; - char *root_dir = join_path_segments(sizeof(segments) / sizeof(char *), segments); + char *root_dir = + join_path_segments(sizeof(segments) / sizeof(char *), segments); struct Config config = { cwd, @@ -68,8 +71,10 @@ static void test_read_spec_json_invalid() { }; cJSON *parsed = 0; - enum SpecParseError retval = read_spec_json(&config, &parsed); - sput_fail_unless(retval == SPE_PARSE_INVALID, "invalid spec.json, JSON_INVALID"); + enum SpecParseError retval = parse_spec_json(&config, &parsed); + sput_fail_unless( + retval == SPE_INVALID_SYNTAX, "invalid spec.json, INVALID_SYNTAX" + ); sput_fail_unless(parsed == 0, "invalid spec.json, not parsed"); free(cwd);