-
Notifications
You must be signed in to change notification settings - Fork 24
Expand file tree
/
Copy pathtest-fn-generation.bash
More file actions
executable file
·118 lines (100 loc) · 3.94 KB
/
test-fn-generation.bash
File metadata and controls
executable file
·118 lines (100 loc) · 3.94 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
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
#!/usr/bin/env bash
set -euo pipefail
export PATH="./node_modules/.bin/:$PATH"
BAILOUT="${BAILOUT:-false}"
FILTER="${FILTER:-}"
rm -f gen-code/*.js
sed -i 's/\/\/ if (global.storeFnString) { global.storeFnString(fnString); }/if (global.storeFnString) { global.storeFnString(fnString); }/' lib/parse.js
node ./node_modules/.bin/mocha test/main.test.js || true
sed -i 's/^[[:blank:]]*if (global.storeFnString) { global.storeFnString(fnString); }/\t\t\/\/ if (global.storeFnString) { global.storeFnString(fnString); }/' lib/parse.js
files_array=(gen-code/*.js)
test() {
set -euo pipefail
file="$1"
prettier --write "$file" --ignore-path /dev/null >/dev/null
sed -i '$d' "$file"
sed -i '1d' "$file"
c="$(cat "$file")"
echo "
function getStringValue(name) { return name + ''; }
function ifDefined(v, d) { return typeof v !== 'undefined' ? v : d; }
const \$filter = Object.create(null);
function plus(a,b) { return a + b } function minus(a,b) { return a -b } function times(a,b) { return a*b } function divide(a,b) { return a / b }
var nativeHasOwn = Object.prototype.hasOwnProperty;
var nativeCall = Function.prototype.call; var \$call = Function.prototype.call.bind(Function.prototype.call);
// This creates a function that effectively does:
// nativeCall.call(nativeHasOwn, obj, key)
/**
* @param {any} obj
* @param {string|number} key
* @returns {obj is Record<string, any>}
*/
var hasOwn = function(obj, key) {
return nativeCall.call(nativeHasOwn, obj, key);
};
$c
" >"$file"
code=0
tsc_result="$(tsc "$file" --allowJs --checkJs --noEmit --noImplicitAny false)" || code="$?"
expected_file="$(echo "$file" | sed -E 's/gen-code/expected-gen-code/g')"
if [ "$code" = 0 ] && [ -f "$expected_file" ]; then
echo "Found expected_file for a working file : $file / $expected_file"
exit 1
fi
if [ "$code" != 0 ]; then
if [ "$tsc_result" = "" ]; then
echo "tsc output was empty, that is unexpected because tsc failed"
exit 3
fi
if [ -f "$expected_file" ]; then
ignores="$(grep --line-number --extended --only-matching "TS[0-9]+" <"$expected_file" || true)"
while read -r ignore; do
line="$(sed -E 's/^([0-9]+):(TS[0-9]+)/\1/g' <<<"$ignore")"
rule="$(sed -E 's/^([0-9]+):(TS[0-9]+)/\2/g' <<<"$ignore")"
if [ "$line" = "" ] || [ "$rule" = "" ]; then
continue
fi
tsc_result="$(grep -vE "\.js.$line.*: error $rule" <<<"$tsc_result" || true)"
done <<<"$ignores"
if [ "$tsc_result" = "" ]; then
return 0
fi
fi
echo TSC_RESULT
echo "$tsc_result"
echo "$tsc_result" | wc -l
exit "$code"
fi
code=0
./node_modules/.bin/eslint --config gen-code/eslint.config.mjs "$file" || code="$?"
if [ "$code" != 0 ]; then
echo "Eslint did not validate this file : '$file'"
cat "$file"
exit "$code"
fi
}
export -f test
MAX_PROCS="80%"
parallel_log="$(mktemp /tmp/fn-validator-XXXX.log)"
parallel_options=(--line-buffer --bar --max-procs "$MAX_PROCS" --joblog "$parallel_log")
if [ "$BAILOUT" = "true" ]; then
parallel_options+=(--halt "now,fail=1")
else
parallel_options+=(--halt "never,fail=1")
fi
parallel_options+=(test)
files="$(printf "%s\n" "${files_array[@]}")"
if [ "$FILTER" != "" ]; then
files="$(grep <<<"$files" "$FILTER")"
fi
echo "Found $(wc -l <<<"$files") files to analyze"
parallel_result=0
parallel "${parallel_options[@]}" <<<"$files" 2>&1 || parallel_result="$?"
if [ "$parallel_result" != 0 ]; then
echo
echo ======================
echo
echo "Failures for following files :"
awk <"$parallel_log" '{ if ($7 != "0" && $7 != "Exitval") { print $10 } }'
exit "$parallel_result"
fi