From 94a604c1837bf39c1297f58e89d82714b3ab47aa Mon Sep 17 00:00:00 2001 From: FredApps Date: Thu, 19 Nov 2026 13:00:49 +0100 Subject: [PATCH] Consolidate menu integration tests --- crates/menu/Cargo.toml | 9 +------- .../tests/{mac_appkit.rs => it/appkit.rs} | 23 ++----------------- crates/menu/tests/it/main.rs | 20 ++++++++++++++++ 3 files changed, 23 insertions(+), 29 deletions(-) rename crates/menu/tests/{mac_appkit.rs => it/appkit.rs} (92%) diff --git a/crates/menu/Cargo.toml b/crates/menu/Cargo.toml index df82fa938..7876d5d3b 100644 --- a/crates/menu/Cargo.toml +++ b/crates/menu/Cargo.toml @@ -8,7 +8,7 @@ rust-version.workspace = true repository.workspace = true [lib] -# Every test lives in the `it` integration binary, except the AppKit one (`mac_appkit`, no harness), so `cargo test` builds the library once. +# All tests share the integration binary, including the AppKit main-thread probe. test = false [dependencies] @@ -37,13 +37,6 @@ path = "tests/it/main.rs" harness = false required-features = ["screen-testing"] -# AppKit end to end: runs on the main thread, so no harness; on other platforms it does nothing. -[[test]] -name = "mac_appkit" -path = "tests/mac_appkit.rs" -harness = false -required-features = ["screen-testing"] - # The test reads AppKit's menu bar back and feeds it real events, through safe objc2 calls. [target.'cfg(target_os = "macos")'.dev-dependencies] objc2 = { version = "0.6.4", default-features = false, features = ["std"] } diff --git a/crates/menu/tests/mac_appkit.rs b/crates/menu/tests/it/appkit.rs similarity index 92% rename from crates/menu/tests/mac_appkit.rs rename to crates/menu/tests/it/appkit.rs index f4f852f34..59f887363 100644 --- a/crates/menu/tests/mac_appkit.rs +++ b/crates/menu/tests/it/appkit.rs @@ -4,14 +4,9 @@ //! press it was, a click (`-[NSMenu performActionForItemAtIndex:]`) must come back from `take_clicks`, also when the //! click is ↩ inside the open menu, and a click made with ⌥ held on a row with an alternate runs the alternate. -// The one sample bar the `it` trials use. This binary needs only `sample()` and its constructors. -#[cfg(target_os = "macos")] -#[allow(dead_code)] -#[path = "it/sample.rs"] -mod sample; +use super::sample; -#[cfg(target_os = "macos")] -fn main() { +pub(super) fn run() { use craft_keymap::Mods; use craft_menu::{Alternate, CommandRef, Document, Gate, Item, LayoutOptions, MenuRole, Node, mac, mac_layout}; use craft_ui::testing::Frames; @@ -20,17 +15,6 @@ fn main() { use objc2_app_kit::{NSApplication, NSEvent, NSEventMask, NSEventModifierFlags, NSEventSubtype, NSEventType, NSMenu}; use objc2_foundation::{NSPoint, NSString}; - // Without a harness nothing answers cargo-nextest's `--list`, so it ran the whole test as its listing and failed - // on the output. List the one test, as libtest's terse format would, and nothing for `--ignored` (nextest asks - // twice). Running it passes ` --exact`, which falls through to the test below. - let args: Vec = std::env::args().collect(); - if args.iter().any(|a| a == "--list") { - if !args.iter().any(|a| a == "--ignored") { - println!("mac_appkit: test"); - } - return; - } - let Some(mtm) = MainThreadMarker::new() else { println!("mac_appkit: harness = false runs on the main thread"); std::process::exit(1); @@ -208,6 +192,3 @@ fn main() { println!("mac_appkit: ok"); } - -#[cfg(not(target_os = "macos"))] -fn main() {} diff --git a/crates/menu/tests/it/main.rs b/crates/menu/tests/it/main.rs index dccdaddd3..a26afa378 100644 --- a/crates/menu/tests/it/main.rs +++ b/crates/menu/tests/it/main.rs @@ -1,11 +1,31 @@ //! The integration binary of craft-menu: every test is a registered trial. +#[cfg(target_os = "macos")] +mod appkit; mod layout; mod mnemonic; mod native; mod sample; mod shortcuts; +#[cfg(target_os = "macos")] +const APPKIT_CHILD: &str = "--craft-menu-appkit-child"; + +#[cfg(target_os = "macos")] +#[craft_ui::testing::trial] +fn mac_appkit() { + // AppKit must own the process main thread. The parent remains a normal filterable trial. + let status = std::process::Command::new(std::env::current_exe().expect("menu test executable")) + .arg(APPKIT_CHILD) + .status() + .expect("start AppKit test process"); + assert!(status.success(), "AppKit test process exited with {status}"); +} + fn main() { + #[cfg(target_os = "macos")] + if std::env::args_os().skip(1).eq([std::ffi::OsString::from(APPKIT_CHILD)]) { + return appkit::run(); + } craft_ui::testing::run(module_path!(), env!("CARGO_PKG_NAME"), &craft_menu::testing::registered()); }