-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcount_ruby_tests
More file actions
executable file
·32 lines (30 loc) · 1.08 KB
/
count_ruby_tests
File metadata and controls
executable file
·32 lines (30 loc) · 1.08 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
#!/usr/bin/env bash
if [ "$1" = '--help' ]; then
exit 1
elif [ "$1" = '--version' ]; then
exit 1
fi
# declare -r TEST_PATTERN='^[[:blank:]]*(should|test)[[:blank:]]+("(\"|[^"]*)+"|'\''(\'\''|[^'\'']*)+'\'')[[:blank:]]+do'
# declare -r TEST_PATTERN='^[[:blank:]]*((should|test)[[:blank:]]+("[^"]*"|'\''[^'\'']*'\'')[[:blank:]]+do|should(_not)? (allow|validate))'
declare -r TEST_PATTERN='^[[:blank:]]*(should(_not)?|test)[[:blank:]]+("[^"]*"|'\''[^'\'']*'\'')[[:blank:]]+do|should(_not)? (allow|validate))'
declare -a params=()
declare -i testCount=0
while [ -n "$1" ]; do
params+=("$1")
if [ -f "$1" ]; then
if [ -r "$1" ] && [ -s "$1" ]; then
# grep --regexp=^[[:blank:]]*should[[:blank:]]+(\"|\') "$1"
((testCount+=$(grep -c -E --regexp="$TEST_PATTERN" "$1")))
fi
elif [ -d "$1" ]; then
mapfile out < <(grep -c -h -R -E --regexp="$TEST_PATTERN" "$1")
# declare -a out=($(grep -c -h -R -E --regexp="$TEST_PATTERN" "$1"))
# ((testCount+=$(grep -c -h -R -E --regexp="$TEST_PATTERN" "$1")))
for item in "${out[@]}"; do
((testCount+=item))
done
fi
shift
done
echo $testCount
exit