diff --git a/bin/format_exercises.sh b/bin/format_exercises.sh index b97c21a7..3420ff9d 100755 --- a/bin/format_exercises.sh +++ b/bin/format_exercises.sh @@ -9,6 +9,9 @@ repo=$(git rev-parse --show-toplevel) # directory and format Cairo files exercises="$repo/exercises/*/*" +# 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" @@ -19,6 +22,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 "${SCARB_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 +47,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 "${SCARB_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 diff --git a/bin/verify-exercises b/bin/verify-exercises index 071a5e74..3ba76a63 100755 --- a/bin/verify-exercises +++ b/bin/verify-exercises @@ -67,9 +67,10 @@ for exercise_path in $exercises; do cd "$tmp_dir" - scarb build + # 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 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,