forked from cloudwego/abcoder
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrun_testdata.sh
More file actions
executable file
·72 lines (65 loc) · 2.22 KB
/
run_testdata.sh
File metadata and controls
executable file
·72 lines (65 loc) · 2.22 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
#!/bin/bash
# Generate uniast for all testdata.
#
# USAGE:
# 1. Save the uniast for all testdata to out/
# $ OUTDIR=out/ ./script/run_testdata.sh all
#
# 2. Save the uniast for the first testdata item (0_*) in each language to out/
# $ OUTDIR=out/ ./script/run_testdata.sh first
#
# 3. Use a custom abcoder executable
# OUTDIR=out/ ABCEXE="./other_abcoder" ./script/run_testdata.sh all
if [[ "$1" != "all" && "$1" != "first" ]]; then
echo "Usage: $0 all|first" >&2
echo " all: Run on all testdata." >&2
echo " first: Run only on testdata starting with '0_*' in each language directory." >&2
exit 1
fi
MODE=$1
SCRIPT_DIR=$(dirname "$(readlink -f "$0")")
REPO_ROOT=$(realpath --relative-to=$(pwd) "$SCRIPT_DIR/..")
ABCEXE=${ABCEXE:-"$REPO_ROOT/abcoder"}
OUTDIR=${OUTDIR:?Error: OUTDIR is a mandatory environment variable}
PARALLEL_FLAGS=${PARALLEL_FLAGS:---tag}
LANGS=${LANGS:-"go rust python cxx"}
detect_jobs() {
local ABCEXE=${1:-$ABCEXE}
for lang in ${LANGS[@]}; do
local repo_glob="$REPO_ROOT/testdata/$lang/*"
if [[ "$MODE" == "first" ]]; then
repo_glob="$REPO_ROOT/testdata/$lang/0_*"
fi
for repo in $repo_glob; do
# Skip if glob doesn't match anything to avoid errors
[[ -e "$repo" ]] || continue
local rel_path=$(realpath --relative-to="$REPO_ROOT/testdata" "$repo")
local outname=$(echo "$rel_path" | sed 's/[/:? ]/_/g')
echo $ABCEXE parse $lang $repo -o $OUTDIR/$outname.json
done
done
}
if [[ ! -x "$ABCEXE" ]]; then
echo "Error: The specified abcoder executable '$ABCEXE' does not exist or is not executable." >&2
exit 1
fi
mkdir -pv "$OUTDIR"
detect_jobs
echo
detect_jobs | parallel $PARALLEL_FLAGS -j$(nproc --all) --jobs 0 "eval {}" 2>&1
echo
echo "Verifying that all expected output files were generated..."
all_files_exist=true
# Rerun detect_jobs to get the list of expected json files and check for their existence.
for file_path in $(detect_jobs | awk '{print $NF}'); do
if [[ ! -f "$file_path" ]]; then
echo "Error: Expected output file does not exist: $file_path" >&2
all_files_exist=false
fi
done
if [[ "$all_files_exist" == "false" ]]; then
echo "One or more output files are missing. Failing." >&2
exit 1
else
echo "All expected output files were successfully generated."
fi