|
| 1 | +#!/usr/bin/env bash |
| 2 | +set -euo pipefail |
| 3 | + |
| 4 | +default_steps=(fetch check) |
| 5 | + |
| 6 | +usage() { |
| 7 | + cat <<EOF |
| 8 | +usage: tools/content/check-features [OPTION]... [STEP]... <CORPUS_DIR> |
| 9 | +
|
| 10 | +Fetch messages from a Zulip server and check the content parser for |
| 11 | +unimplemented features. |
| 12 | +
|
| 13 | +By default, run the following steps: |
| 14 | + ${default_steps[*]} |
| 15 | +
|
| 16 | +CORPUS_DIR is required. It is the directory to store or read corpus files |
| 17 | +which will be created if it does not exist already. |
| 18 | +
|
| 19 | +The steps are: |
| 20 | +
|
| 21 | + fetch Fetch the corpuses needed from the server specified \`--config\` |
| 22 | + file into \`CORPUS_DIR\` incrementally. This step can take a long |
| 23 | + time on servers with a lot of public messages when starting from |
| 24 | + scratch. |
| 25 | + This wraps around tools/content/fetch_messages.dart. |
| 26 | +
|
| 27 | + check Check for unimplemented content parser features. This requires |
| 28 | + the corpus directory \`CORPUS_DIR\` to contain at least one corpus |
| 29 | + file. |
| 30 | + This wraps around tools/content/unimplemented_features_test.dart. |
| 31 | +
|
| 32 | +Options: |
| 33 | +
|
| 34 | + --config <FILE> |
| 35 | + A zuliprc file with identity information including email, API key |
| 36 | + and the Zulip server URL to fetch the messages from. |
| 37 | + Mandatory if running step \`fetch\`. To get the file, see |
| 38 | + https://zulip.com/api/configuring-python-bindings#download-a-zuliprc-file. |
| 39 | +
|
| 40 | + --verbose Print more details about everything, especially when checking for |
| 41 | + unsupported features. |
| 42 | +
|
| 43 | + --help Show this help message. |
| 44 | +EOF |
| 45 | +} |
| 46 | + |
| 47 | +opt_corpus_dir= |
| 48 | +opt_zuliprc= |
| 49 | +opt_verbose= |
| 50 | +opt_steps=() |
| 51 | +while (( $# )); do |
| 52 | + case "$1" in |
| 53 | + fetch|check) opt_steps+=("$1"); shift;; |
| 54 | + --config) shift; opt_zuliprc="$1"; shift;; |
| 55 | + --verbose) opt_verbose=1; shift;; |
| 56 | + --help) usage; exit 0;; |
| 57 | + *) |
| 58 | + if [ -n "$opt_corpus_dir" ]; then |
| 59 | + # Forbid passing mutliple corpus directories. |
| 60 | + usage >&2; exit 2 |
| 61 | + fi |
| 62 | + opt_corpus_dir="$1"; shift;; |
| 63 | + esac |
| 64 | +done |
| 65 | + |
| 66 | +if [ -z "$opt_corpus_dir" ]; then |
| 67 | + echo >&2 "Error: Positional argument CORPUS_DIR is required." |
| 68 | + echo >&2 |
| 69 | + usage >&2; exit 2 |
| 70 | +fi |
| 71 | + |
| 72 | +if (( ! "${#opt_steps[@]} " )); then |
| 73 | + opt_steps=( "${default_steps[@]}" ) |
| 74 | +fi |
| 75 | + |
| 76 | +run_fetch() { |
| 77 | + if [ -z "$opt_zuliprc" ]; then |
| 78 | + echo >&2 "Error: Option \`--config\` is required for step \`fetch\`." |
| 79 | + echo >&2 |
| 80 | + usage >&2; exit 2 |
| 81 | + fi |
| 82 | + |
| 83 | + if [ -n "$opt_verbose" ]; then |
| 84 | + echo "Fetching all public messages using API config \"$opt_zuliprc\"." \ |
| 85 | + " This can take a long time." |
| 86 | + fi |
| 87 | + # This may have a side effect of creating or modifying the corpus |
| 88 | + # file named after the Zulip server's host name. |
| 89 | + tools/content/fetch_messages.dart --config-file "$opt_zuliprc" \ |
| 90 | + --corpus-dir "$opt_corpus_dir" \ |
| 91 | + || return 1 |
| 92 | +} |
| 93 | + |
| 94 | +run_check() { |
| 95 | + flutter test tools/content/unimplemented_features_test.dart \ |
| 96 | + --dart-define=corpusDir="$opt_corpus_dir" \ |
| 97 | + --dart-define=verbose="$opt_verbose" \ |
| 98 | + || return 1 |
| 99 | +} |
| 100 | + |
| 101 | +for step in "${opt_steps[@]}"; do |
| 102 | + echo "Running ${step}" |
| 103 | + case "${step}" in |
| 104 | + fetch) run_fetch ;; |
| 105 | + check) run_check ;; |
| 106 | + *) echo >&2 "Internal error: unknown step ${step}" ;; |
| 107 | + esac |
| 108 | +done |
0 commit comments