┌   ┐
54
└   ┘

summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorSebastian Englbrecht <[email protected]>2026-05-23 13:28:32 +0200
committerSebastian Englbrecht <[email protected]>2026-05-25 13:05:50 +0200
commita33d65a418bf5bdb13d83281ce665d630a95668e (patch)
tree36c60da1f2e3b7b032b93b2151a5687c77608447 /src
parent22d65e047ac75fc3527ddac2401e90a2805a6f04 (diff)
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.
Diffstat (limited to 'src')
-rw-r--r--src/tests/CMakeLists.txt30
1 files changed, 30 insertions, 0 deletions
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: <reason>'; \
+ 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