forked from qt-creator/qt-creator
WebAssembly: Reorganize plugin tests
Change-Id: I1e2be15877ef4d1adc8355b820c1b8fc333d6409 Reviewed-by: Christian Stenger <christian.stenger@qt.io>
This commit is contained in:
@@ -15,3 +15,10 @@ add_qtc_plugin(WebAssembly
|
|||||||
webassemblyrunconfiguration.cpp webassemblyrunconfiguration.h
|
webassemblyrunconfiguration.cpp webassemblyrunconfiguration.h
|
||||||
webassemblytoolchain.cpp webassemblytoolchain.h
|
webassemblytoolchain.cpp webassemblytoolchain.h
|
||||||
)
|
)
|
||||||
|
|
||||||
|
extend_qtc_plugin(WebAssembly
|
||||||
|
CONDITION WITH_TESTS
|
||||||
|
SOURCES
|
||||||
|
webassembly_test.cpp
|
||||||
|
webassembly_test.h
|
||||||
|
)
|
||||||
|
|||||||
@@ -32,4 +32,13 @@ QtcPlugin {
|
|||||||
"webassemblytoolchain.cpp",
|
"webassemblytoolchain.cpp",
|
||||||
"webassemblytoolchain.h",
|
"webassemblytoolchain.h",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
Group {
|
||||||
|
name: "Unit tests"
|
||||||
|
condition: qtc.testsEnabled
|
||||||
|
files: [
|
||||||
|
"webassembly_test.cpp",
|
||||||
|
"webassembly_test.h",
|
||||||
|
]
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
120
src/plugins/webassembly/webassembly_test.cpp
Normal file
120
src/plugins/webassembly/webassembly_test.cpp
Normal file
@@ -0,0 +1,120 @@
|
|||||||
|
// Copyright (C) 2023 The Qt Company Ltd.
|
||||||
|
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0
|
||||||
|
|
||||||
|
#include "webassembly_test.h"
|
||||||
|
|
||||||
|
#include "webassemblyemsdk.h"
|
||||||
|
#include "webassemblyrunconfigurationaspects.h"
|
||||||
|
|
||||||
|
#include <utils/environment.h>
|
||||||
|
|
||||||
|
#include <QTest>
|
||||||
|
|
||||||
|
using namespace Utils;
|
||||||
|
|
||||||
|
namespace WebAssembly::Internal {
|
||||||
|
|
||||||
|
void WebAssemblyTest::testEmSdkEnvParsing()
|
||||||
|
{
|
||||||
|
QFETCH(QString, emSdkEnvOutput);
|
||||||
|
QFETCH(int, osType);
|
||||||
|
QFETCH(int, pathCount);
|
||||||
|
QFETCH(QString, emsdk);
|
||||||
|
QFETCH(QString, em_config);
|
||||||
|
|
||||||
|
Environment env{OsType(osType)};
|
||||||
|
WebAssemblyEmSdk::parseEmSdkEnvOutputAndAddToEnv(emSdkEnvOutput, env);
|
||||||
|
|
||||||
|
QVERIFY(env.path().count() == pathCount);
|
||||||
|
QCOMPARE(env.value("EMSDK"), emsdk);
|
||||||
|
QCOMPARE(env.value("EM_CONFIG"), em_config);
|
||||||
|
}
|
||||||
|
|
||||||
|
void WebAssemblyTest::testEmSdkEnvParsing_data()
|
||||||
|
{
|
||||||
|
// Output of "emsdk_env"
|
||||||
|
QTest::addColumn<QString>("emSdkEnvOutput");
|
||||||
|
QTest::addColumn<int>("osType");
|
||||||
|
QTest::addColumn<int>("pathCount");
|
||||||
|
QTest::addColumn<QString>("emsdk");
|
||||||
|
QTest::addColumn<QString>("em_config");
|
||||||
|
|
||||||
|
QTest::newRow("windows") << R"(
|
||||||
|
Adding directories to PATH:
|
||||||
|
PATH += C:\Users\user\dev\emsdk
|
||||||
|
PATH += C:\Users\user\dev\emsdk\upstream\emscripten
|
||||||
|
PATH += C:\Users\user\dev\emsdk\node\12.18.1_64bit\bin
|
||||||
|
PATH += C:\Users\user\dev\emsdk\python\3.7.4-pywin32_64bit
|
||||||
|
PATH += C:\Users\user\dev\emsdk\java\8.152_64bit\bin
|
||||||
|
|
||||||
|
Setting environment variables:
|
||||||
|
PATH = C:\Users\user\dev\emsdk;C:\Users\user\dev\emsdk\upstream\emscripten;C:\Users\user\dev\emsdk\node\12.18.1_64bit\bin;C:\Users\user\dev\emsdk\python\3.7.4-pywin32_64bit;C:\Users\user\dev\emsdk\java\8.152_64bit\bin;...other_stuff...
|
||||||
|
EMSDK = C:/Users/user/dev/emsdk
|
||||||
|
EM_CONFIG = C:\Users\user\dev\emsdk\.emscripten
|
||||||
|
EM_CACHE = C:/Users/user/dev/emsdk/upstream/emscripten\cache
|
||||||
|
EMSDK_NODE = C:\Users\user\dev\emsdk\node\12.18.1_64bit\bin\node.exe
|
||||||
|
EMSDK_PYTHON = C:\Users\user\dev\emsdk\python\3.7.4-pywin32_64bit\python.exe
|
||||||
|
JAVA_HOME = C:\Users\user\dev\emsdk\java\8.152_64bit
|
||||||
|
)" << int(OsTypeWindows) << 6 << "C:/Users/user/dev/emsdk" << "C:\\Users\\user\\dev\\emsdk\\.emscripten";
|
||||||
|
|
||||||
|
QTest::newRow("linux") << R"(
|
||||||
|
Adding directories to PATH:
|
||||||
|
PATH += /home/user/dev/emsdk
|
||||||
|
PATH += /home/user/dev/emsdk/upstream/emscripten
|
||||||
|
PATH += /home/user/dev/emsdk/node/12.18.1_64bit/bin
|
||||||
|
|
||||||
|
Setting environment variables:
|
||||||
|
PATH = /home/user/dev/emsdk:/home/user/dev/emsdk/upstream/emscripten:/home/user/dev/emsdk/node/12.18.1_64bit/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:/snap/bin
|
||||||
|
EMSDK = /home/user/dev/emsdk
|
||||||
|
EM_CONFIG = /home/user/dev/emsdk/.emscripten
|
||||||
|
EM_CACHE = /home/user/dev/emsdk/upstream/emscripten/cache
|
||||||
|
EMSDK_NODE = /home/user/dev/emsdk/node/12.18.1_64bit/bin/node
|
||||||
|
)" << int(OsTypeLinux) << 3 << "/home/user/dev/emsdk" << "/home/user/dev/emsdk/.emscripten";
|
||||||
|
}
|
||||||
|
|
||||||
|
void WebAssemblyTest::testEmrunBrowserListParsing()
|
||||||
|
{
|
||||||
|
QFETCH(QByteArray, emrunOutput);
|
||||||
|
QFETCH(WebBrowserEntries, expectedBrowsers);
|
||||||
|
|
||||||
|
QCOMPARE(WebBrowserSelectionAspect::parseEmrunOutput(emrunOutput), expectedBrowsers);
|
||||||
|
}
|
||||||
|
|
||||||
|
void WebAssemblyTest::testEmrunBrowserListParsing_data()
|
||||||
|
{
|
||||||
|
QTest::addColumn<QByteArray>("emrunOutput");
|
||||||
|
QTest::addColumn<WebBrowserEntries>("expectedBrowsers");
|
||||||
|
|
||||||
|
QTest::newRow("emsdk 1.39.8")
|
||||||
|
// Output of "emrun --list_browsers"
|
||||||
|
<< QByteArray(
|
||||||
|
R"(emrun has automatically found the following browsers in the default install locations on the system:
|
||||||
|
|
||||||
|
- firefox: Mozilla Firefox
|
||||||
|
- chrome: Google Chrome
|
||||||
|
|
||||||
|
You can pass the --browser <id> option to launch with the given browser above.
|
||||||
|
Even if your browser was not detected, you can use --browser /path/to/browser/executable to launch with that browser.
|
||||||
|
|
||||||
|
)")
|
||||||
|
<< WebBrowserEntries({
|
||||||
|
{QLatin1String("firefox"), QLatin1String("Mozilla Firefox")},
|
||||||
|
{QLatin1String("chrome"), QLatin1String("Google Chrome")}});
|
||||||
|
|
||||||
|
QTest::newRow("emsdk 2.0.14")
|
||||||
|
<< QByteArray(
|
||||||
|
R"(emrun has automatically found the following browsers in the default install locations on the system:
|
||||||
|
|
||||||
|
- firefox: Mozilla Firefox 96.0.0.8041
|
||||||
|
- chrome: Google Chrome 97.0.4692.71
|
||||||
|
|
||||||
|
You can pass the --browser <id> option to launch with the given browser above.
|
||||||
|
Even if your browser was not detected, you can use --browser /path/to/browser/executable to launch with that browser.
|
||||||
|
|
||||||
|
)")
|
||||||
|
<< WebBrowserEntries({
|
||||||
|
{QLatin1String("firefox"), QLatin1String("Mozilla Firefox 96.0.0.8041")},
|
||||||
|
{QLatin1String("chrome"), QLatin1String("Google Chrome 97.0.4692.71")}});
|
||||||
|
}
|
||||||
|
|
||||||
|
} // namespace WebAssembly::Internal
|
||||||
21
src/plugins/webassembly/webassembly_test.h
Normal file
21
src/plugins/webassembly/webassembly_test.h
Normal file
@@ -0,0 +1,21 @@
|
|||||||
|
// Copyright (C) 2023 The Qt Company Ltd.
|
||||||
|
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0
|
||||||
|
|
||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include <qobject.h>
|
||||||
|
|
||||||
|
namespace WebAssembly::Internal {
|
||||||
|
|
||||||
|
class WebAssemblyTest : public QObject
|
||||||
|
{
|
||||||
|
Q_OBJECT
|
||||||
|
|
||||||
|
private slots:
|
||||||
|
void testEmSdkEnvParsing();
|
||||||
|
void testEmSdkEnvParsing_data();
|
||||||
|
void testEmrunBrowserListParsing();
|
||||||
|
void testEmrunBrowserListParsing_data();
|
||||||
|
};
|
||||||
|
|
||||||
|
} // WebAssembly::Internal
|
||||||
@@ -1,25 +1,21 @@
|
|||||||
// Copyright (C) 2020 The Qt Company Ltd.
|
// Copyright (C) 2020 The Qt Company Ltd.
|
||||||
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0
|
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0
|
||||||
|
|
||||||
#include "webassemblyconstants.h"
|
|
||||||
#include "webassemblyemsdk.h"
|
#include "webassemblyemsdk.h"
|
||||||
|
|
||||||
|
#include "webassemblyconstants.h"
|
||||||
|
|
||||||
#include <coreplugin/icore.h>
|
#include <coreplugin/icore.h>
|
||||||
#include <utils/environment.h>
|
#include <utils/environment.h>
|
||||||
#include <utils/qtcprocess.h>
|
#include <utils/qtcprocess.h>
|
||||||
#include <utils/hostosinfo.h>
|
#include <utils/hostosinfo.h>
|
||||||
|
|
||||||
|
#include <QCache>
|
||||||
#include <QSettings>
|
#include <QSettings>
|
||||||
|
|
||||||
#ifdef WITH_TESTS
|
|
||||||
# include <QTest>
|
|
||||||
# include "webassemblyplugin.h"
|
|
||||||
#endif // WITH_TESTS
|
|
||||||
|
|
||||||
using namespace Utils;
|
using namespace Utils;
|
||||||
|
|
||||||
namespace WebAssembly {
|
namespace WebAssembly::Internal::WebAssemblyEmSdk {
|
||||||
namespace Internal {
|
|
||||||
|
|
||||||
using EmSdkEnvCache = QCache<QString, QString>;
|
using EmSdkEnvCache = QCache<QString, QString>;
|
||||||
Q_GLOBAL_STATIC_WITH_ARGS(EmSdkEnvCache, emSdkEnvCache, (10))
|
Q_GLOBAL_STATIC_WITH_ARGS(EmSdkEnvCache, emSdkEnvCache, (10))
|
||||||
@@ -47,7 +43,7 @@ static QString emSdkEnvOutput(const FilePath &sdkRoot)
|
|||||||
return *emSdkEnvCache()->object(cacheKey);
|
return *emSdkEnvCache()->object(cacheKey);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void parseEmSdkEnvOutputAndAddToEnv(const QString &output, Environment &env)
|
void parseEmSdkEnvOutputAndAddToEnv(const QString &output, Environment &env)
|
||||||
{
|
{
|
||||||
const QStringList lines = output.split('\n');
|
const QStringList lines = output.split('\n');
|
||||||
|
|
||||||
@@ -70,25 +66,25 @@ static void parseEmSdkEnvOutputAndAddToEnv(const QString &output, Environment &e
|
|||||||
env.appendOrSetPath(FilePath::fromUserInput(emsdkPython).parentDir());
|
env.appendOrSetPath(FilePath::fromUserInput(emsdkPython).parentDir());
|
||||||
}
|
}
|
||||||
|
|
||||||
bool WebAssemblyEmSdk::isValid(const FilePath &sdkRoot)
|
bool isValid(const FilePath &sdkRoot)
|
||||||
{
|
{
|
||||||
return !version(sdkRoot).isNull();
|
return !version(sdkRoot).isNull();
|
||||||
}
|
}
|
||||||
|
|
||||||
void WebAssemblyEmSdk::addToEnvironment(const FilePath &sdkRoot, Environment &env)
|
void addToEnvironment(const FilePath &sdkRoot, Environment &env)
|
||||||
{
|
{
|
||||||
if (sdkRoot.exists())
|
if (sdkRoot.exists())
|
||||||
parseEmSdkEnvOutputAndAddToEnv(emSdkEnvOutput(sdkRoot), env);
|
parseEmSdkEnvOutputAndAddToEnv(emSdkEnvOutput(sdkRoot), env);
|
||||||
}
|
}
|
||||||
|
|
||||||
QVersionNumber WebAssemblyEmSdk::version(const FilePath &sdkRoot)
|
QVersionNumber version(const FilePath &sdkRoot)
|
||||||
{
|
{
|
||||||
if (!sdkRoot.exists())
|
if (!sdkRoot.exists())
|
||||||
return {};
|
return {};
|
||||||
const QString cacheKey = sdkRoot.toString();
|
const QString cacheKey = sdkRoot.toString();
|
||||||
if (!emSdkVersionCache()->contains(cacheKey)) {
|
if (!emSdkVersionCache()->contains(cacheKey)) {
|
||||||
Environment env = sdkRoot.deviceEnvironment();
|
Environment env = sdkRoot.deviceEnvironment();
|
||||||
WebAssemblyEmSdk::addToEnvironment(sdkRoot, env);
|
addToEnvironment(sdkRoot, env);
|
||||||
QLatin1String scriptFile{sdkRoot.osType() == OsType::OsTypeWindows ? "emcc.bat" : "emcc"};
|
QLatin1String scriptFile{sdkRoot.osType() == OsType::OsTypeWindows ? "emcc.bat" : "emcc"};
|
||||||
FilePath script = sdkRoot.withNewPath(scriptFile).searchInDirectories(env.path());
|
FilePath script = sdkRoot.withNewPath(scriptFile).searchInDirectories(env.path());
|
||||||
const CommandLine command(script, {"-dumpversion"});
|
const CommandLine command(script, {"-dumpversion"});
|
||||||
@@ -103,88 +99,25 @@ QVersionNumber WebAssemblyEmSdk::version(const FilePath &sdkRoot)
|
|||||||
return *emSdkVersionCache()->object(cacheKey);
|
return *emSdkVersionCache()->object(cacheKey);
|
||||||
}
|
}
|
||||||
|
|
||||||
void WebAssemblyEmSdk::registerEmSdk(const FilePath &sdkRoot)
|
void registerEmSdk(const FilePath &sdkRoot)
|
||||||
{
|
{
|
||||||
QSettings *s = Core::ICore::settings();
|
QSettings *s = Core::ICore::settings();
|
||||||
s->setValue(QLatin1String(Constants::SETTINGS_GROUP) + '/'
|
s->setValue(QLatin1String(Constants::SETTINGS_GROUP) + '/'
|
||||||
+ QLatin1String(Constants::SETTINGS_KEY_EMSDK), sdkRoot.toString());
|
+ QLatin1String(Constants::SETTINGS_KEY_EMSDK), sdkRoot.toString());
|
||||||
}
|
}
|
||||||
|
|
||||||
FilePath WebAssemblyEmSdk::registeredEmSdk()
|
FilePath registeredEmSdk()
|
||||||
{
|
{
|
||||||
QSettings *s = Core::ICore::settings();
|
QSettings *s = Core::ICore::settings();
|
||||||
const QString path = s->value(QLatin1String(Constants::SETTINGS_GROUP) + '/'
|
const QString path = s->value(QLatin1String(Constants::SETTINGS_GROUP) + '/'
|
||||||
+ QLatin1String(Constants::SETTINGS_KEY_EMSDK)).toString();
|
+ QLatin1String(Constants::SETTINGS_KEY_EMSDK)).toString();
|
||||||
return FilePath::fromUserInput(path);
|
return FilePath::fromUserInput(path);
|
||||||
}
|
}
|
||||||
|
|
||||||
void WebAssemblyEmSdk::clearCaches()
|
void clearCaches()
|
||||||
{
|
{
|
||||||
emSdkEnvCache()->clear();
|
emSdkEnvCache()->clear();
|
||||||
emSdkVersionCache()->clear();
|
emSdkVersionCache()->clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
// Unit tests:
|
} // namespace WebAssembly::Internal::WebAssemblyEmSdk
|
||||||
#ifdef WITH_TESTS
|
|
||||||
void WebAssemblyPlugin::testEmSdkEnvParsing()
|
|
||||||
{
|
|
||||||
QFETCH(QString, emSdkEnvOutput);
|
|
||||||
QFETCH(int, osType);
|
|
||||||
QFETCH(int, pathCount);
|
|
||||||
QFETCH(QString, emsdk);
|
|
||||||
QFETCH(QString, em_config);
|
|
||||||
|
|
||||||
Environment env{OsType(osType)};
|
|
||||||
parseEmSdkEnvOutputAndAddToEnv(emSdkEnvOutput, env);
|
|
||||||
|
|
||||||
QVERIFY(env.path().count() == pathCount);
|
|
||||||
QCOMPARE(env.value("EMSDK"), emsdk);
|
|
||||||
QCOMPARE(env.value("EM_CONFIG"), em_config);
|
|
||||||
}
|
|
||||||
|
|
||||||
void WebAssemblyPlugin::testEmSdkEnvParsing_data()
|
|
||||||
{
|
|
||||||
// Output of "emsdk_env"
|
|
||||||
QTest::addColumn<QString>("emSdkEnvOutput");
|
|
||||||
QTest::addColumn<int>("osType");
|
|
||||||
QTest::addColumn<int>("pathCount");
|
|
||||||
QTest::addColumn<QString>("emsdk");
|
|
||||||
QTest::addColumn<QString>("em_config");
|
|
||||||
|
|
||||||
QTest::newRow("windows") << R"(
|
|
||||||
Adding directories to PATH:
|
|
||||||
PATH += C:\Users\user\dev\emsdk
|
|
||||||
PATH += C:\Users\user\dev\emsdk\upstream\emscripten
|
|
||||||
PATH += C:\Users\user\dev\emsdk\node\12.18.1_64bit\bin
|
|
||||||
PATH += C:\Users\user\dev\emsdk\python\3.7.4-pywin32_64bit
|
|
||||||
PATH += C:\Users\user\dev\emsdk\java\8.152_64bit\bin
|
|
||||||
|
|
||||||
Setting environment variables:
|
|
||||||
PATH = C:\Users\user\dev\emsdk;C:\Users\user\dev\emsdk\upstream\emscripten;C:\Users\user\dev\emsdk\node\12.18.1_64bit\bin;C:\Users\user\dev\emsdk\python\3.7.4-pywin32_64bit;C:\Users\user\dev\emsdk\java\8.152_64bit\bin;...other_stuff...
|
|
||||||
EMSDK = C:/Users/user/dev/emsdk
|
|
||||||
EM_CONFIG = C:\Users\user\dev\emsdk\.emscripten
|
|
||||||
EM_CACHE = C:/Users/user/dev/emsdk/upstream/emscripten\cache
|
|
||||||
EMSDK_NODE = C:\Users\user\dev\emsdk\node\12.18.1_64bit\bin\node.exe
|
|
||||||
EMSDK_PYTHON = C:\Users\user\dev\emsdk\python\3.7.4-pywin32_64bit\python.exe
|
|
||||||
JAVA_HOME = C:\Users\user\dev\emsdk\java\8.152_64bit
|
|
||||||
)" << int(OsTypeWindows) << 6 << "C:/Users/user/dev/emsdk" << "C:\\Users\\user\\dev\\emsdk\\.emscripten";
|
|
||||||
|
|
||||||
QTest::newRow("linux") << R"(
|
|
||||||
Adding directories to PATH:
|
|
||||||
PATH += /home/user/dev/emsdk
|
|
||||||
PATH += /home/user/dev/emsdk/upstream/emscripten
|
|
||||||
PATH += /home/user/dev/emsdk/node/12.18.1_64bit/bin
|
|
||||||
|
|
||||||
Setting environment variables:
|
|
||||||
PATH = /home/user/dev/emsdk:/home/user/dev/emsdk/upstream/emscripten:/home/user/dev/emsdk/node/12.18.1_64bit/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:/snap/bin
|
|
||||||
EMSDK = /home/user/dev/emsdk
|
|
||||||
EM_CONFIG = /home/user/dev/emsdk/.emscripten
|
|
||||||
EM_CACHE = /home/user/dev/emsdk/upstream/emscripten/cache
|
|
||||||
EMSDK_NODE = /home/user/dev/emsdk/node/12.18.1_64bit/bin/node
|
|
||||||
)" << int(OsTypeLinux) << 3 << "/home/user/dev/emsdk" << "/home/user/dev/emsdk/.emscripten";
|
|
||||||
}
|
|
||||||
|
|
||||||
#endif // WITH_TESTS
|
|
||||||
|
|
||||||
} // namespace Internal
|
|
||||||
} // namespace WebAssembly
|
|
||||||
|
|||||||
@@ -3,7 +3,6 @@
|
|||||||
|
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include <QCache>
|
|
||||||
#include <QVersionNumber>
|
#include <QVersionNumber>
|
||||||
|
|
||||||
namespace Utils {
|
namespace Utils {
|
||||||
@@ -11,19 +10,14 @@ class Environment;
|
|||||||
class FilePath;
|
class FilePath;
|
||||||
}
|
}
|
||||||
|
|
||||||
namespace WebAssembly {
|
namespace WebAssembly::Internal::WebAssemblyEmSdk {
|
||||||
namespace Internal {
|
|
||||||
|
|
||||||
class WebAssemblyEmSdk
|
bool isValid(const Utils::FilePath &sdkRoot);
|
||||||
{
|
void parseEmSdkEnvOutputAndAddToEnv(const QString &output, Utils::Environment &env);
|
||||||
public:
|
void addToEnvironment(const Utils::FilePath &sdkRoot, Utils::Environment &env);
|
||||||
static bool isValid(const Utils::FilePath &sdkRoot);
|
QVersionNumber version(const Utils::FilePath &sdkRoot);
|
||||||
static void addToEnvironment(const Utils::FilePath &sdkRoot, Utils::Environment &env);
|
void registerEmSdk(const Utils::FilePath &sdkRoot);
|
||||||
static QVersionNumber version(const Utils::FilePath &sdkRoot);
|
Utils::FilePath registeredEmSdk();
|
||||||
static void registerEmSdk(const Utils::FilePath &sdkRoot);
|
void clearCaches();
|
||||||
static Utils::FilePath registeredEmSdk();
|
|
||||||
static void clearCaches();
|
|
||||||
};
|
|
||||||
|
|
||||||
} // namespace Internal
|
} // WebAssembly::Internal::WebAssemblyEmSdk
|
||||||
} // namespace WebAssembly
|
|
||||||
|
|||||||
@@ -1,10 +1,14 @@
|
|||||||
// Copyright (C) 2020 The Qt Company Ltd.
|
// Copyright (C) 2020 The Qt Company Ltd.
|
||||||
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0
|
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0
|
||||||
|
|
||||||
|
#include "webassemblyplugin.h"
|
||||||
|
|
||||||
|
#ifdef WITH_TESTS
|
||||||
|
#include "webassembly_test.h"
|
||||||
|
#endif // WITH_TESTS
|
||||||
#include "webassemblyconstants.h"
|
#include "webassemblyconstants.h"
|
||||||
#include "webassemblydevice.h"
|
#include "webassemblydevice.h"
|
||||||
#include "webassemblyoptionspage.h"
|
#include "webassemblyoptionspage.h"
|
||||||
#include "webassemblyplugin.h"
|
|
||||||
#include "webassemblyqtversion.h"
|
#include "webassemblyqtversion.h"
|
||||||
#include "webassemblyrunconfiguration.h"
|
#include "webassemblyrunconfiguration.h"
|
||||||
#include "webassemblytoolchain.h"
|
#include "webassemblytoolchain.h"
|
||||||
@@ -54,6 +58,10 @@ WebAssemblyPlugin::~WebAssemblyPlugin()
|
|||||||
void WebAssemblyPlugin::initialize()
|
void WebAssemblyPlugin::initialize()
|
||||||
{
|
{
|
||||||
dd = new WebAssemblyPluginPrivate;
|
dd = new WebAssemblyPluginPrivate;
|
||||||
|
|
||||||
|
#ifdef WITH_TESTS
|
||||||
|
addTest<WebAssemblyTest>();
|
||||||
|
#endif // WITH_TESTS
|
||||||
}
|
}
|
||||||
|
|
||||||
void WebAssemblyPlugin::extensionsInitialized()
|
void WebAssemblyPlugin::extensionsInitialized()
|
||||||
|
|||||||
@@ -3,8 +3,6 @@
|
|||||||
|
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include "webassembly_global.h"
|
|
||||||
|
|
||||||
#include <extensionsystem/iplugin.h>
|
#include <extensionsystem/iplugin.h>
|
||||||
|
|
||||||
namespace WebAssembly::Internal {
|
namespace WebAssembly::Internal {
|
||||||
@@ -21,14 +19,6 @@ public:
|
|||||||
void initialize() override;
|
void initialize() override;
|
||||||
void extensionsInitialized() override;
|
void extensionsInitialized() override;
|
||||||
static void askUserAboutEmSdkSetup();
|
static void askUserAboutEmSdkSetup();
|
||||||
|
|
||||||
#ifdef WITH_TESTS
|
|
||||||
private slots:
|
|
||||||
void testEmSdkEnvParsing();
|
|
||||||
void testEmSdkEnvParsing_data();
|
|
||||||
void testEmrunBrowserListParsing();
|
|
||||||
void testEmrunBrowserListParsing_data();
|
|
||||||
#endif // WITH_TESTS
|
|
||||||
};
|
};
|
||||||
|
|
||||||
} // WebAssembly::Internal
|
} // WebAssembly::Internal
|
||||||
|
|||||||
@@ -14,11 +14,6 @@
|
|||||||
#include <QComboBox>
|
#include <QComboBox>
|
||||||
#include <QTextStream>
|
#include <QTextStream>
|
||||||
|
|
||||||
#ifdef WITH_TESTS
|
|
||||||
# include <QTest>
|
|
||||||
# include "webassemblyplugin.h"
|
|
||||||
#endif // WITH_TESTS
|
|
||||||
|
|
||||||
using namespace Utils;
|
using namespace Utils;
|
||||||
|
|
||||||
namespace WebAssembly {
|
namespace WebAssembly {
|
||||||
@@ -26,20 +21,6 @@ namespace Internal {
|
|||||||
|
|
||||||
static const char BROWSER_KEY[] = "WASM.WebBrowserSelectionAspect.Browser";
|
static const char BROWSER_KEY[] = "WASM.WebBrowserSelectionAspect.Browser";
|
||||||
|
|
||||||
static WebBrowserEntries parseEmrunOutput(const QByteArray &output)
|
|
||||||
{
|
|
||||||
WebBrowserEntries result;
|
|
||||||
QTextStream ts(output);
|
|
||||||
QString line;
|
|
||||||
const QRegularExpression regExp(" - (.*):(.*)");
|
|
||||||
while (ts.readLineInto(&line)) {
|
|
||||||
const QRegularExpressionMatch match = regExp.match(line);
|
|
||||||
if (match.hasMatch())
|
|
||||||
result.push_back({match.captured(1), match.captured(2).trimmed()});
|
|
||||||
}
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
|
|
||||||
static WebBrowserEntries emrunBrowsers(ProjectExplorer::Target *target)
|
static WebBrowserEntries emrunBrowsers(ProjectExplorer::Target *target)
|
||||||
{
|
{
|
||||||
WebBrowserEntries result;
|
WebBrowserEntries result;
|
||||||
@@ -54,7 +35,8 @@ static WebBrowserEntries emrunBrowsers(ProjectExplorer::Target *target)
|
|||||||
browserLister.start();
|
browserLister.start();
|
||||||
|
|
||||||
if (browserLister.waitForFinished())
|
if (browserLister.waitForFinished())
|
||||||
result.append(parseEmrunOutput(browserLister.readAllRawStandardOutput()));
|
result.append(WebBrowserSelectionAspect::parseEmrunOutput(
|
||||||
|
browserLister.readAllRawStandardOutput()));
|
||||||
}
|
}
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
@@ -103,58 +85,20 @@ QString WebBrowserSelectionAspect::currentBrowser() const
|
|||||||
return m_currentBrowser;
|
return m_currentBrowser;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Unit tests:
|
WebBrowserEntries WebBrowserSelectionAspect::parseEmrunOutput(const QByteArray &output)
|
||||||
#ifdef WITH_TESTS
|
|
||||||
|
|
||||||
void testEmrunBrowserListParsing();
|
|
||||||
void testEmrunBrowserListParsing_data();
|
|
||||||
|
|
||||||
void WebAssemblyPlugin::testEmrunBrowserListParsing()
|
|
||||||
{
|
{
|
||||||
QFETCH(QByteArray, emrunOutput);
|
WebBrowserEntries result;
|
||||||
QFETCH(WebBrowserEntries, expectedBrowsers);
|
QTextStream ts(output);
|
||||||
|
QString line;
|
||||||
QCOMPARE(parseEmrunOutput(emrunOutput), expectedBrowsers);
|
static const QRegularExpression regExp(R"( - (.*):\s*(.*))"); // ' - firefox: Mozilla Firefox'
|
||||||
|
// ^__1__^ ^______2______^
|
||||||
|
while (ts.readLineInto(&line)) {
|
||||||
|
const QRegularExpressionMatch match = regExp.match(line);
|
||||||
|
if (match.hasMatch())
|
||||||
|
result.push_back({match.captured(1), match.captured(2)});
|
||||||
|
}
|
||||||
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
void WebAssemblyPlugin::testEmrunBrowserListParsing_data()
|
|
||||||
{
|
|
||||||
QTest::addColumn<QByteArray>("emrunOutput");
|
|
||||||
QTest::addColumn<WebBrowserEntries>("expectedBrowsers");
|
|
||||||
|
|
||||||
QTest::newRow("emsdk 1.39.8")
|
|
||||||
// Output of "emrun --list_browsers"
|
|
||||||
<< QByteArray(
|
|
||||||
R"(emrun has automatically found the following browsers in the default install locations on the system:
|
|
||||||
|
|
||||||
- firefox: Mozilla Firefox
|
|
||||||
- chrome: Google Chrome
|
|
||||||
|
|
||||||
You can pass the --browser <id> option to launch with the given browser above.
|
|
||||||
Even if your browser was not detected, you can use --browser /path/to/browser/executable to launch with that browser.
|
|
||||||
|
|
||||||
)")
|
|
||||||
<< WebBrowserEntries({
|
|
||||||
{QLatin1String("firefox"), QLatin1String("Mozilla Firefox")},
|
|
||||||
{QLatin1String("chrome"), QLatin1String("Google Chrome")}});
|
|
||||||
|
|
||||||
QTest::newRow("emsdk 2.0.14")
|
|
||||||
<< QByteArray(
|
|
||||||
R"(emrun has automatically found the following browsers in the default install locations on the system:
|
|
||||||
|
|
||||||
- firefox: Mozilla Firefox 96.0.0.8041
|
|
||||||
- chrome: Google Chrome 97.0.4692.71
|
|
||||||
|
|
||||||
You can pass the --browser <id> option to launch with the given browser above.
|
|
||||||
Even if your browser was not detected, you can use --browser /path/to/browser/executable to launch with that browser.
|
|
||||||
|
|
||||||
)")
|
|
||||||
<< WebBrowserEntries({
|
|
||||||
{QLatin1String("firefox"), QLatin1String("Mozilla Firefox 96.0.0.8041")},
|
|
||||||
{QLatin1String("chrome"), QLatin1String("Google Chrome 97.0.4692.71")}});
|
|
||||||
}
|
|
||||||
|
|
||||||
#endif // WITH_TESTS
|
|
||||||
|
|
||||||
} // namespace Internal
|
} // namespace Internal
|
||||||
} // namespace Webassembly
|
} // namespace Webassembly
|
||||||
|
|||||||
@@ -27,6 +27,8 @@ public:
|
|||||||
|
|
||||||
QString currentBrowser() const;
|
QString currentBrowser() const;
|
||||||
|
|
||||||
|
static WebBrowserEntries parseEmrunOutput(const QByteArray &output);
|
||||||
|
|
||||||
struct Data : BaseAspect::Data
|
struct Data : BaseAspect::Data
|
||||||
{
|
{
|
||||||
QString currentBrowser;
|
QString currentBrowser;
|
||||||
|
|||||||
Reference in New Issue
Block a user