Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
C
cs283
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
Luis Hernandez
cs283
Commits
ba6731ea
Commit
ba6731ea
authored
2 months ago
by
luishernandez
Browse files
Options
Downloads
Patches
Plain Diff
other test file
parent
94d1a25a
Branches
Branches containing commit
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
bats/student_tests.sh
+52
-0
52 additions, 0 deletions
bats/student_tests.sh
with
52 additions
and
0 deletions
bats/student_tests.sh
0 → 100644
+
52
−
0
View file @
ba6731ea
#!/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
]]
}
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