-
Notifications
You must be signed in to change notification settings - Fork 59
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
panic-test.sh script under .traivs dir detect panic/unwrap calls, which will panic the thread and cause process abortion.
- Loading branch information
1 parent
5ff1ed3
commit 063d0d9
Showing
3 changed files
with
40 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
unwrap() | ||
panic!(.*) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
#!/bin/bash | ||
|
||
# Check the unwrap and panic function presenting in src/ directory | ||
# of the repo. Testing suite is excluded. If such a function presents | ||
# return exit 1 for fail, otherwise return exit 0 for sucess. | ||
|
||
# Getting the banned list from banned functions | ||
banned_list=() | ||
banned_function="$1" | ||
while read -r line; do | ||
banned_list=(${banned_list[@]} "$line") | ||
done < "$banned_function" | ||
|
||
output="" | ||
catch_panic=$false | ||
|
||
# Match panic call based on the given banned funciton list | ||
for i in src/*; do | ||
for func in "${banned_list[@]}"; do | ||
tmp_line=$(sed '/#\[cfg(test)]/q' $i | grep -e "$func" | awk 'END {print NR}') | ||
if [ "$tmp_line" -gt 0 ]; then | ||
tmp_output=$(sed '/#\[cfg(test)]/q' $i | grep -n -e "$func") | ||
output="${output}${tmp_output}\n" | ||
catch_panic=$true | ||
fi | ||
done | ||
done | ||
|
||
# Output result | ||
if [ $catch_panic ]; then | ||
echo "exit 1. Please removed all the following panic calls." | ||
printf "$output" | ||
exit 1 | ||
else | ||
echo "exit 0. Not panic violation occurs." | ||
exit 0 | ||
fi |