|
1 | 1 | #!/bin/bash
|
| 2 | +# |
| 3 | +#------------------------------------------------------------------------------ |
2 | 4 |
|
3 |
| -EXITSTATUS=0 |
| 5 | +function usage() { |
| 6 | + cat <<'EOM' |
| 7 | +
|
| 8 | +Usage: runtests.sh [-q|+h|-h] |
| 9 | +
|
| 10 | + -h print this usage message. |
| 11 | + +h report all hints as problems; otherwise only unused imports are counted |
| 12 | + as problems. |
| 13 | + -q quiet mode (only emit output if the analyzer finds problems). Verbose by |
| 14 | + default. |
| 15 | +EOM |
| 16 | +} |
| 17 | + |
| 18 | +#------------------------------------------------------------------------------ |
| 19 | + |
| 20 | +declare -i problem_count |
| 21 | + |
| 22 | +EXIT_STATUS=0 |
4 | 23 | PASSING=0
|
5 |
| -WARNINGS=0 |
6 | 24 | FAILURES=0
|
| 25 | +VERBOSE=1; |
| 26 | +BASE_DIR=$(dirname $0) |
7 | 27 |
|
8 |
| -echo "Running dartanalyzer on *.dart files" |
| 28 | +while [ $# -gt 0 ]; do |
| 29 | + case $1 in |
| 30 | + -h) usage; exit 0;; |
| 31 | + +h) count_all_hints_as_problems=1; |
| 32 | + shift;; |
| 33 | + -q) VERBOSE=; |
| 34 | + shift;; |
| 35 | + -*) echo "Invalid option: $1"; |
| 36 | + usage; |
| 37 | + exit 1;; |
| 38 | + esac |
| 39 | +done |
9 | 40 |
|
10 |
| -for file in `find . -name "*dart"` |
| 41 | +[[ -n "$VERBOSE" ]] && echo "Running dartanalyzer on *.dart files in $BASE_DIR" |
| 42 | + |
| 43 | +for file in `find $BASE_DIR -name "*.dart"` |
11 | 44 | do
|
12 |
| - echo $file |
13 |
| - results=`dartanalyzer $file 2>&1` |
14 |
| - |
15 |
| - # hints such as 'Unused import' should be treated as warnings. |
16 |
| - if [[ "$results" == *\[hint\]* ]]; then |
17 |
| - echo "$results" |
18 |
| - let WARNINGS++ |
19 |
| - EXITSTATUS=1 |
20 |
| - fi |
| 45 | + [[ -n "$VERBOSE" ]] && echo $file |
| 46 | + results=$(dartanalyzer $file 2>&1) |
| 47 | + problem_count=$(echo "$results" | grep -E "^\[(error|warning)\]" | wc -l) |
21 | 48 |
|
22 |
| - exit_code=$? |
23 |
| - if [ $exit_code -eq 2 ]; then |
24 |
| - let FAILURES++ |
25 |
| - EXITSTATUS=1 |
26 |
| - elif [ $exit_code -eq 1 ]; then |
27 |
| - let WARNINGS++ |
28 |
| - EXITSTATUS=1 |
29 |
| - elif [ $exit_code -eq 0 ]; then |
30 |
| - let PASSING++ |
| 49 | + if [[ -n "$count_all_hints_as_problems" ]]; then |
| 50 | + problem_count+=$(echo "$results" | grep -E "^\[hint\]" | wc -l) |
31 | 51 | else
|
32 |
| - echo "$file: Unknown exit code: $exit_code." |
| 52 | + # hints such as 'Unused import' should be treated as warnings. |
| 53 | + problem_count+=$(echo "$results" | grep -E "^\[hint\] Unused import" | wc -l) |
33 | 54 | fi
|
34 |
| - # Remove the output directory so that subsequent test runs will still see |
35 |
| - # the warnings and errors. |
36 |
| - rm -rf out/ |
| 55 | + |
| 56 | + if [ "$problem_count" -gt 0 ]; then |
| 57 | + echo "$results" |
| 58 | + EXIT_STATUS=1 |
| 59 | + let FAILURES++ |
| 60 | + else |
| 61 | + let PASSING++ |
| 62 | + fi; |
37 | 63 | done
|
38 | 64 |
|
39 |
| -echo |
40 |
| -echo "-------------------------------------------------------------------------" |
41 |
| -echo "PASSING = $PASSING" |
42 |
| -echo "WARNINGS = $WARNINGS" |
43 |
| -echo "FAILURES = $FAILURES" |
44 |
| -echo "-------------------------------------------------------------------------" |
45 |
| -echo |
46 |
| -exit $EXITSTATUS |
| 65 | +if [[ -n "$VERBOSE" || "$FAILURES" -gt 0 ]]; then |
| 66 | + echo "-------------------------------------------------------------------" |
| 67 | + echo "$PASSING PASSED, $FAILURES FAILED " |
| 68 | + echo "-------------------------------------------------------------------" |
| 69 | +fi |
| 70 | +exit $EXIT_STATUS |
0 commit comments