summaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
authorKai Koehne <kai.koehne@qt.io>2017-08-04 08:54:31 +0200
committerKai Koehne <kai.koehne@qt.io>2017-08-28 11:37:15 +0000
commite5de0f5b308fb4f5357633279816f211c799e8bb (patch)
treef26ec84d5531e07c21ceac4a7c0867d92b08760b /tests
parent78722f6c6c89de6b0c49d9d6ce49db8506104aaf (diff)
qtattributionsscanner: Allow to use it for one single file
This allows a saner use with qbs, where we can and should actually handle the dependencies correctly. In addition, this patch adds an optional '--basedir' argument that is needed to correctly root relative paths that are printed in the documentation. Change-Id: I0abf769ad5c0a3ac15b6907f83b77d369eb78d1f GPush-Base: 5c8d5742dc7b5e00a6aed447e8f288680b58e225 Reviewed-by: Christian Kandeler <christian.kandeler@qt.io>
Diffstat (limited to 'tests')
-rw-r--r--tests/auto/qtattributionsscanner/testdata/good/minimal/expected.error0
-rw-r--r--tests/auto/qtattributionsscanner/testdata/good/minimal/expected.json21
-rw-r--r--tests/auto/qtattributionsscanner/tst_qtattributionsscanner.cpp44
3 files changed, 54 insertions, 11 deletions
diff --git a/tests/auto/qtattributionsscanner/testdata/good/minimal/expected.error b/tests/auto/qtattributionsscanner/testdata/good/minimal/expected.error
new file mode 100644
index 000000000..e69de29bb
--- /dev/null
+++ b/tests/auto/qtattributionsscanner/testdata/good/minimal/expected.error
diff --git a/tests/auto/qtattributionsscanner/testdata/good/minimal/expected.json b/tests/auto/qtattributionsscanner/testdata/good/minimal/expected.json
new file mode 100644
index 000000000..6a75269c0
--- /dev/null
+++ b/tests/auto/qtattributionsscanner/testdata/good/minimal/expected.json
@@ -0,0 +1,21 @@
+[
+ {
+ "Copyright": "Copyright",
+ "Description": "",
+ "Homepage": "",
+ "Id": "minimal",
+ "License": "License",
+ "LicenseFile": "",
+ "LicenseId": "",
+ "Name": "Minimal",
+ "Path": "%{PWD}",
+ "Files": "",
+ "QDocModule": "qtest",
+ "QtParts": [
+ "libs"
+ ],
+ "QtUsage": "Usage",
+ "Version": "",
+ "DownloadLocation": ""
+ }
+]
diff --git a/tests/auto/qtattributionsscanner/tst_qtattributionsscanner.cpp b/tests/auto/qtattributionsscanner/tst_qtattributionsscanner.cpp
index c3e8bb9b6..7740fde9b 100644
--- a/tests/auto/qtattributionsscanner/tst_qtattributionsscanner.cpp
+++ b/tests/auto/qtattributionsscanner/tst_qtattributionsscanner.cpp
@@ -47,6 +47,8 @@ private slots:
void test();
private:
+ void readExpectedFile(const QString &baseDir, const QString &fileName, QByteArray *content);
+
QString m_cmd;
QString m_basePath;
};
@@ -62,25 +64,45 @@ tst_qtattributionsscanner::tst_qtattributionsscanner()
void tst_qtattributionsscanner::test_data()
{
- QTest::addColumn<QString>("directory");
- QTest::newRow("good") << QStringLiteral("good");
- QTest::newRow("warnings (incomplete)") << QStringLiteral("warnings/incomplete");
- QTest::newRow("warnings (unknown attribute)") << QStringLiteral("warnings/unknown");
+ QTest::addColumn<QString>("input");
+ QTest::addColumn<QString>("stdout_file");
+ QTest::addColumn<QString>("stderr_file");
+
+ QTest::newRow("good")
+ << QStringLiteral("good")
+ << QStringLiteral("good/expected.json")
+ << QStringLiteral("good/expected.error");
+ QTest::newRow("warnings (incomplete)")
+ << QStringLiteral("warnings/incomplete")
+ << QStringLiteral("warnings/incomplete/expected.json")
+ << QStringLiteral("warnings/incomplete/expected.error");
+ QTest::newRow("warnings (unknown attribute)")
+ << QStringLiteral("warnings/unknown")
+ << QStringLiteral("warnings/unknown/expected.json")
+ << QStringLiteral("warnings/unknown/expected.error");
+ QTest::newRow("singlefile")
+ << QStringLiteral("good/minimal/qt_attribution.json")
+ << QStringLiteral("good/minimal/expected.json")
+ << QStringLiteral("good/minimal/expected.error");
}
-static void readExpectedFile(const QString &dir, const QString &fileName, QByteArray *content)
+void tst_qtattributionsscanner::readExpectedFile(const QString &baseDir, const QString &fileName, QByteArray *content)
{
- QFile file(QDir(dir).absoluteFilePath(fileName));
+ QFile file(QDir(m_basePath).absoluteFilePath(fileName));
QVERIFY2(file.open(QIODevice::ReadOnly | QIODevice::Text), "Could not open " + file.fileName().toLocal8Bit());
*content = file.readAll();
- content->replace("%{PWD}", dir.toUtf8());
+ content->replace("%{PWD}", baseDir.toUtf8());
}
void tst_qtattributionsscanner::test()
{
- QFETCH(QString, directory);
+ QFETCH(QString, input);
+ QFETCH(QString, stdout_file);
+ QFETCH(QString, stderr_file);
- QString dir = QDir(m_basePath).absoluteFilePath(directory);
+ QString dir = QDir(m_basePath).absoluteFilePath(input);
+ if (QFileInfo(dir).isFile())
+ dir = QFileInfo(dir).absolutePath();
QProcess proc;
QString command = m_cmd + " " + dir + " --output-format json";
@@ -100,7 +122,7 @@ void tst_qtattributionsscanner::test()
stdErr.replace(QDir::separator(), "/");
QByteArray expectedErrorOutput;
- readExpectedFile(dir, "expected.error", &expectedErrorOutput);
+ readExpectedFile(dir, stderr_file, &expectedErrorOutput);
QCOMPARE(stdErr, expectedErrorOutput);
}
@@ -113,7 +135,7 @@ void tst_qtattributionsscanner::test()
QVERIFY2(!actualJson.isNull(), "Invalid output: " + jsonError.errorString().toLatin1());
QByteArray expectedOutput;
- readExpectedFile(dir, "expected.json", &expectedOutput);
+ readExpectedFile(dir, stdout_file, &expectedOutput);
QJsonDocument expectedJson = QJsonDocument::fromJson(expectedOutput);
if (!QTest::qCompare(actualJson, expectedJson, "actualJson", "expectedJson", __FILE__, __LINE__)) {