summaryrefslogtreecommitdiff
blob: e526f3a89f0b0ab9e1ede1069914509a4f26d1de (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
https://github.com/hluk/CopyQ/commit/42c02f2dc74b188ea7982a30c38acaf668bbf76a

From 42c02f2dc74b188ea7982a30c38acaf668bbf76a Mon Sep 17 00:00:00 2001
From: Lukas Holecek <hluk@email.cz>
Date: Mon, 4 Sep 2023 21:12:44 +0200
Subject: [PATCH] Avoid showing warnings about invalid regex

--- a/src/scriptable/scriptableitemselection.cpp
+++ b/src/scriptable/scriptableitemselection.cpp
@@ -46,10 +46,6 @@ QVector<int> toIntVector(const QJSValue &value)
 
 QRegularExpression toRegularExpression(const QJSValue &value)
 {
-    // If argument is invalid/not-regexp, create an invalid regex to match nothing.
-    if ( !value.isRegExp() )
-        return QRegularExpression("(");
-
     const QVariant variant = value.toVariant();
     QRegularExpression regexp = variant.toRegularExpression();
 
@@ -136,7 +132,7 @@ QJSValue ScriptableItemSelection::selectAll()
 
 QJSValue ScriptableItemSelection::select(const QJSValue &re, const QString &mimeFormat)
 {
-    const QVariant regexp = re.isUndefined() ? QVariant() : toRegularExpression(re);
+    const QVariant regexp = re.isRegExp() ? toRegularExpression(re) : QVariant();
     m_proxy->selectionSelect(m_id, regexp, mimeFormat);
     return m_self;
 }
--- a/src/tests/testinterface.h
+++ b/src/tests/testinterface.h
@@ -85,9 +85,6 @@ class TestInterface {
     /// Clean up tabs and items. Return error string on error.
     virtual QByteArray cleanup() = 0;
 
-    /// Ignore given text in logs for current unit test.
-    virtual void setIgnoreError(const QByteArray &ignoreError) = 0;
-
     /// Platform specific key to remove (usually Delete, Backspace on OS X).
     virtual QString shortcutToRemove() = 0;
 
--- a/src/tests/tests.cpp
+++ b/src/tests/tests.cpp
@@ -150,8 +150,6 @@ bool testStderr(const QByteArray &stderrData, TestInterface::ReadStderrFlag flag
     // Ignore exceptions and errors from clients in application log
     // (these are expected in some tests).
     static const std::vector<QRegularExpression> ignoreList{
-        plain("[EXPECTED-IN-TEST]"),
-
         regex(R"(CopyQ Note \[\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2}\.\d{3}\] <Client-[^\n]*)"),
 
         // X11 (Linux)
@@ -520,8 +518,6 @@ class TestInterfaceImpl final : public TestInterface {
         if (m_server) {
             QCoreApplication::processEvents();
             QByteArray output = readLogFile(maxReadLogSize);
-            if ( !m_ignoreError.isEmpty() )
-                output.replace(m_ignoreError, "[EXPECTED-IN-TEST] " + m_ignoreError);
             if ( flag == ReadAllStderr || !testStderr(output, flag) )
               return decorateOutput("Server STDERR", output);
         }
@@ -645,16 +641,10 @@ class TestInterfaceImpl final : public TestInterface {
 
     QByteArray cleanup() override
     {
-        m_ignoreError.clear();
         addFailedTest();
         return QByteArray();
     }
 
-    void setIgnoreError(const QByteArray &ignoreError) override
-    {
-        m_ignoreError = ignoreError;
-    }
-
     QString shortcutToRemove() override
     {
         return ::shortcutToRemove();
@@ -771,8 +761,6 @@ class TestInterfaceImpl final : public TestInterface {
     QStringList m_failed;
 
     PlatformClipboardPtr m_clipboard;
-
-    QByteArray m_ignoreError;
 };
 
 QString keyNameFor(QKeySequence::StandardKey standardKey)
@@ -2272,9 +2260,8 @@ void Tests::classItemSelection()
     RUN(args << "ItemSelection().select(undefined, mimeItemNotes).str()", outRows.arg("0,2"));
 
     // Match nothing if select() argument is not a regular expression.
-    m_test->setIgnoreError("QtWarning: QString::contains: invalid QRegularExpression object");
+    RUN(args << "add" << "", "");
     RUN(args << "ItemSelection().select('A').str()", outRows.arg(""));
-    m_test->setIgnoreError(QByteArray());
 }
 
 void Tests::classItemSelectionGetCurrent()