Homebrew moves the extracted archive directory into the Caskroom without stripping the top-level name, so font artifact paths need the homebrew-fonts/ prefix. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
63 lines
2.5 KiB
Python
63 lines
2.5 KiB
Python
"""Tests for cask content: correct font paths and valid cask identifier."""
|
|
import re
|
|
|
|
import pytest
|
|
|
|
from tests.conftest import CASKS_DIR, FONT_FILES_DIR, get_font_dir_names
|
|
|
|
|
|
def _skip_if_no_cask(font_name):
|
|
cask_path = CASKS_DIR / f"{font_name}.rb"
|
|
if not cask_path.exists():
|
|
pytest.skip(f"No cask for {font_name} (no installable font files)")
|
|
|
|
|
|
@pytest.mark.parametrize("font_name", get_font_dir_names())
|
|
def test_cask_references_correct_font_path(font_name):
|
|
"""Generated cask contains the correct font_files/font-<name>/ path."""
|
|
_skip_if_no_cask(font_name)
|
|
cask_path = CASKS_DIR / f"{font_name}.rb"
|
|
content = cask_path.read_text()
|
|
assert f"homebrew-fonts/font_files/{font_name}/" in content, (
|
|
f"{font_name}: cask does not reference homebrew-fonts/font_files/{font_name}/"
|
|
)
|
|
|
|
|
|
@pytest.mark.parametrize("font_name", get_font_dir_names())
|
|
def test_cask_identifier_matches(font_name):
|
|
"""Cask declares the correct identifier matching the file name."""
|
|
_skip_if_no_cask(font_name)
|
|
cask_path = CASKS_DIR / f"{font_name}.rb"
|
|
content = cask_path.read_text()
|
|
match = re.search(r'cask\s+"([^"]+)"\s+do', content)
|
|
assert match, f"{font_name}: no 'cask \"...\" do' found"
|
|
assert match.group(1) == font_name, (
|
|
f"{font_name}: expected cask \"{font_name}\", got \"{match.group(1)}\""
|
|
)
|
|
|
|
|
|
@pytest.mark.parametrize("font_name", get_font_dir_names())
|
|
def test_cask_has_font_artifacts(font_name):
|
|
"""Cask declares at least one font artifact."""
|
|
_skip_if_no_cask(font_name)
|
|
cask_path = CASKS_DIR / f"{font_name}.rb"
|
|
content = cask_path.read_text()
|
|
font_lines = re.findall(r'^\s*font\s+"[^"]+"', content, re.MULTILINE)
|
|
assert font_lines, f"{font_name}: cask has no font artifacts"
|
|
|
|
|
|
@pytest.mark.parametrize("font_name", get_font_dir_names())
|
|
def test_cask_font_files_exist_on_disk(font_name):
|
|
"""Every font artifact declared in the cask corresponds to a real file in font_files/."""
|
|
_skip_if_no_cask(font_name)
|
|
cask_path = CASKS_DIR / f"{font_name}.rb"
|
|
content = cask_path.read_text()
|
|
# Extract paths from font "..." lines; strip the homebrew-fonts/ archive prefix
|
|
paths = re.findall(r'^\s*font\s+"([^"]+)"', content, re.MULTILINE)
|
|
for rel_path in paths:
|
|
# Cask paths include archive root prefix: homebrew-fonts/font_files/...
|
|
local_path = rel_path.replace("homebrew-fonts/", "", 1)
|
|
full_path = FONT_FILES_DIR.parent / local_path
|
|
assert full_path.is_file(), (
|
|
f"{font_name}: font artifact references missing file: {rel_path}"
|
|
)
|