From 8625e02b8e7077b41002d3a1edc8819226ea5850 Mon Sep 17 00:00:00 2001 From: "J. Nick Koston" Date: Tue, 25 Aug 2026 13:50:01 -0500 Subject: [PATCH] Cover the remaining pch branches --- tests/unit_tests/build_gen/test_espidf.py | 32 +++++++++++++++++++++++ tests/unit_tests/test_espidf_framework.py | 11 ++++++++ 2 files changed, 43 insertions(+) diff --git a/tests/unit_tests/build_gen/test_espidf.py b/tests/unit_tests/build_gen/test_espidf.py index 3ff85295bd..4bf394db39 100644 --- a/tests/unit_tests/build_gen/test_espidf.py +++ b/tests/unit_tests/build_gen/test_espidf.py @@ -681,3 +681,35 @@ def test_prepare_pch_disabled_is_noop( CORE.build_path = dev with patch("esphome.build_gen.espidf.subprocess.run", side_effect=AssertionError): prepare_pch() + + +def test_prepare_pch_without_compile_commands(tmp_path: Path) -> None: + """Stale checksum but no configured TU yet: no compile, no sidecars.""" + from esphome.build_gen.espidf import prepare_pch + + dev = _make_pch_device(tmp_path, "dev_n") + (dev / "build" / "compile_commands.json").unlink() + CORE.build_path = dev + with ( + patch.object(CORE, "name", "test"), + patch("esphome.build_gen.espidf.subprocess.run", side_effect=AssertionError), + ): + prepare_pch() + assert not (dev / "build" / "esphome_pch.h.gch.sum").exists() + assert not (dev / "build" / "esphome_pch.h.gch.failed").exists() + + +def test_write_project_pch_disabled_writes_no_header( + tmp_path: Path, monkeypatch: pytest.MonkeyPatch +) -> None: + from esphome.build_gen.espidf import write_project + + monkeypatch.setenv("ESPHOME_PCH_ENABLE", "0") + _write_project_description(tmp_path, {}) + CORE.build_path = tmp_path + with ( + patch("esphome.build_gen.espidf.get_esp32_variant", return_value="ESP32"), + patch.object(CORE, "name", "test"), + ): + write_project() + assert not (tmp_path / "build" / "esphome_pch.h").exists() diff --git a/tests/unit_tests/test_espidf_framework.py b/tests/unit_tests/test_espidf_framework.py index fe9a357c28..1494021809 100644 --- a/tests/unit_tests/test_espidf_framework.py +++ b/tests/unit_tests/test_espidf_framework.py @@ -1946,3 +1946,14 @@ def test_check_windows_path_length_long_path_warns( assert "long path support" in message # The install is global now; the remedy is the prefix env, not moving the project. assert "ESPHOME_ESP_IDF_PREFIX" in message + + +def test_ccache_env_opt_in_with_usable_binary( + tmp_path: Path, caplog: pytest.LogCaptureFixture +) -> None: + # Forced on with a runnable binary: no warning, full env exported. + p1, p2, p3 = _ccache_patches(tmp_path, "/usr/bin/ccache", tmp_path / "build") + with patch.dict("os.environ", {"IDF_CCACHE_ENABLE": "1"}, clear=True), p1, p2, p3: + env = _ccache_env() + assert env["IDF_CCACHE_ENABLE"] == "1" + assert "ccache" not in caplog.text