test: add parse-examples script

pull/708/head
Munif Tanjim 2021-08-08 22:41:52 +07:00
parent 3360ebc999
commit 2f1a12b9b0
5 changed files with 74 additions and 1 deletions

2
.gitignore vendored

@ -6,3 +6,5 @@ build
node_modules
package-lock.json
target
examples/luvit

@ -0,0 +1,3 @@
#!/usr/bin/env lua
return 42

@ -27,7 +27,8 @@
"scripts": {
"build": "tree-sitter generate",
"postbuild": "node-gyp build",
"test": "tree-sitter test"
"test": "tree-sitter test",
"posttest": "../script/parse-examples lua"
},
"dependencies": {
"nan": "^2.14.2"

@ -0,0 +1,67 @@
#!/usr/bin/env bash
set -euo pipefail
cd "$(dirname "${0}")/.."
declare language="all"
if test -n "${1}"; then
language="${1}";
shift;
fi
checkout_repo() {
local -r path="${1}"
local -r repo="${2}"
local -r sha="${3}"
echo "Checking out github.com/${repo}#${sha} in ${path}"
mkdir -p "${path}"
pushd "${path}" >/dev/null
if [[ ! -d ".git" ]]; then
git init --quiet
git remote add origin "https://github.com/${repo}.git"
git fetch --quiet --depth 1 origin "${sha}"
elif [[ "${sha}" != "$(git rev-parse HEAD)" ]]; then
git fetch --quiet --depth 1 origin "${sha}"
fi
git checkout --quiet FETCH_HEAD
popd >/dev/null
echo
}
checkout_repo "./examples/luvit" "luvit/luvit" "9841bc17aaab32fa63e11063cf68f82da615eefd"
lua_parse_examples() {
local -r known_failures="$(cat script/known_failures.txt)"
pushd "./lua" >/dev/null
tree-sitter parse --quiet \
"../examples/luvit/**/*.lua" \
$(for file in ${known_failures}; do echo "!${file}"; done)
declare -r example_count=$(find ../examples -name "*.lua" | wc -l)
declare -r failure_count=$(wc -w <<< "${known_failures}")
declare -r success_count=$(( ${example_count} - ${failure_count} ))
declare -r success_percent=$(bc -l <<< "100*${success_count}/${example_count}")
printf \
"[Lua] Successfully parsed %d of %d example files (%.1f%%)\n" \
${success_count} ${example_count} ${success_percent}
popd >/dev/null
}
case "${language}" in
lua) lua_parse_examples;;
all)
lua_parse_examples
;;
esac