Skip to content

Commit a859882

Browse files
authored
tool/analyze-and-test-examples.sh: analyze options file too (#1905)
1 parent 718feab commit a859882

File tree

3 files changed

+55
-44
lines changed

3 files changed

+55
-44
lines changed

examples/misc/analyzer-2-results.txt

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
Analyzing lib, test...
1+
Analyzing analysis_options.yaml, lib, test...
22
# https://github.com/dart-lang/sdk/issues/32236 - flow analysis can't yet figure out that the variable is of type Person.
33
error • 'Object' doesn't extend 'SomeBaseClass' at lib/language_tour/generics/misc.dart:29:19 • type_argument_not_matching_bounds
44
error • The argument type 'int' can't be assigned to the parameter type 'String' at lib/library_tour/core/collections.dart:5:14 • argument_type_not_assignable

examples/strong/analyzer-2-results.txt

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
Analyzing lib, test...
1+
Analyzing analysis_options.yaml, lib, test...
22
error • 'HoneyBadger.parent' ('Root Function()') isn't a valid override of 'Animal.parent' ('parent') at lib/animal_bad.dart:15:3 • invalid_override
33
error • 'Cat.chase' ('void Function(Mouse)') isn't a valid override of 'Animal.chase' ('chase') at lib/animal_bad.dart:26:3 • invalid_override
44
error • A value of type 'List' can't be assigned to a variable of type 'List<Cat>' at lib/animal_bad.dart:49:19 • invalid_assignment

tool/analyze-and-test-examples.sh

+53-42
Original file line numberDiff line numberDiff line change
@@ -43,61 +43,71 @@ function analyze_and_test() {
4343
pub $PUB_ARGS
4444
travis_fold end analyzeAndTest.get
4545

46+
# TODO: rename DIR since it now more generally contains analysis targets, not only directories
4647
DIR=()
47-
for d in bin lib test; do
48-
if [[ -d $d ]]; then DIR+=($d); fi
48+
for d in analysis_options.yaml bin lib test; do
49+
if [[ -e $d ]]; then DIR+=($d); fi
4950
done
5051

5152
if [[ ${#DIR} -le 0 ]]; then
5253
echo
5354
echo "NOTHING TO ANALYZE in this project."
54-
else
55-
echo
56-
EXPECTED_FILE=$PROJECT_ROOT/analyzer-$DART_MAJOR_VERS-results.txt
57-
if [[ ! -e $EXPECTED_FILE ]]; then
58-
EXPECTED_FILE=$PROJECT_ROOT/analyzer-results.txt
59-
fi
60-
travis_fold start analyzeAndTest.analyze
61-
if [[ -e $EXPECTED_FILE && -z $QUICK ]]; then
62-
# Run the analyzer a first time to ensure that there are no errors.
63-
#
64-
# Note: catch non-zero exit codes to avoid aborting this script when the
65-
# analyzer reports "foo.dart is a part and cannot be analyzed":
66-
$ANALYZE ${DIR[*]} > $LOG_FILE || {
67-
echo "WARNING: Ignoring Analyzer exit code $?"
68-
}
69-
if grep -qvE '^Analyzing|^No issues found' $LOG_FILE; then
70-
cat $LOG_FILE
71-
echo "No analysis errors or warnings should be present in original source files."
72-
echo "Ensure that these issues are disabled using appropriate markers like: "
73-
echo " // ignore_for_file: $DART_MAJOR_VERS, some_analyzer_error_or_warning_id"
74-
EXIT_STATUS=1
75-
return 1;
76-
fi
77-
fi
78-
disableInFileAnalyzerFlags ${DIR[*]}
55+
return
56+
fi
57+
58+
echo
59+
EXPECTED_FILE=$PROJECT_ROOT/analyzer-$DART_MAJOR_VERS-results.txt
60+
if [[ ! -e $EXPECTED_FILE ]]; then
61+
EXPECTED_FILE=$PROJECT_ROOT/analyzer-results.txt
62+
fi
63+
travis_fold start analyzeAndTest.analyze
64+
if [[ -e $EXPECTED_FILE && -z $QUICK ]]; then
65+
# Run the analyzer a first time to ensure that there are no errors.
66+
#
67+
# Note: catch non-zero exit codes to avoid aborting this script when the
68+
# analyzer reports "foo.dart is a part and cannot be analyzed":
69+
echo "$ $ANALYZE ${DIR[*]}"
7970
$ANALYZE ${DIR[*]} > $LOG_FILE || {
8071
echo "WARNING: Ignoring Analyzer exit code $?"
8172
}
82-
if [[ -e $EXPECTED_FILE ]]; then
83-
if grep -ve '^#' $EXPECTED_FILE | diff - $LOG_FILE > /dev/null; then
84-
echo "Analyzer output is as expected ($EXPECTED_FILE)."
85-
else
86-
cat $LOG_FILE
87-
echo "Unexpected analyzer output ($EXPECTED_FILE); here's the diff:"
88-
(set -x; diff $LOG_FILE $EXPECTED_FILE) || true
89-
EXIT_STATUS=1
90-
if [[ -n $SAVE_LOGS ]]; then cp $LOG_FILE $EXPECTED_FILE; fi
91-
fi
92-
elif grep -qvE '^Analyzing|^No issues found' $LOG_FILE; then
73+
if grep -qvE '^Analyzing|^No issues found' $LOG_FILE; then
9374
cat $LOG_FILE
75+
echo "No analysis errors or warnings should be present in original source files."
76+
echo "Ensure that these issues are disabled using appropriate markers like: "
77+
echo " // ignore_for_file: $DART_MAJOR_VERS, some_analyzer_error_or_warning_id"
9478
EXIT_STATUS=1
95-
if [[ -n $SAVE_LOGS ]]; then cp $LOG_FILE $EXPECTED_FILE; fi
79+
return 1;
80+
fi
81+
fi
82+
disableInFileAnalyzerFlags ${DIR[*]}
83+
echo "$ $ANALYZE ${DIR[*]}"
84+
$ANALYZE ${DIR[*]} > $LOG_FILE || {
85+
echo "WARNING: Ignoring analyzer exit code $?"
86+
}
87+
if [[ -e $EXPECTED_FILE ]]; then
88+
if grep -ve '^#' $EXPECTED_FILE | diff - $LOG_FILE > /dev/null; then
89+
echo "Analyzer output is as expected ($EXPECTED_FILE)."
9690
else
9791
cat $LOG_FILE
92+
echo "Unexpected analyzer output ($EXPECTED_FILE); here's the diff:"
93+
(set -x; diff $LOG_FILE $EXPECTED_FILE) || true
94+
EXIT_STATUS=1
95+
if [[ -n $SAVE_LOGS ]]; then cp $LOG_FILE $EXPECTED_FILE; fi
9896
fi
99-
reEnableInFileAnalyzerFlags ${DIR[*]}
100-
travis_fold end analyzeAndTest.analyze
97+
elif grep -qvE '^Analyzing|^No issues found' $LOG_FILE; then
98+
cat $LOG_FILE
99+
EXIT_STATUS=1
100+
if [[ -n $SAVE_LOGS ]]; then cp $LOG_FILE $EXPECTED_FILE; fi
101+
else
102+
cat $LOG_FILE
103+
fi
104+
reEnableInFileAnalyzerFlags ${DIR[*]}
105+
travis_fold end analyzeAndTest.analyze
106+
107+
if [[ ! -d test ]]; then
108+
echo
109+
echo "NOTHING TO TEST in this project."
110+
return
101111
fi
102112

103113
echo
@@ -107,7 +117,7 @@ function analyze_and_test() {
107117
TEST="pub run test"
108118
TEST_ARGS="--exclude-tags=browser"
109119

110-
echo $TEST $TEST_ARGS
120+
echo "$ $TEST $TEST_ARGS"
111121
$TEST $TEST_ARGS | tee $LOG_FILE | $FILTER1 | $FILTER2 "$FILTER_ARG"
112122
LOG=$(grep -E 'All tests passed!|^No tests ran' $LOG_FILE)
113123
if [[ -z "$LOG" ]]; then EXIT_STATUS=1; fi
@@ -125,6 +135,7 @@ function analyze_and_test() {
125135
if [[ -n $TRAVIS ]]; then PLATFORM=travischrome; fi
126136
# Name the sole browser test file, otherwise all other files get compiled too:
127137
TEST="pub run test"
138+
echo "$ $TEST --tags browser --platform $PLATFORM $TEST_FILES"
128139
$TEST --tags browser --platform $PLATFORM $TEST_FILES \
129140
| tee $LOG_FILE | $FILTER1 | $FILTER2 "$FILTER_ARG"
130141
LOG=$(grep 'All tests passed!' $LOG_FILE)

0 commit comments

Comments
 (0)