Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update format and verify scripts to check scaffold, solution and test files #317

Merged
merged 6 commits into from
Dec 15, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 22 additions & 5 deletions bin/format_exercises.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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"

Expand All @@ -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
Expand All @@ -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
5 changes: 3 additions & 2 deletions bin/verify-exercises
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion exercises/practice/resistor-color/src/lib.cairo
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#[derive(Debug, Drop)]
#[derive(Drop, Debug, PartialEq)]
pub enum Color {
Black,
Brown,
Expand Down
Loading