Browse Source

feat(remake): clarify exercise

- specify what happens when directory passed as argument does not
exist
- add hints in subjects
- update solution and tests accordingly
pull/1724/head
nprimo 1 year ago committed by Niccolò Primo
parent
commit
9bdb8f1217
  1. 11
      sh/tests/remake_test.sh
  2. 3
      sh/tests/solutions/remake.sh
  3. 16
      subjects/devops/remake/README.md

11
sh/tests/remake_test.sh

@ -4,16 +4,19 @@ IFS='
'
challenge () {
if [[ $# -eq 1 ]]; then
if [[ $# -eq 1 && -d "$1" ]]; then
submitted=$(bash student/remake.sh "$1")
expected=$(bash solutions/remake.sh "$1"-expected)
diff <(echo $submitted) <(echo $expected)
diff <(ls -ltr $1) <(ls -ltr $1-expected)
rm -rf "$1" "$1-expected"
else
diff <(bash student/remake.sh "$@") <(bash solutions/remake.sh "$@")
fi
}
challenge remake
challenge
mkdir remake remake-expected
challenge remake
challenge
challenge not-there
rm -rf remake remake-expected

3
sh/tests/solutions/remake.sh

@ -3,8 +3,7 @@
IFS='
'
if [[ $# -eq 1 ]]; then
mkdir -p $1
if [[ $# -eq 1 && -d "$1" ]]; then
cd $1
touch -t 01010001 ciao
chmod 442 ciao

16
subjects/devops/remake/README.md

@ -4,7 +4,7 @@
Create a file `remake.sh`, which will take one argument, the relative path of a directory, and will create new files and directories in it. The new files and directories created must have the same name, permission and modification dates as shown in the example below.
If the number of given arguments is not one, your script should print `Error` and exit with the status code 1.
If the number of given arguments is not one or if the directory given as argument does not exist, your script should print `Error` and exit with the status code 1.
Below the expected behavior of your script:
@ -25,5 +25,19 @@ $
- `touch -t <file-path>` allows to specify the modification time in the format `[[CC]YY]MMDDhhmm[.ss]` instead of the current time for the file at `<file-path>`.
- it is possible to check whether a file or a directory exists with the following commands:
```bash
if [[ -d $DIRPATH ]]; then # for a directory
echo "the $DIRPATH exists"
fi
```
```bash
if [[ -f $FILEPATH ]]; then # for a file
echo "the $FILEPATH exists"
fi
```
> 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!

Loading…
Cancel
Save