Skip to content
Snippets Groups Projects
Commit ba6731ea authored by luishernandez's avatar luishernandez
Browse files

other test file

parent 94d1a25a
No related branches found
No related tags found
No related merge requests found
#!/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 ]]
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment