Skip to content

Commit be9d79a

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. Fixes: zulip#190 Signed-off-by: Zixuan James Li <[email protected]>
1 parent b321908 commit be9d79a

File tree

4 files changed

+54
-3
lines changed

4 files changed

+54
-3
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: 44 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|shellcheck|parser)
8686
opt_suites+=("$1"); shift;;
8787
*) usage;;
8888
esac
@@ -416,6 +416,48 @@ EOF
416416
shellcheck -x --shell=bash -- "${targets[@]}"
417417
}
418418

419+
run_parser() {
420+
# This is needed to check if there is no match for the
421+
# `config_files` and `corpus_files` globs.
422+
shopt -s nullglob
423+
424+
local config_dir=.api_configs
425+
local config_files=("$config_dir"/*)
426+
427+
# `tools/content/fetch_messages.dart` will create corpus files in
428+
# `corpus_dir` for each host from the zuliprc files, which is needed for
429+
# running `tools/content/unimplemented_features_test.dart`.
430+
local corpus_dir=.corpuses
431+
for config in "${config_files[@]}"; do
432+
echo "Fetching all public messages using API config \"$config\"."\
433+
"This can take a long time."
434+
tools/content/fetch_messages.dart --config-file "$config" \
435+
--corpus-dir $corpus_dir \
436+
|| return 1
437+
done
438+
local corpus_files=("$corpus_dir"/*)
439+
440+
if (( ! "${#config_files[@]}" )) && (( ! ${#corpus_files[@]} )); then
441+
cat >&2 <<EOF
442+
tools/check parser: bad configuration
443+
444+
Running checks for unimplemented features requires either zuliprc files in
445+
$config_dir to fetch corpuses or existing corpus files in $corpus_dir,
446+
but both directories are found non-existent or empty.
447+
448+
Consider downloading zuliprc to $config_dir:
449+
https://zulip.com/api/configuring-python-bindings#download-a-zuliprc-file
450+
or copying pre-fetched corpuses to $corpus_dir.
451+
EOF
452+
return 1
453+
fi
454+
455+
flutter test tools/content/unimplemented_features_test.dart \
456+
--dart-define=corpusDir=$corpus_dir \
457+
--dart-define=verbose=$opt_verbose \
458+
|| return 1
459+
}
460+
419461
describe_git_head() {
420462
local name="$1" repo_path="$2"
421463
local commit_data
@@ -461,6 +503,7 @@ for suite in "${opt_suites[@]}"; do
461503
icons) run_icons ;;
462504
android) run_android ;;
463505
shellcheck) run_shellcheck ;;
506+
parser) run_parser ;;
464507
*) echo >&2 "Internal error: unknown suite $suite" ;;
465508
esac || failed+=( "$suite" )
466509
done

tools/content/fetch_messages.dart

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,10 @@ import 'model.dart';
2121
/// Because message IDs are only unique within a single server, the script
2222
/// names corpuses from each server differently (if --corpus-dir is specified).
2323
///
24+
/// This script is meant to be run via `tools/check parser`.
25+
///
26+
/// For more help, run `tools/content/fetch_message.dart --help`.
27+
///
2428
/// See tools/content/unimplemented_features_test.dart for more details.
2529
void main(List<String> args) async {
2630
final argParser = ArgParser();

tools/content/unimplemented_features_test.dart

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,9 @@ import 'model.dart';
1616
/// Check if there are unimplemented features from the given corpuses of HTML
1717
/// contents from Zulip messages.
1818
///
19-
/// This test is meant to be manually run.
19+
/// This test is meant to be run via `tools/check parser`.
2020
///
21-
/// To run it, use:
21+
/// To run it directly, use:
2222
///
2323
/// flutter test tools/content --dart-define=corpusDir=path/to/corpusDir
2424
///

0 commit comments

Comments
 (0)