Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
C
cs503zchen
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Container registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Ziheng Chen
cs503zchen
Commits
141ec1c7
There was an error fetching the commit references. Please try again later.
Commit
141ec1c7
authored
3 months ago
by
Ziheng Chen
Browse files
Options
Downloads
Patches
Plain Diff
Upload New File
parent
0d038439
No related branches found
No related tags found
No related merge requests found
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
w6/student_tests.sh
+100
-0
100 additions, 0 deletions
w6/student_tests.sh
with
100 additions
and
0 deletions
w6/student_tests.sh
0 → 100644
+
100
−
0
View file @
141ec1c7
#!/usr/bin/env bats
# File: student_tests.sh
#
# Create your unit tests suit in this file
@test
"Check if shell starts"
{
run ./dsh
<<<
"exit"
[
"
$status
"
-eq
0
]
# 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
"
echo
"
${
stripped_output
}
->
${
expected_output
}
"
# Check exact match
[
"
$stripped_output
"
=
"
$expected_output
"
]
}
@test
"Example: check ls runs without errors"
{
run ./dsh
<<
EOF
ls
EOF
# Assertions
[
"
$status
"
-eq
0
]
# 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
"
echo
"
${
stripped_output
}
->
${
expected_output
}
"
# Check exact match
[
"
$stripped_output
"
=
"
$expected_output
"
]
}
@test
"Create and navigate into new directory"
{
run ./dsh
<<
EOF
mkdir -p /tmp/student_test_dir
cd /tmp/student_test_dir
pwd
EOF
# Remove extra spaces but **preserve newlines**
stripped_output
=
$(
echo
"
$output
"
|
tr
-s
'[:space:]'
|
tr
'\n'
'|'
)
# Adjust expected output to match actual shell behavior
expected_output
=
"/tmp/student_test_dir|dsh2> dsh2> dsh2> dsh2> |cmd loop returned 0|"
# Debugging output
echo
"Captured stdout:"
echo
"Output:
$output
"
echo
"Exit Status:
$status
"
echo
"
${
stripped_output
}
->
${
expected_output
}
"
# Assertion: Check exact match
[
"
$stripped_output
"
=
"
$expected_output
"
]
}
@test
"Handle command execution failures gracefully"
{
run ./dsh
<<<
"command_that_does_not_exist"
# Expected error message
expected_error
=
"execvp failed: No such file or directory"
# Check if output contains the expected error message
[[
"
$output
"
==
*
"
$expected_error
"
*
]]
# Debugging output
echo
"Captured stdout:"
echo
"Output:
$output
"
echo
"Exit Status:
$status
"
echo
"
${
stripped_output
}
->
${
expected_output
}
"
# Assertion: Check exact match
[
"
$stripped_output
"
=
"
$expected_output
"
]
}
@test
"Detect too many arguments for built-in cd"
{
run ./dsh
<<<
"cd /tmp extra_argument"
# Expected error message
expected_error
=
"error: cd command accepts at most 1 argument"
# Check if output contains the expected error message
[[
"
$output
"
==
*
"
$expected_error
"
*
]]
# Debugging output
echo
"Captured stdout:"
echo
"Output:
$output
"
echo
"Exit Status:
$status
"
# Assertion: Check exact match
[
"
$stripped_output
"
=
"
$expected_output
"
]
}
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment