diff --git a/WEEK-7/bats/student_tests.sh b/WEEK-7/bats/student_tests.sh new file mode 100644 index 0000000000000000000000000000000000000000..8b20e75f4873c173c576588d259b87ce51650118 --- /dev/null +++ b/WEEK-7/bats/student_tests.sh @@ -0,0 +1,34 @@ +#!/usr/bin/env bats + +@test "Basic piping: ls | grep .c" { + run ./dsh <<EOF +ls | grep .c +EOF + [ "$status" -eq 0 ] +} + +@test "Count words using wc -w" { + run ./dsh <<EOF +echo "Hello World" | wc -w +EOF + output_trimmed=$(echo "$output" | tr -cd '0-9') # Remove non-numeric characters + echo "DEBUG: Output was '$output_trimmed'" + [ "$output_trimmed" = "2" ] +} + + +@test "Invalid command in pipe" { + run ./dsh <<EOF +ls | invalid_cmd +EOF + echo "DEBUG: Output was '$output'" + [[ "$output" == *"error: command not found"* ]] || [[ "$output" == *"command not found"* ]] +} + + +@test "Multiple pipes working" { + run ./dsh <<EOF +cat dshlib.c | grep "int" | wc -l +EOF + [ "$status" -eq 0 ] +}