Skip to content

Commit

Permalink
Add parse and highlight tests for all files
Browse files Browse the repository at this point in the history
  • Loading branch information
tgross35 committed Jan 22, 2024
1 parent 0ec1645 commit 1ce16d0
Show file tree
Hide file tree
Showing 3 changed files with 197 additions and 27 deletions.
41 changes: 14 additions & 27 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,16 @@ on:

jobs:
deno:
name: Deno format and lint
name: Codestyle (format and lint)
runs-on: ubuntu-latest
timeout-minutes: 15
steps:
- uses: actions/checkout@v4
- uses: taiki-e/install-action@just
- uses: denoland/setup-deno@v1
with:
deno-version: "~1.39"
- run: deno lint
- run: deno fmt --check
- run: just --verbose ci-codestyle

test:
runs-on: ${{ matrix.os }}
Expand All @@ -26,6 +26,7 @@ jobs:
os: [macos-latest, ubuntu-latest, windows-latest]
steps:
- uses: actions/checkout@v4
- uses: taiki-e/install-action@just
- uses: actions/setup-node@v4
with:
node-version: 18
Expand All @@ -40,21 +41,15 @@ jobs:
key: ${{ runner.os }}-node-${{ hashFiles('**/package-lock.json') }}
restore-keys: |
${{ runner.os }}-node-
- run: git tag pre-updates
- run: npm install --locked
- name: Create generated files
shell: bash
run: |
npm run gen
failed=false
git diff pre-updates --exit-code || failed=true
if ! [ "$failed" = "false" ]; then
echo '::warning::Generated files are out of date!'
echo '::warning::run `npm run gen` and commit the changes'
fi
- run: npm test
- name: Configure
run: just --verbose configure-tree-sitter
- name: Check generated files
run: just --verbose ci-validate-generated-files
- name: Run tests
run: just --verbose test
- name: Check C files with args
run: just --verbose check-c

static-validation:
runs-on: ubuntu-latest
Expand All @@ -63,14 +58,6 @@ jobs:
- uses: actions/checkout@v4
- uses: taiki-e/install-action@just
- name: Verify Just can parse test files
shell: bash
run: |
# skip readme.just because it is broken but works for testing
find . -type f -iregex '.*[\./]just[^\./]*' |
grep -v readme.just | while read -r fname
do
echo checking "$fname"
just --list --unstable --justfile "$fname"
done
run: just --verbose verify-just-parsing
- name: Look for tests that contain errors
run: "! grep -r -E '(ERROR|MISSING|UNEXPECTED)' test"
run: just --verbose verify-no-error-tests
114 changes: 114 additions & 0 deletions justfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,114 @@
# List all recipes

Check notice on line 1 in justfile

View workflow job for this annotation

GitHub Actions / static-validation

checking Just parsing
default:
just --list

# Run deno lint
lint:
deno lint

alias fmt := format

# Run deno format
format:
deno fmt

# Run tests that are built into tree-sitter
test-ts:
npm test

# Verify that tree-sitter can parse and highlight all files in the repo. Requires a tree-sitter configuration.
test-parse-highlight:
#!/bin/sh
set -eaux

echo '::group::Parse and highlight testing'
# skip readme.just because it is broken but works for testing
find {{justfile_directory()}} -type f -iregex '.*[\./]just[^\./]*' |
grep -v readme.just |
while read -r fname
do
echo "::notice:: checking parsing of $fname"
npx tree-sitter parse "$fname"
echo "::notice:: checking highlight of $fname"
npx tree-sitter highlight "$fname"
done
echo '::endgroup::'

# Run all test options
test: test-ts test-parse-highlight

# Check C files with more strict arguments
check-c:
#!/bin/sh
set -eaux

find src/ -name '*.c' ! -name "parser.c" |
xargs -IFNAME sh -c \
'echo && echo "::notice:: checking file FNAME"' &&
clang FNAME -c -Wall -Werror --pedantic \
-Wno-format-pedantic \
-o/dev/null'
# Verify that the `just` tool parses all files we are using
verify-just-parsing:
#!/bin/sh
set -eaux
# skip readme.just because it is broken but works for testing
find . -type f -iregex '.*[\./]just[^\./]*' |
grep -v readme.just |
while read -r fname
do
echo "::notice file=$fname:: checking Just parsing"
just --list --unstable --justfile "$fname"
done
# Make sure that no tests contain errors
verify-no-error-tests:
! grep -nr -C4 -E '(ERROR|MISSING|UNEXPECTED)' test
# Configure tree-sitter to use this directory
configure-tree-sitter:
#!/usr/bin/env python3
import json
import os
import subprocess as sp
cfg_fname = """{{ config_directory() / "tree-sitter" / "config.json" }}"""
if not os.path.isfile(cfg_fname):
sp.run(["npx", "tree-sitter", "init-config"], check=True)
with open(cfg_fname, "r+") as f:
s = json.loads(f.read())
f.seek(0)
# Add this directory to the config file
parent_dir = os.path.dirname("{{ justfile_directory() }}")
s["parser-directories"].append(parent_dir)
f.write(s.dumps())
f.truncate()
# Run lint and check formatting
ci-codestyle:
deno lint
deno fmt --check
# Make sure that files have not changed
ci-validate-generated-files:
#!/bin/sh
set -eaux
git tag ci-tmp-pre-updates
npm run gen
failed=false
git diff ci-tmp-pre-updates --exit-code || failed=true
if ! [ "$failed" = "false" ]; then
echo '::warning::Generated files are out of date!'
echo '::warning::run `npm run gen` and commit the changes'
fi
git tag -d ci-tmp-pre-updates
69 changes: 69 additions & 0 deletions test/issue69-segfault.just
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
alias b := build

Check notice on line 1 in test/issue69-segfault.just

View workflow job for this annotation

GitHub Actions / static-validation

checking Just parsing
alias c := check
alias dr := dry-run
alias sw := switch
alias t := test
alias u := update
alias ui := update-input

rebuildArgs := "--verbose"
rebuild := if os() == "macos" { "darwin-rebuild" } else { "nixos-rebuild" }

default:
@just --choose

[private]
rebuild subcmd:
{{ rebuild }} {{ subcmd }} {{ rebuildArgs }} --flake .

build: (rebuild "build")

dry-run: (rebuild "dry-run")

switch: (rebuild "switch")

test: (rebuild "test")

ci:
nix run \
--inputs-from . \
--override-input nixpkgs nixpkgs \
github:Mic92/nix-fast-build -- \
--no-nom \
--skip-cached \
--option accept-flake-config true \
--option allow-import-from-derivation false \
--flake '.#hydraJobs'

check:
nix flake check \
--print-build-logs \
--show-trace \
--accept-flake-config

update:
nix flake update

update-input input:
nix flake lock \
--update-input {{ input }} \
--commit-lock-file \
--commit-lockfile-summary "flake: update {{ input }}"

deploy system:
nix run \
--inputs-from . \
'nixpkgs#deploy-rs' -- \
-s '.#{{ system }}'

deploy-all:
nix run \
--inputs-from . \
'nixpkgs#deploy-rs' -- -s

clean:
rm -rf \
result* \
repl-result-out* \
config.tf.json \
.terraform*

0 comments on commit 1ce16d0

Please sign in to comment.