Skip to content

Commit

Permalink
Add a lint for failing and orphaned tests.
Browse files Browse the repository at this point in the history
  • Loading branch information
tabatkins committed Dec 6, 2024
1 parent 6f89a28 commit e463bb9
Show file tree
Hide file tree
Showing 2 changed files with 60 additions and 0 deletions.
25 changes: 25 additions & 0 deletions .github/workflows/lint-tests.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
name: Lint the test files

on:
push:
paths:
- "tests/**"
pull_request:
paths:
- "tests/**"
workflow_dispatch: {}

jobs:
lint:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v4
- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: '3.10'
- name: Verify failing tests and orphaned tests
run: |
cd tests/test_cases
python ../../.github/workflows/lint-tests/lint.py
35 changes: 35 additions & 0 deletions .github/workflows/lint-tests/lint.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
from __future__ import annotations

import os
import sys
import typing

def findTestFiles(path) -> typing.Generator[str, None, None]:
for root, _, filenames in os.walk(path):
for filename in filenames:
yield os.path.join(root, filename)

# strip the leading folder name, so they can be directly compared
inputFiles = set(x[len("input")+1:] for x in findTestFiles("input"))
validFiles = set(x[len("expected_kdl")+1:] for x in findTestFiles("expected_kdl"))

invalidFiles = inputFiles - validFiles
orphanedFiles = validFiles - inputFiles

SUCCESS = True

if orphanedFiles:
SUCCESS = False
print("ERROR: There are outputs in /expected_kdl without corresponding tests in /input:\n" + "\n".join([" "+x for x in orphanedFiles]))

misnamedFiles: list[str] = []
for filepath in invalidFiles:
basepath, ext = os.path.splitext(filepath)
if not basepath.endswith("_fail"):
misnamedFiles.append(filepath)
if misnamedFiles:
SUCCESS = False
print("ERROR: There are tests in /input without corresponding outputs in /expected_kdl, but they don't have a _fail suffix:\n" + "\n".join([" "+x for x in misnamedFiles]))

if not SUCCESS:
sys.exit(1)

0 comments on commit e463bb9

Please sign in to comment.