diff --git a/bats/student_tests.sh b/bats/student_tests.sh new file mode 100644 index 0000000000000000000000000000000000000000..19f78b40b3b603622723dbcde97366de6e6b965d --- /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 ]] +}