aboutsummaryrefslogtreecommitdiffstats
path: root/tests/auto/qml/qmllint/tst_qmllint.cpp
blob: 20819b30e663a6eb9637ca345233237fe3a05717 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
/****************************************************************************
**
** Copyright (C) 2016 Klaralvdalens Datakonsult AB, a KDAB Group company, info@kdab.com, author Sergio Martins <sergio.martins@kdab.com>
** Copyright (C) 2021 The Qt Company Ltd.
** Contact: https://www.qt.io/licensing/
**
** This file is part of the test suite of the Qt Toolkit.
**
** $QT_BEGIN_LICENSE:GPL-EXCEPT$
** Commercial License Usage
** Licensees holding valid commercial Qt licenses may use this file in
** accordance with the commercial license agreement provided with the
** Software or, alternatively, in accordance with the terms contained in
** a written agreement between you and The Qt Company. For licensing terms
** and conditions see https://www.qt.io/terms-conditions. For further
** information use the contact form at https://www.qt.io/contact-us.
**
** GNU General Public License Usage
** Alternatively, this file may be used under the terms of the GNU
** General Public License version 3 as published by the Free Software
** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT
** included in the packaging of this file. Please review the following
** information to ensure the GNU General Public License requirements will
** be met: https://www.gnu.org/licenses/gpl-3.0.html.
**
** $QT_END_LICENSE$
**
****************************************************************************/

#include <QtTest/QtTest>
#include <QProcess>
#include <QString>
#include <QtQuickTestUtils/private/qmlutils_p.h>
#include <QtQmlLint/private/qqmllinter_p.h>

class TestQmllint: public QQmlDataTest
{
    Q_OBJECT

public:
    TestQmllint();

private Q_SLOTS:
    void initTestCase() override;

    void testUnqualified();
    void testUnqualified_data();

    void cleanQmlCode_data();
    void cleanQmlCode();

    void dirtyQmlCode_data();
    void dirtyQmlCode();

    void testUnknownCausesFail();

    void directoryPassedAsQmlTypesFile();
    void oldQmltypes();

    void qmltypes_data();
    void qmltypes();

    void functionDeclaration();

    void signalHandler();

    void anchors();

#ifdef QT_QMLJSROOTGEN_PRESENT
    void verifyJsRoot();
#endif

    void autoqmltypes();
    void resources();

    void requiredProperty();

    void settingsFile();

    void additionalImplicitImport();
    void listIndices();
    void lazyAndDirect();

    void attachedPropertyReuse();

    void shadowable();
    void tooFewParameters();
    void qQmlV4Function();
    void missingBuiltinsNoCrash();
    void absolutePath();
    void multiGrouped();
    void javascriptVariableArgs();
    void unknownTypeInRegister();

    void importMultipartUri();

private:
    enum DefaultIncludeOption { NoDefaultIncludes, UseDefaultIncludes };
    enum ContainOption { StringNotContained, StringContained };
    enum ReplacementOption {
        NoReplacementSearch,
        DoReplacementSearch,
    };

    QString runQmllint(const QString &fileToLint, std::function<void(QProcess &)> handleResult,
                       const QStringList &extraArgs = QStringList(), bool ignoreSettings = true,
                       bool addIncludeDirs = true);
    QString runQmllint(const QString &fileToLint, bool shouldSucceed,
                       const QStringList &extraArgs = QStringList(), bool ignoreSettings = true,
                       bool addIncludeDirs = true);
    void callQmllint(const QString &fileToLint, bool shouldSucceed, QJsonArray *warnings = nullptr,
                     QStringList includeDirs = {}, QStringList qmltypesFiles = {},
                     QStringList resources = {},
                     DefaultIncludeOption defaultIncludes = UseDefaultIncludes);

    void searchWarnings(const QJsonArray &warnings, const QString &string, const QString &filename,
                        ContainOption shouldContain = StringContained,
                        ReplacementOption searchReplacements = NoReplacementSearch);

    QString m_qmllintPath;
    QString m_qmljsrootgenPath;
    QString m_qmltyperegistrarPath;

    QStringList m_defaultImportPaths;
    QQmlLinter m_linter;
};

TestQmllint::TestQmllint()
    : QQmlDataTest(QT_QMLTEST_DATADIR),
      m_defaultImportPaths({ QLibraryInfo::path(QLibraryInfo::QmlImportsPath), dataDirectory() }),
      m_linter(m_defaultImportPaths)

{
}

void TestQmllint::initTestCase()
{
    QQmlDataTest::initTestCase();
    m_qmllintPath = QLibraryInfo::path(QLibraryInfo::BinariesPath) + QLatin1String("/qmllint");
    m_qmljsrootgenPath = QLibraryInfo::path(QLibraryInfo::LibraryExecutablesPath)
            + QLatin1String("/qmljsrootgen");
    m_qmltyperegistrarPath = QLibraryInfo::path(QLibraryInfo::LibraryExecutablesPath)
            + QLatin1String("/qmltyperegistrar");
#ifdef Q_OS_WIN
    m_qmllintPath += QLatin1String(".exe");
    m_qmljsrootgenPath += QLatin1String(".exe");
    m_qmltyperegistrarPath += QLatin1String(".exe");
#endif
    if (!QFileInfo(m_qmllintPath).exists()) {
        QString message = QStringLiteral("qmllint executable not found (looked for %0)").arg(m_qmllintPath);
        QFAIL(qPrintable(message));
    }

#ifdef QT_QMLJSROOTGEN_PRESENT
    if (!QFileInfo(m_qmljsrootgenPath).exists()) {
        QString message = QStringLiteral("qmljsrootgen executable not found (looked for %0)").arg(m_qmljsrootgenPath);
        QFAIL(qPrintable(message));
    }
    if (!QFileInfo(m_qmltyperegistrarPath).exists()) {
        QString message = QStringLiteral("qmltypesregistrar executable not found (looked for %0)").arg(m_qmltyperegistrarPath);
        QFAIL(qPrintable(message));
    }
#endif
}

void TestQmllint::testUnqualified()
{
    QFETCH(QString, filename);
    QFETCH(QString, warningMessage);
    QFETCH(int, warningLine);
    QFETCH(int, warningColumn);

    const QString output = runQmllint(filename, false);
    QVERIFY(output.contains(QStringLiteral("%1:%2:%3: Unqualified access").arg(testFile(filename)).arg(warningLine).arg(warningColumn)));
    QVERIFY(output.contains(warningMessage));
}

void TestQmllint::testUnqualified_data()
{
    QTest::addColumn<QString>("filename");
    QTest::addColumn<QString>("warningMessage");
    QTest::addColumn<int>("warningLine");
    QTest::addColumn<int>("warningColumn");

    // id from nowhere (as with setContextProperty)
    QTest::newRow("IdFromOuterSpaceDirect") << QStringLiteral("IdFromOuterSpace.qml") << "alien.x" << 4 << 8;
    QTest::newRow("IdFromOuterSpaceAccess") << QStringLiteral("IdFromOuterSpace.qml") << "console.log(alien)" << 7 << 21;
    // access property of root object
    QTest::newRow("FromRootDirect") << QStringLiteral("FromRoot.qml") << QStringLiteral("x: root.unqualified") << 9 << 16; // new property
    QTest::newRow("FromRootAccess") << QStringLiteral("FromRoot.qml") << QStringLiteral("property int check: root.x") << 13 << 33;  // builtin property
    // access injected name from signal
    QTest::newRow("SignalHandler1")
            << QStringLiteral("SignalHandler.qml")
            << QStringLiteral("onDoubleClicked:  function(mouse) {") << 5 << 21;
    QTest::newRow("SignalHandler2")
            << QStringLiteral("SignalHandler.qml")
            << QStringLiteral("onPositionChanged:  function(mouse) {") << 10 << 21;
    QTest::newRow("SignalHandlerShort1") << QStringLiteral("SignalHandler.qml")
                                         << QStringLiteral("onClicked:  (mouse) => ") << 8 << 29;
    QTest::newRow("SignalHandlerShort2")
            << QStringLiteral("SignalHandler.qml") << QStringLiteral("onPressAndHold:  (mouse) => ")
            << 12 << 34;
    // access catch identifier outside catch block
    QTest::newRow("CatchStatement") << QStringLiteral("CatchStatement.qml") << QStringLiteral("err") << 6 << 21;

    QTest::newRow("NonSpuriousParent") << QStringLiteral("nonSpuriousParentWarning.qml") << QStringLiteral("property int x: <id>.parent.x") << 6 << 25;

    QTest::newRow("crashConnections")
        << QStringLiteral("crashConnections.qml")
        << QStringLiteral("target: FirstRunDialog") << 4 << 13;
}

void TestQmllint::testUnknownCausesFail()
{
    {
        QJsonArray warnings;
        callQmllint("unknownElement.qml", false, &warnings);
        searchWarnings(
                warnings,
                QStringLiteral(
                        "Warning: %1:4:5: Unknown was not found. Did you add all import paths?")
                        .arg(testFile("unknownElement.qml")),
                "unknownElement.qml");
    }
    {
        QJsonArray warnings;
        callQmllint("TypeWithUnknownPropertyType.qml", false, &warnings);
        searchWarnings(
                warnings,
                QStringLiteral(
                        "Warning: %1:4:5: Something was not found. Did you add all import paths?")
                        .arg(testFile("TypeWithUnknownPropertyType.qml")),
                "TypeWithUnknownPropertyType.qml");
    }
}

void TestQmllint::directoryPassedAsQmlTypesFile()
{
    QJsonArray warnings;
    callQmllint("unknownElement.qml", false, &warnings, {}, { dataDirectory() });
    searchWarnings(warnings,
                   QStringLiteral("QML types file cannot be a directory: ") + dataDirectory(),
                   "unknownElement.qml");
}

void TestQmllint::oldQmltypes()
{
    QJsonArray warnings;
    callQmllint("oldQmltypes.qml", false, &warnings);
    searchWarnings(warnings, QStringLiteral("typeinfo not declared in qmldir file"),
                   "oldQmltypes.qml");
    searchWarnings(warnings,
                   QStringLiteral("QQuickItem was not found. Did you add all import paths?"),
                   "oldQmltypes.qml", StringNotContained);
    searchWarnings(warnings, QStringLiteral("Found deprecated dependency specifications"),
                   "oldQmltypes.qml");

    // Checking for both lines separately so that we don't have to mess with the line endings.b
    searchWarnings(warnings,
                   QStringLiteral("Meta object revision and export version differ."),
                   "oldQmltypes.qml");
    searchWarnings(warnings,
                   QStringLiteral("Revision 0 corresponds to version 0.0; it should be 1.0."),
                   "oldQmltypes.qml");
}

void TestQmllint::qmltypes_data()
{
    QTest::addColumn<QString>("file");

    const QString importsPath = QLibraryInfo::path(QLibraryInfo::QmlImportsPath);
    QDirIterator it(importsPath, { "*.qmltypes" },
                    QDir::Files, QDirIterator::Subdirectories);
    while (it.hasNext())
        QTest::addRow("%s", qPrintable(it.next().mid(importsPath.length()))) << it.filePath();
}

void TestQmllint::qmltypes()
{
    QFETCH(QString, file);
    callQmllint(file, true);
}

#ifdef QT_QMLJSROOTGEN_PRESENT
void TestQmllint::verifyJsRoot()
{
    QProcess process;

    const QString importsPath = QLibraryInfo::path(QLibraryInfo::QmlImportsPath);
    QDirIterator it(importsPath, { "jsroot.qmltypes" },
                    QDir::Files, QDirIterator::Subdirectories);

    QVERIFY(it.hasNext());

    QString currentJsRootPath = it.next();

    QTemporaryDir dir;

    QProcess jsrootProcess;
    connect(&jsrootProcess, &QProcess::errorOccurred, [&](QProcess::ProcessError error) {
        qWarning() << error << jsrootProcess.errorString();
    });
    jsrootProcess.setWorkingDirectory(dir.path());
    jsrootProcess.start(m_qmljsrootgenPath, {"jsroot.json"});

    jsrootProcess.waitForFinished();

    QCOMPARE(jsrootProcess.exitStatus(), QProcess::NormalExit);
    QCOMPARE(jsrootProcess.exitCode(), 0);


    QProcess typeregistrarProcess;
    typeregistrarProcess.setWorkingDirectory(dir.path());
    typeregistrarProcess.start(m_qmltyperegistrarPath, {"jsroot.json", "--generate-qmltypes", "jsroot.qmltypes"});

    typeregistrarProcess.waitForFinished();

    QCOMPARE(typeregistrarProcess.exitStatus(), QProcess::NormalExit);
    QCOMPARE(typeregistrarProcess.exitCode(), 0);

    QString currentJsRootContent, generatedJsRootContent;

    QFile currentJsRoot(currentJsRootPath);
    QVERIFY(currentJsRoot.open(QFile::ReadOnly));
    currentJsRootContent = QString::fromUtf8(currentJsRoot.readAll());
    currentJsRoot.close();

    QFile generatedJsRoot(dir.path() + QDir::separator() + "jsroot.qmltypes");
    QVERIFY(generatedJsRoot.open(QFile::ReadOnly));
    generatedJsRootContent = QString::fromUtf8(generatedJsRoot.readAll());
    generatedJsRoot.close();

    // If any of the following asserts fail you need to update jsroot.qmltypes using the following commands:
    //
    // qmljsrootgen jsroot.json
    // qmltyperegistrar jsroot.json --generate-qmltypes src/imports/builtins/jsroot.qmltypes
    QStringList currentLines = currentJsRootContent.split(QLatin1Char('\n'));
    QStringList generatedLines = generatedJsRootContent.split(QLatin1Char('\n'));

    QCOMPARE(currentLines.count(), generatedLines.count());

    for (qsizetype i = 0; i < currentLines.count(); i++) {
        QCOMPARE(currentLines[i], generatedLines[i]);
    }
}
#endif

void TestQmllint::autoqmltypes()
{
    QProcess process;
    process.setWorkingDirectory(testFile("autoqmltypes"));
    process.start(m_qmllintPath, { QStringLiteral("test.qml") });

    process.waitForFinished();

    QCOMPARE(process.exitStatus(), QProcess::NormalExit);
    QVERIFY(process.exitCode() != 0);

    QVERIFY(process.readAllStandardError()
                .contains("is not a qmldir file. Assuming qmltypes"));
    QVERIFY(process.readAllStandardOutput().isEmpty());
}

void TestQmllint::resources()
{
    callQmllint(testFile("resource.qml"), true, nullptr, {}, {}, { testFile("resource.qrc") });
    callQmllint(testFile("badResource.qml"), false, nullptr, {}, {}, { testFile("resource.qrc") });
    callQmllint(testFile("resource.qml"), false);
    callQmllint(testFile("badResource.qml"), true);
    callQmllint(testFile("T/b.qml"), true, nullptr, {}, {}, { testFile("T/a.qrc") });
}

void TestQmllint::dirtyQmlCode_data()
{
    QTest::addColumn<QString>("filename");
    QTest::addColumn<QString>("warningMessage");
    QTest::addColumn<QString>("notContained");
    QTest::addColumn<QString>("replacement");
    QTest::addColumn<bool>("exitsNormally");

    QTest::newRow("Invalid_syntax_QML")
            << QStringLiteral("failure1.qml") << QStringLiteral("%1:4:8: Expected token `:'")
            << QString() << QString() << false;
    QTest::newRow("Invalid_syntax_JS")
            << QStringLiteral("failure1.js") << QStringLiteral("%1:4:12: Expected token `;'")
            << QString() << QString() << false;
    QTest::newRow("AutomatchedSignalHandler")
            << QStringLiteral("AutomatchedSignalHandler.qml")
            << QString("Warning: %1:12:36: Unqualified access") << QString() << QString() << false;
    QTest::newRow("AutomatchedSignalHandler2")
            << QStringLiteral("AutomatchedSignalHandler.qml")
            << QString("Info: Implicitly defining onClicked as signal handler") << QString()
            << QString() << false;
    QTest::newRow("MemberNotFound")
            << QStringLiteral("memberNotFound.qml")
            << QString("Warning: %1:6:31: Property \"foo\" not found on type \"QtObject\"")
            << QString() << QString() << false;
    QTest::newRow("UnknownJavascriptMethd")
            << QStringLiteral("unknownJavascriptMethod.qml")
            << QString("Warning: %1:5:25: Property \"foo2\" not found on type \"Methods\"")
            << QString() << QString() << false;
    QTest::newRow("badAlias") << QStringLiteral("badAlias.qml")
                              << QString("Warning: %1:3:1: Cannot resolve alias \"wrong\"")
                              << QString() << QString() << false;
    QTest::newRow("badAliasProperty1") << QStringLiteral("badAliasProperty.qml")
                                       << QString("Warning: %1:3:1: Cannot resolve alias \"wrong\"")
                                       << QString() << QString() << false;
    QTest::newRow("badAliasExpression")
            << QStringLiteral("badAliasExpression.qml")
            << QString("Warning: %1:5:26: Invalid alias expression. Only IDs and field member "
                       "expressions can be aliased")
            << QString() << QString() << false;
    QTest::newRow("aliasCycle1") << QStringLiteral(
            "aliasCycle.qml") << QString("Warning: %1:3:1: Alias \"b\" is part of an alias cycle")
                                 << QString() << QString() << false;
    QTest::newRow("aliasCycle2") << QStringLiteral(
            "aliasCycle.qml") << QString("Warning: %1:3:1: Alias \"a\" is part of an alias cycle")
                                 << QString() << QString() << false;
    QTest::newRow("badParent")
            << QStringLiteral("badParent.qml")
            << QString("Warning: %1:5:34: Property \"rrr\" not found on type \"Item\"") << QString()
            << QString() << false;
    QTest::newRow("parentIsComponent")
            << QStringLiteral("parentIsComponent.qml")
            << QString("Warning: %1:7:39: Property \"progress\" not found on type \"QQuickItem\"")
            << QString() << QString() << false;
    QTest::newRow("badTypeAssertion")
            << QStringLiteral("badTypeAssertion.qml")
            << QString("Warning: %1:5:39: Property \"rrr\" not found on type \"QQuickItem\"")
            << QString() << QString() << false;
    QTest::newRow("incompleteQmltypes")
            << QStringLiteral("incompleteQmltypes.qml")
            << QString("Warning: %1:5:26: Type \"QPalette\" of property \"palette\" not found")
            << QString() << QString() << false;
    QTest::newRow("incompleteQmltypes2") << QStringLiteral("incompleteQmltypes2.qml")
                                         << QString("Warning: %1:5:35: Property \"weDontKnowIt\" "
                                                    "not found on type \"CustomPalette\"")
                                         << QString() << QString() << false;
    QTest::newRow("inheritanceCylce") << QStringLiteral("Cycle1.qml")
                                      << QString("Warning: %1: Cycle2 is part of an inheritance "
                                                 "cycle: Cycle2 -> Cycle3 -> Cycle1 -> Cycle2")
                                      << QString() << QString() << false;
    QTest::newRow("incompleteQmltypes3")
            << QStringLiteral("incompleteQmltypes3.qml")
            << QString("Warning: %1:5:21: Type \"QPalette\" of property \"palette\" not found")
            << QString() << QString() << false;
    QTest::newRow("badQmldirImportAndDepend")
            << QStringLiteral("qmldirImportAndDepend/bad.qml")
            << QString("Warning: %1:3:1: Item was not found. Did you add all import paths?")
            << QString() << QString() << false;
    QTest::newRow("javascriptMethodsInModule")
            << QStringLiteral("javascriptMethodsInModuleBad.qml")
            << QString("Warning: %1:5:21: Property \"unknownFunc\" not found on type \"Foo\"")
            << QString() << QString() << false;
    QTest::newRow("badEnumFromQtQml") << QStringLiteral("badEnumFromQtQml.qml")
                                      << QString("Warning: %1:4:30: Property \"Linear123\" not "
                                                 "found on type \"QQmlEasingEnums\"")
                                      << QString() << QString() << false;
    QTest::newRow("anchors3")
            << QStringLiteral("anchors3.qml")
            << QString("Cannot assign binding of type QQuickItem to QQuickAnchorLine") << QString()
            << QString() << false;
    QTest::newRow("nanchors1") << QStringLiteral("nanchors1.qml")
                               << QString("unknown grouped property scope nanchors.") << QString()
                               << QString() << false;
    QTest::newRow("nanchors2") << QStringLiteral("nanchors2.qml")
                               << QString("unknown grouped property scope nanchors.") << QString()
                               << QString() << false;
    QTest::newRow("nanchors3") << QStringLiteral("nanchors3.qml")
                               << QString("unknown grouped property scope nanchors.") << QString()
                               << QString() << false;
    QTest::newRow("badAliasObject") << QStringLiteral("badAliasObject.qml")
                                    << QString("Warning: %1:8:40: Property \"wrongwrongwrong\" not "
                                               "found on type \"QtObject\"")
                                    << QString() << QString() << false;
    QTest::newRow("badScript")
            << QStringLiteral("badScript.qml")
            << QString("Warning: %1:5:21: Property \"stuff\" not found on type \"Empty\"")
            << QString() << QString() << false;
    QTest::newRow("badScriptOnAttachedProperty")
            << QStringLiteral("badScript.attached.qml")
            << QString("Warning: %1:3:26: Unqualified access") << QString() << QString() << false;
    QTest::newRow("brokenNamespace") << QStringLiteral("brokenNamespace.qml")
                                     << QString("Warning: %1:4:19: Type not found in namespace")
                                     << QString() << QString() << false;
    QTest::newRow("segFault (bad)")
            << QStringLiteral("SegFault.bad.qml")
            << QStringLiteral("Property \"foobar\" not found on type \"QQuickScreenAttached\"")
            << QString() << QString() << false;
    QTest::newRow("VariableUsedBeforeDeclaration")
            << QStringLiteral("useBeforeDeclaration.qml")
            << QStringLiteral("%1:5:9: Variable \"argq\" is used here before its declaration. "
                              "The declaration is at 6:13.")
            << QString() << QString() << false;
    QTest::newRow("SignalParameterMismatch")
            << QStringLiteral("namedSignalParameters.qml")
            << QStringLiteral("Parameter 1 to signal handler for \"onSig\" is called \"argarg\". "
                              "The signal has a parameter of the same name in position 2.")
            << QStringLiteral("onSig2") << QString() << false;
    QTest::newRow("TooManySignalParameters")
            << QStringLiteral("tooManySignalParameters.qml")
            << QStringLiteral("Signal handler for \"onSig\" has more formal parameters "
                              "than the signal it handles.")
            << QString() << QString() << false;
    QTest::newRow("OnAssignment") << QStringLiteral("onAssignment.qml")
                                  << QStringLiteral("Property \"loops\" not found on type \"bool\"")
                                  << QString() << QString() << false;
    QTest::newRow("BadAttached") << QStringLiteral("badAttached.qml")
                                 << QStringLiteral("unknown attached property scope WrongAttached.")
                                 << QString() << QString() << false;
    QTest::newRow("BadBinding") << QStringLiteral("badBinding.qml")
                                << QStringLiteral(
                                           "Binding assigned to \"doesNotExist\", but no property "
                                           "\"doesNotExist\" exists in the current element.")
                                << QString() << QString() << false;
    QTest::newRow("bad template literal (simple)")
            << QStringLiteral("badTemplateStringSimple.qml")
            << QStringLiteral("Cannot assign binding of type string to int") << QString()
            << QString() << false;
    QTest::newRow("bad template literal (substitution)")
            << QStringLiteral("badTemplateStringSubstitution.qml")
            << QStringLiteral("Cannot assign binding of type QString to int") << QString()
            << QString() << false;
    QTest::newRow("bad constant number to string")
            << QStringLiteral("numberToStringProperty.qml")
            << QStringLiteral("Cannot assign a numeric constant to a string property") << QString()
            << QString() << false;
    QTest::newRow("bad unary minus to string")
            << QStringLiteral("unaryMinusToStringProperty.qml")
            << QStringLiteral("Cannot assign a numeric constant to a string property") << QString()
            << QString() << false;
    QTest::newRow("bad tranlsation binding (qsTr)")
            << QStringLiteral("bad_qsTr.qml") << QStringLiteral("") << QString() << QString()
            << false;
    QTest::newRow("bad string binding (QT_TR_NOOP)")
            << QStringLiteral("bad_QT_TR_NOOP.qml")
            << QStringLiteral("Cannot assign binding of type string to int") << QString()
            << QString() << false;
    QTest::newRow("BadScriptBindingOnGroup")
            << QStringLiteral("badScriptBinding.group.qml")
            << QStringLiteral("Warning: %1:3:10: Binding assigned to \"bogusProperty\", but no "
                              "property \"bogusProperty\" exists in the current element.")
            << QString() << QString() << false;
    QTest::newRow("BadScriptBindingOnAttachedType")
            << QStringLiteral("badScriptBinding.attached.qml")
            << QStringLiteral("Warning: %1:5:12: Binding assigned to \"bogusProperty\", but no "
                              "property \"bogusProperty\" exists in the current element.")
            << QString() << QString() << false;
    QTest::newRow("BadScriptBindingOnAttachedSignalHandler")
            << QStringLiteral("badScriptBinding.attachedSignalHandler.qml")
            << QStringLiteral(
                       "Warning: %1:3:10: no matching signal found for handler \"onBogusSignal\"")
            << QString() << QString() << false;
    QTest::newRow("BadPropertyType")
            << QStringLiteral("badPropertyType.qml")
            << QStringLiteral("No type found for property \"bad\". This may be due to a missing "
                              "import statement or incomplete qmltypes files.")
            << QString() << QString() << false;
    QTest::newRow("Deprecation (Property, with reason)")
            << QStringLiteral("deprecatedPropertyReason.qml")
            << QStringLiteral("Property \"deprecated\" is deprecated (Reason: Test)") << QString()
            << QString() << false;
    QTest::newRow("Deprecation (Property, no reason)")
            << QStringLiteral("deprecatedProperty.qml")
            << QStringLiteral("Property \"deprecated\" is deprecated") << QString() << QString()
            << false;
    QTest::newRow("Deprecation (Property binding, with reason)")
            << QStringLiteral("deprecatedPropertyBindingReason.qml")
            << QStringLiteral("Binding on deprecated property \"deprecatedReason\" (Reason: Test)")
            << QString() << QString() << false;
    QTest::newRow("Deprecation (Property binding, no reason)")
            << QStringLiteral("deprecatedPropertyBinding.qml")
            << QStringLiteral("Binding on deprecated property \"deprecated\"") << QString()
            << QString() << false;
    QTest::newRow("Deprecation (Type, with reason)")
            << QStringLiteral("deprecatedTypeReason.qml")
            << QStringLiteral("Type \"TypeDeprecatedReason\" is deprecated (Reason: Test)")
            << QString() << QString() << false;
    QTest::newRow("Deprecation (Type, no reason)")
            << QStringLiteral("deprecatedType.qml")
            << QStringLiteral("Type \"TypeDeprecated\" is deprecated") << QString() << QString()
            << false;
    QTest::newRow("MissingDefaultProperty")
            << QStringLiteral("defaultPropertyWithoutKeyword.qml")
            << QStringLiteral("Cannot assign to non-existent default property") << QString()
            << QString() << false;
    QTest::newRow("MissingDefaultPropertyDefinedInTheSameType")
            << QStringLiteral("defaultPropertyWithinTheSameType.qml")
            << QStringLiteral("Cannot assign to non-existent default property") << QString()
            << QString() << false;
    QTest::newRow("DoubleAssignToDefaultProperty")
            << QStringLiteral("defaultPropertyWithDoubleAssignment.qml")
            << QStringLiteral("Cannot assign multiple objects to a default non-list property")
            << QString() << QString() << false;
    QTest::newRow("DefaultPropertyWithWrongType(string)")
            << QStringLiteral("defaultPropertyWithWrongType.qml")
            << QStringLiteral("Cannot assign to default property of incompatible type")
            << QStringLiteral("Cannot assign to non-existent default property") << QString()
            << false;
    QTest::newRow("MultiDefaultPropertyWithWrongType")
            << QStringLiteral("multiDefaultPropertyWithWrongType.qml")
            << QStringLiteral("Cannot assign to default property of incompatible type")
            << QStringLiteral("Cannot assign to non-existent default property") << QString()
            << false;
    QTest::newRow("InvalidImport")
            << QStringLiteral("invalidImport.qml")
            << QStringLiteral("Failed to import FooBar. Are your include paths set up properly?")
            << QString() << QString() << false;
    QTest::newRow("Unused Import (simple)")
            << QStringLiteral("unused_simple.qml") << QStringLiteral("Unused import at %1:1:1")
            << QString() << QString() << true;
    QTest::newRow("Unused Import (prefix)")
            << QStringLiteral("unused_prefix.qml") << QStringLiteral("Unused import at %1:1:1")
            << QString() << QString() << true;
    QTest::newRow("TypePropertAccess") << QStringLiteral("typePropertyAccess.qml") << QString()
                                       << QString() << QString() << false;
    QTest::newRow("badAttachedProperty")
            << QStringLiteral("badAttachedProperty.qml")
            << QString("Property \"progress\" not found on type \"TestType\"") << QString()
            << QString() << false;
    QTest::newRow("badAttachedPropertyNested")
            << QStringLiteral("badAttachedPropertyNested.qml")
            << QString("12:41: Property \"progress\" not found on type \"QObject\"")
            << QString("6:37: Property \"progress\" not found on type \"QObject\"") << QString()
            << false;
    QTest::newRow("badAttachedPropertyTypeString")
            << QStringLiteral("badAttachedPropertyTypeString.qml")
            << QString("Cannot assign binding of type string to int") << QString() << QString()
            << false;
    QTest::newRow("badAttachedPropertyTypeQtObject")
            << QStringLiteral("badAttachedPropertyTypeQtObject.qml")
            << QString("Property \"count\" of type \"int\" is assigned an incompatible type "
                       "\"QtObject\"")
            << QString() << QString() << false;
    // should succeed, but it does not:
    QTest::newRow("attachedPropertyAccess") << QStringLiteral("goodAttachedPropertyAccess.qml")
                                            << QString() << QString() << QString() << true;
    // should succeed, but it does not:
    QTest::newRow("attachedPropertyNested") << QStringLiteral("goodAttachedPropertyNested.qml")
                                            << QString() << QString() << QString() << true;
    QTest::newRow("deprecatedFunction")
            << QStringLiteral("deprecatedFunction.qml")
            << QStringLiteral("Method \"deprecated(foobar)\" is deprecated (Reason: No particular "
                              "reason.)")
            << QString() << QString() << false;
    QTest::newRow("deprecatedFunctionInherited")
            << QStringLiteral("deprecatedFunctionInherited.qml")
            << QStringLiteral("Method \"deprecatedInherited(c, d)\" is deprecated (Reason: This "
                              "deprecation should be visible!)")
            << QString() << QString() << false;

    QTest::newRow("string as id") << QStringLiteral("stringAsId.qml")
                                  << QStringLiteral("ids do not need quotation marks") << QString()
                                  << QString() << false;
    QTest::newRow("stringIdUsedInWarning") << QStringLiteral("stringIdUsedInWarning.qml")
                                           << QStringLiteral("i is a member of a parent element")
                                           << QString() << QStringLiteral("stringy.") << false;
    QTest::newRow("Invalid id (expression)")
            << QStringLiteral("invalidId1.qml") << QStringLiteral("Failed to parse id") << QString()
            << QString() << false;
    QTest::newRow("multilineString")
            << QStringLiteral("multilineString.qml")
            << QStringLiteral("String contains unescaped line terminator which is deprecated. Use "
                              "a template literal instead.")
            << QString() << QString() << true;
    QTest::newRow("unresolvedType")
            << QStringLiteral("unresolvedType.qml")
            << QStringLiteral("UnresolvedType was not found. Did you add all import paths?")
            << QStringLiteral("incompatible type") << QString() << false;
    QTest::newRow("invalidInterceptor")
            << QStringLiteral("invalidInterceptor.qml")
            << QStringLiteral("On-binding for property \"angle\" has wrong type \"Item\"")
            << QString() << QString() << false;
    QTest::newRow("2Interceptors") << QStringLiteral("2interceptors.qml")
                                   << QStringLiteral("Duplicate interceptor on property \"x\"")
                                   << QString() << QString() << false;
    QTest::newRow("ValueSource+2Interceptors")
            << QStringLiteral("valueSourceBetween2interceptors.qml")
            << QStringLiteral("Duplicate interceptor on property \"x\"") << QString() << QString()
            << false;
    QTest::newRow("2ValueSources") << QStringLiteral("2valueSources.qml")
                                   << QStringLiteral("Duplicate value source on property \"x\"")
                                   << QString() << QString() << false;
    QTest::newRow("ValueSource+Value")
            << QStringLiteral("valueSource_Value.qml")
            << QStringLiteral("Cannot combine value source and binding on property \"obj\"")
            << QString() << QString() << false;
    QTest::newRow("ValueSource+ListValue")
            << QStringLiteral("valueSource_listValue.qml")
            << QStringLiteral("Cannot combine value source and binding on property \"objs\"")
            << QString() << QString() << false;
    QTest::newRow("NonExistentListProperty")
            << QStringLiteral("nonExistentListProperty.qml")
            << QStringLiteral("Property \"objs\" is invalid or does not exist") << QString()
            << QString() << false;
    QTest::newRow("QtQuick.Window 2.0")
            << QStringLiteral("qtquickWindow20.qml")
            << QStringLiteral("Property \"window\" not found on type \"QQuickWindow\"") << QString()
            << QString() << false;
    QTest::newRow("unresolvedAttachedType")
            << QStringLiteral("unresolvedAttachedType.qml")
            << QStringLiteral("unknown attached property scope UnresolvedAttachedType.")
            << QStringLiteral("Property \"property\" is invalid or does not exist") << QString()
            << false;
    QTest::newRow("nestedInlineComponents")
            << QStringLiteral("nestedInlineComponents.qml")
            << QStringLiteral("Nested inline components are not supported") << QString()
            << QString() << false;
    QTest::newRow("WithStatement") << QStringLiteral("WithStatement.qml")
                                   << QStringLiteral("with statements are strongly discouraged")
                                   << QString() << QString() << false;
    QTest::newRow("BindingTypeMismatch")
            << QStringLiteral("bindingTypeMismatch.qml")
            << QStringLiteral("Cannot assign binding of type QString to int") << QString()
            << QString() << false;
    QTest::newRow("BindingTypeMismatchFunction")
            << QStringLiteral("bindingTypeMismatchFunction.qml")
            << QStringLiteral("Cannot assign binding of type QString to int") << QString()
            << QString() << false;
    QTest::newRow("BadLiteralBinding")
            << QStringLiteral("badLiteralBinding.qml")
            << QStringLiteral("Cannot assign binding of type string to int") << QString()
            << QString() << false;
    QTest::newRow("BadLiteralBindingDate")
            << QStringLiteral("badLiteralBindingDate.qml")
            << QStringLiteral("Cannot assign binding of type QString to QDateTime") << QString()
            << QString() << false;
    QTest::newRow("BadModulePrefix")
            << QStringLiteral("badModulePrefix.qml")
            << QStringLiteral("Cannot load singleton as property of object") << QString()
            << QString() << false;
    QTest::newRow("BadModulePrefix2")
            << QStringLiteral("badModulePrefix2.qml")
            << QStringLiteral("Cannot use non-reference type QRectF as base "
                              "of namespaced attached type")
            << QString() << QString() << false;
    QTest::newRow("AssignToReadOnlyProperty")
            << QStringLiteral("assignToReadOnlyProperty.qml")
            << QStringLiteral("Cannot assign to read-only property activeFocus") << QString()
            << QString() << false;
    QTest::newRow("AssignToReadOnlyProperty")
            << QStringLiteral("assignToReadOnlyProperty2.qml")
            << QStringLiteral("Cannot assign to read-only property activeFocus") << QString()
            << QString() << false;
    QTest::newRow("DeferredPropertyID")
            << QStringLiteral("deferredPropertyID.qml")
            << QStringLiteral(
                       "Cannot defer property assignment to "
                       "\"contentData\". Assigning an id to an object or one of its sub-objects "
                       "bound to a deferred property will make the assignment immediate.")
            << QString() << QString() << false;
    QTest::newRow("DeferredPropertyNestedID")
            << QStringLiteral("deferredPropertyNestedID.qml")
            << QStringLiteral(
                       "Cannot defer property assignment to "
                       "\"contentData\". Assigning an id to an object or one of its sub-objects "
                       "bound to a deferred property will make the assignment immediate.")
            << QString() << QString() << false;
    QTest::newRow("cachedDependency")
            << QStringLiteral("cachedDependency.qml") << QStringLiteral("Unused import at %1:1:1")
            << QStringLiteral("Cannot assign binding of type QQuickItem to QObject") << QString()
            << true;
    QTest::newRow("cycle in import")
            << QStringLiteral("cycleHead.qml")
            << QStringLiteral("MenuItem is part of an inheritance cycle: MenuItem -> MenuItem")
            << QString() << QString() << false;
    QTest::newRow("badGeneralizedGroup1")
            << QStringLiteral("badGeneralizedGroup1.qml")
            << QStringLiteral("Binding assigned to \"aaaa\", "
                              "but no property \"aaaa\" exists in the current element")
            << QString() << QString() << false;
    QTest::newRow("badGeneralizedGroup2") << QStringLiteral("badGeneralizedGroup2.qml")
                                          << QStringLiteral("unknown grouped property scope aself")
                                          << QString() << QString() << false;
    QTest::newRow("missingQmltypes")
            << QStringLiteral("missingQmltypes.qml")
            << QStringLiteral("QML types file does not exist") << QString() << QString() << false;
    QTest::newRow("enumInvalid") << QStringLiteral(
            "enumInvalid.qml") << QStringLiteral("Property \"red\" not found on type \"QtObject\"")
                                 << QString() << QString() << false;
    QTest::newRow("inaccessibleId")
            << QStringLiteral("inaccessibleId.qml")
            << QStringLiteral("Property \"objectName\" not found on type \"int\"") << QString()
            << QString() << false;
    QTest::newRow("inaccessibleId2")
            << QStringLiteral("inaccessibleId2.qml")
            << QStringLiteral("Property \"objectName\" not found on type \"int\"") << QString()
            << QString() << false;
    QTest::newRow("unknownTypeCustomParser")
            << QStringLiteral("unknownTypeCustomParser.qml")
            << QStringLiteral("TypeDoesNotExist was not found.") << QString() << QString() << false;
    QTest::newRow("nonNullStored")
            << QStringLiteral("nonNullStored.qml")
            << QStringLiteral("Property \"objectName\" not found on type \"Foozle\"")
            << QStringLiteral("Unqualified access")
            << QString() << false;
    QTest::newRow("cppPropertyChangeHandlers-wrong-parameters-size-bindable")
            << QStringLiteral("badCppPropertyChangeHandlers1.qml")
            << QStringLiteral("Signal handler for \"onAChanged\" has more formal parameters than "
                              "the signal it handles")
            << QString() << QString() << false;
    QTest::newRow("cppPropertyChangeHandlers-wrong-parameters-size-notify")
            << QStringLiteral("badCppPropertyChangeHandlers2.qml")
            << QStringLiteral("Signal handler for \"onBChanged\" has more formal parameters than "
                              "the signal it handles")
            << QString() << QString() << false;
    QTest::newRow("cppPropertyChangeHandlers-no-property")
            << QStringLiteral("badCppPropertyChangeHandlers3.qml")
            << QStringLiteral("no matching signal found for handler \"onXChanged\"") << QString()
            << QString() << false;
    QTest::newRow("cppPropertyChangeHandlers-not-a-signal")
            << QStringLiteral("badCppPropertyChangeHandlers4.qml")
            << QStringLiteral("no matching signal found for handler \"onWannabeSignal\"")
            << QString() << QString() << false;
}

void TestQmllint::dirtyQmlCode()
{
    QFETCH(QString, filename);
    QFETCH(QString, warningMessage);
    QFETCH(QString, notContained);
    QFETCH(QString, replacement);
    QFETCH(bool, exitsNormally);

    if (warningMessage.contains(QLatin1String("%1")))
        warningMessage = warningMessage.arg(testFile(filename));

    QJsonArray warnings;

    QEXPECT_FAIL("attachedPropertyAccess", "We cannot discern between types and instances", Abort);
    QEXPECT_FAIL("attachedPropertyNested", "We cannot discern between types and instances", Abort);
    QEXPECT_FAIL("BadLiteralBindingDate",
                 "We're currently not able to verify any non-trivial QString conversion that "
                 "requires QQmlStringConverters",
                 Abort);
    QEXPECT_FAIL("bad tranlsation binding (qsTr)", "We currently do not check translation binding",
                 Abort);

    callQmllint(filename, exitsNormally, &warnings);

    if (!warningMessage.isEmpty()) {
        // output.contains() expect fails:
        QEXPECT_FAIL("BadLiteralBindingDate",
                     "We're currently not able to verify any non-trivial QString conversion that "
                     "requires QQmlStringConverters",
                     Abort);

        searchWarnings(warnings, warningMessage, filename);
    }

    if (!notContained.isEmpty()) {
        // !output.contains() expect fails:
        QEXPECT_FAIL("badAttachedPropertyNested", "We cannot discern between types and instances",
                     Abort);

        searchWarnings(warnings, notContained, filename, StringNotContained);
    }

    if (!replacement.isEmpty())
        searchWarnings(warnings, replacement, filename, StringContained, DoReplacementSearch);
}

void TestQmllint::cleanQmlCode_data()
{
    QTest::addColumn<QString>("filename");
    QTest::newRow("Simple_QML")                << QStringLiteral("Simple.qml");
    QTest::newRow("QML_importing_JS")          << QStringLiteral("importing_js.qml");
    QTest::newRow("JS_with_pragma_and_import") << QStringLiteral("QTBUG-45916.js");
    QTest::newRow("uiQml")                     << QStringLiteral("FormUser.qml");
    QTest::newRow("methodInScope")             << QStringLiteral("MethodInScope.qml");
    QTest::newRow("importWithPrefix")          << QStringLiteral("ImportWithPrefix.qml");
    QTest::newRow("catchIdentifier")           << QStringLiteral("catchIdentifierNoWarning.qml");
    QTest::newRow("qmldirAndQmltypes")         << QStringLiteral("qmldirAndQmltypes.qml");
    QTest::newRow("forLoop")                   << QStringLiteral("forLoop.qml");
    QTest::newRow("esmodule")                  << QStringLiteral("esmodule.mjs");
    QTest::newRow("methodsInJavascript")       << QStringLiteral("javascriptMethods.qml");
    QTest::newRow("goodAlias")                 << QStringLiteral("goodAlias.qml");
    QTest::newRow("goodParent")                << QStringLiteral("goodParent.qml");
    QTest::newRow("goodTypeAssertion")         << QStringLiteral("goodTypeAssertion.qml");
    QTest::newRow("AttachedProps")             << QStringLiteral("AttachedProps.qml");
    QTest::newRow("unknownBuiltinFont")        << QStringLiteral("ButtonLoader.qml");
    QTest::newRow("confusingImport")           << QStringLiteral("Dialog.qml");
    QTest::newRow("qualifiedAttached")         << QStringLiteral("Drawer.qml");
    QTest::newRow("EnumAccess1") << QStringLiteral("EnumAccess1.qml");
    QTest::newRow("EnumAccess2") << QStringLiteral("EnumAccess2.qml");
    QTest::newRow("ListProperty") << QStringLiteral("ListProperty.qml");
    QTest::newRow("AttachedType") << QStringLiteral("AttachedType.qml");
    QTest::newRow("qmldirImportAndDepend") << QStringLiteral("qmldirImportAndDepend/good.qml");
    QTest::newRow("ParentEnum") << QStringLiteral("parentEnum.qml");
    QTest::newRow("Signals") << QStringLiteral("Signal.qml");
    QTest::newRow("javascriptMethodsInModule")
            << QStringLiteral("javascriptMethodsInModuleGood.qml");
    QTest::newRow("enumFromQtQml") << QStringLiteral("enumFromQtQml.qml");
    QTest::newRow("anchors1") << QStringLiteral("anchors1.qml");
    QTest::newRow("anchors2") << QStringLiteral("anchors2.qml");
    QTest::newRow("optionalImport") << QStringLiteral("optionalImport.qml");
    QTest::newRow("goodAliasObject") << QStringLiteral("goodAliasObject.qml");
    QTest::newRow("jsmoduleimport") << QStringLiteral("jsmoduleimport.qml");
    QTest::newRow("overridescript") << QStringLiteral("overridescript.qml");
    QTest::newRow("multiExtension") << QStringLiteral("multiExtension.qml");
    QTest::newRow("segFault") << QStringLiteral("SegFault.qml");
    QTest::newRow("grouped scope failure") << QStringLiteral("groupedScope.qml");
    QTest::newRow("layouts depends quick") << QStringLiteral("layouts.qml");
    QTest::newRow("attached") << QStringLiteral("attached.qml");
    QTest::newRow("enumProperty") << QStringLiteral("enumProperty.qml");
    QTest::newRow("externalEnumProperty") << QStringLiteral("externalEnumProperty.qml");
    QTest::newRow("shapes") << QStringLiteral("shapes.qml");
    QTest::newRow("var") << QStringLiteral("var.qml");
    QTest::newRow("defaultProperty") << QStringLiteral("defaultProperty.qml");
    QTest::newRow("defaultPropertyList") << QStringLiteral("defaultPropertyList.qml");
    QTest::newRow("defaultPropertyComponent") << QStringLiteral("defaultPropertyComponent.qml");
    QTest::newRow("defaultPropertyComponent2") << QStringLiteral("defaultPropertyComponent.2.qml");
    QTest::newRow("defaultPropertyListModel") << QStringLiteral("defaultPropertyListModel.qml");
    QTest::newRow("defaultPropertyVar") << QStringLiteral("defaultPropertyVar.qml");
    QTest::newRow("multiDefaultProperty") << QStringLiteral("multiDefaultPropertyOk.qml");
    QTest::newRow("propertyDelegate") << QStringLiteral("propertyDelegate.qml");
    QTest::newRow("duplicateQmldirImport") << QStringLiteral("qmldirImport/duplicate.qml");
    QTest::newRow("Used imports") << QStringLiteral("used.qml");
    QTest::newRow("Unused imports (multi)") << QStringLiteral("unused_multi.qml");
    QTest::newRow("compositeSingleton") << QStringLiteral("compositesingleton.qml");
    QTest::newRow("stringLength") << QStringLiteral("stringLength.qml");
    QTest::newRow("stringLength2") << QStringLiteral("stringLength2.qml");
    QTest::newRow("stringLength3") << QStringLiteral("stringLength3.qml");
    QTest::newRow("attachedPropertyAssignments")
            << QStringLiteral("attachedPropertyAssignments.qml");
    QTest::newRow("groupedPropertyAssignments") << QStringLiteral("groupedPropertyAssignments.qml");
    QTest::newRow("goodAttachedProperty") << QStringLiteral("goodAttachedProperty.qml");
    QTest::newRow("objectBindingOnVarProperty") << QStringLiteral("objectBoundToVar.qml");
    QTest::newRow("Unversioned change signal without arguments") << QStringLiteral("unversionChangedSignalSansArguments.qml");
    QTest::newRow("deprecatedFunctionOverride") << QStringLiteral("deprecatedFunctionOverride.qml");
    QTest::newRow("multilineStringEscaped") << QStringLiteral("multilineStringEscaped.qml");
    QTest::newRow("propertyOverride") << QStringLiteral("propertyOverride.qml");
    QTest::newRow("propertyBindingValue") << QStringLiteral("propertyBindingValue.qml");
    QTest::newRow("customParser") << QStringLiteral("customParser.qml");
    QTest::newRow("customParser.recursive") << QStringLiteral("customParser.recursive.qml");
    QTest::newRow("2Behavior") << QStringLiteral("2behavior.qml");
    QTest::newRow("interceptor") << QStringLiteral("interceptor.qml");
    QTest::newRow("valueSource") << QStringLiteral("valueSource.qml");
    QTest::newRow("interceptor+valueSource") << QStringLiteral("interceptor_valueSource.qml");
    QTest::newRow("groupedProperty (valueSource+interceptor)")
            << QStringLiteral("groupedProperty_valueSource_interceptor.qml");
    QTest::newRow("QtQuick.Window 2.1") << QStringLiteral("qtquickWindow21.qml");
    QTest::newRow("attachedTypeIndirect") << QStringLiteral("attachedTypeIndirect.qml");
    QTest::newRow("objectArray") << QStringLiteral("objectArray.qml");
    QTest::newRow("aliasToList") << QStringLiteral("aliasToList.qml");
    QTest::newRow("QVariant") << QStringLiteral("qvariant.qml");
    QTest::newRow("Accessible") << QStringLiteral("accessible.qml");
    QTest::newRow("qjsroot") << QStringLiteral("qjsroot.qml");
    QTest::newRow("InlineComponent") << QStringLiteral("inlineComponent.qml");
    QTest::newRow("InlineComponentWithComponents") << QStringLiteral("inlineComponentWithComponents.qml");
    QTest::newRow("InlineComponentsChained") << QStringLiteral("inlineComponentsChained.qml");
    QTest::newRow("ignoreWarnings") << QStringLiteral("ignoreWarnings.qml");
    QTest::newRow("BindingBeforeDeclaration") << QStringLiteral("bindingBeforeDeclaration.qml");
    QTest::newRow("CustomParserUnqualifiedAccess")
            << QStringLiteral("customParserUnqualifiedAccess.qml");
    QTest::newRow("ImportQMLModule") << QStringLiteral("importQMLModule.qml");
    QTest::newRow("ImportDirectoryQmldir") << QStringLiteral("Things/LintDirectly.qml");
    QTest::newRow("BindingsOnGroupAndAttachedProperties")
            << QStringLiteral("goodBindingsOnGroupAndAttached.qml");
    QTest::newRow("QQmlEasingEnums::Type") << QStringLiteral("animationEasing.qml");
    QTest::newRow("ValidLiterals") << QStringLiteral("validLiterals.qml");
    QTest::newRow("GoodModulePrefix") << QStringLiteral("goodModulePrefix.qml");
    QTest::newRow("required property in Component") << QStringLiteral("requiredPropertyInComponent.qml");
    QTest::newRow("bytearray") << QStringLiteral("bytearray.qml");
    QTest::newRow("initReadonly") << QStringLiteral("initReadonly.qml");
    QTest::newRow("connectionNoParent") << QStringLiteral("connectionNoParent.qml"); // QTBUG-97600
    QTest::newRow("goodGeneralizedGroup") << QStringLiteral("goodGeneralizedGroup.qml");
    QTest::newRow("on binding in grouped property") << QStringLiteral("onBindingInGroupedProperty.qml");
    QTest::newRow("declared property of JS object") << QStringLiteral("bareQt.qml");
    QTest::newRow("ID overrides property") << QStringLiteral("accessibleId.qml");
    QTest::newRow("matchByName") << QStringLiteral("matchByName.qml");
    QTest::newRow("cppPropertyChangeHandlers")
            << QStringLiteral("goodCppPropertyChangeHandlers.qml");
    QTest::newRow("unexportedCppBase") << QStringLiteral("unexportedCppBase.qml");
    QTest::newRow("qmodelIndex") << QStringLiteral("qmodelIndex.qml");
}

void TestQmllint::cleanQmlCode()
{
    QFETCH(QString, filename);

    QJsonArray warnings;

    callQmllint(filename, true, &warnings);
    QVERIFY2(warnings.isEmpty(), qPrintable(QJsonDocument(warnings).toJson()));
}

QString TestQmllint::runQmllint(const QString &fileToLint,
                                std::function<void(QProcess &)> handleResult,
                                const QStringList &extraArgs, bool ignoreSettings,
                                bool addIncludeDirs)
{
    auto qmlImportDir = QLibraryInfo::path(QLibraryInfo::QmlImportsPath);
    QStringList args;

    args << (QFileInfo(fileToLint).isAbsolute() ? fileToLint : testFile(fileToLint));

    if (addIncludeDirs) {
        args << QStringLiteral("-I") << qmlImportDir
             << QStringLiteral("-I") << dataDirectory();
    }

    if (ignoreSettings)
        QStringLiteral("--ignore-settings");

    args << extraArgs;
    args << QStringLiteral("--silent");
    QString errors;
    auto verify = [&](bool isSilent) {
        QProcess process;
        process.start(m_qmllintPath, args);
        handleResult(process);
        errors = process.readAllStandardError();

        QStringList lines = errors.split(u'\n', Qt::SkipEmptyParts);

        auto end = std::remove_if(lines.begin(), lines.end(), [](const QString &line) {
            return !line.startsWith("Warning: ") && !line.startsWith("Error: ");
        });

        std::sort(lines.begin(), end);
        auto it = std::unique(lines.begin(), end);
        if (it != end) {
            qDebug() << "The warnings and errors were generated more than once:";
            do {
                qDebug() << *it;
            } while (++it != end);
            QTest::qFail("Duplicate warnings and errors", __FILE__, __LINE__);
        }

        if (isSilent) {
            QTest::qVerify(errors.isEmpty(), "errors.isEmpty()", "Silent mode outputs messages",
                           __FILE__, __LINE__);
        }

        if (QTest::currentTestFailed()) {
            qDebug().noquote() << "Command:" << process.program() << args.join(u' ');
            qDebug() << "Exit status:" << process.exitStatus();
            qDebug() << "Exit code:" << process.exitCode();
            qDebug() << "stderr:" << errors;
            qDebug() << "stdout:" << process.readAllStandardOutput();
        }
    };
    verify(true);
    args.removeLast();
    verify(false);
    return errors;
}

QString TestQmllint::runQmllint(const QString &fileToLint, bool shouldSucceed,
                                const QStringList &extraArgs, bool ignoreSettings,
                                bool addIncludeDirs)
{
    return runQmllint(
            fileToLint,
            [&](QProcess &process) {
                QVERIFY(process.waitForFinished());
                QCOMPARE(process.exitStatus(), QProcess::NormalExit);

                if (shouldSucceed)
                    QCOMPARE(process.exitCode(), 0);
                else
                    QVERIFY(process.exitCode() != 0);
            },
            extraArgs, ignoreSettings, addIncludeDirs);
}

void TestQmllint::callQmllint(const QString &fileToLint, bool shouldSucceed, QJsonArray *warnings,
                              QStringList includeDirs, QStringList qmltypesFiles,
                              QStringList resources, DefaultIncludeOption defaultIncludes)
{
    QJsonArray jsonOutput;

    bool success = m_linter.lintFile(
            QFileInfo(fileToLint).isAbsolute() ? fileToLint : testFile(fileToLint), nullptr, true,
            warnings ? &jsonOutput : nullptr,
            defaultIncludes == UseDefaultIncludes ? m_defaultImportPaths + includeDirs
                                                  : includeDirs,
            qmltypesFiles, resources, {});
    QCOMPARE(success, shouldSucceed);

    if (warnings) {
        QVERIFY2(jsonOutput.size() == 1, QJsonDocument(jsonOutput).toJson());
        *warnings = jsonOutput.at(0)[u"warnings"_qs].toArray();
    }

    QCOMPARE(success, shouldSucceed);
}

void TestQmllint::searchWarnings(const QJsonArray &warnings, const QString &substring,
                                 const QString &filename, ContainOption shouldContain,
                                 ReplacementOption searchReplacements)
{
    bool contains = false;

    auto toDisplayWarningType = [](const QString &warningType) {
        return warningType.first(1).toUpper() + warningType.mid(1);
    };

    for (const QJsonValue &warning : warnings) {
        // We're currently recreating the output that the logger would write to the console,
        // so we can keep using our existing test data without modification.
        // In the future our test data should be replaced with a structured representation of the
        // warning it expects, possibly as a QQmlJS::DiagnosticMessage.
        const QString warningMessage =
                u"%1: %2:%3 %4"_qs
                        .arg(toDisplayWarningType(warning[u"type"].toString()), testFile(filename))
                        .arg(warning[u"line"].isUndefined()
                                     ? u""_qs
                                     : u"%1:%2:"_qs.arg(warning[u"line"].toInt())
                                               .arg(warning[u"column"].toInt()))
                        .arg(warning[u"message"].toString());
        if (warningMessage.contains(substring)) {
            contains = true;
            break;
        }

        for (const QJsonValue &fix : warning[u"suggestions"].toArray()) {
            const QString jsonFixMessage = u"Info: "_qs + fix[u"message"].toString();
            if (jsonFixMessage.contains(substring)) {
                contains = true;
                break;
            }
            if (searchReplacements == DoReplacementSearch
                && fix[u"replacement"].toString().contains(substring)) {
                contains = true;
                break;
            }
        }
    }

    const auto toDescription = [](const QJsonArray &warnings, const QString &substring,
                                  bool must = true) {
        // Note: this actually produces a very poorly formatted multi-line
        // description, but this is how we also do it in cleanQmlCode test case,
        // so this should suffice. in any case this mainly aids the debugging
        // and CI stays (or should stay) clean.
        return QStringLiteral("qmllint output '%1' %2 contain '%3'")
                .arg(QString::fromUtf8(QJsonDocument(warnings).toJson(QJsonDocument::Compact)),
                     must ? u"must" : u"must NOT", substring);
    };

    if (shouldContain == StringContained)
        QVERIFY2(contains, qPrintable(toDescription(warnings, substring)));
    else
        QVERIFY2(!contains, qPrintable(toDescription(warnings, substring, false)));
}

void TestQmllint::requiredProperty()
{
    QVERIFY(runQmllint("requiredProperty.qml", true).isEmpty());

    {
        QJsonArray warnings;
        callQmllint("requiredMissingProperty.qml", false, &warnings);
        searchWarnings(
                warnings,
                QStringLiteral("Property \"foo\" was marked as required but does not exist."),
                "requiredMissingProperty.qml");
    }

    QVERIFY(runQmllint("requiredPropertyBindings.qml", true).isEmpty());

    {
        QJsonArray warnings;
        callQmllint("requiredPropertyBindingsNow.qml", false, &warnings);

        searchWarnings(
                warnings,
                QStringLiteral(
                        "Component is missing required property required_now_string from Base"),
                "requiredPropertyBindingsNow.qml");
        searchWarnings(warnings,
                       QStringLiteral("Component is missing required property "
                                      "required_defined_here_string from here"),
                       "requiredPropertyBindingsNow.qml");
    }

    {
        QJsonArray warnings;
        callQmllint("requiredPropertyBindingsLater.qml", false, &warnings);
        searchWarnings(
                warnings,
                QStringLiteral("Component is missing required property required_later_string from "
                               "Base (marked as required by Derived)"),
                "requiredPropertyBindingsLater.qml");
        searchWarnings(
                warnings,
                QStringLiteral("Component is missing required property required_even_later_string "
                               "from Base (marked as required by here)"),
                "requiredPropertyBindingsLater.qml");
    }
}

void TestQmllint::settingsFile()
{
    QVERIFY(runQmllint("settings/unqualifiedSilent/unqualified.qml", true, QStringList(), false)
                    .isEmpty());
    QVERIFY(runQmllint("settings/unusedImportWarning/unused.qml", false, QStringList(), false)
                    .contains(QStringLiteral("Info: %1:2:1: Unused import at %1:2:1")
                                      .arg(testFile("settings/unusedImportWarning/unused.qml"))));
    QVERIFY(runQmllint("settings/bare/bare.qml", false, { "--bare" }, false, false)
                    .contains(QStringLiteral("Failed to find the following builtins: "
                                             "builtins.qmltypes, jsroot.qmltypes")));
    QVERIFY(runQmllint("settings/qmltypes/qmltypes.qml", false, QStringList(), false)
                    .contains(QStringLiteral("not a qmldir file. Assuming qmltypes.")));
}

void TestQmllint::additionalImplicitImport()
{
    QJsonArray warnings;
    callQmllint("additionalImplicitImport.qml", true, &warnings, {}, {},
                { testFile("implicitImportResource.qrc") });
    QVERIFY(warnings.isEmpty());
}

void TestQmllint::listIndices()
{
    QVERIFY(runQmllint("listIndices.qml", true, {"--compiler=warning"}, false).isEmpty());
}

void TestQmllint::lazyAndDirect()
{
    QVERIFY(runQmllint("LazyAndDirect/Lazy.qml", true, {"--compiler=warning"}, false).isEmpty());
}

void TestQmllint::functionDeclaration()
{
    QVERIFY(runQmllint("functionDeclarations.qml", false, { "--controls-sanity=warning" }, false)
                    .contains(u"Declared function \"add\""_qs));
}

void TestQmllint::signalHandler()
{
    QVERIFY(runQmllint("signalHandlers.qml", false, { "--controls-sanity=warning" }, false)
                    .contains(u"Declared signal handler \"onCompleted\""_qs));
}

void TestQmllint::anchors()
{
    QVERIFY(runQmllint("anchors.qml", false, { "--controls-sanity=warning" }, false)
                    .contains(u"Using anchors here"_qs));
}

void TestQmllint::attachedPropertyReuse()
{
    QVERIFY(runQmllint("attachedPropNotReused.qml", false,
                       QStringList() << "--multiple-attached-objects"
                                     << "warning",
                       false)
                    .contains(QStringLiteral("Using attached type QQuickKeyNavigationAttached "
                                             "already initialized in a parent "
                                             "scope")));
    QVERIFY(runQmllint("attachedPropEnum.qml", true,
                       QStringList() << "--multiple-attached-objects"
                                     << "warning")
                    .isEmpty());
}

void TestQmllint::shadowable()
{
    QVERIFY(runQmllint("shadowable.qml", false, {"--compiler=warning"}, false).contains(
            QStringLiteral("with type NotSoSimple can be shadowed")));
}

void TestQmllint::tooFewParameters()
{
    QVERIFY(runQmllint("tooFewParams.qml", false, {"--compiler=warning"}, false).contains(
            QStringLiteral("No matching override found")));
}

void TestQmllint::qQmlV4Function()
{
    QVERIFY(runQmllint("varargs.qml", true, {"--compiler=warning"}, false).isEmpty());
}

void TestQmllint::missingBuiltinsNoCrash()
{
    QVERIFY(runQmllint("missingBuiltinsNoCrash.qml", false, { "--bare" }, false, false)
                    .contains(QStringLiteral("Failed to find the following builtins: "
                                             "builtins.qmltypes, jsroot.qmltypes")));
}

void TestQmllint::absolutePath()
{
    const QString absolutePath = QFileInfo(testFile("memberNotFound.qml")).absoluteFilePath();
    QVERIFY(runQmllint(absolutePath, false, { "--absolute-path" }).contains(absolutePath));
}

void TestQmllint::multiGrouped()
{
    QVERIFY(runQmllint("multiGrouped.qml", true, {"--compiler=warning"}).isEmpty());
}

void TestQmllint::javascriptVariableArgs()
{
    QVERIFY(runQmllint("javascriptVariableArgs.qml", false, { "--compiler", "warning" })
            .contains(QStringLiteral("Function expects 0 arguments, but 2 were provided")));
}

void TestQmllint::unknownTypeInRegister()
{
    QVERIFY(runQmllint("unknownTypeInRegister.qml", false, { "--compiler", "warning" })
                    .contains(QStringLiteral(
                            "Functions without type annotations won't be compiled")));
}

void TestQmllint::importMultipartUri()
{
    QJsonArray warnings;
    callQmllint("here.qml", true, &warnings, {}, { testFile("Elsewhere/qmldir") });
    QVERIFY(warnings.isEmpty());
}

QTEST_MAIN(TestQmllint)
#include "tst_qmllint.moc"