Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 13 additions & 3 deletions tests/conformance/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,14 +21,24 @@


@pytest.fixture
def plain_environment() -> dict[str, str]:
"""The environment with any compiler launcher taken off `PATH`."""
def plain_toolchain(monkeypatch: pytest.MonkeyPatch) -> None:
"""Takes any compiler launcher off `PATH` for the whole test.

Not just for the recording: CMake and Meson resolve the compiler when they
configure, and write the path they found into the build files, so a
launcher they saw would be used however the recording is run.
"""
directories = [
directory
for directory in os.environ.get("PATH", "").split(os.pathsep)
if not LAUNCHERS & set(Path(directory).parts)
]
return dict(os.environ, LC_ALL="C", PATH=os.pathsep.join(directories))
monkeypatch.setenv("PATH", os.pathsep.join(directories))
# Meson goes looking for a launcher binary rather than taking the one in
# front of the compiler on PATH, and only leaves the compiler alone when
# it is told which one to use.
monkeypatch.setenv("CC", "cc")
monkeypatch.setenv("CXX", "c++")


def pytest_addoption(parser: pytest.Parser) -> None:
Expand Down
11 changes: 5 additions & 6 deletions tests/conformance/test_build_systems.py
Original file line number Diff line number Diff line change
Expand Up @@ -200,9 +200,7 @@ def tool_of(pid: int) -> str:


@pytest.mark.parametrize("case", sorted(CASES))
def test_build_system(
case, buildprof: Path, tmp_path: Path, request, plain_environment: dict
):
def test_build_system(case, buildprof: Path, tmp_path: Path, request, plain_toolchain):
for tool in REQUIRED_TOOLS[case]:
if shutil.which(tool) is None:
message = f"{tool} is not installed in this environment"
Expand All @@ -216,13 +214,14 @@ def test_build_system(
command = build(project)

trace = tmp_path / f"{case}.pftrace"
env = dict(os.environ, LC_ALL="C")
result = subprocess.run(
[str(buildprof), "-o", str(trace), "--", *command],
cwd=project,
text=True,
capture_output=True,
timeout=300,
env=plain_environment,
env=env,
)
assert result.returncode == 0, f"{case} build failed:\n{result.stdout}{result.stderr}"
assert trace.is_file(), f"{case} produced no trace"
Expand All @@ -242,7 +241,7 @@ def test_build_system(
)


def test_npm_build(buildprof: Path, tmp_path: Path, plain_environment: dict):
def test_npm_build(buildprof: Path, tmp_path: Path, plain_toolchain):
for tool in ("npm", "node"):
if shutil.which(tool) is None:
message = f"{tool} is not installed in this environment"
Expand All @@ -255,7 +254,7 @@ def test_npm_build(buildprof: Path, tmp_path: Path, plain_environment: dict):
result = subprocess.run(
[str(buildprof), "--no-open", "-o", str(trace), "--", *command],
cwd=tmp_path,
env=dict(plain_environment, npm_config_cache=str(tmp_path / ".npm")),
env=dict(os.environ, LC_ALL="C", npm_config_cache=str(tmp_path / ".npm")),
text=True,
capture_output=True,
timeout=60,
Expand Down
Loading