Skip to content
This repository was archived by the owner on Jun 3, 2020. It is now read-only.

Commit e2271b0

Browse files
committed
fix(runtest): report errors even if pub get has not been run; and other improvements
- Fixes problem of all tests passing when there is no packages. - Command line option +h can be used to report all hints. - Added -q for quiet mode.
1 parent 59e197e commit e2271b0

File tree

1 file changed

+58
-34
lines changed

1 file changed

+58
-34
lines changed

dart_io_mini_samples/runtests.sh

Lines changed: 58 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -1,46 +1,70 @@
11
#!/bin/bash
2+
#
3+
#------------------------------------------------------------------------------
24

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
423
PASSING=0
5-
WARNINGS=0
624
FAILURES=0
25+
VERBOSE=1;
26+
BASE_DIR=$(dirname $0)
727

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
940

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"`
1144
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)
2148

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)
3151
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)
3354
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;
3763
done
3864

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

Comments
 (0)