diff options
author | Joseph Hunkeler <jhunkeler@gmail.com> | 2020-04-24 13:42:39 -0400 |
---|---|---|
committer | Joseph Hunkeler <jhunkeler@gmail.com> | 2020-04-24 13:42:39 -0400 |
commit | 7b6c6cb4cad10e3aac170dc4204b4ca782974a28 (patch) | |
tree | fa107692adbd4eaff3885e87fb7621df6d26b83d /tests | |
parent | 532273c0a91e729bdaf5e522bc2e827ec7f5fd8f (diff) | |
download | spmc-7b6c6cb4cad10e3aac170dc4204b4ca782974a28.tar.gz |
Find libraries on darwin and linux
Diffstat (limited to 'tests')
-rw-r--r-- | tests/test_shlib_spm_shlib_deps.c | 45 |
1 files changed, 44 insertions, 1 deletions
diff --git a/tests/test_shlib_spm_shlib_deps.c b/tests/test_shlib_spm_shlib_deps.c index 40e52f8..46a06db 100644 --- a/tests/test_shlib_spm_shlib_deps.c +++ b/tests/test_shlib_spm_shlib_deps.c @@ -1,6 +1,45 @@ #include "spm.h" #include "framework.h" +static char *LIBRARY_SEARCH_PATH[] = { +#if OS_DARWIN + "/usr/lib", + "/usr/local/lib", +#elif OS_LINUX + "/lib", + "/usr/lib", + "/usr/local/lib", + "/lib64", + "/usr/lib64", + "/usr/local/lib64", +#endif + NULL, +}; + +/** + * Find a library based on known library search paths. This cannot handle macos-style `@string` paths, and + * will not follow RPATHs. + * @param name + * @return path to library (or NULL) + */ +static char *find_library(const char *name) { + char *path = NULL; + + if (strstr(name, DIRSEPS) != NULL) { + return strdup(name); + } + + for (size_t i = 0; LIBRARY_SEARCH_PATH[i] != NULL; i++) { + path = join_ex(path, DIRSEPS, LIBRARY_SEARCH_PATH[i], name); + if (path != NULL && exists(path) == 0) { + break; + } + free(path); + path = NULL; + } + return path; +} + struct TestCase testCase[] = { {.caseValue.sptr = "/bin/sh", .truthValue.signed_integer = 0}, {.caseValue.sptr = "/usr/bin/tar", .truthValue.signed_integer = 0}, @@ -9,11 +48,13 @@ struct TestCase testCase[] = { }; size_t numCases = sizeof(testCase) / sizeof(struct TestCase); + int main(int argc, char *argv[]) { for (size_t i = 0; i < numCases; i++) { StrList *result = shlib_deps(testCase[i].caseValue.sptr); if (result == NULL && testCase[i].truthValue.signed_integer < 0) { // expected failure + fprintf(stderr, "case %zu: trapped expected failure (ignore any stderr text)\n", i); continue; } @@ -21,8 +62,10 @@ int main(int argc, char *argv[]) { myassert(result != NULL, "case %zu: unexpected NULL", i); for (size_t j = 0; j < strlist_count(result); j++) { char *item = strlist_item(result, j); - myassert(exists(item) == testCase[i].truthValue.signed_integer, + char *libpath = find_library(item); + myassert(libpath != NULL, "library record found, but does not exist: '%s' (your OS is broken)\n", item); + free(libpath); } strlist_free(result); } |