diff options
Diffstat (limited to 'interpreter')
-rw-r--r-- | interpreter/interpreter.pro | 4 | ||||
-rw-r--r-- | interpreter/qscriptsystemtest.cpp | 86 | ||||
-rw-r--r-- | interpreter/qscriptsystemtest.h | 12 |
3 files changed, 99 insertions, 3 deletions
diff --git a/interpreter/interpreter.pro b/interpreter/interpreter.pro index eb3be3f..c91e4ee 100644 --- a/interpreter/interpreter.pro +++ b/interpreter/interpreter.pro @@ -57,3 +57,7 @@ mac { CONFIG(debug,debug|release): LIBS += -L$$BUILDROOT/lib -lqsystemtest_debug -lqtuitest_debug CONFIG(release,debug|release): LIBS += -L$$BUILDROOT/lib -lqsystemtest -lqtuitest } + + +target.path += \ + /usr/local/bin
\ No newline at end of file diff --git a/interpreter/qscriptsystemtest.cpp b/interpreter/qscriptsystemtest.cpp index 93b0725..2dbe531 100644 --- a/interpreter/qscriptsystemtest.cpp +++ b/interpreter/qscriptsystemtest.cpp @@ -489,6 +489,89 @@ bool QScriptSystemTest::setQueryError( const QString &errString ) return ret; } +#ifdef QTCREATOR_QTEST +int QScriptSystemTest::runTest(const QString &fname, const QStringList ¶meters, + const QStringList &environment) +{ + m_env = environment; + qDebug() << "Running " << fname; + filename = fname; + + QFile file(filename); + if (!file.open(QFile::ReadOnly)) { + qDebug() << "Can't open " << filename; + return -1; + } + + QTextStream stream(&file); + QString script = stream.readAll(); + + ScriptPreprocessor().preprocess(script); + + setupEnums(&m_engine); + + // include() imports scripts directly into the parent script. + m_engine.globalObject().setProperty + ("include", m_engine.newFunction(includeFunction, 1)); + m_engine.globalObject().setProperty + ("setFlags", m_engine.newFunction(setFlags, 3)); + + + m_engine.globalObject().setProperty("_dateToString", m_engine.newFunction(dateToString)); + m_engine.evaluate("_old_date_toString = Date.prototype.toString;" + "Date.prototype.toString = function() {" + " if (arguments[0] == undefined)" + " return _old_date_toString.apply(this, arguments);" + " return _dateToString.apply(this, arguments);" + "}"); + + m_engine.globalObject().setProperty("ParentTestObject", m_engine.newQObject(this)); + m_engine.globalObject().setProperty("ParentTestMetaObject", m_engine.newQMetaObject(metaObject())); + + loadBuiltins(m_engine); + importIntoGlobalNamespace(m_engine, "ParentTestObject"); + + // Allow shebangs without giving syntax errors. + if (script.startsWith("#!")) script.prepend("//"); + script.prepend("with(ParentTestMetaObject){"); + script.append("\n}"); + + QtScriptTest tc(filename, script, &m_engine); + testObject = &tc; + + qScriptRegisterMetaType(&m_engine, variantToScriptValue, variantFromScriptValue); + qScriptRegisterSequenceMetaType<QList<qint64> >(&m_engine); + + // Only set up the test data path if not explicitly set by user + if (!QCoreApplication::arguments().contains("-data")) { + setupTestDataPath(qPrintable(filename)); + } + + enableQueryWarnings(false); + + // If we get here, the syntax of the script is definitely OK + // (a syntax error causes a qFatal in the QtScriptTest ctor). + if (m_checkOnly) + return 0; + + // If an IDE is connected, set the agent to enable script debugging + if (testIDE() && testIDE()->isConnected()) { + m_engine.setAgent(m_agent); + } + + int retval = QTest::qExec(&tc, parameters); + + testObject = 0; + + // After a full test run, QTestLib sometimes returns 0 or sometimes returns + // the number of test failures, depending on how it was compiled. In both + // cases, a negative number denotes an error. + // We don't want test failures to affect the exit code. + return (retval < 0) ? retval : 0; +} +#endif + +#ifndef QTCREATOR_QTEST int QScriptSystemTest::runTest(int argc, char *argv[]) { if (argc > 1) filename = argv[1]; @@ -574,6 +657,7 @@ int QScriptSystemTest::runTest(int argc, char *argv[]) // We don't want test failures to affect the exit code. return (retval < 0) ? retval : 0; } +#endif /*! \internal @@ -630,6 +714,7 @@ QVariantMap QScriptSystemTest::sendRaw(const QString& event, const QScriptValue& return ret; } +#ifndef QTCREATOR_QTEST /*! \internal Print any special usage information which should be shown when test is launched @@ -644,6 +729,7 @@ void QScriptSystemTest::printUsage(int argc, char *argv[]) const " contains any syntax errors.\n" ); } +#endif /*! \internal diff --git a/interpreter/qscriptsystemtest.h b/interpreter/qscriptsystemtest.h index b7b185c..7244db3 100644 --- a/interpreter/qscriptsystemtest.h +++ b/interpreter/qscriptsystemtest.h @@ -65,6 +65,11 @@ public: void scriptPositionChange(qint64, int, int); void scriptContextChange(bool); +#ifdef QTCREATOR_QTEST + virtual int runTest(const QString &fname, const QStringList ¶meters, + const QStringList &environment); +#endif + public slots: virtual bool fail(QString const &message); virtual void expectFail( const QString &reason ); @@ -86,13 +91,14 @@ protected: virtual bool setQueryError( const QTestMessage &message ); virtual bool setQueryError( const QString &errString ); +#ifndef QTCREATOR_QTEST virtual int runTest(int argc, char *argv[]); + virtual void printUsage(int,char*[]) const; +#endif + virtual void processCommandLine(int&, char*[]); virtual bool isFailExpected(); - virtual void processCommandLine(int&, char*[]); - virtual void printUsage(int,char*[]) const; - virtual void processMessage(const QTestMessage& message); |