From 943581a4d59b42a684666f146324d908b0dac428 Mon Sep 17 00:00:00 2001 From: Tavian Barnes Date: Wed, 27 Mar 2024 15:27:26 -0400 Subject: tests/xspawn: Test path resolution failure --- tests/xspawn.c | 33 ++++++++++++++++++++++++++++++--- 1 file 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; } -- cgit v1.2.3