aboutsummaryrefslogtreecommitdiff
path: root/tests/test_utils.c
diff options
context:
space:
mode:
authorJoseph Hunkeler <jhunkeler@users.noreply.github.com>2024-06-21 12:49:45 -0400
committerGitHub <noreply@github.com>2024-06-21 12:49:45 -0400
commit77a0276d9f37bcf828c77f9bcc59ff945116274e (patch)
tree91cf7cb955798ad40718341172b0a8ffbc59a1f2 /tests/test_utils.c
parent931ee28eb9c5b5e3c2b0d3008f5f65d810dc9b0c (diff)
downloadstasis-77a0276d9f37bcf828c77f9bcc59ff945116274e.tar.gz
Rebrand OhMyCal (OMC) as STASIS (#7)
Diffstat (limited to 'tests/test_utils.c')
-rw-r--r--tests/test_utils.c132
1 files changed, 66 insertions, 66 deletions
diff --git a/tests/test_utils.c b/tests/test_utils.c
index a2fa8c6..4b19604 100644
--- a/tests/test_utils.c
+++ b/tests/test_utils.c
@@ -18,8 +18,8 @@ void test_listdir() {
}
struct StrList *listing;
listing = listdir(dirs[0]);
- OMC_ASSERT(listing != NULL, "listdir failed");
- OMC_ASSERT(listing && (strlist_count(listing) == (sizeof(dirs) / sizeof(*dirs)) - 1), "should have 3");
+ STASIS_ASSERT(listing != NULL, "listdir failed");
+ STASIS_ASSERT(listing && (strlist_count(listing) == (sizeof(dirs) / sizeof(*dirs)) - 1), "should have 3");
guard_strlist_free(&listing);
}
@@ -45,7 +45,7 @@ void test_redact_sensitive() {
char *input = strdup(data[i]);
char output[100] = {0};
redact_sensitive(to_redact, sizeof(to_redact) / sizeof(*to_redact), input, output, sizeof(output) - 1);
- OMC_ASSERT(strcmp(output, expected[i]) == 0, "incorrect redaction");
+ STASIS_ASSERT(strcmp(output, expected[i]) == 0, "incorrect redaction");
}
}
@@ -64,13 +64,13 @@ void test_fix_tox_conf() {
if (fp) {
fprintf(fp, "%s", data);
fclose(fp);
- OMC_ASSERT(fix_tox_conf(filename, &result) == 0, "fix_tox_conf failed");
+ STASIS_ASSERT(fix_tox_conf(filename, &result) == 0, "fix_tox_conf failed");
} else {
- OMC_ASSERT(false, "writing mock tox.ini failed");
+ STASIS_ASSERT(false, "writing mock tox.ini failed");
}
char **lines = file_readlines(result, 0, 0, NULL);
- OMC_ASSERT(strstr_array(lines, expected) != NULL, "{posargs} not found in result");
+ STASIS_ASSERT(strstr_array(lines, expected) != NULL, "{posargs} not found in result");
remove(result);
guard_free(result);
@@ -91,30 +91,30 @@ void test_xml_pretty_print_in_place() {
if (fp) {
fprintf(fp, "%s", data);
fclose(fp);
- OMC_ASSERT(xml_pretty_print_in_place(
+ STASIS_ASSERT(xml_pretty_print_in_place(
filename,
- OMC_XML_PRETTY_PRINT_PROG,
- OMC_XML_PRETTY_PRINT_ARGS) == 0,
+ STASIS_XML_PRETTY_PRINT_PROG,
+ STASIS_XML_PRETTY_PRINT_ARGS) == 0,
"xml pretty print failed (xmllint not installed?)");
} else {
- OMC_ASSERT(false, "failed to create input file");
+ STASIS_ASSERT(false, "failed to create input file");
}
fp = fopen(filename, "r");
char buf[BUFSIZ] = {0};
if (fread(buf, sizeof(*buf), sizeof(buf) - 1, fp) < 1) {
- OMC_ASSERT(false, "failed to consume formatted xml file contents");
+ STASIS_ASSERT(false, "failed to consume formatted xml file contents");
}
- OMC_ASSERT(strcmp(expected, buf) == 0, "xml file was not reformatted");
+ STASIS_ASSERT(strcmp(expected, buf) == 0, "xml file was not reformatted");
}
void test_path_store() {
char *dest = NULL;
chdir(cwd_workspace);
int result = path_store(&dest, PATH_MAX, cwd_workspace, "test_path_store");
- OMC_ASSERT(result == 0, "path_store encountered an error");
- OMC_ASSERT(dest != NULL, "dest should not be NULL");
- OMC_ASSERT(dest && (access(dest, F_OK) == 0), "destination path was not created");
+ STASIS_ASSERT(result == 0, "path_store encountered an error");
+ STASIS_ASSERT(dest != NULL, "dest should not be NULL");
+ STASIS_ASSERT(dest && (access(dest, F_OK) == 0), "destination path was not created");
rmtree(dest);
}
@@ -122,13 +122,13 @@ void test_isempty_dir() {
const char *dname = "test_isempty_dir";
rmtree(dname);
mkdir(dname, 0755);
- OMC_ASSERT(isempty_dir(dname) > 0, "empty directory went undetected");
+ STASIS_ASSERT(isempty_dir(dname) > 0, "empty directory went undetected");
char path[PATH_MAX];
sprintf(path, "%s/file.txt", dname);
touch(path);
- OMC_ASSERT(isempty_dir(dname) == 0, "populated directory went undetected");
+ STASIS_ASSERT(isempty_dir(dname) == 0, "populated directory went undetected");
}
void test_xmkstemp() {
@@ -137,7 +137,7 @@ void test_xmkstemp() {
const char *data = "Hello, world!\n";
tempfile = xmkstemp(&tempfp, "w");
- OMC_ASSERT(tempfile != NULL, "failed to create temporary file");
+ STASIS_ASSERT(tempfile != NULL, "failed to create temporary file");
fprintf(tempfp, "%s", data);
fclose(tempfp);
@@ -146,7 +146,7 @@ void test_xmkstemp() {
fgets(buf, sizeof(buf) - 1, tempfp);
fclose(tempfp);
- OMC_ASSERT(strcmp(buf, data) == 0, "data written to temp file is incorrect");
+ STASIS_ASSERT(strcmp(buf, data) == 0, "data written to temp file is incorrect");
remove(tempfile);
free(tempfile);
}
@@ -154,16 +154,16 @@ void test_xmkstemp() {
void test_msg() {
int flags_indent[] = {
0,
- OMC_MSG_L1,
- OMC_MSG_L2,
- OMC_MSG_L3,
+ STASIS_MSG_L1,
+ STASIS_MSG_L2,
+ STASIS_MSG_L3,
};
int flags_info[] = {
- //OMC_MSG_NOP,
- OMC_MSG_SUCCESS,
- OMC_MSG_WARN,
- OMC_MSG_ERROR,
- //OMC_MSG_RESTRICT,
+ //STASIS_MSG_NOP,
+ STASIS_MSG_SUCCESS,
+ STASIS_MSG_WARN,
+ STASIS_MSG_ERROR,
+ //STASIS_MSG_RESTRICT,
};
for (size_t i = 0; i < sizeof(flags_indent) / sizeof(*flags_indent); i++) {
for (size_t x = 0; x < sizeof(flags_info) / sizeof(*flags_info); x++) {
@@ -193,13 +193,13 @@ void test_git_clone_and_describe() {
system(init_cmd);
// clone the bare repo
- OMC_ASSERT(git_clone(&proc, repo_git, repo, NULL) == 0,
+ STASIS_ASSERT(git_clone(&proc, repo_git, repo, NULL) == 0,
"a local clone of bare repository should have succeeded");
chdir(repo);
// interact with it
touch("README.md");
- system("git config user.name omc");
+ system("git config user.name stasis");
system("git config user.email null@null.null");
system("git add README.md");
system("git commit --no-gpg-sign -m Test");
@@ -208,33 +208,33 @@ void test_git_clone_and_describe() {
// test git_describe is functional
char *taginfo_none = git_describe(".");
- OMC_ASSERT(taginfo_none != NULL, "should be a git hash, not NULL");
+ STASIS_ASSERT(taginfo_none != NULL, "should be a git hash, not NULL");
system("git tag -a 1.0.0 -m Mock");
system("git push --tags origin");
char *taginfo = git_describe(".");
- OMC_ASSERT(taginfo != NULL, "should be 1.0.0, not NULL");
- OMC_ASSERT(strcmp(taginfo, "1.0.0") == 0, "just-created tag was not described correctly");
+ STASIS_ASSERT(taginfo != NULL, "should be 1.0.0, not NULL");
+ STASIS_ASSERT(strcmp(taginfo, "1.0.0") == 0, "just-created tag was not described correctly");
chdir("..");
char *taginfo_outer = git_describe(repo);
- OMC_ASSERT(taginfo_outer != NULL, "should be 1.0.0, not NULL");
- OMC_ASSERT(strcmp(taginfo_outer, "1.0.0") == 0, "just-created tag was not described correctly (out-of-dir invocation)");
+ STASIS_ASSERT(taginfo_outer != NULL, "should be 1.0.0, not NULL");
+ STASIS_ASSERT(strcmp(taginfo_outer, "1.0.0") == 0, "just-created tag was not described correctly (out-of-dir invocation)");
char *taginfo_bad = git_describe("abc1234_not_here_or_there");
- OMC_ASSERT(taginfo_bad == NULL, "a repository that shouldn't exist... exists and has a tag.");
+ STASIS_ASSERT(taginfo_bad == NULL, "a repository that shouldn't exist... exists and has a tag.");
chdir(cwd);
}
void test_touch() {
- OMC_ASSERT(touch("touchedfile.txt") == 0, "touch failed");
- OMC_ASSERT(access("touchedfile.txt", F_OK) == 0, "touched file does not exist");
+ STASIS_ASSERT(touch("touchedfile.txt") == 0, "touch failed");
+ STASIS_ASSERT(access("touchedfile.txt", F_OK) == 0, "touched file does not exist");
remove("touchedfile.txt");
}
void test_find_program() {
- OMC_ASSERT(find_program("willnotexist123") == NULL, "did not return NULL");
- OMC_ASSERT(find_program("find") != NULL, "program not available (OS dependent)");
+ STASIS_ASSERT(find_program("willnotexist123") == NULL, "did not return NULL");
+ STASIS_ASSERT(find_program("find") != NULL, "program not available (OS dependent)");
}
static int file_readlines_callback_modify(size_t size, char **line) {
@@ -276,16 +276,16 @@ void test_file_readlines() {
result = file_readlines(filename, 0, 0, NULL);
int i;
for (i = 0; result[i] != NULL; i++);
- OMC_ASSERT(num_chars(data, '\n') == i, "incorrect number of lines in data");
- OMC_ASSERT(strcmp(result[3], "see?\n") == 0, "last line in data is incorrect'");
+ STASIS_ASSERT(num_chars(data, '\n') == i, "incorrect number of lines in data");
+ STASIS_ASSERT(strcmp(result[3], "see?\n") == 0, "last line in data is incorrect'");
GENERIC_ARRAY_FREE(result);
result = file_readlines(filename, 0, 0, file_readlines_callback_modify);
- OMC_ASSERT(strcmp(result[3], "xxx?\n") == 0, "last line should be: 'xxx?\\n'");
+ STASIS_ASSERT(strcmp(result[3], "xxx?\n") == 0, "last line should be: 'xxx?\\n'");
GENERIC_ARRAY_FREE(result);
result = file_readlines(filename, 0, 0, file_readlines_callback_get_specific_line);
- OMC_ASSERT(strcmp(result[0], "see?\n") == 0, "the first record of the result is not the last line of the file 'see?\\n'");
+ STASIS_ASSERT(strcmp(result[0], "see?\n") == 0, "the first record of the result is not the last line of the file 'see?\\n'");
GENERIC_ARRAY_FREE(result);
remove(filename);
}
@@ -302,7 +302,7 @@ void test_path_dirname() {
strcpy(tmp, input);
char *result = path_dirname(tmp);
- OMC_ASSERT(strcmp(expected, result) == 0, NULL);
+ STASIS_ASSERT(strcmp(expected, result) == 0, NULL);
}
}
@@ -315,7 +315,7 @@ void test_path_basename() {
const char *input = data[i];
const char *expected = data[i + 1];
char *result = path_basename(input);
- OMC_ASSERT(strcmp(expected, result) == 0, NULL);
+ STASIS_ASSERT(strcmp(expected, result) == 0, NULL);
}
}
@@ -338,8 +338,8 @@ void test_expandpath() {
strcat(path, DIR_SEP);
char *expanded = expandpath(path);
- OMC_ASSERT(startswith(expanded, home) > 0, expanded);
- OMC_ASSERT(endswith(expanded, DIR_SEP) > 0, "the input string ends with a directory separator, the result did not");
+ STASIS_ASSERT(startswith(expanded, home) > 0, expanded);
+ STASIS_ASSERT(endswith(expanded, DIR_SEP) > 0, "the input string ends with a directory separator, the result did not");
free(expanded);
}
@@ -361,12 +361,12 @@ void test_rmtree() {
sprintf(mockfile, "%s/%zu.txt", path, i);
if (mkdir(path, 0755)) {
perror(path);
- OMC_ASSERT(false, NULL);
+ STASIS_ASSERT(false, NULL);
}
touch(mockfile);
}
- OMC_ASSERT(rmtree(root) == 0, "rmtree should have been able to remove the directory");
- OMC_ASSERT(access(root, F_OK) < 0, "the directory is still present");
+ STASIS_ASSERT(rmtree(root) == 0, "rmtree should have been able to remove the directory");
+ STASIS_ASSERT(access(root, F_OK) < 0, "the directory is still present");
}
void test_dirstack() {
@@ -384,18 +384,18 @@ void test_dirstack() {
pushd(data[i]);
getcwd(cwd, PATH_MAX);
}
- OMC_ASSERT(dirstack_len == sizeof(data) / sizeof(*data), NULL);
- OMC_ASSERT(strcmp(dirstack[0], cwd_workspace) == 0, NULL);
+ STASIS_ASSERT(dirstack_len == sizeof(data) / sizeof(*data), NULL);
+ STASIS_ASSERT(strcmp(dirstack[0], cwd_workspace) == 0, NULL);
for (int i = 1; i < dirstack_len; i++) {
- OMC_ASSERT(endswith(dirstack[i], data[i - 1]), NULL);
+ STASIS_ASSERT(endswith(dirstack[i], data[i - 1]), NULL);
}
for (size_t i = 0, x = dirstack_len - 1; x != 0 && i < sizeof(data) / sizeof(*data); i++, x--) {
char *expected = strdup(dirstack[x]);
popd();
getcwd(cwd, PATH_MAX);
- OMC_ASSERT(strcmp(cwd, expected) == 0, NULL);
+ STASIS_ASSERT(strcmp(cwd, expected) == 0, NULL);
free(expected);
}
}
@@ -405,16 +405,16 @@ void test_pushd_popd() {
chdir(cwd_workspace);
rmtree(dname);
- OMC_ASSERT(mkdir(dname, 0755) == 0, "directory should not exist yet");
- OMC_ASSERT(pushd(dname) == 0, "failed to enter directory");
+ STASIS_ASSERT(mkdir(dname, 0755) == 0, "directory should not exist yet");
+ STASIS_ASSERT(pushd(dname) == 0, "failed to enter directory");
char *cwd = getcwd(NULL, PATH_MAX);
// we should be inside the test directory, not the starting directory
- OMC_ASSERT(strcmp(cwd_workspace, cwd) != 0, "");
- OMC_ASSERT(popd() == 0, "return from directory failed");
+ STASIS_ASSERT(strcmp(cwd_workspace, cwd) != 0, "");
+ STASIS_ASSERT(popd() == 0, "return from directory failed");
char *cwd_after_popd = getcwd(NULL, PATH_MAX);
- OMC_ASSERT(strcmp(cwd_workspace, cwd_after_popd) == 0, "should be the path where we started");
+ STASIS_ASSERT(strcmp(cwd_workspace, cwd_after_popd) == 0, "should be the path where we started");
}
void test_pushd_popd_suggested_workflow() {
@@ -426,23 +426,23 @@ void test_pushd_popd_suggested_workflow() {
if (!mkdir(dname, 0755)) {
if (!pushd(dname)) {
char *cwd = getcwd(NULL, PATH_MAX);
- OMC_ASSERT(strcmp(cwd_workspace, cwd) != 0, NULL);
+ STASIS_ASSERT(strcmp(cwd_workspace, cwd) != 0, NULL);
// return from dir
popd();
free(cwd);
}
// cwd should be our starting directory
char *cwd = getcwd(NULL, PATH_MAX);
- OMC_ASSERT(strcmp(cwd_workspace, cwd) == 0, NULL);
+ STASIS_ASSERT(strcmp(cwd_workspace, cwd) == 0, NULL);
} else {
- OMC_ASSERT(false, "mkdir function failed");
+ STASIS_ASSERT(false, "mkdir function failed");
}
}
int main(int argc, char *argv[]) {
- OMC_TEST_BEGIN_MAIN();
- OMC_TEST_FUNC *tests[] = {
+ STASIS_TEST_BEGIN_MAIN();
+ STASIS_TEST_FUNC *tests[] = {
test_listdir,
test_redact_sensitive,
test_fix_tox_conf,
@@ -469,11 +469,11 @@ int main(int argc, char *argv[]) {
chdir(ws);
getcwd(cwd_workspace, sizeof(cwd_workspace) - 1);
- OMC_TEST_RUN(tests);
+ STASIS_TEST_RUN(tests);
chdir(cwd_start);
if (rmtree(cwd_workspace)) {
perror(cwd_workspace);
}
- OMC_TEST_END_MAIN();
+ STASIS_TEST_END_MAIN();
} \ No newline at end of file