summaryrefslogtreecommitdiffstats
path: root/mkspecs/features/testcase.prf
blob: a6b8d82f1ef5643d512d57df9f5fb4bd3fce110c (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
110
111
112
113
114
115
!contains(TEMPLATE,subdirs) {

check.files                =
check.path                 = .

# If the test ends up in a different directory, we should cd to that directory.
# Note that qmake modifies DESTDIR after this file is processed,
# therefore, testing DESTDIR for emptiness is not sufficient.
# Also note that in debug-and-release mode we don't want to cd into the debug/release
# directory (e.g. if the test goes to foo/release/tst_thing.exe, we want to do
#  cd foo && release/tst_thing.exe ).
MUNGED_DESTDIR=$$DESTDIR
MUNGED_TARGET=$$TARGET
win32:debug_and_release {
    contains(DESTDIR,^release$)|contains(DESTDIR,^debug$):MUNGED_DESTDIR=

    # In debug-and-release mode, the first ../ in TARGET breaks out of the debug/release
    # subdirectory. However, since make's working directory is already outside of the
    # debug/release subdirectory, this first ../ should be ignored when deciding if
    # we have to change directory before running the test.
    MUNGED_TARGET=$$replace(MUNGED_TARGET,^\\.\\./,)
}
!isEmpty(MUNGED_DESTDIR):!contains(MUNGED_DESTDIR,^\\./?):check.commands = cd $(DESTDIR) &&
contains(MUNGED_TARGET,.*/.*):check.commands = cd $(DESTDIR) &&

# Allow for a custom test runner script
check.commands += $(TESTRUNNER)

macx {
    app_bundle: check.commands += ./$(QMAKE_TARGET).app/Contents/MacOS/$(QMAKE_TARGET)
    else:       check.commands += ./$(QMAKE_TARGET)
}
else:unix:      check.commands += ./$(QMAKE_TARGET)
else:           check.commands += $(DESTDIR_TARGET)

# For Qt/Embedded, run every test app as a QWS server
embedded:       check.commands += -qws

# Allow for custom arguments to tests
check.commands += $(TESTARGS)

# If the test is marked as insignificant, discard the exit code
insignificant_test:check.commands = -$${check.commands}

QMAKE_EXTRA_TARGETS *= check

!debug_and_release|build_pass {
    check.depends = first
} else {
    check.CONFIG = recursive
    # In debug and release mode, only run the test once.
    # Run debug if available, release otherwise.
    debug_and_release {
        check.target = dummy_check
        check.recurse_target = check
        debug {
            real_check.depends = debug-check
            real_check.target = check
            QMAKE_EXTRA_TARGETS += real_check
        } else {
            real_check.depends = release-check
            real_check.target = check
            QMAKE_EXTRA_TARGETS += real_check
        }
    }
}

!no_testcase_installs:!contains(INSTALLS, target) {
    # Install tests unless no_testcase_installs is set, or there is already
    # a `target' in INSTALLS.
    #
    # Tests are installed under a directory named after the target so that each
    # test has its own directory for testdata etc.
    #
    load(resolve_target)
    TARGET_BASENAME = $$basename(QMAKE_RESOLVED_TARGET)
    target.path = $$[QT_INSTALL_TESTS]/$$TARGET_BASENAME
    INSTALLS += target
}

contains(INSTALLS, target) {
    # Install testdata as well, but only if we're actually installing the test.
    #
    # Testdata is installed relative to the directory containing the testcase
    # binary itself, e.g. this:
    #
    #   CONFIG += testcase
    #   TARGET = tst_qxmlreader
    #
    #   TESTDATA += testdata/test1.xml testdata/test2.xml
    #
    # ... will result in:
    #
    #   /usr/lib/qt5/tests/tst_qxmlreader/tst_qxmlreader
    #   /usr/lib/qt5/tests/tst_qxmlreader/testdata/test1.xml
    #   /usr/lib/qt5/tests/tst_qxmlreader/testdata/test2.xml
    #   ...
    #
    for(file, TESTDATA) {
        tdi = testdata_install_$${file}
        tdif = $${tdi}.files
        tdip = $${tdi}.path

        # TESTDATA consists of the files to install (source)...
        $$tdif = $$file

        # ... and the destination preserves the relative path
        $$tdip = $${target.path}/$$dirname(file)

        INSTALLS += $$tdi
    }
}

}