"""Run the Void C++26 reference cases with GCC in a private module cache.""" import argparse import os from pathlib import Path import subprocess import tempfile FIXTURES = Path(__file__).resolve().parent def check_case(name, argv, work, *, diagnostic=None, stdout=None): result = subprocess.run( argv, cwd=work, env={**os.environ, "LC_ALL": "C"}, timeout=45, capture_output=True, text=True, errors="replace", ) if diagnostic is None: matched = result.returncode == 0 else: matched = result.returncode == 1 and diagnostic in result.stderr if not matched or (stdout is not None and result.stdout.strip() != stdout): raise SystemExit( f"{name}: exit {result.returncode}\n{result.stdout}\n{result.stderr}" ) print(f"{name}: exit {result.returncode}") def verify(compiler, include, work): flags = [compiler, "-std=c++26", "-freflection", "-fdiagnostics-color=never"] syntax = ["-fsyntax-only"] for public in (False, True): name = "public" if public else "detail" defines = ["-DPUBLIC_ENTRY"] if public else [] program = work / f"enum-{name}" check_case(f"compile {name} enum helper", [*flags, *defines, "-I", include, FIXTURES / "enum.cpp", "-o", program], work) check_case(f"run {name} enum helper", [program], work, stdout="Ready ? 17 0 41 0") check_case("GCC reflection library", [*flags, *syntax, FIXTURES / "library.cpp"], work) check_case("library without reflection", [compiler, "-std=c++26", "-fno-reflection", *syntax, FIXTURES / "library.cpp"], work, diagnostic="GCC 16.2 reflection declarations are inactive") check_case("constexpr span with static storage", [*flags, *syntax, FIXTURES / "range-static.cpp"], work) check_case("constexpr span with automatic storage", [*flags, *syntax, FIXTURES / "range.cpp"], work, diagnostic="constant expression") for defines in ([], ["-DINIT_LIST"]): check_case("constexpr range expansion", [*flags, *defines, *syntax, FIXTURES / "expansion-static.cpp"], work) provider = ["-x", "c++", "-c", FIXTURES / "gate.cppm", "-o", "gate.o"] importer = ["-c", FIXTURES / "importer.cpp", "-o", "importer.o"] modules = [*flags, "-fmodules"] check_case("import before module is built", [*modules, *importer], work, diagnostic="gate") check_case("provider without module flag", [*flags, *provider], work, diagnostic="-fmodules") check_case("module interface", [*modules, *provider], work) check_case("module importer", [*modules, *importer], work) check_case("link module program", [compiler, "gate.o", "importer.o", "-o", "module"], work) check_case("run imported reflection", [work / "module"], work) for source, location in (("invalid-name.cpp", ":4:48:"), ("invalid-splice.cpp", ":5:35:")): check_case(f"diagnose {source}", [*modules, *syntax, FIXTURES / source], work, diagnostic=source + location) check_case("valid importer after invalid edit", [*modules, *syntax, FIXTURES / "importer.cpp"], work) if __name__ == "__main__": parser = argparse.ArgumentParser(description=__doc__) parser.add_argument("--cxx", default="g++", help="GCC 16+ C++ compiler") parser.add_argument("--void-include", type=Path, required=True, help="tested VoidLibrary include directory") args = parser.parse_args() include = args.void_include.resolve(strict=True) with tempfile.TemporaryDirectory(prefix="vls-gcc-corpus-") as scratch: verify(args.cxx, include, Path(scratch))