aboutsummaryrefslogtreecommitdiff
path: root/autotests/test_kconf_update.cpp
diff options
context:
space:
mode:
authorAlex Richardson <arichardson.kde@gmail.com>2014-05-07 20:40:48 +0200
committerAlex Richardson <arichardson.kde@gmail.com>2014-05-07 20:48:16 +0200
commit94419b6f0cd469dc7cb0184a6fb48c1fe304c4d8 (patch)
tree1171622e05b6c1d4dc2cc02e0ced0f8af7a227bc /autotests/test_kconf_update.cpp
parent7544b8344254cc60dc18fac564ca5f24c52ce66b (diff)
downloadkconfig-94419b6f0cd469dc7cb0184a6fb48c1fe304c4d8.tar.gz
kconfig-94419b6f0cd469dc7cb0184a6fb48c1fe304c4d8.tar.bz2
Fix kconf_update test on Windows
We get a CMake warning for reading the LOCATION property, but I don't see how else to do it (generator expressions don't seem to work)
Diffstat (limited to 'autotests/test_kconf_update.cpp')
-rw-r--r--autotests/test_kconf_update.cpp32
1 files changed, 27 insertions, 5 deletions
diff --git a/autotests/test_kconf_update.cpp b/autotests/test_kconf_update.cpp
index 90faf989..d4f5c52d 100644
--- a/autotests/test_kconf_update.cpp
+++ b/autotests/test_kconf_update.cpp
@@ -49,7 +49,12 @@ static QString readFile(const QString &path)
bool ok = file.open(QIODevice::ReadOnly);
Q_UNUSED(ok) // silence warnings
Q_ASSERT(ok);
- return QString::fromUtf8(file.readAll());
+ QString ret = QString::fromUtf8(file.readAll());
+#ifdef Q_OS_WIN
+ // KConfig always writes files with the native line ending, the test comparison uses \n
+ ret.replace("\r\n", "\n");
+#endif
+ return ret;
}
static QTemporaryFile *writeUpdFile(const QString &content)
@@ -65,9 +70,8 @@ static QTemporaryFile *writeUpdFile(const QString &content)
static void runKConfUpdate(const QString &updPath)
{
- QString exePath = KCONF_UPDATE_BINARY_DIR "/kconf_update";
- QVERIFY(QFile::exists(exePath));
- QProcess::execute(exePath, QStringList() << "--debug" << updPath);
+ QVERIFY(QFile::exists(KCONF_UPDATE_EXECUTABLE));
+ QCOMPARE(0, QProcess::execute(KCONF_UPDATE_EXECUTABLE, QStringList() << "--debug" << updPath));
}
void TestKConfUpdate::test_data()
@@ -265,6 +269,7 @@ void TestKConfUpdate::test()
QFile::remove(newConfPath);
writeFile(oldConfPath, oldConfContent);
+ QCOMPARE(readFile(oldConfPath), oldConfContent);
QSharedPointer<QTemporaryFile> updFile(writeUpdFile(updContent));
runKConfUpdate(updFile->fileName());
@@ -285,6 +290,12 @@ void TestKConfUpdate::test()
void TestKConfUpdate::testScript_data()
{
+#ifdef Q_OS_WIN
+ // add sh.exe and sed.exe to PATH on Windows
+ // uncomment and adapt path to run all tests
+ // qputenv("PATH", qgetenv("PATH") + ";C:\\kde\\msys\\bin");
+#endif
+
QTest::addColumn<QString>("updContent");
QTest::addColumn<QString>("updScript");
QTest::addColumn<QString>("oldConfContent");
@@ -474,7 +485,10 @@ void TestKConfUpdate::testScript_data()
"new=value3\n"
;
- QTest::newRow("filter")
+ if (QStandardPaths::findExecutable("sed").isEmpty()) {
+ qWarning("sed executable not found, cannot run all tests!");
+ } else {
+ QTest::newRow("filter")
<<
"File=testrc\n"
"Script=test.sh,sh\n"
@@ -519,10 +533,16 @@ void TestKConfUpdate::testScript_data()
"changed=VALUE\n"
"unchanged=value\n"
;
+ }
}
void TestKConfUpdate::testScript()
{
+ if (QStandardPaths::findExecutable("sh").isEmpty()) {
+ QSKIP("Could not find sh executable, cannot run test");
+ return;
+ }
+
QFETCH(QString, updContent);
QFETCH(QString, updScript);
QFETCH(QString, oldConfContent);
@@ -537,9 +557,11 @@ void TestKConfUpdate::testScript()
QVERIFY(QDir().mkpath(scriptDir));
QString scriptPath = scriptDir + "/test.sh";
writeFile(scriptPath, updScript);
+ QCOMPARE(readFile(scriptPath), updScript);
QString confPath = QStandardPaths::writableLocation(QStandardPaths::GenericConfigLocation) + QLatin1Char('/') + "testrc";
writeFile(confPath, oldConfContent);
+ QCOMPARE(readFile(confPath), oldConfContent);
runKConfUpdate(updFile->fileName());