Skip to content
Snippets Groups Projects
Commit 2322ab0f authored by Wendy Nguyen's avatar Wendy Nguyen
Browse files

update

parent 73bf2e50
No related branches found
No related tags found
No related merge requests found
No preview for this file type
...@@ -61,6 +61,10 @@ int main() ...@@ -61,6 +61,10 @@ int main()
clist->num = 0; clist->num = 0;
printf("%s", SH_PROMPT); printf("%s", SH_PROMPT);
// flush prompt before encountering any error
fflush(stdout);
if (fgets(cmd_buff, ARG_MAX, stdin) == NULL){ if (fgets(cmd_buff, ARG_MAX, stdin) == NULL){
break; break;
} }
...@@ -76,6 +80,10 @@ int main() ...@@ -76,6 +80,10 @@ int main()
else { else {
// printf("Command line: %s\n", cmd_buff); // printf("Command line: %s\n", cmd_buff);
code = build_cmd_list(cmd_buff, clist); code = build_cmd_list(cmd_buff, clist);
if (code == ERR_TOO_MANY_COMMANDS) {
printf(CMD_ERR_PIPE_LIMIT, CMD_MAX);
}
} }
} }
... ...
......
...@@ -121,8 +121,8 @@ int build_cmd_list(char *cmd_line, command_list_t *clist) ...@@ -121,8 +121,8 @@ int build_cmd_list(char *cmd_line, command_list_t *clist)
} }
if (clist->num > CMD_MAX) { if (clist->num > CMD_MAX) {
printf("dsh> "); // printf("dsh> ");
printf(CMD_ERR_PIPE_LIMIT, CMD_MAX); // printf(CMD_ERR_PIPE_LIMIT, CMD_MAX);
return ERR_TOO_MANY_COMMANDS; return ERR_TOO_MANY_COMMANDS;
} }
... ...
......
#!/usr/bin/env bats
@test "Simple Command" {
run ./dsh <<EOF
test_command
exit
EOF
# Strip all whitespace (spaces, tabs, newlines) from the output
stripped_output=$(echo "$output" | tr -d '[:space:]')
# Expected output with all whitespace removed for easier matching
expected_output="dsh>PARSEDCOMMANDLINE-TOTALCOMMANDS1<1>test_commanddsh>"
# These echo commands will help with debugging and will only print
#if the test fails
echo "Captured stdout:"
echo "Output: $output"
echo "Exit Status: $status"
# Check exact match
[ "$stripped_output" = "$expected_output" ]
# Assertions
[ "$status" -eq 0 ]
}
@test "Simple Command with Args" {
run ./dsh <<EOF
cmd -a1 -a2
exit
EOF
# Strip all whitespace (spaces, tabs, newlines) from the output
stripped_output=$(echo "$output" | tr -d '[:space:]')
# Expected output
expected_output="dsh>PARSEDCOMMANDLINE-TOTALCOMMANDS1<1>cmd[-a1-a2]dsh>"
# These echo commands will help with debugging and will only print
#if the test fails
echo "Captured stdout:"
echo "Output: $output"
echo "Exit Status: $status"
# Check exact match
[ "$stripped_output" = "$expected_output" ]
# Assertions
[ "$status" -eq 0 ]
}
@test "No command provided" {
run ./dsh <<EOF
exit
EOF
# Strip all whitespace (spaces, tabs, newlines) from the output
stripped_output=$(echo "$output" | tr -d '[:space:]')
# Expected output with all whitespace removed for easier matching
expected_output="dsh>warning:nocommandsprovideddsh>"
# These echo commands will help with debugging and will only print
#if the test fails
echo "Captured stdout:"
echo "Output: $output"
echo "Exit Status: $status"
# Check exact match
[ "$stripped_output" = "$expected_output" ]
# Assertions
[ "$status" -eq 0 ]
}
@test "Two commands" {
run ./dsh <<EOF
command_one | command_two
exit
EOF
# Strip all whitespace (spaces, tabs, newlines) from the output
stripped_output=$(echo "$output" | tr -d '[:space:]')
# Expected output with all whitespace removed for easier matching
expected_output="dsh>PARSEDCOMMANDLINE-TOTALCOMMANDS2<1>command_one<2>command_twodsh>"
# These echo commands will help with debugging and will only print
#if the test fails
echo "Captured stdout:"
echo "Output: $output"
echo "Exit Status: $status"
# Check exact match
[ "$stripped_output" = "$expected_output" ]
# Assertions
[ "$status" -eq 0 ]
}
@test "three commands with args" {
run ./dsh <<EOF
cmd1 a1 a2 a3 | cmd2 a4 a5 a6 | cmd3 a7 a8 a9
exit
EOF
# Strip all whitespace (spaces, tabs, newlines) from the output
stripped_output=$(echo "$output" | tr -d '[:space:]')
# Expected output with all whitespace removed for easier matching
expected_output="dsh>PARSEDCOMMANDLINE-TOTALCOMMANDS3<1>cmd1[a1a2a3]<2>cmd2[a4a5a6]<3>cmd3[a7a8a9]dsh>"
# These echo commands will help with debugging and will only print
#if the test fails
echo "Captured stdout:"
echo "Output: $output"
echo "Exit Status: $status"
# Check exact match
[ "$stripped_output" = "$expected_output" ]
# Assertions
[ "$status" -eq 0 ]
}
@test "try max (8) commands" {
run ./dsh <<EOF
cmd1 | cmd2 | cmd3 | cmd4 | cmd5 | cmd6 | cmd7 | cmd8
exit
EOF
# Strip all whitespace (spaces, tabs, newlines) from the output
stripped_output=$(echo "$output" | tr -d '[:space:]')
# Expected output with all whitespace removed for easier matching
expected_output="dsh>PARSEDCOMMANDLINE-TOTALCOMMANDS8<1>cmd1<2>cmd2<3>cmd3<4>cmd4<5>cmd5<6>cmd6<7>cmd7<8>cmd8dsh>"
# These echo commands will help with debugging and will only print
#if the test fails
echo "Captured stdout:"
echo "Output: $output"
echo "Exit Status: $status"
# Check exact match
[ "$stripped_output" = "$expected_output" ]
# Assertions
[ "$status" -eq 0 ]
}
@test "try too many commands" {
run ./dsh <<EOF
cmd1 | cmd2 | cmd3 | cmd4 | cmd5 | cmd6 | cmd7 | cmd8 | cmd9
exit
EOF
# Strip all whitespace (spaces, tabs, newlines) from the output
stripped_output=$(echo "$output" | tr -d '[:space:]')
# Expected output with all whitespace removed for easier matching
expected_output="dsh>error:pipinglimitedto8commandsdsh>"
# These echo commands will help with debugging and will only print
#if the test fails
echo "Captured stdout:"
echo "Your output: $stripped_output"
echo "Expected: $expected_output"
echo "Exit Status: $status"
# Check exact match
[ "$stripped_output" = "$expected_output" ]
# Assertions
[ "$status" -eq 0 ]
}
@test "kitchen sink - multiple commands" {
run ./dsh <<EOF
cmd1
cmd2 arg arg2
p1 | p2
p3 p3a1 p3a2 | p4 p4a1 p4a2
EOF
# Strip all whitespace (spaces, tabs, newlines) from the output
stripped_output=$(echo "$output" | tr -d '[:space:]')
# Expected output with all whitespace removed for easier matching
expected_output="dsh>PARSEDCOMMANDLINE-TOTALCOMMANDS1<1>cmd1dsh>PARSEDCOMMANDLINE-TOTALCOMMANDS1<1>cmd2[argarg2]dsh>PARSEDCOMMANDLINE-TOTALCOMMANDS2<1>p1<2>p2dsh>PARSEDCOMMANDLINE-TOTALCOMMANDS2<1>p3[p3a1p3a2]<2>p4[p4a1p4a2]dsh>"
# These echo commands will help with debugging and will only print
#if the test fails
echo "Captured stdout:"
echo "Output: $output"
echo "Exit Status: $status"
# Check exact match
[ "$stripped_output" = "$expected_output" ]
# Assertions
[ "$status" -eq 0 ]
}
\ No newline at end of file
...@@ -172,7 +172,8 @@ EOF ...@@ -172,7 +172,8 @@ EOF
# These echo commands will help with debugging and will only print # These echo commands will help with debugging and will only print
#if the test fails #if the test fails
echo "Captured stdout:" echo "Captured stdout:"
echo "Output: $output" echo "Your output: $stripped_output"
echo "Expected: $expected_output"
echo "Exit Status: $status" echo "Exit Status: $status"
# Check exact match # Check exact match
... ...
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please to comment