DEV-3916 feat(bin-status) add subject and tests for bin-status exercise

This commit is contained in:
Zouhair AMAZZAL 2022-12-13 12:36:10 +01:00 committed by Michele
parent ab5b82d1bd
commit 95509fae9a
3 changed files with 70 additions and 0 deletions

34
sh/tests/bin-status_test.sh Executable file
View File

@ -0,0 +1,34 @@
#!/usr/bin/env bash
# Unofficial Bash Strict Mode
set -euo pipefail
IFS='
'
FILENAME="student/bin-status.sh"
challenge() {
submitted=$(eval "$1" ; bash $FILENAME)
expected=$(eval "$1" ; bash solutions/bin-status.sh)
diff <(echo "$submitted") <(echo "$expected")
}
# True if FILE exists and is a regular file
if [ -f ${FILENAME} ]; then
# FILE exists and it's not empty
if [ -s ${FILENAME} ]; then
challenge true
challenge false
challenge ls -l
challenge ls asdasdasdasdad
else
echo "The file exist but is empty"
exit 1
fi
else
echo "File does not exist"
exit 1
fi

View File

@ -0,0 +1,3 @@
#!/usr/bin/env bash
echo $?

View File

@ -0,0 +1,33 @@
## json-researcher
### Instructions
Create the script `bin-status.sh` that will return the exit status of last command
- What to use : `echo`
- The output should be exactly like the example bellow but with the expected name
```console
$ true ; ./bin-status.sh
0
$ false ; ./bin-status.sh
1
$
```
### Hints
`$?` is a variable that holds the return value of the last executed command.
`echo $?` displays 0 if the last command has been successfully executed and displays a non-zero value if some error has occurred.
The bash sets `$?` To the exit status of the last executed process. By convention 0 is a successful exit and non-zero indicates some kind of error. It can be used to check if the previous command has been executed without any errors. If it has executed successfully then it stores 0. `$?` is also useful in shell scripts as a way to decide what to do depending on how the last executed command worked by checking the exit status.
```console
$ random-binary ; echo $?
<...>
<the exit status of random-binary>
$
```
> You have to use Man or Google to know more about commands flags, in order to solve this exercise!
> Google and Man will be your friends!