mirror of https://github.com/kdl-org/kdl.git
Add a lint for test expectations that don't end in a newline.
This commit is contained in:
parent
a60d27c99d
commit
91f7ec05fa
|
|
@ -18,10 +18,14 @@ orphanedFiles = validFiles - inputFiles
|
||||||
|
|
||||||
SUCCESS = True
|
SUCCESS = True
|
||||||
|
|
||||||
|
# Check for any expected_kdl files without a corresponding input file.
|
||||||
if orphanedFiles:
|
if orphanedFiles:
|
||||||
SUCCESS = False
|
SUCCESS = False
|
||||||
print("ERROR: There are outputs in /expected_kdl without corresponding tests in /input:\n" + "\n".join([" "+x for x in orphanedFiles]))
|
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] = []
|
misnamedFiles: list[str] = []
|
||||||
for filepath in invalidFiles:
|
for filepath in invalidFiles:
|
||||||
basepath, ext = os.path.splitext(filepath)
|
basepath, ext = os.path.splitext(filepath)
|
||||||
|
|
@ -31,5 +35,16 @@ if misnamedFiles:
|
||||||
SUCCESS = False
|
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]))
|
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:
|
if not SUCCESS:
|
||||||
sys.exit(1)
|
sys.exit(1)
|
||||||
Loading…
Reference in New Issue