ascii-chat
Binary v0.16.50-198-g78f51665f
Library lib/v0.3.2-2240-g78f51665f
Video chat in your terminal
Loading...
Searching...
No Matches
include/ascii-chat/tests/common.h
Go to the documentation of this file.
1#pragma once
2
3#ifndef M_PI
4#define M_PI 3.14159265358979323846
5#endif
6
41
42/* Storage capacities in elements; text buffers include the terminating NUL. */
43#define TESTS_COMMON_VERSION_BUFFER_SIZE 256
44
45#include <stdint.h>
46#include <stdbool.h>
47
48#ifdef _WIN32
49#ifndef F_OK
50#define F_OK 0
51#endif
52#endif
53
54// Standard C headers
55#include <stdio.h>
56#include <stdlib.h>
57#include <string.h>
58
59// System headers needed by tests
60#ifndef _WIN32
61#include <unistd.h> // For unlink(), access(), etc.
62#endif
63#include <sys/stat.h> // For stat(), struct stat
64
65// =============================================================================
66// Test Environment Detection
67// =============================================================================
68
99static inline bool test_is_in_headless_environment(void) {
100 // Check for CI environment
101 if (getenv("CI") != NULL) {
102 return true;
103 }
104
105 // Docker and WSL detection use POSIX paths and are not applicable to native
106 // Windows test processes.
107#ifndef _WIN32
108 if (access("/.dockerenv", F_OK) == 0) {
109 return true;
110 }
111
112 // Check for WSL (look for "microsoft" or "WSL" in /proc/version)
113 FILE *version_file = fopen("/proc/version", "r");
114 if (version_file) {
115 char version_buf[TESTS_COMMON_VERSION_BUFFER_SIZE];
116 if (fgets(version_buf, sizeof(version_buf), version_file)) {
117 if (strstr(version_buf, "microsoft") || strstr(version_buf, "Microsoft") || strstr(version_buf, "WSL")) {
118 (void)fclose(version_file);
119 return true;
120 }
121 }
122 (void)fclose(version_file);
123 }
124#endif
125
126 return false;
127}
128
129// =============================================================================
130// Test Binary Path Detection
131// =============================================================================
132
167#ifdef __cplusplus
168extern "C" {
169#endif
170const char *test_get_binary_path(void);
171#ifdef __cplusplus
172}
173#endif
const char * test_get_binary_path(void)
Get the path to the ascii-chat binary for integration tests.
#define TESTS_COMMON_VERSION_BUFFER_SIZE
🔤 String Manipulation and Shell Escaping Utilities