test_executor.c
Comprehensive test suite for the executor module.
Tests: exec_utils, command_search, redirections, heredoc, logical operators, pipeline, subshell, block, background, simple command execution (builtins + externals).
Uses functional stubs from test_stubs.c for dependencies.
Functions
-
static int fork_exit_and_get(int code)
-
static int fork_signal_and_get(int sig)
-
static void test_get_exit_status(void)
-
static void test_split_assignment(void)
-
static void test_find_command(void)
-
static void test_redirections_output(void)
-
static void test_redirections_append(void)
-
static void test_redirections_input(void)
-
static int write_to_pipe(char *content)
-
static void test_redirections_heredoc_in_list(void)
-
static void test_redirections_bad_file(void)
-
static void test_redirections_save_restore(void)
-
static void test_execute_and(void)
-
static void test_execute_or(void)
-
static void test_execute_sequence(void)
-
static void test_execute_external_command(void)
-
static void test_execute_builtin_command(void)
-
static void test_execute_assignment_only(void)
-
static void test_execute_pipeline(void)
-
static void test_execute_pipeline_three(void)
-
static void test_pipeline_exit_status(void)
-
static void test_execute_subshell(void)
-
static void test_execute_subshell_isolation(void)
-
static void test_execute_block(void)
-
static void test_execute_background(void)
-
static void test_executor_dispatch(void)
-
static void test_complex_logical_chains(void)
-
static void test_builtin_temp_assignments(void)
A
VAR=val builtinassignment is visible to the builtin and restored afterwards.Drives
HOME=/tmp cd: cd with no arguments changes to $HOME, so a successful chdir to /tmp proves the builtin saw the temporary HOME, and HOME reverting to its prior value proves exec_builtin restored it. The process cwd is saved and restored sincecdruns in-process.
-
static void test_pipeline_with_heredoc(void)
-
static void test_sequence_mixed(void)
-
static int run_shell(const char *input, int which_fd, char *out, size_t outsz)
Run ./42sh, feed
inputon stdin, capture one fd, return exit code.which_fdselects the captured stream (1 = stdout, 2 = stderr); the other stream is sent to /dev/null.- Parameters:
input – Command text written to the shell’s stdin.
which_fd – 1 to capture stdout, 2 to capture stderr.
out – Buffer receiving the captured output (NUL-terminated).
outsz – Size of
out.
- Returns:
The shell’s exit code, or -1 on failure.
-
static void test_b1_exit_stops_sequence(void)
B1: a
;list must stop atexit; nothing after it runs.
-
static void test_b1_exit_stops_or_chain(void)
B1: an
||branch must not run onceexithas stopped the shell.
-
static void test_b2_assignment_reaches_pipeline(void)
B2:
FOO=val env | catmust show FOO in the piped command’s env.
-
static void test_b4_not_executable_is_126(void)
B4: a non-executable file invoked by path exits 126 (permission).
-
static void test_b4_missing_path_is_127(void)
B4: a genuinely missing path still exits 127 (not found).
-
void test_executor_suite(void)