Skip to content

Commit ad9f338

Browse files
committed
tools/check: Add suite (message content) parser.
Some main benefits of adding both tools/content scripts to tools/check are that you don't need to manage your directories for storing the zuliprc files and corpuses, or specify any command line options for fetching message contents and running the unimplemented features test. The script is intended to be run manually, not as a part of the CI, because it is very slow, and it relies on some out of tree files like API configs (zuliprc files) and big dumps of chat history. Signed-off-by: Zixuan James Li <[email protected]>
1 parent 5d94339 commit ad9f338

File tree

2 files changed

+51
-1
lines changed

2 files changed

+51
-1
lines changed

.gitignore

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,3 +53,7 @@ app.*.map.json
5353

5454
# Old scaffolding hack
5555
lib/credential_fixture.dart
56+
57+
# Directories used by `tools/check parser`
58+
.corpuses
59+
.api_configs

tools/check

Lines changed: 47 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ while (( $# )); do
8282
--all) opt_files=all; opt_all=1; shift;;
8383
--fix) opt_fix=1; shift;;
8484
--verbose) opt_verbose=1; shift;;
85-
analyze|test|build_runner|drift|pigeon|icons|android|shellcheck)
85+
analyze|test|build_runner|drift|pigeon|icons|android|parser|shellcheck)
8686
opt_suites+=("$1"); shift;;
8787
*) usage;;
8888
esac
@@ -386,6 +386,51 @@ run_android() {
386386
flutter build appbundle
387387
}
388388

389+
run_parser() {
390+
# Needed to skip fetching messages when there is no match for the
391+
# `config_files` glob.
392+
shopt -s nullglob
393+
local config_dir=.api_configs
394+
local config_files=("$config_dir"/*)
395+
396+
local corpus_dir=.corpuses
397+
local corpus_files=("$corpus_dir"/*)
398+
399+
# `tools/content/fetch_messages.dart` will create corpus files in
400+
# `corpus_dir` for each host from the zuliprc files, which is needed for
401+
# running `tools/content/unimplemented_features_test`.
402+
for config in "${config_files[@]}"; do
403+
echo "Fetching all public messages using API config \"$config\"."\
404+
"This can take a long time."
405+
tools/content/fetch_messages.dart --config-file "$config" \
406+
--corpus-dir $corpus_dir \
407+
|| return 1
408+
done
409+
410+
if (( ! "${#config_files[@]}" )) && (( ! ${#corpus_files[@]} )); then
411+
cat >&2 <<EOF
412+
tools/check parser: bad configuration
413+
414+
Running checks for unimplemented features require either zuliprc files in
415+
$config_dir to fetch corpuses or existing corpus files in $corpus_dir,
416+
but both directories are found empty.
417+
418+
Consider downloading zuliprc to $config_dir:
419+
https://zulip.com/api/configuring-python-bindings#download-a-zuliprc-file
420+
or copying pre-fetched corpuses to $corpus_dir.
421+
EOF
422+
return 1
423+
fi
424+
425+
# This test fails on a fresh clone that do not have .api_configs or
426+
# .corpus set up. This is intentional because it is supposed to be run
427+
# manually with some API keys and/or corpuses prepared.
428+
flutter test tools/content/unimplemented_features_test.dart \
429+
--dart-define=corpusDir=$corpus_dir \
430+
--dart-define=verbose=$opt_verbose \
431+
|| return 1
432+
}
433+
389434
run_shellcheck() {
390435
# Omitted from this check: nothing (nothing known, anyway).
391436
files_check tools/ '!*.'{dart,js,json} \
@@ -460,6 +505,7 @@ for suite in "${opt_suites[@]}"; do
460505
pigeon) run_pigeon ;;
461506
icons) run_icons ;;
462507
android) run_android ;;
508+
parser) run_parser ;;
463509
shellcheck) run_shellcheck ;;
464510
*) echo >&2 "Internal error: unknown suite $suite" ;;
465511
esac || failed+=( "$suite" )

0 commit comments

Comments
 (0)