mirror of
https://github.com/storytold/craft-libs.git
synced 2026-11-25 20:22:39 +00:00
Merge pull request #2373 from storytold/perf/2218-menu
menu: consolidate tests and keep AppKit on the main thread
This commit is contained in:
@@ -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"] }
|
||||
|
||||
@@ -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 `<name> --exact`, which falls through to the test below.
|
||||
let args: Vec<String> = 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() {}
|
||||
@@ -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());
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user