fix: Somehow, test file changed line endings to CRLF. Changed it back to LF.

pull/6/head
GreekStapler 2023-01-25 23:55:04 +01:00
parent fbbc15cf73
commit d0914adbb5
1 changed files with 84 additions and 86 deletions

View File

@ -1,86 +1,84 @@
#include "acutest.h" #include "acutest.h"
#include "package.h" #include "package.h"
void test_pkg_info_parse() { void test_pkg_info_parse() {
FILE *f = fopen("./test/package/.PKGINFO", "r"); FILE *f = fopen("./test/package/.PKGINFO", "r");
TEST_ASSERT_(f != NULL, "could not find test .PKGINFO file in ./test/package "); TEST_ASSERT_(f != NULL, "could not find test .PKGINFO file in ./test/package ");
fseek(f, 0L, SEEK_END); fseek(f, 0L, SEEK_END);
size_t size = ftell(f); size_t size = ftell(f);
fflush(stdout); fflush(stdout);
rewind(f); rewind(f);
char *pkg_info_str = malloc(size); char *pkg_info_str = malloc(size);
fread(pkg_info_str, 1, size, f); fread(pkg_info_str, 1, size, f);
fclose(f); fclose(f);
PkgInfo *pkg_info = package_info_init(); PkgInfo *pkg_info = package_info_init();
package_info_parse(pkg_info, pkg_info_str); package_info_parse(pkg_info, pkg_info_str);
TEST_CHECK(!strcmp(pkg_info->name, "xcursor-dmz")); TEST_CHECK(!strcmp(pkg_info->name, "xcursor-dmz"));
TEST_CHECK(!strcmp(pkg_info->base, "xcursor-dmz")); TEST_CHECK(!strcmp(pkg_info->base, "xcursor-dmz"));
TEST_CHECK(!strcmp(pkg_info->version, "0.4.5-2")); TEST_CHECK(!strcmp(pkg_info->version, "0.4.5-2"));
TEST_CHECK(!strcmp(pkg_info->description, "Style neutral, scalable cursor theme")); TEST_CHECK(!strcmp(pkg_info->description, "Style neutral, scalable cursor theme"));
TEST_CHECK(!strcmp(pkg_info->url, "https://packages.debian.org/sid/dmz-cursor-theme")); TEST_CHECK(!strcmp(pkg_info->url, "https://packages.debian.org/sid/dmz-cursor-theme"));
TEST_CHECK(pkg_info->build_date == 1673751613); TEST_CHECK(pkg_info->build_date == 1673751613);
TEST_CHECK(!strcmp(pkg_info->packager, "Unknown Packager")); TEST_CHECK(!strcmp(pkg_info->packager, "Unknown Packager"));
TEST_CHECK(pkg_info->size == 3469584); TEST_CHECK(pkg_info->size == 3469584);
TEST_CHECK(!strcmp(pkg_info->arch, "any")); TEST_CHECK(!strcmp(pkg_info->arch, "any"));
TEST_CHECK(!strcmp(pkg_info->licenses->array[0], "MIT")); TEST_CHECK(!strcmp(pkg_info->licenses->array[0], "MIT"));
TEST_CHECK(!strcmp(pkg_info->replaces->array[0], "test1")); TEST_CHECK(!strcmp(pkg_info->replaces->array[0], "test1"));
TEST_CHECK(!strcmp(pkg_info->groups->array[0], "x11")); TEST_CHECK(!strcmp(pkg_info->groups->array[0], "x11"));
TEST_CHECK(!strcmp(pkg_info->conflicts->array[0], "test2")); TEST_CHECK(!strcmp(pkg_info->conflicts->array[0], "test2"));
TEST_CHECK(!strcmp(pkg_info->conflicts->array[1], "test3")); TEST_CHECK(!strcmp(pkg_info->conflicts->array[1], "test3"));
TEST_CHECK(!strcmp(pkg_info->provides->array[0], "test4")); TEST_CHECK(!strcmp(pkg_info->provides->array[0], "test4"));
TEST_CHECK(!strcmp(pkg_info->depends->array[0], "test5")); TEST_CHECK(!strcmp(pkg_info->depends->array[0], "test5"));
TEST_CHECK(!strcmp(pkg_info->depends->array[1], "test6")); TEST_CHECK(!strcmp(pkg_info->depends->array[1], "test6"));
TEST_CHECK(!strcmp(pkg_info->optdepends->array[0], "test7")); TEST_CHECK(!strcmp(pkg_info->optdepends->array[0], "test7"));
TEST_CHECK(!strcmp(pkg_info->makedepends->array[0], "xorg-xcursorgen")); TEST_CHECK(!strcmp(pkg_info->makedepends->array[0], "xorg-xcursorgen"));
TEST_CHECK(!strcmp(pkg_info->checkdepends->array[0], "test8")); TEST_CHECK(!strcmp(pkg_info->checkdepends->array[0], "test8"));
}
}
void test_pkg_read_archive_files() {
void test_pkg_read_archive_files() { Pkg *pkg = package_read_archive("./test/package/xcursor-dmz-0.4.5-2-any.pkg.tar.zst");
Pkg *pkg = package_read_archive("./test/package/xcursor-dmz-0.4.5-2-any.pkg.tar.zst"); TEST_ASSERT_(pkg != NULL, "failure parsing pkg archive");
TEST_ASSERT_(pkg != NULL, "failure parsing pkg archive");
FILE *f = fopen("./test/package/files", "r");
FILE *f = fopen("./test/package/files", "r"); TEST_ASSERT_(f != NULL, "could not find test files file in ./test/package");
TEST_ASSERT_(f != NULL, "could not find test files file in ./test/package"); char buff[128];
char *buff = malloc(sizeof(char) * 128); size_t i = 0;
size_t i = 0;
while ((fgets(buff, 128, f)) != NULL || i < pkg->files->size) {
while ((fgets(buff, 128, f)) != NULL || i < pkg->files->size) { if (buff[strlen(buff) - 1] == '\n') {
if (buff[strlen(buff) - 1] == '\n') { buff[strlen(buff) - 1] = '\0';
buff[strlen(buff) - 1] = '\0'; }
}
TEST_CHECK_(!strcmp(pkg->files->array[i], buff), "%s != %s", pkg->files->array[i], buff);
TEST_CHECK_(!strcmp(pkg->files->array[i], buff), "%s != %s", pkg->files->array[i], buff); i++;
i++; }
} TEST_CHECK(pkg->compression = 14);
TEST_CHECK(pkg->compression = 14);
}
}
void test_pkg_read_archive_desc() {
void test_pkg_read_archive_desc() { Pkg *pkg = package_read_archive("./test/package/xcursor-dmz-0.4.5-2-any.pkg.tar.zst");
Pkg *pkg = package_read_archive("./test/package/xcursor-dmz-0.4.5-2-any.pkg.tar.zst"); TEST_ASSERT_(pkg != NULL, "failure parsing pkg archive");
TEST_ASSERT_(pkg != NULL, "failure parsing pkg archive");
char *description = package_to_description(pkg);
char *description = package_to_description(pkg);
FILE *f = fopen("./test/package/desc", "r");
FILE *f = fopen("./test/package/desc", "r"); TEST_ASSERT_(f != NULL, "could not find test desc file in ./test/package");
TEST_ASSERT_(f != NULL, "could not find test desc file in ./test/package"); fseek(f, 0, SEEK_END);
fseek(f, 0, SEEK_END); size_t size = ftell(f);
size_t size = ftell(f); rewind(f);
rewind(f); char *desc = malloc(size);
char *desc = malloc(size); fread(desc, 1, size, f);
fread(desc, 1, size, f); fclose(f);
fclose(f);
TEST_CHECK(!strcmp(description, desc));
TEST_CHECK(!strcmp(description, desc)); }
} TEST_LIST = {
{"pkg_info_valid_parse", test_pkg_info_parse},
TEST_LIST = { {"pkg_read_archive_files", test_pkg_read_archive_files},
{"pkg_info_valid_parse", test_pkg_info_parse}, {"pkg_read_archive_desc", test_pkg_read_archive_desc},
{"pkg_read_archive_files", test_pkg_read_archive_files}, {NULL, NULL}
{"pkg_read_archive_desc", test_pkg_read_archive_desc}, };
{NULL, NULL}
};