Files
pebrel/scripts/tests/test_platform_cfg.py
T
kuddev 0e6acf89e3 wip: prepare cross-platform previews and workspace improvements
Capture cross-platform startup, SSH credentials, preview packaging gates, and current SSH, answer-reader, math, and icon work. Remove unrelated product comparisons from public source comments.

Preview helper and shell tests pass locally. Native macOS/Linux build, test, and package validation remain pending in CI. Local Windows-only hooks cannot execute under WSL; content and workflow checks were run separately.
2026-09-05 14:51:55 +08:00

27 lines
1.1 KiB
Python

import tempfile
import unittest
from pathlib import Path
from scripts.check_platform_cfg import count_platform_cfgs
class PlatformCfgTests(unittest.TestCase):
def count(self, source: str) -> int:
with tempfile.TemporaryDirectory() as directory:
path = Path(directory) / "source.rs"
path.write_text(source, encoding="utf-8")
return count_platform_cfgs(path)
def test_plain_target_os_is_counted(self) -> None:
for target in ("macos", "linux", "freebsd"):
self.assertEqual(self.count(f'#[cfg(target_os = "{target}")] fn example() {{}}'), 1)
def test_nested_conditions_and_macros_are_counted(self) -> None:
self.assertEqual(self.count('#[cfg(all(unix, not(target_os = "macos")))]'), 2)
self.assertEqual(self.count('cfg!(any(windows, target_os = "linux"))'), 2)
self.assertEqual(self.count('#[cfg_attr(target_os="macos", allow(dead_code))]'), 1)
def test_features_are_not_platforms(self) -> None:
self.assertEqual(self.count('#[cfg(feature = "gpui-shell")]'), 0)
self.assertEqual(self.count('let windows = true;'), 0)