mirror of
https://github.com/cuberite/libevent.git
synced 2025-09-13 14:26:30 -04:00
Simplify windows commandname logic in tinytest
Instead of using a dup'd pointer, let's use a static array, so we don't need to free it. This patch also makes tinytest build on non-windows again.
This commit is contained in:
parent
57def3460a
commit
812d42e886
@ -66,8 +66,8 @@ const char *cur_test_prefix = NULL; /**< prefix of the current test group */
|
|||||||
const char *cur_test_name = NULL;
|
const char *cur_test_name = NULL;
|
||||||
|
|
||||||
#ifdef WIN32
|
#ifdef WIN32
|
||||||
/** Pointer to argv[0] for win32. */
|
/* Copy of argv[0] for win32. */
|
||||||
static char *commandname = NULL;
|
static char commandname[MAX_PATH+1];
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
static void usage(struct testgroup_t *groups, int list_groups)
|
static void usage(struct testgroup_t *groups, int list_groups)
|
||||||
@ -291,19 +291,12 @@ tinytest_main(int c, const char **v, struct testgroup_t *groups)
|
|||||||
int i, j, n=0;
|
int i, j, n=0;
|
||||||
|
|
||||||
#ifdef WIN32
|
#ifdef WIN32
|
||||||
const char* sp = strrchr (v[0], '.');
|
const char *sp = strrchr(v[0], '.');
|
||||||
if (0 != sp) {
|
const char *extension = "";
|
||||||
if (0 != stricmp (sp, ".exe")) { /* not exe extension */
|
if (!sp || stricmp(sp, ".exe"))
|
||||||
sp = 0;
|
extension = ".exe"; /* Add an exe so CreateProcess will work */
|
||||||
}
|
snprintf(commandname, sizeof(commandname), "%s%s", v[0], extension);
|
||||||
}
|
commandname[MAX_PATH]='\0';
|
||||||
if (0 == sp) {
|
|
||||||
commandname = (char*) malloc (strlen(v[0]) + 5);
|
|
||||||
strcpy (commandname, v[0]);
|
|
||||||
strcat (commandname, ".exe");
|
|
||||||
}
|
|
||||||
else
|
|
||||||
commandname = strdup (v[0]);
|
|
||||||
#endif
|
#endif
|
||||||
for (i=1; i<c; ++i) {
|
for (i=1; i<c; ++i) {
|
||||||
if (v[i][0] == '-') {
|
if (v[i][0] == '-') {
|
||||||
@ -326,7 +319,6 @@ tinytest_main(int c, const char **v, struct testgroup_t *groups)
|
|||||||
usage(groups, 1);
|
usage(groups, 1);
|
||||||
} else {
|
} else {
|
||||||
printf("Unknown option %s. Try --help\n",v[i]);
|
printf("Unknown option %s. Try --help\n",v[i]);
|
||||||
free (commandname);
|
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
@ -340,7 +332,6 @@ tinytest_main(int c, const char **v, struct testgroup_t *groups)
|
|||||||
}
|
}
|
||||||
if (!_tinytest_set_flag(groups, test, flag)) {
|
if (!_tinytest_set_flag(groups, test, flag)) {
|
||||||
printf("No such test as %s!\n", v[i]);
|
printf("No such test as %s!\n", v[i]);
|
||||||
free (commandname);
|
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -368,8 +359,6 @@ tinytest_main(int c, const char **v, struct testgroup_t *groups)
|
|||||||
else if (opt_verbosity >= 1)
|
else if (opt_verbosity >= 1)
|
||||||
printf("%d tests ok. (%d skipped)\n", n_ok, n_skipped);
|
printf("%d tests ok. (%d skipped)\n", n_ok, n_skipped);
|
||||||
|
|
||||||
free (commandname);
|
|
||||||
|
|
||||||
return (n_bad == 0) ? 0 : 1;
|
return (n_bad == 0) ? 0 : 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user