60 lines
2.3 KiB
Python
60 lines
2.3 KiB
Python
from __future__ import annotations
|
|
|
|
import io
|
|
import tarfile
|
|
import tempfile
|
|
import unittest
|
|
from pathlib import Path
|
|
|
|
from scripts.vendor_libghostty_vt import parse_archive_root
|
|
|
|
|
|
class VendorLibghosttyVtTests(unittest.TestCase):
|
|
def test_parse_archive_root_returns_single_top_level_directory(self) -> None:
|
|
with tempfile.TemporaryDirectory() as temp_dir:
|
|
archive = Path(temp_dir) / "libghostty-vt.tar.gz"
|
|
with tarfile.open(archive, "w:gz") as tar:
|
|
data = b"hello"
|
|
info = tarfile.TarInfo("libghostty-vt-1.0.0/README.md")
|
|
info.size = len(data)
|
|
tar.addfile(info, io.BytesIO(data))
|
|
|
|
self.assertEqual(parse_archive_root(archive), "libghostty-vt-1.0.0")
|
|
|
|
def test_vendored_tree_contains_required_upstream_files(self) -> None:
|
|
root = Path(__file__).resolve().parent.parent / "vendor" / "libghostty-vt"
|
|
required = [
|
|
root / "build.zig",
|
|
root / "build.zig.zon",
|
|
root / "CMakeLists.txt",
|
|
root / "dist" / "cmake" / "ghostty-vt-config.cmake.in",
|
|
root / "include" / "ghostty" / "vt.h",
|
|
root / "include" / "ghostty" / "vt" / "render.h",
|
|
root / "src" / "lib_vt.zig",
|
|
]
|
|
|
|
missing = [str(path.relative_to(root)) for path in required if not path.exists()]
|
|
self.assertEqual(missing, [])
|
|
|
|
def test_vendor_metadata_exists_and_points_at_vendored_tree(self) -> None:
|
|
project_root = Path(__file__).resolve().parent.parent
|
|
metadata = project_root / "vendor" / "libghostty-vt.vendor.json"
|
|
self.assertTrue(metadata.exists())
|
|
text = metadata.read_text()
|
|
self.assertIn('"source_commit"', text)
|
|
self.assertIn('"dist_archive"', text)
|
|
self.assertIn('"extracted_dir"', text)
|
|
|
|
def test_embedded_libghostty_logging_is_silenced(self) -> None:
|
|
root = Path(__file__).resolve().parent.parent / "vendor" / "libghostty-vt"
|
|
lib_vt = root / "src" / "lib_vt.zig"
|
|
sys_zig = root / "src" / "terminal" / "c" / "sys.zig"
|
|
lib_text = lib_vt.read_text()
|
|
sys_text = sys_zig.read_text()
|
|
self.assertIn('.logFn = @import("terminal/c/sys.zig").logFn', lib_text)
|
|
self.assertIn("if (global.log == null) return;", sys_text)
|
|
|
|
|
|
if __name__ == "__main__":
|
|
unittest.main()
|