Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Test parsing for external sources on CI #28

Merged
merged 5 commits into from
Apr 13, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 35 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
name: CI

on:
push:
branches:
- main

pull_request:
branches:
- main
types:
- opened
- synchronize
- reopened
- unlocked
- ready_for_review

jobs:
test-parsing:
if: github.event.pull_request.draft != true
concurrency:
group: ci-${{ github.event.pull_request.number || github.ref }}
cancel-in-progress: true
runs-on: ubuntu-latest
steps:
- name: Checkout source code
uses: actions/checkout@v3

- name: Install the tools
run: npm install

- name: Run the parsing tests
run: |
npm run generate
npm run test-parsing
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,4 @@ target
/bindings/c/tree-sitter-*.pc
/build
/node_modules
/test/sources
7 changes: 4 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,10 @@
"tree-sitter-cli": "^0.20.1"
},
"scripts": {
"test": "tree-sitter test"
}
,
"test": "tree-sitter test",
"generate": "tree-sitter generate",
"test-parsing": "scripts/test-parsing"
},
"tree-sitter": [
{
"scope": "source.zig",
Expand Down
47 changes: 47 additions & 0 deletions scripts/known-parsing-failures.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
zig/test/cases/safety/slice with sentinel out of bounds - runtime len.zig
zig/test/behavior/struct.zig
zig/test/behavior/slice.zig
zig/test/behavior/array.zig
zig/test/behavior/pointers.zig
zig/test/behavior/slice_sentinel_comptime.zig
zig/test/behavior/bugs/12972.zig
zig/test/behavior/packed_struct_explicit_backing_int.zig
zig/lib/std/os.zig
zig/lib/std/array_hash_map.zig
zig/lib/std/hash/auto_hash.zig
zig/lib/std/fs.zig
zig/lib/std/mem.zig
zig/lib/std/zig/c_translation.zig
zig/lib/std/zig/system/windows.zig
zig/lib/std/os/test.zig
zig/lib/std/os/linux/bpf/btf.zig
zig/lib/std/os/linux/bpf.zig
zig/lib/std/os/windows.zig
zig/lib/std/os/uefi/protocols/ip6_protocol.zig
zig/lib/std/os/uefi/protocols/hii.zig
zig/lib/std/os/uefi/protocols/simple_text_input_ex_protocol.zig
zig/lib/std/os/uefi/protocols/simple_network_protocol.zig
zig/lib/std/os/uefi/protocols/absolute_pointer_protocol.zig
zig/lib/std/os/uefi/protocols/edid_override_protocol.zig
zig/lib/std/os/uefi/tables/boot_services.zig
zig/lib/std/unicode.zig
zig/lib/std/meta/trait.zig
zig/lib/std/Thread.zig
zig/lib/std/mem/Allocator.zig
zig/lib/std/json/test.zig
zig/lib/std/child_process.zig
zig/lib/std/macho.zig
zig/lib/std/process.zig
zig/lib/std/dwarf.zig
zig/lib/std/json.zig
zig/lib/std/c/openbsd.zig
zig/lib/std/meta.zig
zig/src/main.zig
zig/src/link/Wasm/Object.zig
zig/src/link/Wasm/Archive.zig
zig/src/link/MachO/Archive.zig
zig/src/Air.zig
zig/src/codegen/llvm/bindings.zig
zig/src/Autodoc.zig
zig/src/Zir.zig
zig/tools/process_headers.zig
90 changes: 90 additions & 0 deletions scripts/test-parsing
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
#!/bin/env bash
# adapted from tree-sitter-typescript/script/parse-examples

set -Eeu -o pipefail
shopt -s inherit_errexit

this_file="${BASH_SOURCE[0]}"
if [ "${this_file::1}" != '/' ]; then
this_file="$PWD/$this_file"
fi

this_dir="${this_file%/*}"
project_root="${this_dir%/*}"
sources_dir="$project_root/test/sources"

cd "$project_root"

clone_repo() {
local owner=$1
local name=$2
local sha=$3
local path="$sources_dir/$name"

if [ -d "$path" ]; then
pushd "$path" > /dev/null
if [ "$(git rev-parse HEAD 2>/dev/null)" == "$sha" ]; then
popd > /dev/null
return
else
popd > /dev/null
rm -rf "$path"
echo "Updating $owner/$name to $sha"
fi
else
echo "Cloning $owner/$name"
fi

mkdir -p "$path"
pushd "$path" > /dev/null
git init --quiet
git remote add origin "https://github.com/$owner/$name"
git pull --quiet --ff-only --depth 1 origin "$sha"
popd > /dev/null
}

# zig 0.10.1 -> https://github.com/ziglang/zig/releases/tag/0.10.1
clone_repo ziglang zig b57081f039bd3f8f82210e8896e336e3c3a6869b

known_failures=()
while IFS= read -r line; do
if [[ "$line" =~ [^[:space:]] ]]; then
full_path="$sources_dir/$line"
if [ -e "$full_path" ]; then
if tree-sitter parse -q "$full_path" &>/dev/null; then
>&2 echo "File $full_path can be parsed without errors, but it's listed in $this_dir/known-parsing-failures.txt"
saw_error=true
else
known_failures+=("$sources_dir/$line")
fi
else
>&2 echo "File $full_path (listed in $this_dir/known-parsing-failures.txt) does not exist"
saw_error=true
fi
fi
done < "$this_dir/known-parsing-failures.txt"
if [ "${saw_error:-}" ]; then
exit 1
fi

while IFS= read -r line; do
for known_failure in "${known_failures[@]}"; do
if [ "$known_failure" == "$line" ]; then
continue 2
fi
done
parse_args+=("$line")
done < <(
find "$sources_dir" \
-name "*.zig" \
-not -path "$sources_dir/zig/test/cases/compile_errors/**"
)
if [ ${#parse_args[*]} -eq 0 ]; then
>&2 echo "No files found to test"
exit 1
fi

echo "[STEP] The following files will be tested:"
printf "%s\n" "${parse_args[@]}"

tree-sitter parse -q "${parse_args[@]}"