mirror of
https://github.com/jart/cosmopolitan.git
synced 2025-08-07 10:20:29 +00:00
Turn on tests, check argv[0]
This commit is contained in:
parent
316b72e331
commit
d49857e4fa
1 changed files with 9 additions and 14 deletions
|
@ -28,25 +28,20 @@
|
|||
#include "libc/testlib/testlib.h"
|
||||
|
||||
static char *self;
|
||||
static bool skipcosmotests;
|
||||
|
||||
void SetUp(void) {
|
||||
self = GetProgramExecutableName();
|
||||
}
|
||||
|
||||
void SetUpOnce(void) {
|
||||
if (!getenv("COSMOPOLITAN_PROGRAM_EXECUTABLE")) {
|
||||
fprintf(stderr,
|
||||
"warning: old ape loader detected; skipping some tests %m\n");
|
||||
skipcosmotests = true;
|
||||
}
|
||||
testlib_enable_tmp_setup_teardown();
|
||||
}
|
||||
|
||||
__attribute__((__constructor__)) static void Child(int argc, char *argv[]) {
|
||||
if (argc >= 2 && !strcmp(argv[1], "Child")) {
|
||||
ASSERT_EQ(3, argc);
|
||||
ASSERT_EQ(argc, 4);
|
||||
EXPECT_STREQ(argv[2], GetProgramExecutableName());
|
||||
EXPECT_STREQ(argv[3], argv[0]);
|
||||
exit(g_testlib_failed);
|
||||
}
|
||||
}
|
||||
|
@ -59,33 +54,33 @@ TEST(GetProgramExecutableName, ofThisFile) {
|
|||
|
||||
TEST(GetProgramExecutableName, nullEnv) {
|
||||
SPAWN(fork);
|
||||
execve(self, (char *[]){self, "Child", self, 0}, (char *[]){0});
|
||||
execve(self, (char *[]){self, "Child", self, self, 0}, (char *[]){0});
|
||||
abort();
|
||||
EXITS(0);
|
||||
}
|
||||
|
||||
TEST(GetProramExecutableName, weirdArgv0NullEnv) {
|
||||
SPAWN(fork);
|
||||
execve(self, (char *[]){"hello", "Child", self, 0}, (char *[]){0});
|
||||
execve(self, (char *[]){"hello", "Child", self, "hello", 0}, (char *[]){0});
|
||||
abort();
|
||||
EXITS(0);
|
||||
}
|
||||
|
||||
TEST(GetProgramExecutableName, weirdArgv0CosmoVar) {
|
||||
if (skipcosmotests) return;
|
||||
char buf[32 + PATH_MAX];
|
||||
stpcpy(stpcpy(buf, "COSMOPOLITAN_PROGRAM_EXECUTABLE="), self);
|
||||
SPAWN(fork);
|
||||
execve(self, (char *[]){"hello", "Child", self, 0}, (char *[]){buf, 0});
|
||||
execve(self, (char *[]){"hello", "Child", self, "hello", 0},
|
||||
(char *[]){buf, 0});
|
||||
abort();
|
||||
EXITS(0);
|
||||
}
|
||||
|
||||
TEST(GetProgramExecutableName, weirdArgv0WrongCosmoVar) {
|
||||
if (skipcosmotests) return;
|
||||
char *bad = "COSMOPOLITAN_PROGRAM_EXECUTABLE=hi";
|
||||
SPAWN(fork);
|
||||
execve(self, (char *[]){"hello", "Child", self, 0}, (char *[]){bad, 0});
|
||||
execve(self, (char *[]){"hello", "Child", self, "hello", 0},
|
||||
(char *[]){bad, 0});
|
||||
abort();
|
||||
EXITS(0);
|
||||
}
|
||||
|
@ -104,7 +99,7 @@ TEST(GetProgramExecutableName, movedSelf) {
|
|||
ASSERT_NE(NULL, getcwd(buf, BUFSIZ - 5));
|
||||
stpcpy(buf + strlen(buf), "/test");
|
||||
SPAWN(fork);
|
||||
execve(buf, (char *[]){"hello", "Child", buf, 0}, (char *[]){0});
|
||||
execve(buf, (char *[]){"hello", "Child", buf, "hello", 0}, (char *[]){0});
|
||||
abort();
|
||||
EXITS(0);
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue