ascii-chat
Binary v0.16.50-198-g78f51665f
Library lib/v0.3.2-2240-g78f51665f
Video chat in your terminal
Loading...
Searching...
No Matches
tests/common.c
Go to the documentation of this file.
1
6
7/* Storage capacities in elements; text buffers include the terminating NUL. */
8#define TESTS_COMMON_BINARY_PATH_BUFFER_SIZE 256
9
10#include <stdbool.h>
11#include <stdlib.h>
12
13#ifndef _WIN32
14#include <unistd.h>
15#endif
16
17#include <ascii-chat/common.h>
18
19const char *test_get_binary_path(void) {
20 static char binary_path[TESTS_COMMON_BINARY_PATH_BUFFER_SIZE];
21 static bool initialized = false;
22
23 if (initialized) {
24 return binary_path;
25 }
26
27#ifdef _WIN32
28 // Windows: try several paths
29 const char *candidates[] = {
30 "./build/bin/ascii-chat.exe",
31 "./bin/ascii-chat.exe",
32 "ascii-chat.exe",
33 };
34 const char *fallback = "./build/bin/ascii-chat.exe";
35#else
36 // Check if we're in Docker (/.dockerenv file exists)
37 bool in_docker = (access("/.dockerenv", F_OK) == 0);
38 const char *build_dir = SAFE_GETENV("BUILD_DIR");
39
40 // Try BUILD_DIR first if set
41 if (build_dir) {
42 safe_snprintf(binary_path, sizeof(binary_path), "%s/bin/ascii-chat", build_dir);
43 if (access(binary_path, X_OK) == 0) {
44 initialized = true;
45 return binary_path;
46 }
47 }
48
49 // Try several paths in order of preference
50 const char *candidates[] = {
51 // Relative paths from repo root
52 in_docker ? "./build_docker/bin/ascii-chat" : "./build/bin/ascii-chat",
53 // Relative paths from build directory (when ctest runs from there)
54 "./bin/ascii-chat",
55 // Absolute paths for Docker
56 in_docker ? "/app/build_docker/bin/ascii-chat" : NULL,
57 };
58 const char *fallback = in_docker ? "./build_docker/bin/ascii-chat" : "./build/bin/ascii-chat";
59#endif
60
61 // Try each candidate path
62 for (size_t i = 0; i < sizeof(candidates) / sizeof(candidates[0]); i++) {
63 if (candidates[i] && access(candidates[i], X_OK) == 0) {
64 safe_snprintf(binary_path, sizeof(binary_path), "%s", candidates[i]);
65 initialized = true;
66 return binary_path;
67 }
68 }
69
70 // Fallback to default (will likely fail but gives useful error)
71 safe_snprintf(binary_path, sizeof(binary_path), "%s", fallback);
72 initialized = true;
73 return binary_path;
74}
#define SAFE_GETENV(name)
const char * test_get_binary_path(void)
Get the path to the ascii-chat binary for integration tests.
⚙️ Common definitions, error codes, macros, and types shared throughout the application
bool initialized
Definition mmap.c:41
#define TESTS_COMMON_BINARY_PATH_BUFFER_SIZE
Definition tests/common.c:8