┌   ┐
54
└   ┘

summaryrefslogtreecommitdiff
path: root/src/tests/CMakeLists.txt
blob: 6a07ff8b986f70b0ec1208c853479f205b37e5c6 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
set( EXECUTABLE_OUTPUT_PATH ${CMAKE_CURRENT_BINARY_DIR} )

find_package(Qt6Test CONFIG REQUIRED)
include(ECMAddTests)

include(FindGem)  # For servicemenutest, see bottom of this file

# KItemSetTest
ecm_add_test(kitemsettest.cpp LINK_LIBRARIES dolphinprivate Qt6::Test)

# KItemRangeTest
ecm_add_test(kitemrangetest.cpp LINK_LIBRARIES dolphinprivate Qt6::Test)


# KItemListSelectionManagerTest
ecm_add_test(kitemlistselectionmanagertest.cpp LINK_LIBRARIES dolphinprivate Qt6::Test)

# KItemListControllerTest
ecm_add_test(kitemlistcontrollertest.cpp testdir.cpp
TEST_NAME kitemlistcontrollertest
LINK_LIBRARIES dolphinprivate Qt6::Test)

# KItemListControllerExpandTest
ecm_add_test(kitemlistcontrollerexpandtest.cpp testdir.cpp
TEST_NAME kitemlistcontrollerexpandtest
LINK_LIBRARIES dolphinprivate Qt6::Test)

# KFileItemListViewTest
ecm_add_test(kfileitemlistviewtest.cpp testdir.cpp
TEST_NAME kfileitemlistviewtest
LINK_LIBRARIES dolphinprivate Qt6::Test)

# KFileItemModelTest
ecm_add_test(kfileitemmodeltest.cpp testdir.cpp
TEST_NAME kfileitemmodeltest
LINK_LIBRARIES dolphinprivate dolphinstatic Qt6::Test)

# KFileItemModelBenchmark, not run automatically with `ctest` or `make test`
add_executable(kfileitemmodelbenchmark kfileitemmodelbenchmark.cpp testdir.cpp)
target_link_libraries(kfileitemmodelbenchmark dolphinprivate Qt6::Test)

# KItemListKeyboardSearchManagerTest
ecm_add_test(kitemlistkeyboardsearchmanagertest.cpp LINK_LIBRARIES dolphinprivate Qt6::Test)

# DolphinSearchBar
if (KF6Baloo_FOUND)
    ecm_add_test(dolphinsearchbartest.cpp
    TEST_NAME dolphinsearchbartest
    LINK_LIBRARIES dolphinprivate dolphinstatic Qt6::Test)
endif()

# DolphinQuery
if (KF6Baloo_FOUND)
    ecm_add_test(dolphinquerytest.cpp
    TEST_NAME dolphinquerytest
    LINK_LIBRARIES dolphinprivate dolphinstatic Qt6::Test)
endif()

# ViewPropertiesTest
ecm_add_test(viewpropertiestest.cpp testdir.cpp
TEST_NAME viewpropertiestest
LINK_LIBRARIES dolphinprivate dolphinstatic Qt6::Test KF6::FileMetaData)

# DolphinMainWindowTest
ecm_add_test(dolphinmainwindowtest.cpp testdir.cpp ${CMAKE_SOURCE_DIR}/src/dolphin.qrc
TEST_NAME dolphinmainwindowtest
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
    DESCRIPTION "Ruby gem 'test-unit' required for testing of servicemenu helpers.")
if (Gem_test-unit_FOUND)
    add_test(NAME servicemenutest
    COMMAND ${CMAKE_CURRENT_SOURCE_DIR}/../settings/contextmenu/test/test_run.rb)
endif()