From e5de0f5b308fb4f5357633279816f211c799e8bb Mon Sep 17 00:00:00 2001 From: Kai Koehne Date: Fri, 4 Aug 2017 08:54:31 +0200 Subject: 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 --- .../testdata/good/minimal/expected.error | 0 .../testdata/good/minimal/expected.json | 21 +++++++++++ .../tst_qtattributionsscanner.cpp | 44 ++++++++++++++++------ 3 files changed, 54 insertions(+), 11 deletions(-) create mode 100644 tests/auto/qtattributionsscanner/testdata/good/minimal/expected.error create mode 100644 tests/auto/qtattributionsscanner/testdata/good/minimal/expected.json (limited to 'tests') 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 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("directory"); - QTest::newRow("good") << QStringLiteral("good"); - QTest::newRow("warnings (incomplete)") << QStringLiteral("warnings/incomplete"); - QTest::newRow("warnings (unknown attribute)") << QStringLiteral("warnings/unknown"); + QTest::addColumn("input"); + QTest::addColumn("stdout_file"); + QTest::addColumn("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__)) { -- cgit v1.2.3