Skip to content
This repository has been archived by the owner. It is now read-only.
Permalink
Browse files

Fix test-get-currentexe on darwin.

Darwin uses _NSGetExecutablePath to determine
the path of an executable, but that can return
an absolute path. This patch tweaks the executable
path to strip off a potential "./" prefix from
argv[0], which fixes the test.
  • Loading branch information...
erickt authored and ry committed Aug 29, 2011
1 parent 70bc6c0 commit f4e2d5559fabbf60b801d7583a4d3384a8c63fa7
Showing with 12 additions and 2 deletions.
  1. +12 −2 test/test-get-currentexe.c
@@ -30,15 +30,25 @@ TEST_IMPL(get_currentexe) {
char buffer[PATHMAX];
size_t size;
char* match;
char* path;
int r;

size = sizeof(buffer) / sizeof(buffer[0]);
r = uv_exepath(buffer, &size);
ASSERT(!r);

match = strstr(buffer, executable_path);
/* uv_exepath can return an absolute path on darwin, so if the test runner
* was run with a relative prefix of "./", we need to strip that prefix off
* executable_path or we'll fail. */
if (executable_path[0] == '.' && executable_path[1] == '/') {
path = executable_path + 2;
} else {
path = executable_path;
}

match = strstr(buffer, path);
/* Verify that the path returned from uv_exepath is a subdirectory of executable_path */
ASSERT(match && !strcmp(match, executable_path));
ASSERT(match && !strcmp(match, path));
ASSERT(size == strlen(buffer));

/* Negative tests */

0 comments on commit f4e2d55

Please sign in to comment.
You can’t perform that action at this time.