2023-11-23 18:02:40 +00:00
|
|
|
#ifndef _BOOTSTRAP_TEST_CONFIG
|
|
|
|
#define _BOOTSTRAP_TEST_CONFIG
|
2023-11-23 11:09:32 +00:00
|
|
|
|
2023-11-24 18:47:23 +00:00
|
|
|
#include <unistd.h>
|
|
|
|
|
2023-11-23 11:09:32 +00:00
|
|
|
#include "config.h"
|
2023-11-24 18:47:23 +00:00
|
|
|
#include "path.h"
|
2023-11-23 11:09:32 +00:00
|
|
|
#include "sput.h"
|
|
|
|
|
2023-11-24 18:47:23 +00:00
|
|
|
struct TestConfigFixture {
|
|
|
|
char *cwd;
|
|
|
|
char *root_dir;
|
|
|
|
char *target;
|
|
|
|
};
|
|
|
|
|
|
|
|
static struct TestConfigFixture *test_config_setup() {
|
|
|
|
char *cwd = getcwd(0, 0);
|
|
|
|
const char *segments[] = {cwd, "test", "specs"};
|
|
|
|
char *root_dir =
|
|
|
|
join_path_segments(sizeof(segments) / sizeof(char *), segments);
|
|
|
|
|
|
|
|
struct TestConfigFixture *fixture = malloc(sizeof(struct TestConfigFixture));
|
|
|
|
fixture->cwd = getcwd(0, 0);
|
|
|
|
fixture->root_dir = root_dir;
|
|
|
|
fixture->target = "minimal_spec_json";
|
|
|
|
|
|
|
|
return fixture;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void test_config_teardown(struct TestConfigFixture *fixture) {
|
|
|
|
free(fixture->cwd);
|
|
|
|
free(fixture->root_dir);
|
|
|
|
free(fixture);
|
|
|
|
}
|
|
|
|
|
2023-11-25 18:51:42 +00:00
|
|
|
static void test_config_new_invalid_args() {
|
2023-11-24 18:47:23 +00:00
|
|
|
struct TestConfigFixture *fixture = test_config_setup();
|
2023-11-23 14:40:17 +00:00
|
|
|
|
2023-11-25 15:55:02 +00:00
|
|
|
struct Error *error = 0;
|
2023-11-23 15:07:22 +00:00
|
|
|
struct Config *config = 0;
|
2023-11-24 18:47:23 +00:00
|
|
|
|
2023-11-25 18:51:42 +00:00
|
|
|
error = config_new(0, fixture->root_dir, fixture->target, &config);
|
2023-11-25 15:55:02 +00:00
|
|
|
sput_fail_unless(error->code == ERROR_CONFIG_ENV_CWD_INVALID, "cwd == 0");
|
|
|
|
error_free(error);
|
2023-11-25 18:51:42 +00:00
|
|
|
error = config_new(fixture->cwd, 0, fixture->target, &config);
|
2023-11-25 15:55:02 +00:00
|
|
|
sput_fail_unless(
|
|
|
|
error->code == ERROR_CONFIG_ENV_ROOT_DIR_INVALID, "root_dir == 0"
|
|
|
|
);
|
|
|
|
error_free(error);
|
2023-11-24 18:47:23 +00:00
|
|
|
|
|
|
|
test_config_teardown(fixture);
|
2023-11-23 15:07:22 +00:00
|
|
|
}
|
2023-11-23 14:40:17 +00:00
|
|
|
|
2023-11-25 18:51:42 +00:00
|
|
|
static void test_config_new_spec_not_found() {
|
2023-11-24 18:47:23 +00:00
|
|
|
struct TestConfigFixture *fixture = test_config_setup();
|
|
|
|
|
2023-11-25 15:55:02 +00:00
|
|
|
struct Error *error = 0;
|
2023-11-23 15:07:22 +00:00
|
|
|
struct Config *config = 0;
|
2023-11-25 15:55:02 +00:00
|
|
|
|
2023-11-25 18:51:42 +00:00
|
|
|
error = config_new(fixture->cwd, fixture->root_dir, "not_found", &config);
|
2023-11-25 15:55:02 +00:00
|
|
|
sput_fail_unless(
|
|
|
|
error->code == ERROR_CONFIG_TARGET_NOT_FOUND, "target not found"
|
|
|
|
);
|
|
|
|
error_free(error);
|
2023-11-24 18:47:23 +00:00
|
|
|
|
|
|
|
test_config_teardown(fixture);
|
2023-11-23 11:09:32 +00:00
|
|
|
}
|
|
|
|
|
2023-11-25 18:51:42 +00:00
|
|
|
static void test_config_new_spec_not_dir() {
|
2023-11-24 18:47:23 +00:00
|
|
|
struct TestConfigFixture *fixture = test_config_setup();
|
|
|
|
|
2023-11-25 15:55:02 +00:00
|
|
|
struct Error *error = 0;
|
2023-11-23 14:40:17 +00:00
|
|
|
struct Config *config = 0;
|
2023-11-25 15:55:02 +00:00
|
|
|
|
2023-11-25 18:51:42 +00:00
|
|
|
error = config_new(fixture->cwd, fixture->root_dir, "not_dir", &config);
|
2023-11-25 15:55:02 +00:00
|
|
|
sput_fail_unless(
|
|
|
|
error->code == ERROR_CONFIG_TARGET_NOT_DIR, "target not dir"
|
|
|
|
);
|
|
|
|
error_free(error);
|
2023-11-24 18:47:23 +00:00
|
|
|
|
|
|
|
test_config_teardown(fixture);
|
2023-11-23 11:09:32 +00:00
|
|
|
}
|
|
|
|
|
2023-11-25 18:51:42 +00:00
|
|
|
static void test_config_new_success() {
|
2023-11-24 18:47:23 +00:00
|
|
|
struct TestConfigFixture *fixture = test_config_setup();
|
|
|
|
|
2023-11-25 15:55:02 +00:00
|
|
|
struct Error *error = 0;
|
2023-11-23 14:40:17 +00:00
|
|
|
struct Config *config = 0;
|
|
|
|
|
2023-11-25 18:51:42 +00:00
|
|
|
error = config_new(fixture->cwd, fixture->root_dir, fixture->target, &config);
|
|
|
|
sput_fail_unless(error == 0, "config_new() success");
|
|
|
|
sput_fail_unless(strcmp(config->cwd, fixture->cwd) == 0, "config_new() cwd");
|
2023-11-24 18:47:23 +00:00
|
|
|
sput_fail_unless(
|
2023-11-25 18:51:42 +00:00
|
|
|
strcmp(config->root_dir, fixture->root_dir) == 0, "config_new() root_dir"
|
2023-11-24 18:47:23 +00:00
|
|
|
);
|
|
|
|
sput_fail_unless(
|
2023-11-25 18:51:42 +00:00
|
|
|
strcmp(config->target, fixture->target) == 0, "config_new() target"
|
2023-11-24 18:47:23 +00:00
|
|
|
);
|
2023-11-23 14:40:17 +00:00
|
|
|
|
|
|
|
config_free(config);
|
2023-11-24 18:47:23 +00:00
|
|
|
test_config_teardown(fixture);
|
2023-11-23 11:09:32 +00:00
|
|
|
}
|
|
|
|
|
2023-11-23 18:02:40 +00:00
|
|
|
#endif /* _BOOTSTRAP_TEST_CONFIG */
|