From 1633ff620d4cbe9c72784568eef339dcd55ac69b Mon Sep 17 00:00:00 2001 From: Nenad Date: Fri, 13 Dec 2024 12:47:50 +0100 Subject: [PATCH 1/5] Update format_exercises.sh to check lib.cairo formatting too --- bin/format_exercises.sh | 26 +++++++++++++++++++++----- 1 file changed, 21 insertions(+), 5 deletions(-) diff --git a/bin/format_exercises.sh b/bin/format_exercises.sh index b97c21a7..07354b58 100755 --- a/bin/format_exercises.sh +++ b/bin/format_exercises.sh @@ -9,6 +9,8 @@ repo=$(git rev-parse --show-toplevel) # directory and format Cairo files exercises="$repo/exercises/*/*" +FMT_ARGS="$@" + for exercise_dir in $exercises; do cd "$exercise_dir" @@ -19,6 +21,16 @@ for exercise_dir in $exercises; do continue fi + if [ -f "./src/lib.cairo" ]; then + scaffold_solution="./src/lib.cairo" + else + echo "Could not locate scaffold implementation for $exercise" + exit 1 + fi + + # check scaffold solution formatting + scarb fmt $FMT_ARGS + # scarb fmt cannot currently format individual files, so we have to # temporarily move the solution files into the Cairo package, where # 'scarb fmt' can format it as well @@ -34,13 +46,17 @@ for exercise_dir in $exercises; do exit 1 fi - # move the solution file into the package - cp "$solution_file" "$tmp_file" + # backup scaffold solution + cp "$scaffold_solution" "$tmp_file" + + # copy the example solution file into the package + cp "$solution_file" "$scaffold_solution" - scarb fmt "$@" + # check example solution formatting + scarb fmt $FMT_ARGS - # move the solution file back - cp "$tmp_file" "$solution_file" + # copy the scaffold solution back + cp "$tmp_file" "$scaffold_solution" rm "$tmp_file" done From 0eb8c125d79895c63fd05d06bbcecb1aeeef2b8c Mon Sep 17 00:00:00 2001 From: Nenad Date: Sat, 14 Dec 2024 20:16:54 +0100 Subject: [PATCH 2/5] add PartialEq to Color in resistor-color lib.cairo --- exercises/practice/resistor-color/src/lib.cairo | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/exercises/practice/resistor-color/src/lib.cairo b/exercises/practice/resistor-color/src/lib.cairo index d486d6e8..87351942 100644 --- a/exercises/practice/resistor-color/src/lib.cairo +++ b/exercises/practice/resistor-color/src/lib.cairo @@ -1,4 +1,4 @@ -#[derive(Debug, Drop)] +#[derive(Drop, Debug, PartialEq)] pub enum Color { Black, Brown, From 143af73c0a516ee37a6aa4a9017d46c9b9719aee Mon Sep 17 00:00:00 2001 From: Nenad Date: Sat, 14 Dec 2024 20:17:17 +0100 Subject: [PATCH 3/5] add test flag to scarb build in verify-exercises --- bin/verify-exercises | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bin/verify-exercises b/bin/verify-exercises index 071a5e74..e9890774 100755 --- a/bin/verify-exercises +++ b/bin/verify-exercises @@ -67,7 +67,7 @@ for exercise_path in $exercises; do cd "$tmp_dir" - scarb build + scarb build --test # Move example files to where Cargo expects them if [ -f "$repo/$exercise_path/.meta/example.cairo" ]; then From b14531d30171257983a4a915c9f1447ba2c03fc5 Mon Sep 17 00:00:00 2001 From: Nenad Date: Sat, 14 Dec 2024 20:18:03 +0100 Subject: [PATCH 4/5] add/update comments to verify-exercises --- bin/verify-exercises | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/bin/verify-exercises b/bin/verify-exercises index e9890774..3ba76a63 100755 --- a/bin/verify-exercises +++ b/bin/verify-exercises @@ -67,9 +67,10 @@ for exercise_path in $exercises; do cd "$tmp_dir" + # test that the scaffold + tests combination compiles scarb build --test - # Move example files to where Cargo expects them + # Copy solution files to where Cargo expects them if [ -f "$repo/$exercise_path/.meta/example.cairo" ]; then cp -f "$repo/$exercise_path/.meta/example.cairo" "$tmp_dir/src/lib.cairo" elif [ -f "$repo/$exercise_path/.meta/exemplar.cairo" ]; then From 2efb51e9572bbbbd46aee882cb961affaf7eecaa Mon Sep 17 00:00:00 2001 From: Nenad Date: Sat, 14 Dec 2024 20:22:15 +0100 Subject: [PATCH 5/5] fix spellcheck errors for format_exercises script --- bin/format_exercises.sh | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/bin/format_exercises.sh b/bin/format_exercises.sh index 07354b58..3420ff9d 100755 --- a/bin/format_exercises.sh +++ b/bin/format_exercises.sh @@ -9,7 +9,8 @@ repo=$(git rev-parse --show-toplevel) # directory and format Cairo files exercises="$repo/exercises/*/*" -FMT_ARGS="$@" +# Capture all arguments passed to the script to pass them to scarb fmt +SCARB_FMT_ARGS=("$@") for exercise_dir in $exercises; do cd "$exercise_dir" @@ -29,7 +30,7 @@ for exercise_dir in $exercises; do fi # check scaffold solution formatting - scarb fmt $FMT_ARGS + scarb fmt "${SCARB_FMT_ARGS[@]}" # scarb fmt cannot currently format individual files, so we have to # temporarily move the solution files into the Cairo package, where @@ -53,7 +54,7 @@ for exercise_dir in $exercises; do cp "$solution_file" "$scaffold_solution" # check example solution formatting - scarb fmt $FMT_ARGS + scarb fmt "${SCARB_FMT_ARGS[@]}" # copy the scaffold solution back cp "$tmp_file" "$scaffold_solution"