From 91f7ec05fa37954de513e13b3d69c0117b1e70f2 Mon Sep 17 00:00:00 2001 From: Tab Atkins-Bittner Date: Tue, 10 Dec 2024 16:03:05 -0800 Subject: [PATCH] Add a lint for test expectations that don't end in a newline. --- .github/workflows/lint-tests/lint.py | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/.github/workflows/lint-tests/lint.py b/.github/workflows/lint-tests/lint.py index d23f6dc..9afc80d 100644 --- a/.github/workflows/lint-tests/lint.py +++ b/.github/workflows/lint-tests/lint.py @@ -18,10 +18,14 @@ orphanedFiles = validFiles - inputFiles SUCCESS = True +# Check for any expected_kdl files without a corresponding input file. 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])) +# Check for any input files lacking an expected_kdl file +# (aka inputs expected to generate a parse error) +# that don't have a _fail suffix. misnamedFiles: list[str] = [] for filepath in invalidFiles: basepath, ext = os.path.splitext(filepath) @@ -31,5 +35,16 @@ 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])) +# Check for any expected_kdl files that don't end in a newline. +noNewlineFiles: list[str] = [] +for filepath in validFiles: + with open("expected_kdl/" + filepath, "r", encoding="utf-8") as fh: + text = fh.read() + if not text.endswith("\n"): + noNewlineFiles.append(filepath) +if noNewlineFiles: + SUCCESS = False + print("ERROR: There are outputs in /expected_kdl that don't end with a newline:\n" + "\n".join([" "+x for x in noNewlineFiles])) + if not SUCCESS: sys.exit(1) \ No newline at end of file