Make the coroutine-friendly versions of QTest macros public
Closed this issue · 3 comments
QCoro has a re-defined some of the common QTest macros (QCOMPARE
, QVERIFY
, ...) to a be coroutine-friendly (i.e. using co_return
instead of return
) in its own test suite. This might be useful for our users who want to test their QCoro-based code. With a little bit of polishing we could have a QCoroTest module with those macros as part of public API
On this note, can one use QCoro in general with QTest? Specifically slumming it and doing waitFor? So far I can't do it since waitFor (and I wager QCoro::Task) needs a QApplication, and it's mysterious to me how to satisfy that requirement
QTest actually requires QApplication (that's what's hidden inside the QTEST_(GUILESS)_MAIN
macro), so QCoro coroutines work very well with QTest. You can use waitFor()
just fine, it waits with a nested event loop, so the test doesn't get stuck or anything. You can check the test
folder in this repo, although the infrastructure here is slightly more complex than just waitFor
.
What you need (and what this ticket is about) are coroutine-compatible assertions, i.e. you can't use QVERIFY
inside a coroutine, because the macro calls return
internally. I have most of the basic QTest assertions reimplemented in coroutine-compatible way in QCoro (= they use co_return
instead of return
, see here: https://github.com/danvratil/qcoro/blob/main/tests/testlibs/testmacros.h for the list. This ticket is basically about making that header more complete and public :)
@danvratil Thank you for the clarifications. I was overthinking my problem to the max. Keep up the good work!