1 #include "config_ast.h" // IWYU pragma: keep
2
3 #include <errno.h>
4 #include <stdio.h>
5 #include <stdlib.h>
6 #include <string.h>
7 #include <unistd.h>
8
9 #include "ast.h"
10 #include "terror.h"
11
tmain()12 tmain() {
13 UNUSED(argc);
14 UNUSED(argv);
15 int failed = 0;
16 char *result = NULL;
17 char default_cs_path[BUFSIZ];
18
19 char *custom_path = "/foo:/bar:/baz";
20
21 // Set custom path for testing
22 if (setenv("PATH", custom_path, 1)) {
23 fprintf(stderr, "Failed to set custom path");
24 failed = 1;
25 }
26
27 // Check return value of `pathbin()` when `PATH` is a custom path
28 result = pathbin();
29 if (strcmp(result, custom_path)) {
30 fprintf(stderr, "pathbin() function fails when PATH is set to custom path");
31 failed = 1;
32 }
33
34 // Unset `PATH`
35 if (unsetenv("PATH")) {
36 fprintf(stderr, "Failed to set custom path");
37 failed = 1;
38 }
39
40 // When `PATH` is not set, `pathbin()` gets default value from `confstr()` function
41 if (confstr(_CS_PATH, default_cs_path, BUFSIZ) == 0 && errno == EINVAL) {
42 fprintf(stderr, "Failed to get default cs_path");
43 failed = 1;
44 }
45
46 // Check return value of `pathbin()` when `PATH` is not set
47 result = pathbin();
48 if (strcmp(result, default_cs_path)) {
49 fprintf(stderr, "pathbin() function fails when PATH is not set");
50 failed = 1;
51 }
52
53 texit(failed);
54 }
55