Add tests for dump commands
[tinc] / test / integration / testlib / check.py
index 1d1dfb0..a82e0e4 100755 (executable)
@@ -1,6 +1,8 @@
 """Simple assertions which print the expected and received values on failure."""
 
+import os.path
 import typing as T
+from pathlib import Path
 
 from .log import log
 
@@ -50,6 +52,13 @@ def in_range(value: Num, gte: Num, lte: Num) -> None:
         raise ValueError(f"value {value} must be between {gte} and {lte}")
 
 
+def lines(text: T.AnyStr, num: int) -> None:
+    """Check that text splits into `num` lines."""
+    rows = text.splitlines()
+    if len(rows) != num:
+        raise ValueError(f"expected {num} lines, got {len(rows)}: {rows}")
+
+
 def is_in(needle: Val, *haystacks: T.Container[Val]) -> None:
     """Check that at least one haystack includes needle."""
     for haystack in haystacks:
@@ -86,3 +95,9 @@ def files_eq(path0: str, path1: str) -> None:
 
     if content0 != content1:
         raise ValueError(f"expected files {path0} and {path1} to match")
+
+
+def file_exists(path: T.Union[str, Path]) -> None:
+    """Check that file or directory exists."""
+    if not os.path.exists(path):
+        raise ValueError("expected path '{path}' to exist")