Changeset View
Changeset View
Standalone View
Standalone View
autotests/src/script_test_base.cpp
Show All 28 Lines | |||||
29 | 29 | | |||
30 | #include "kateview.h" | 30 | #include "kateview.h" | ||
31 | #include "katedocument.h" | 31 | #include "katedocument.h" | ||
32 | #include "kateglobal.h" | 32 | #include "kateglobal.h" | ||
33 | 33 | | |||
34 | #include <QProcess> | 34 | #include <QProcess> | ||
35 | #include <QDirIterator> | 35 | #include <QDirIterator> | ||
36 | #include <QMainWindow> | 36 | #include <QMainWindow> | ||
37 | #include <QScriptEngine> | 37 | #include <QJSEngine> | ||
38 | #include <QCryptographicHash> | 38 | #include <QCryptographicHash> | ||
39 | #include <QTest> | 39 | #include <QTest> | ||
40 | 40 | | |||
41 | #include "testutils.h" | 41 | #include "testutils.h" | ||
42 | 42 | | |||
43 | #include "script_test_base.h" | 43 | #include "script_test_base.h" | ||
44 | 44 | | |||
45 | const QString testDataPath(QLatin1String(TEST_DATA_DIR)); | 45 | const QString testDataPath(QLatin1String(TEST_DATA_DIR)); | ||
Show All 28 Lines | |||||
74 | { | 74 | { | ||
75 | QTest::addColumn<QString>("testcase"); | 75 | QTest::addColumn<QString>("testcase"); | ||
76 | 76 | | |||
77 | // make sure the script files are valid | 77 | // make sure the script files are valid | ||
78 | if (!m_script_dir.isEmpty()) { | 78 | if (!m_script_dir.isEmpty()) { | ||
79 | QFile scriptFile(QLatin1String(JS_DATA_DIR) + m_script_dir + QLatin1Char('/') + script + QLatin1String(".js")); | 79 | QFile scriptFile(QLatin1String(JS_DATA_DIR) + m_script_dir + QLatin1Char('/') + script + QLatin1String(".js")); | ||
80 | if (scriptFile.exists()) { | 80 | if (scriptFile.exists()) { | ||
81 | QVERIFY(scriptFile.open(QFile::ReadOnly)); | 81 | QVERIFY(scriptFile.open(QFile::ReadOnly)); | ||
82 | QScriptValue result = m_env->engine()->evaluate(QString::fromLatin1(scriptFile.readAll()), scriptFile.fileName()); | 82 | QJSValue result = m_env->engine()->evaluate(QString::fromLatin1(scriptFile.readAll()), scriptFile.fileName()); | ||
83 | QVERIFY2(!result.isError(), qPrintable(QString(result.toString() + QLatin1String("\nat ") | 83 | QVERIFY2(!result.isError(), (result.toString() + QLatin1String(" in file ") + scriptFile.fileName()).toUtf8().constData()); | ||
84 | + m_env->engine()->uncaughtExceptionBacktrace().join(QLatin1String("\n"))))); | | |||
85 | } | 84 | } | ||
86 | } | 85 | } | ||
87 | 86 | | |||
88 | const QString testDir(testDataPath + m_section + QLatin1Char('/') + script + QLatin1Char('/')); | 87 | const QString testDir(testDataPath + m_section + QLatin1Char('/') + script + QLatin1Char('/')); | ||
89 | if (!QFile::exists(testDir)) { | 88 | if (!QFile::exists(testDir)) { | ||
90 | QSKIP(qPrintable(QString(testDir + QLatin1String(" does not exist"))), SkipAll); | 89 | QSKIP(qPrintable(QString(testDir + QLatin1String(" does not exist"))), SkipAll); | ||
91 | } | 90 | } | ||
92 | QDirIterator contents(testDir); | 91 | QDirIterator contents(testDir); | ||
Show All 33 Lines | 106 | { | |||
126 | } | 125 | } | ||
127 | 126 | | |||
128 | QTextStream stream(&sourceFile); | 127 | QTextStream stream(&sourceFile); | ||
129 | stream.setCodec("UTF8"); | 128 | stream.setCodec("UTF8"); | ||
130 | QString code = stream.readAll(); | 129 | QString code = stream.readAll(); | ||
131 | sourceFile.close(); | 130 | sourceFile.close(); | ||
132 | 131 | | |||
133 | // Execute script | 132 | // Execute script | ||
134 | QScriptValue result = m_env->engine()->evaluate(code, testcase + QLatin1String("/input.js"), 1); | 133 | QJSValue result = m_env->engine()->evaluate(code, testcase + QLatin1String("/input.js"), 1); | ||
135 | QVERIFY2(!result.isError(), result.toString().toUtf8().constData()); | 134 | QVERIFY2(!result.isError(), result.toString().toUtf8().constData()); | ||
136 | 135 | | |||
137 | const QString fileExpected = testcase + QLatin1String("/expected"); | 136 | const QString fileExpected = testcase + QLatin1String("/expected"); | ||
138 | const QString fileActual = testcase + QLatin1String("/actual"); | 137 | const QString fileActual = testcase + QLatin1String("/actual"); | ||
139 | 138 | | |||
140 | url.setPath(fileActual); | 139 | url.setPath(fileActual); | ||
141 | m_document->saveAs(url); | 140 | m_document->saveAs(url); | ||
142 | 141 | | |||
▲ Show 20 Lines • Show All 51 Lines • Show Last 20 Lines |