Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ability to run cargo tests on main thread. #128061

Closed
VladasZ opened this issue Jul 20, 2024 · 2 comments
Closed

Ability to run cargo tests on main thread. #128061

VladasZ opened this issue Jul 20, 2024 · 2 comments
Labels
A-libtest Area: `#[test]` / the `test` library C-feature-request Category: A feature request, i.e: not implemented / a PR. T-testing-devex Relevant to the testing devex team (testing DX), which will review and decide on the PR/issue.

Comments

@VladasZ
Copy link

VladasZ commented Jul 20, 2024

Problem

While working with winit or glfw I would like to use regular cargo test to test some screens or views. The problem is that macOS requires all the GUI stuff to be initialized from main thread and these tests panic.
winit:

thread 'interface::tempo_control::test_tempo_control' panicked at /Users/vladas/.cargo/registry/src/index.crates.io-6f17d22bba15001f/winit-0.30.4/src/platform_impl/macos/event_loop.rs:214:14:
on macOS, `EventLoop` must be created on the main thread!

glfw:

*** Assertion failure in -[NSMenu _setMenuName:], NSMenu.m:777

Proposed Solution

Add the ability for cargo tests to be run on the main thread. It may look something like this:

#[test]
#[main_thread]
fn test() {}

Notes

This issue bothers many Rust developers. Here are some related issues:

gtk-rs/gtk4-rs#1235
rust-lang/cargo#3927
rust-lang/cargo#5438
https://stackoverflow.com/questions/43458194/is-there-any-way-to-tell-cargo-to-run-its-tests-on-the-main-thread

@VladasZ VladasZ added the C-feature-request Category: A feature request, i.e: not implemented / a PR. label Jul 20, 2024
@epage
Copy link
Contributor

epage commented Jul 22, 2024

As this is a function of the test harness, libtest, and not cargo test, I'm going to move this to appropriate repo.

@epage epage transferred this issue from rust-lang/cargo Jul 22, 2024
@rustbot rustbot added the needs-triage This issue may need triage. Remove it if it has been sufficiently triaged. label Jul 22, 2024
@epage epage added the A-libtest Area: `#[test]` / the `test` library label Jul 22, 2024
@jieyouxu jieyouxu added T-testing-devex Relevant to the testing devex team (testing DX), which will review and decide on the PR/issue. and removed needs-triage This issue may need triage. Remove it if it has been sufficiently triaged. labels Aug 5, 2024
@RalfJung
Copy link
Member

RalfJung commented Aug 6, 2024

This is a duplicate of #104053.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-libtest Area: `#[test]` / the `test` library C-feature-request Category: A feature request, i.e: not implemented / a PR. T-testing-devex Relevant to the testing devex team (testing DX), which will review and decide on the PR/issue.
Projects
Development

No branches or pull requests

5 participants