Files
FreeCADWasmDev/tools/test_web_link_closure.py
wangdequan 9a7c4f0335 Save FreeCAD Web workspace sources and user validation evidence
IFC native binding remains incomplete; preserve accurate test results.
2026-09-15 22:01:58 +08:00

53 lines
2.4 KiB
Python

import contextlib
import io
import json
from pathlib import Path
import sys
import tempfile
import unittest
from unittest.mock import patch
sys.path.insert(0, str(Path(__file__).resolve().parent))
import check_web_link_closure as preflight
class LinkClosureTests(unittest.TestCase):
def test_pthread_in_asset_path_is_not_a_link_flag(self):
options = preflight.link_options('--embed-file="/python-pthread-install/lib@/lib" -sWASM=1', "")
self.assertFalse(options["hasPthreadFlag"])
self.assertFalse(options["needsPthread"])
def test_separate_settings_and_quoted_concurrent_library(self):
options = preflight.link_options("-pthread -s WASM=1 -sMODULARIZE=1 -s PTHREAD_POOL_SIZE=2", '"/qt install/lib/libQt5Concurrent.a"')
self.assertTrue(options["hasPthreadFlag"])
self.assertTrue(options["needsPthread"])
self.assertEqual(options["settings"], {"WASM": "1", "MODULARIZE": "1", "PTHREAD_POOL_SIZE": "2"})
def test_pthread_settings_require_real_flag(self):
for flags in ("-sUSE_PTHREADS=1", "-s PTHREAD_POOL_SIZE=0"):
with self.subTest(flags=flags):
options = preflight.link_options(flags, "")
self.assertTrue(options["needsPthread"])
self.assertFalse(options["hasPthreadFlag"])
def test_reports_missing_flag_and_pool_together_before_link(self):
with tempfile.TemporaryDirectory() as directory:
root = Path(directory)
(root / "build.ninja").write_text(
"build bin/Probe.js: LINKER object.o\n"
" LINK_FLAGS = -sWASM=1 -sMODULARIZE=1 --embed-file=/python-pthread-install/lib@/lib\n"
" LINK_LIBRARIES = /qt/lib/libQt5Concurrent.a\n")
output = io.StringIO()
with patch.object(preflight, "CACHE_PATH", root / "cache.json"), \
patch.object(sys, "argv", ["check", str(root), "Probe", "--json"]), contextlib.redirect_stdout(output):
code = preflight.main()
result = json.loads(output.getvalue())
self.assertEqual(code, 1)
self.assertFalse(result["hasPthreadFlag"])
self.assertEqual(result["errors"], ["pthread-dependent closure has no -pthread link flag",
"pthread-dependent closure has no explicit PTHREAD_POOL_SIZE link setting"])
if __name__ == "__main__":
unittest.main()