summaryrefslogtreecommitdiffstats
path: root/tests/xspawn.c
diff options
context:
space:
mode:
authorTavian Barnes <tavianator@tavianator.com>2024-03-27 15:27:26 -0400
committerTavian Barnes <tavianator@tavianator.com>2024-03-27 15:27:26 -0400
commit943581a4d59b42a684666f146324d908b0dac428 (patch)
treef9cc5c902a62e946802ae409a8ed26adfff3c522 /tests/xspawn.c
parent5b58f0223c18aed1b2bd3e8224a3f2f3760e9ada (diff)
downloadbfs-943581a4d59b42a684666f146324d908b0dac428.tar.xz
tests/xspawn: Test path resolution failure
Diffstat (limited to 'tests/xspawn.c')
-rw-r--r--tests/xspawn.c33
1 files changed, 30 insertions, 3 deletions
diff --git a/tests/xspawn.c b/tests/xspawn.c
index d1d5473..5f80e76 100644
--- a/tests/xspawn.c
+++ b/tests/xspawn.c
@@ -50,7 +50,7 @@ fail:
}
/** Check that we resolve executables in $PATH correctly. */
-static bool check_path_resolution(bool use_posix) {
+static bool check_use_path(bool use_posix) {
bool ret = true;
struct bfs_spawn spawn;
@@ -146,11 +146,38 @@ out:
return ret;
}
+/** Check path resolution of non-existent executables. */
+static bool check_enoent(bool use_posix) {
+ bool ret = true;
+
+ struct bfs_spawn spawn;
+ ret &= bfs_pcheck(bfs_spawn_init(&spawn) == 0);
+ if (!ret) {
+ goto out;
+ }
+
+ spawn.flags |= BFS_SPAWN_USE_PATH;
+ if (!use_posix) {
+ spawn.flags &= ~BFS_SPAWN_USE_POSIX;
+ }
+
+ char *argv[] = {"eW6f5RM9Qi", NULL};
+ pid_t pid = bfs_spawn("eW6f5RM9Qi", &spawn, argv, NULL);
+ ret &= bfs_pcheck(pid < 0 && errno == ENOENT, "bfs_spawn()");
+
+ ret &= bfs_pcheck(bfs_spawn_destroy(&spawn) == 0);
+out:
+ return ret;
+}
+
bool check_xspawn(void) {
bool ret = true;
- ret &= check_path_resolution(true);
- ret &= check_path_resolution(false);
+ ret &= check_use_path(true);
+ ret &= check_use_path(false);
+
+ ret &= check_enoent(true);
+ ret &= check_enoent(false);
return ret;
}