aboutsummaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
authorUlf Hermann <ulf.hermann@qt.io>2021-02-11 13:54:10 +0100
committerUlf Hermann <ulf.hermann@qt.io>2021-02-15 19:18:07 +0100
commite337ba277beb6d08dbb9ca78e74d6cc22f56e3b6 (patch)
tree5db664bd00693e28cdde09636a0ea38bcce9bc10 /tests
parent9f864cc12753a1b9b4d58139df7509b411693e28 (diff)
qmllint: Warn about too many or mismatched signal parameters
It's easy to mess this up when you transform your signal handlers into functions. Task-number: QTBUG-89943 Change-Id: If35be2f6828a0e19aada19abb41d8135b0c6ab45 Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io> (cherry picked from commit f0ecad1e99461109e69cd2b0f6271012c20005dd) Reviewed-by: Andrei Golubev <andrei.golubev@qt.io>
Diffstat (limited to 'tests')
-rw-r--r--tests/auto/qml/qmllint/data/namedSignalParameters.qml15
-rw-r--r--tests/auto/qml/qmllint/data/tooManySignalParameters.qml8
-rw-r--r--tests/auto/qml/qmllint/tst_qmllint.cpp10
3 files changed, 33 insertions, 0 deletions
diff --git a/tests/auto/qml/qmllint/data/namedSignalParameters.qml b/tests/auto/qml/qmllint/data/namedSignalParameters.qml
new file mode 100644
index 0000000000..00746d5d83
--- /dev/null
+++ b/tests/auto/qml/qmllint/data/namedSignalParameters.qml
@@ -0,0 +1,15 @@
+import QtQuick 2.0
+Window {
+ width: 800
+ height: 600
+ visible: true
+ signal sig(string arg, int argarg)
+ signal sig2(int foo, bool bar)
+
+ onSig: function(argarg) {
+ print("SIG", argarg);
+ }
+
+ onSig2: (foo, bar)=> { sig(foo, bar); }
+}
+
diff --git a/tests/auto/qml/qmllint/data/tooManySignalParameters.qml b/tests/auto/qml/qmllint/data/tooManySignalParameters.qml
new file mode 100644
index 0000000000..f5d5977a99
--- /dev/null
+++ b/tests/auto/qml/qmllint/data/tooManySignalParameters.qml
@@ -0,0 +1,8 @@
+import QtQml
+QtObject {
+ signal sig(string arg, int argarg)
+ onSig: function(arg, b, c, d) {
+ print("SIG", arg, b, c, d);
+ }
+}
+
diff --git a/tests/auto/qml/qmllint/tst_qmllint.cpp b/tests/auto/qml/qmllint/tst_qmllint.cpp
index 97840cc2dd..18b5090dcf 100644
--- a/tests/auto/qml/qmllint/tst_qmllint.cpp
+++ b/tests/auto/qml/qmllint/tst_qmllint.cpp
@@ -282,6 +282,16 @@ void TestQmllint::dirtyQmlCode_data()
<< QStringLiteral("Variable \"argq\" is used before its declaration at 5:9. "
"The declaration is at 6:13.")
<< QString();
+ 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");
+ QTest::newRow("TooManySignalParameters")
+ << QStringLiteral("tooManySignalParameters.qml")
+ << QStringLiteral("Signal handler for \"onSig\" has more formal parameters "
+ "than the signal it handles.")
+ << QString();
}
void TestQmllint::dirtyQmlCode()