|
| 1 | +#!/usr/bin/env bash |
| 2 | +# SPDX-License-Identifier: PMPL-1.0-or-later |
| 3 | +# Copyright (c) 2026 Jonathan D.A. Jewell (hyperpolymath) <j.d.a.jewell@open.ac.uk> |
| 4 | +# validate_extension.sh — Structural tests for vscode-a2ml extension |
| 5 | +# |
| 6 | +# Validates required VS Code extension assets, package.json fields, |
| 7 | +# grammar file structure, and RSR compliance. |
| 8 | +# |
| 9 | +# Usage: bash tests/validate_extension.sh [repo-root] |
| 10 | + |
| 11 | +set -euo pipefail |
| 12 | + |
| 13 | +ROOT="${1:-$(cd "$(dirname "$0")/.." && pwd)}" |
| 14 | +PASS=0; FAIL=0 |
| 15 | + |
| 16 | +check() { |
| 17 | + local desc="$1"; local path="$2" |
| 18 | + if [ -e "$ROOT/$path" ]; then |
| 19 | + echo " PASS: $desc" |
| 20 | + ((PASS++)) || true |
| 21 | + else |
| 22 | + echo " FAIL: $desc — missing $path" |
| 23 | + ((FAIL++)) || true |
| 24 | + fi |
| 25 | +} |
| 26 | + |
| 27 | +check_json_field() { |
| 28 | + local desc="$1"; local file="$2"; local field="$3" |
| 29 | + if grep -q "\"$field\"" "$ROOT/$file" 2>/dev/null; then |
| 30 | + echo " PASS: $desc" |
| 31 | + ((PASS++)) || true |
| 32 | + else |
| 33 | + echo " FAIL: $desc — field '$field' missing in $file" |
| 34 | + ((FAIL++)) || true |
| 35 | + fi |
| 36 | +} |
| 37 | + |
| 38 | +echo "=== vscode-a2ml extension validation ===" |
| 39 | +echo "" |
| 40 | + |
| 41 | +# --- Required files --- |
| 42 | +echo "--- Required files ---" |
| 43 | +check "package.json" "package.json" |
| 44 | +check "language-configuration.json" "language-configuration.json" |
| 45 | +check "A2ML grammar (tmLanguage)" "syntaxes/a2ml.tmLanguage.json" |
| 46 | +check "Snippets file" "snippets/a2ml.json" |
| 47 | +check "Extension icon (png or svg)" "icons" |
| 48 | + |
| 49 | +# --- package.json required fields --- |
| 50 | +echo "" |
| 51 | +echo "--- package.json fields ---" |
| 52 | +check_json_field "name field" "package.json" "name" |
| 53 | +check_json_field "displayName field" "package.json" "displayName" |
| 54 | +check_json_field "version field" "package.json" "version" |
| 55 | +check_json_field "publisher field" "package.json" "publisher" |
| 56 | +check_json_field "engines field" "package.json" "engines" |
| 57 | +check_json_field "contributes field" "package.json" "contributes" |
| 58 | +check_json_field "languages contrib" "package.json" "languages" |
| 59 | +check_json_field "grammars contrib" "package.json" "grammars" |
| 60 | + |
| 61 | +# --- Grammar file validity (JSON parse) --- |
| 62 | +echo "" |
| 63 | +echo "--- Grammar file validation ---" |
| 64 | +if command -v python3 >/dev/null 2>&1; then |
| 65 | + if python3 -c "import json; json.load(open('$ROOT/syntaxes/a2ml.tmLanguage.json'))" 2>/dev/null; then |
| 66 | + echo " PASS: a2ml.tmLanguage.json is valid JSON" |
| 67 | + ((PASS++)) || true |
| 68 | + else |
| 69 | + echo " FAIL: a2ml.tmLanguage.json has JSON syntax errors" |
| 70 | + ((FAIL++)) || true |
| 71 | + fi |
| 72 | + if python3 -c "import json; json.load(open('$ROOT/snippets/a2ml.json'))" 2>/dev/null; then |
| 73 | + echo " PASS: snippets/a2ml.json is valid JSON" |
| 74 | + ((PASS++)) || true |
| 75 | + else |
| 76 | + echo " FAIL: snippets/a2ml.json has JSON syntax errors" |
| 77 | + ((FAIL++)) || true |
| 78 | + fi |
| 79 | + if python3 -c "import json; json.load(open('$ROOT/language-configuration.json'))" 2>/dev/null; then |
| 80 | + echo " PASS: language-configuration.json is valid JSON" |
| 81 | + ((PASS++)) || true |
| 82 | + else |
| 83 | + echo " FAIL: language-configuration.json has JSON syntax errors" |
| 84 | + ((FAIL++)) || true |
| 85 | + fi |
| 86 | +else |
| 87 | + echo " SKIP: python3 not available for JSON validation" |
| 88 | +fi |
| 89 | + |
| 90 | +# --- Grammar structural checks --- |
| 91 | +echo "" |
| 92 | +echo "--- Grammar structural checks ---" |
| 93 | +if [ -f "$ROOT/syntaxes/a2ml.tmLanguage.json" ]; then |
| 94 | + if grep -q '"scopeName"' "$ROOT/syntaxes/a2ml.tmLanguage.json"; then |
| 95 | + echo " PASS: grammar has scopeName" |
| 96 | + ((PASS++)) || true |
| 97 | + else |
| 98 | + echo " FAIL: grammar missing scopeName" |
| 99 | + ((FAIL++)) || true |
| 100 | + fi |
| 101 | + if grep -q '"patterns"' "$ROOT/syntaxes/a2ml.tmLanguage.json"; then |
| 102 | + echo " PASS: grammar has patterns" |
| 103 | + ((PASS++)) || true |
| 104 | + else |
| 105 | + echo " FAIL: grammar missing patterns" |
| 106 | + ((FAIL++)) || true |
| 107 | + fi |
| 108 | +fi |
| 109 | + |
| 110 | +# --- Snippet count check --- |
| 111 | +echo "" |
| 112 | +echo "--- Snippet count ---" |
| 113 | +if [ -f "$ROOT/snippets/a2ml.json" ] && command -v python3 >/dev/null 2>&1; then |
| 114 | + count=$(python3 -c "import json; d=json.load(open('$ROOT/snippets/a2ml.json')); print(len(d))" 2>/dev/null || echo "0") |
| 115 | + if [ "$count" -gt 0 ]; then |
| 116 | + echo " PASS: $count snippet(s) defined" |
| 117 | + ((PASS++)) || true |
| 118 | + else |
| 119 | + echo " WARN: 0 snippets — add at least one" |
| 120 | + fi |
| 121 | +fi |
| 122 | + |
| 123 | +# --- RSR compliance --- |
| 124 | +echo "" |
| 125 | +echo "--- RSR compliance ---" |
| 126 | +check "EXPLAINME.adoc" "EXPLAINME.adoc" |
| 127 | +check "0-AI-MANIFEST.a2ml" "0-AI-MANIFEST.a2ml" |
| 128 | +check "SECURITY.md" "SECURITY.md" |
| 129 | +check "CONTRIBUTING.md or adoc" "CONTRIBUTING.md" |
| 130 | + |
| 131 | +# --- Zig FFI test --- |
| 132 | +echo "" |
| 133 | +echo "--- Zig FFI ---" |
| 134 | +check "Zig integration test" "src/interface/ffi/test/integration_test.zig" |
| 135 | + |
| 136 | +echo "" |
| 137 | +echo "Results: $PASS passed, $FAIL failed" |
| 138 | +[ "$FAIL" -eq 0 ] |
0 commit comments