From ba6731eae80d1c6e55781557f7b0b32379146f92 Mon Sep 17 00:00:00 2001 From: luishernandez <lahr730@gmail.com> Date: Sun, 2 Mar 2025 15:28:54 -0500 Subject: [PATCH] other test file --- bats/student_tests.sh | 52 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 52 insertions(+) create mode 100644 bats/student_tests.sh diff --git a/bats/student_tests.sh b/bats/student_tests.sh new file mode 100644 index 0000000..19f78b4 --- /dev/null +++ b/bats/student_tests.sh @@ -0,0 +1,52 @@ +#!/usr/bin/env bats + +# File: student_tests.sh +# +# A simple unit test suite for our shell + +@test "Example: check ls runs without errors" { + run ./dsh <<EOF +ls +exit +EOF + # Assert that the shell exited with status 0. + [ "$status" -eq 0 ] +} + +@test "Echo preserves quoted spaces" { + run ./dsh <<EOF +echo "hello, world" +exit +EOF + [ "$status" -eq 0 ] + # Check that the exact quoted string (with extra spaces) appears in the output. + [[ "$output" =~ "hello, world" ]] +} + +@test "Built-in cd changes directory" { + # This test uses 'pwd' to capture the current directory, then changes directory. + # It assumes that moving to the parent directory changes the pwd output. + run ./dsh <<EOF +pwd +cd .. +pwd +exit +EOF + [ "$status" -eq 0 ] + # Extract directory outputs. + # Depending on your prompt, the actual pwd lines might not be on fixed lines. + # Here we assume the first and third non-empty output lines are from pwd. + dir1=$(echo "$output" | sed '/^$/d' | sed -n '1p') + dir2=$(echo "$output" | sed '/^$/d' | sed -n '3p') + [ "$dir1" != "$dir2" ] +} + +@test "Empty input prints warning" { + run ./dsh <<EOF + +exit +EOF + [ "$status" -eq 0 ] + # Assume that a warning message contains the word "warning". + [[ "$output" =~ warning ]] +} -- GitLab