diff options
author | Marius Ungureanu <marius.ungureanu@xamarin.com> | 2015-10-08 21:53:49 +0300 |
---|---|---|
committer | Marius Ungureanu <marius.ungureanu@xamarin.com> | 2015-10-08 21:53:49 +0300 |
commit | 7df2bc9d474fea6e32b6cf14d78b844dd79e99e3 (patch) | |
tree | df1513120ce5b74d330cb94602943ad64c7a29f2 /main/build | |
parent | 73e9880764f4791ddd90f78c6aea73037752b1f5 (diff) |
[Mac] Robustify update_environment test.
Diffstat (limited to 'main/build')
-rw-r--r-- | main/build/MacOSX/monostub-test.m | 57 | ||||
-rw-r--r-- | main/build/MacOSX/monostub-utils.h | 6 |
2 files changed, 51 insertions, 12 deletions
diff --git a/main/build/MacOSX/monostub-test.m b/main/build/MacOSX/monostub-test.m index 2c540f8ea2..7cb4b1596e 100644 --- a/main/build/MacOSX/monostub-test.m +++ b/main/build/MacOSX/monostub-test.m @@ -150,23 +150,62 @@ void test_push_env(void) } } +void check_path_has_components(char *path, const char **components, int count) +{ + char *token, *tofree, *copy; + + + for (int i = 0; i < count; ++i) { + BOOL found = FALSE; + tofree = copy = strdup(path); + + while ((token = strsep(©, ":"))) { + if (!strncmp(token, components[i], strlen(components[i]))) + found = TRUE; + } + + if (!found) { + printf("Expected '%s'\nIn '%s'", components[i], tofree); + fail(); + } + free(tofree); + } +} + void test_update_environment(void) { - const char *added_path = "/Library/Frameworks/Mono.framework/Commands:./Resources:./MacOS:/Library/Frameworks/Mono.framework/Versions/Current/bin"; + const char *path_components[] = { + "/Library/Frameworks/Mono.framework/Commands", + "./Resources", + "./MacOS", + "/Library/Frameworks/Mono.framework/Versions/Current/bin", + }; + const char *dyld_components[] = { + "/usr/local/lib", + "/Library/Developer/CommandLineTools/usr/lib", + "/usr/lib", + "/lib", + "/Library/Frameworks/Mono.framework/Versions/Current/lib", + "./Resources/lib/monodevelop/bin", + "./Resources/lib", + }; + const char *pkg_components[] = { + "./Resources/lib/pkgconfig", + "/Library/Frameworks/Mono.framework/External/pkgconfig", + }; + const char *gac_components[] = { + "./Resources", + }; // Check that we only get updates one time, that's how monostub works. check_bool_equal(TRUE, update_environment(".")); check_bool_equal(FALSE, update_environment(".")); - check_string_equal("/usr/local/lib:/Library/Developer/CommandLineTools/usr/lib:/usr/lib:/lib:/Library/Frameworks/Mono.framework/Versions/Current/lib:./Resources/lib/monodevelop/bin:./Resources/lib", getenv("DYLD_FALLBACK_LIBRARY_PATH")); - check_string_equal("./Resources/lib/pkgconfig:/Library/Frameworks/Mono.framework/External/pkgconfig", getenv("PKG_CONFIG_PATH")); - check_string_equal("./Resources", getenv("MONO_GAC_PREFIX")); - - const char *new_path = getenv("PATH"); - // Check we have the new components in the beginning. - if (strstr(new_path, added_path) != new_path) - fail(); + check_path_has_components(getenv("DYLD_FALLBACK_LIBRARY_PATH"), dyld_components, sizeof(dyld_components) / sizeof(char *)); + check_path_has_components(getenv("PATH"), path_components, sizeof(path_components) / sizeof(char *)); + check_path_has_components(getenv("PKG_CONFIG_PATH"), pkg_components, sizeof(pkg_components) / sizeof(char *)); + check_path_has_components(getenv("MONO_GAC_PREFIX"), gac_components, sizeof(gac_components) / sizeof(char *)); } void (*tests[])(void) = { diff --git a/main/build/MacOSX/monostub-utils.h b/main/build/MacOSX/monostub-utils.h index 86e2dfade8..03f78d1785 100644 --- a/main/build/MacOSX/monostub-utils.h +++ b/main/build/MacOSX/monostub-utils.h @@ -121,9 +121,9 @@ push_env (const char *variable, const char *value) BOOL updated = YES; if ((current = getenv (variable)) && *current) { - char *token, *copy; + char *token, *copy, *tofree; - copy = strdup (current); + tofree = copy = strdup (current); len = strlen (value); while ((token = strsep(©, ":"))) { if (!strncmp (token, value, len)) { @@ -144,7 +144,7 @@ push_env (const char *variable, const char *value) setenv (variable, buf, 1); free (buf); done: - free (copy); + free (tofree); } else { setenv (variable, value, 1); } |