4 #include <mach-o/dyld.h>
8 extern struct mach_header_64 __dso_handle
;
10 extern struct mach_header __dso_handle
;
13 static bool sIsATTY
= false;
14 static const char * sTestName
= NULL
;
15 static uint64_t sTestCount
= 0;
17 __attribute__((constructor
))
19 void BEGIN(int argc
, const char* argv
[], const char* envp
[]) {
20 // Set up values we need to print in PASS() and FAIL()
21 sIsATTY
= isatty(fileno(stdout
));
23 // Early returnif this not the main executbale, we only need to print the [BEGIN] line once
24 if (__dso_handle
.filetype
!= MH_EXECUTE
) {
28 for (uint32_t i
= 0; envp
[i
] != NULL
; ++i
) {
29 if (strncmp("DYLD_", envp
[i
], 5) == 0) {
30 printf(" %s", envp
[i
]);
33 char buffer
[MAXPATHLEN
];
34 uint32_t bufsize
= MAXPATHLEN
;
35 if (_NSGetExecutablePath(buffer
, &bufsize
) == 0) {
36 printf(" %s", buffer
);
38 printf(" %s", argv
[0]);
40 for (uint32_t i
= 1; i
< argc
; ++i
) {
41 printf (" %s", argv
[i
]);
46 __attribute__((format(printf
, 1, 2)))
48 void PASS(const char *format
, ...) {
50 printf("[\033[0;32mPASS\033[0m] %s (%llu): ", sTestName
, sTestCount
++);
52 printf("[PASS] %s (%llu): ", sTestName
, sTestCount
++);
55 va_start (args
, format
);
56 vprintf (format
, args
);
61 __attribute__((format(printf
, 1, 2)))
63 void FAIL(const char *format
, ...) {
65 printf("[\033[0;31mFAIL\033[0m] %s (%llu): ", sTestName
, sTestCount
++);
67 printf("[FAIL] %s (%llu): ", sTestName
, sTestCount
++);
70 va_start (args
, format
);
71 vprintf (format
, args
);