From a33d65a418bf5bdb13d83281ce665d630a95668e Mon Sep 17 00:00:00 2001 From: Sebastian Englbrecht Date: Sat, 23 May 2026 13:28:32 +0200 Subject: tests: add ctest lint rule forbidding bare QTest::qWait() Bare qWait(N) calls in tests are easy to reintroduce inadvertently. Add a ctest check that greps test sources for qWait() and fails if any call is found without an // UNAVOIDABLE: comment on the same line. The error message explains why the pattern is forbidden, lists the signal-based alternatives, and shows how to suppress the check for the rare cases where no signal or pollable condition exists. --- src/tests/CMakeLists.txt | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) (limited to 'src/tests') diff --git a/src/tests/CMakeLists.txt b/src/tests/CMakeLists.txt index e77d7d7bf..6a07ff8b9 100644 --- a/src/tests/CMakeLists.txt +++ b/src/tests/CMakeLists.txt @@ -69,6 +69,36 @@ LINK_LIBRARIES dolphinprivate dolphinstatic Qt6::Test) # DragAndDropHelperTest ecm_add_test(draganddrophelpertest.cpp LINK_LIBRARIES dolphinprivate Qt6::Test) +# Lint: forbid bare QTest::qWait() in test sources without an // UNAVOIDABLE: justification. +# Every unavoidable delay must carry a comment explaining why no signal-based wait is possible. +add_test( + NAME no_bare_qwait_in_tests + COMMAND bash -c + "result=\$(grep -rn 'qWait(' '${CMAKE_CURRENT_SOURCE_DIR}' --include='*.cpp' | grep -v '//.*UNAVOIDABLE:'); \ + if [ -n \"\$result\" ]; then \ + echo ''; \ + echo 'LINT FAILURE: bare QTest::qWait(N) found in test sources.'; \ + echo ''; \ + echo 'Why this is forbidden:'; \ + echo ' qWait(N) is a fixed-time sleep. On slow CI machines the delay may be'; \ + echo ' too short, causing sporadic failures unrelated to the code under test.'; \ + echo ''; \ + echo 'How to fix it:'; \ + echo ' Replace with a signal-based wait:'; \ + echo ' QTRY_COMPARE(someValue, expected); // polls up to 5 s'; \ + echo ' QTRY_VERIFY(someCondition); // polls up to 5 s'; \ + echo ' QVERIFY(signalSpy.wait(5000)); // waits for a signal'; \ + echo ' QVERIFY(QTest::qWaitFor([&]{ ... }, 5000)); // waits for a lambda'; \ + echo ''; \ + echo ' If no signal or pollable condition exists, add // UNAVOIDABLE: '; \ + echo ' on the same line to suppress this check and document why.'; \ + echo ''; \ + echo 'Offending lines:'; \ + echo \"\$result\"; \ + exit 1; \ + fi" +) + find_gem(test-unit) set_package_properties(Gem_test-unit PROPERTIES TYPE RECOMMENDED -- cgit v1.3.1