diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml new file mode 100644 index 0000000..b3a0a0c --- /dev/null +++ b/.github/workflows/ci.yml @@ -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 diff --git a/.gitignore b/.gitignore index c16bc53..7a0dbae 100644 --- a/.gitignore +++ b/.gitignore @@ -8,3 +8,4 @@ target /bindings/c/tree-sitter-*.pc /build /node_modules +/test/sources diff --git a/package.json b/package.json index 781bb4a..3d17917 100644 --- a/package.json +++ b/package.json @@ -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", diff --git a/scripts/known-parsing-failures.txt b/scripts/known-parsing-failures.txt new file mode 100644 index 0000000..5dcc09c --- /dev/null +++ b/scripts/known-parsing-failures.txt @@ -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 diff --git a/scripts/test-parsing b/scripts/test-parsing new file mode 100755 index 0000000..2403285 --- /dev/null +++ b/scripts/test-parsing @@ -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[@]}"