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:
@@ -14,11 +14,6 @@
|
||||
#include <QComboBox>
|
||||
#include <QTextStream>
|
||||
|
||||
#ifdef WITH_TESTS
|
||||
# include <QTest>
|
||||
# include "webassemblyplugin.h"
|
||||
#endif // WITH_TESTS
|
||||
|
||||
using namespace Utils;
|
||||
|
||||
namespace WebAssembly {
|
||||
@@ -26,20 +21,6 @@ namespace Internal {
|
||||
|
||||
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)
|
||||
{
|
||||
WebBrowserEntries result;
|
||||
@@ -54,7 +35,8 @@ static WebBrowserEntries emrunBrowsers(ProjectExplorer::Target *target)
|
||||
browserLister.start();
|
||||
|
||||
if (browserLister.waitForFinished())
|
||||
result.append(parseEmrunOutput(browserLister.readAllRawStandardOutput()));
|
||||
result.append(WebBrowserSelectionAspect::parseEmrunOutput(
|
||||
browserLister.readAllRawStandardOutput()));
|
||||
}
|
||||
return result;
|
||||
}
|
||||
@@ -103,58 +85,20 @@ QString WebBrowserSelectionAspect::currentBrowser() const
|
||||
return m_currentBrowser;
|
||||
}
|
||||
|
||||
// Unit tests:
|
||||
#ifdef WITH_TESTS
|
||||
|
||||
void testEmrunBrowserListParsing();
|
||||
void testEmrunBrowserListParsing_data();
|
||||
|
||||
void WebAssemblyPlugin::testEmrunBrowserListParsing()
|
||||
WebBrowserEntries WebBrowserSelectionAspect::parseEmrunOutput(const QByteArray &output)
|
||||
{
|
||||
QFETCH(QByteArray, emrunOutput);
|
||||
QFETCH(WebBrowserEntries, expectedBrowsers);
|
||||
|
||||
QCOMPARE(parseEmrunOutput(emrunOutput), expectedBrowsers);
|
||||
WebBrowserEntries result;
|
||||
QTextStream ts(output);
|
||||
QString line;
|
||||
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 Webassembly
|
||||
|
||||
Reference in New Issue
Block a user