mirror of
https://github.com/zed-industries/zed.git
synced 2026-11-19 15:10:34 +01:00
95cd535a5f
Projects that depend on GPUI rebuild it, and everything above it, whenever they switch between running their app and running their tests: `cargo test` turns on `test-support` through dev-dependencies, and `cargo build` doesn't. Turning `test-support` on in every build would remove that split, but today the feature changes runtime behavior, so it can't ship in a production binary. This PR makes it additive where it mattered. - **Leak detection is opt-in.** `gpui/test-support` no longer turns on `leak-detection`, which takes the entity map's write lock on every handle create and drop. It's now enabled by the `leak-detection` feature (as `zed/track-project-leak` already does) or by setting `GPUI_LEAK_DETECTION=1` when building. Without it: - `leak_detector_snapshot()` and `assert_no_new_leaks()` are no-ops; - `WeakEntity::assert_released()` still panics when the entity is alive, but can't list the live handles. - **`util::paths::home_dir()`** returns the fixed fake path (`/Users/zed`) only in `util`'s own tests, not whenever `util/test-support` is on. No test outside `util` depended on the fake path. - **`is_test()` on GPUI contexts.** `App::is_test`, `AsyncApp::is_test` and `BackgroundExecutor::is_test` (in gpui and scheduler) report whether the executor is a `TestScheduler`, in every build. Code that must behave differently under tests should use these instead of `cfg(feature = "test-support")`, so compiling the feature into an app doesn't change its behavior. For code with no executor, such as expensive invariant checks, `scheduler::test_scheduler_created()` reports whether the process has created a `TestScheduler`, which test harnesses do before the test body runs. - **Metal `framebuffer_only(false)`** (needed for offscreen capture) now only applies in debug builds, so optimized builds that compile `test-support` keep the faster presentation path. **Open question:** CI doesn't set `GPUI_LEAK_DETECTION`, so with this change leak checks outside gpui's own unit tests are skipped in CI. If we go ahead, the test jobs should set it. I've left that out until we agree on the approach. This PR is mainly to see what CI says about crates whose tests read `home_dir()` (`project`, `worktree`, `workspace`, …), which now see the real home directory. Release Notes: - [GPUI] Made the `test-support` feature safe to enable in production builds: leak detection is now opt-in via the `leak-detection` feature or `GPUI_LEAK_DETECTION`, and `App::is_test` reports whether code runs under the test scheduler