diff options
author | Simon Hausmann <simon.hausmann@qt.io> | 2019-06-04 12:07:20 +0200 |
---|---|---|
committer | Simon Hausmann <simon.hausmann@qt.io> | 2019-06-04 10:14:39 +0000 |
commit | 5c954b89a9bd94b085a49d05dfa25644b2eda1c8 (patch) | |
tree | 4f7a392af74a9db67167a118c351c35f77cac330 /src/testlib/qtestcase.h | |
parent | fae5691c7f78f8a0154c9cea28b6639327a90550 (diff) |
Fix qFindTestData with cmake and ninja generator
In order for test lib to locate the file requested via QFINDTESTDATA, it
needs the build directory of the test (for example
$builddir/tests/auto/foo/bar) and __FILE__ expanding to a path to the
source relative to this build directory.
With ninja, __FILE__ is a path that is always relative to the top-level
build directory, not the per-test case one. Therefore the path
resolution in testlib fails.
To accommodate this, add_qt_test() now always sets QT_TESTCASE_BUILDDIR
as well as the newly introduced QT_TESTCASE_SOURCEDIR, which, as an
absolute path, removes the need to use __FILE__.
Change-Id: I16c2b0001e38162e6da9fdb1a61f4f8ce634fe46
Reviewed-by: Ville Voutilainen <ville.voutilainen@qt.io>
Diffstat (limited to 'src/testlib/qtestcase.h')
-rw-r--r-- | src/testlib/qtestcase.h | 11 |
1 files changed, 8 insertions, 3 deletions
diff --git a/src/testlib/qtestcase.h b/src/testlib/qtestcase.h index 794283ff78..8136452791 100644 --- a/src/testlib/qtestcase.h +++ b/src/testlib/qtestcase.h @@ -213,8 +213,13 @@ do {\ QTest::qWarn(static_cast<const char *>(msg), __FILE__, __LINE__) #ifdef QT_TESTCASE_BUILDDIR + +#ifndef QT_TESTCASE_SOURCEDIR +#define QT_TESTCASE_SOURCEDIR nullptr +#endif + # define QFINDTESTDATA(basepath)\ - QTest::qFindTestData(basepath, __FILE__, __LINE__, QT_TESTCASE_BUILDDIR) + QTest::qFindTestData(basepath, __FILE__, __LINE__, QT_TESTCASE_BUILDDIR, QT_TESTCASE_SOURCEDIR) #else # define QFINDTESTDATA(basepath)\ QTest::qFindTestData(basepath, __FILE__, __LINE__) @@ -309,8 +314,8 @@ namespace QTest #if QT_CONFIG(temporaryfile) Q_TESTLIB_EXPORT QSharedPointer<QTemporaryDir> qExtractTestData(const QString &dirName); #endif - Q_TESTLIB_EXPORT QString qFindTestData(const char* basepath, const char* file = nullptr, int line = 0, const char* builddir = nullptr); - Q_TESTLIB_EXPORT QString qFindTestData(const QString& basepath, const char* file = nullptr, int line = 0, const char* builddir = nullptr); + Q_TESTLIB_EXPORT QString qFindTestData(const char* basepath, const char* file = nullptr, int line = 0, const char* builddir = nullptr, const char* sourcedir = nullptr); + Q_TESTLIB_EXPORT QString qFindTestData(const QString& basepath, const char* file = nullptr, int line = 0, const char* builddir = nullptr, const char *sourcedir = nullptr); Q_TESTLIB_EXPORT void *qData(const char *tagName, int typeId); Q_TESTLIB_EXPORT void *qGlobalData(const char *tagName, int typeId); |