Skip to content

Added ignore/tests counter #363

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

Closed
wants to merge 1 commit into from
Closed
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
40 changes: 40 additions & 0 deletions count_ignores.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
current_dir=$(pwd)

cd exercises
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

because this always does cd exercises, the caller of this script must be at the root of https://github.com/exercism/rust when running it, which is more disadvantageous compared to being able to run it anywhere


for exercise_name in *
do

#Get filename
file_name="$exercise_name/tests/*.rs"

#Commented tests
comment_test_num=$(cat $file_name | grep "// \#\[test\]" | wc -l)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is probably preferable to grep PATTERN FILE rather than cat FILE | grep PATTERN, right? Is there a difference between the two?


#Number of tests
test_num=$(cat $file_name | grep "\#\[test\]" | wc -l)
test_num=$(($test_num - $comment_test_num))
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

could consider counting those number of lines for which #[test] is the first thing on the line (possibly preceded by some number of spaces), rather than taking all lines with #[test] anywhere on them and subtracting the comments.


#Commented ignores
comment_ignore_num=$(cat $file_name | grep "// \#\[ignore\]" | wc -l)

#Number of ignores
ignore_num=$(cat $file_name | grep "\#\[ignore\]" | wc -l)
ignore_num=$(($ignore_num - $comment_ignore_num))
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

could consider counting those number of lines for which #[ignore] is the first thing on the line (possibly preceded by some number of spaces), rather than taking all lines with #[ignore] anywhere on them and subtracting the comments.


#Number of tests minus 1 should be the number of ignores
compare=$(($test_num - 1))

#Print logic
if [ "$compare" -eq "$ignore_num" ]
then
#Valid
echo -n
else
echo "$file_name : "
echo "Tests: $test_num"
echo "Ignores: $ignore_num"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it would be good if the script would exit nonzero if any file were found to have an unexpected number of ignore lines. That will make it usable in CI.

fi
done

cd $current_dir