Skip to content
Snippets Groups Projects
Commit 6ddb516a authored by jl4589's avatar jl4589
Browse files

added students tests

parent f3d702a5
Branches
No related tags found
No related merge requests found
File added
...@@ -4,6 +4,18 @@ ...@@ -4,6 +4,18 @@
# #
# Create your unit tests suit in this file # Create your unit tests suit in this file
start_server() {
./dsh -s -i 127.0.0.1 -p 5678 > /dev/null 2>&1 &
SERVER_PID=$!
sleep 1 # Give the server time to start
}
# Helper function to stop the server
stop_server() {
kill $SERVER_PID 2>/dev/null || true
wait $SERVER_PID 2>/dev/null || true
}
@test "Example: check ls runs without errors" { @test "Example: check ls runs without errors" {
run ./dsh <<EOF run ./dsh <<EOF
ls ls
...@@ -12,3 +24,66 @@ EOF ...@@ -12,3 +24,66 @@ EOF
# Assertions # Assertions
[ "$status" -eq 0 ] [ "$status" -eq 0 ]
} }
@test "Start server and client without errors" {
# Start the server
start_server
# Check if the server is running
run ps -p $SERVER_PID
[ "$status" -eq 0 ]
# Start the client and send a simple command
run ./dsh -c -i 127.0.0.1 -p 5678 <<EOF
echo Hello, World!
exit
EOF
# Assertions
[ "$status" -eq 0 ]
[[ "$output" == *"Hello, World!"* ]]
stop_server
}
@test "Server handles pipes" {
start_server
echo "testfile1" > testfile1.txt
echo "testfile2" >> testfile1.txt
run ./dsh -c -i 127.0.0.1 -p 5678 <<EOF
ls -1 | wc -l
exit
EOF
[ "$status" -eq 0 ]
[[ "$output" == *"2"* ]]
rm -f testfile1.txt
stop_server
}
@test "Stop server with stop-server command" {
start_server
run ps -p $SERVER_PID
[ "$status" -eq 0 ]
run ./dsh -c -i 127.0.0.1 -p 5678 <<EOF
stop-server
EOF
[ "$status" -eq 0 ]
sleep 1
run ps -p $SERVER_PID
[ "$status" -ne 0 ]
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment