Skip to content

Commit 9d2b375

Browse files
committed
Separate tests from the app
Fixes #3274
1 parent d54623c commit 9d2b375

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

72 files changed

+1396
-1405
lines changed

.github/workflows/build-linux.yml

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -154,14 +154,21 @@ jobs:
154154
run: mkdir -p ~/.gnupg && chmod go-rwx ~/.gnupg
155155

156156
- name: Test on Wayland
157-
working-directory: '${{runner.workspace}}/install/copyq/${{ matrix.cmake_preset }}/bin'
157+
working-directory: >-
158+
${{runner.workspace}}/build/copyq/${{ matrix.cmake_preset }}
158159
if: matrix.test_wayland
159160
run: '${{github.workspace}}/utils/github/test-linux-wayland.sh'
161+
env:
162+
COPYQ_TESTS_EXECUTABLE: >-
163+
${{runner.workspace}}/install/copyq/${{ matrix.cmake_preset }}/bin/copyq
160164
161165
- name: Test on X11
162-
working-directory: '${{runner.workspace}}/install/copyq/${{ matrix.cmake_preset }}/bin'
166+
working-directory: >-
167+
${{runner.workspace}}/build/copyq/${{ matrix.cmake_preset }}
163168
run: '${{github.workspace}}/utils/github/test-linux.sh'
164169
env:
170+
COPYQ_TESTS_EXECUTABLE: >-
171+
${{runner.workspace}}/install/copyq/${{ matrix.cmake_preset }}/bin/copyq
165172
COPYQ_TESTS_SKIP_DRAG_AND_DROP: >-
166173
${{ matrix.with_qt6 && '0' || '1' }}
167174

CMakeLists.txt

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@ endif()
1818
OPTION(PEDANTIC "Enable all compiler warnings" OFF)
1919

2020
# Options (cmake -LH)
21-
OPTION(WITH_TESTS "Run test cases from command line" ${COPYQ_DEBUG})
2221
OPTION(WITH_PLUGINS "Compile plugins" ON)
2322

2423
add_definitions( -DQT_USE_STRINGBUILDER )
@@ -130,15 +129,6 @@ if (PEDANTIC)
130129
)
131130
endif()
132131

133-
if(WITH_TESTS)
134-
message(STATUS "Building with tests.")
135-
136-
add_definitions( -DHAS_TESTS )
137-
138-
find_package(${copyq_qt}Test REQUIRED)
139-
list(APPEND copyq_LIBRARIES ${copyq_qt}::Test)
140-
endif()
141-
142132
include(src/version.cmake)
143133
message(STATUS "Building CopyQ version ${copyq_version}.")
144134

@@ -198,3 +188,9 @@ if (WITH_PLUGINS)
198188
endif()
199189

200190
add_subdirectory(src)
191+
192+
# Compile with tests?
193+
OPTION(WITH_TESTS "Run test cases from command line" OFF)
194+
if(WITH_TESTS)
195+
include(tests/tests.cmake)
196+
endif()

plugins/CMakeLists.txt

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,6 @@ macro (copyq_add_plugin copyq_pkg)
1414
${copyq_plugin_${copyq_pkg}_SOURCES} PROPERTIES
1515
COMPILE_OPTIONS "${copyq_pedantic_flags}")
1616

17-
if (WITH_TESTS)
18-
file(GLOB copyq_plugin_SOURCES ${copyq_plugin_SOURCES} tests/*.cpp)
19-
endif (WITH_TESTS)
20-
2117
include_directories(${CMAKE_CURRENT_BINARY_DIR} ../../src)
2218

2319
include_directories(${${copyq_qt}Widgets_INCLUDES})

plugins/itemencrypted/itemencrypted.cpp

Lines changed: 19 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,6 @@
1515
#include "gui/fromiconid.h"
1616
#include "item/serialize.h"
1717

18-
#ifdef HAS_TESTS
19-
# include "tests/itemencryptedtests.h"
20-
#endif
21-
2218
#include <QAbstractItemModel>
2319
#include <QDebug>
2420
#include <QDir>
@@ -406,7 +402,7 @@ bool ItemEncryptedScriptable::isEncrypted()
406402
bool ok;
407403
const int row = arg.toInt(&ok);
408404
if (ok) {
409-
const auto result = call("read", QVariantList() << "?" << row);
405+
const auto result = call("read", {QStringLiteral("?"), row});
410406
if ( result.toByteArray().contains(mimeEncryptedData.data()) )
411407
return true;
412408
}
@@ -432,43 +428,43 @@ QByteArray ItemEncryptedScriptable::decrypt()
432428
void ItemEncryptedScriptable::encryptItem()
433429
{
434430
QVariantMap dataMap;
435-
const auto formats = call("dataFormats").toList();
431+
const auto formats = call("dataFormats", {}).toList();
436432
for (const auto &formatValue : formats) {
437433
const auto format = formatValue.toString();
438434
if ( !format.startsWith(COPYQ_MIME_PREFIX) ) {
439-
const auto data = call("data", QVariantList() << format).toByteArray();
435+
const auto data = call("data", {format}).toByteArray();
440436
dataMap.insert(format, data);
441437
}
442438
}
443439

444-
const auto bytes = call("pack", QVariantList() << dataMap).toByteArray();
440+
const auto bytes = call("pack", {dataMap}).toByteArray();
445441
const auto encryptedBytes = encrypt(bytes);
446442
if (encryptedBytes.isEmpty())
447443
return;
448444

449-
call("setData", QVariantList() << mimeEncryptedData << encryptedBytes);
445+
call("setData", {mimeEncryptedData, encryptedBytes});
450446

451447
for (auto it = dataMap.constBegin(); it != dataMap.constEnd(); ++it)
452-
call("removeData", QVariantList() << it.key());
448+
call("removeData", {it.key()});
453449
}
454450

455451
void ItemEncryptedScriptable::decryptItem()
456452
{
457-
const auto encryptedBytes = call("data", QVariantList() << mimeEncryptedData).toByteArray();
453+
const auto encryptedBytes = call("data", {mimeEncryptedData}).toByteArray();
458454
const auto itemData = decrypt(encryptedBytes);
459455
if (itemData.isEmpty())
460456
return;
461457

462-
const auto dataMap = call("unpack", QVariantList() << itemData).toMap();
458+
const auto dataMap = call("unpack", {itemData}).toMap();
463459
for (auto it = dataMap.constBegin(); it != dataMap.constEnd(); ++it) {
464460
const auto &format = it.key();
465-
call("setData", QVariantList() << format << dataMap[format]);
461+
call("setData", {format, dataMap[format]});
466462
}
467463
}
468464

469465
void ItemEncryptedScriptable::encryptItems()
470466
{
471-
const auto dataValueList = call("selectedItemsData").toList();
467+
const auto dataValueList = call("selectedItemsData", {}).toList();
472468

473469
QVariantList dataList;
474470
for (const auto &itemDataValue : dataValueList) {
@@ -483,7 +479,7 @@ void ItemEncryptedScriptable::encryptItems()
483479
}
484480
}
485481

486-
const auto bytes = call("pack", QVariantList() << itemDataToEncrypt).toByteArray();
482+
const auto bytes = call("pack", {itemDataToEncrypt}).toByteArray();
487483
const auto encryptedBytes = encrypt(bytes);
488484
if (encryptedBytes.isEmpty())
489485
return;
@@ -492,12 +488,12 @@ void ItemEncryptedScriptable::encryptItems()
492488
dataList.append(itemData);
493489
}
494490

495-
call( "setSelectedItemsData", QVariantList() << QVariant(dataList) );
491+
call( "setSelectedItemsData", {QVariant(dataList)} );
496492
}
497493

498494
void ItemEncryptedScriptable::decryptItems()
499495
{
500-
const auto dataValueList = call("selectedItemsData").toList();
496+
const auto dataValueList = call("selectedItemsData", {}).toList();
501497

502498
QVariantList dataList;
503499
for (const auto &itemDataValue : dataValueList) {
@@ -511,20 +507,20 @@ void ItemEncryptedScriptable::decryptItems()
511507
if (decryptedBytes.isEmpty())
512508
return;
513509

514-
const auto decryptedItemData = call("unpack", QVariantList() << decryptedBytes).toMap();
510+
const auto decryptedItemData = call("unpack", {decryptedBytes}).toMap();
515511
for (auto it = decryptedItemData.constBegin(); it != decryptedItemData.constEnd(); ++it)
516512
itemData.insert(it.key(), it.value());
517513
}
518514

519515
dataList.append(itemData);
520516
}
521517

522-
call( "setSelectedItemsData", QVariantList() << QVariant(dataList) );
518+
call( "setSelectedItemsData", {QVariant(dataList)} );
523519
}
524520

525521
void ItemEncryptedScriptable::copyEncryptedItems()
526522
{
527-
const auto dataValueList = call("selectedItemsData").toList();
523+
const auto dataValueList = call("selectedItemsData", {}).toList();
528524
QString text;
529525
for (const auto &dataValue : dataValueList) {
530526
if ( !text.isEmpty() )
@@ -540,15 +536,13 @@ void ItemEncryptedScriptable::copyEncryptedItems()
540536
const auto itemData = decrypt(encryptedBytes);
541537
if (itemData.isEmpty())
542538
return;
543-
const auto dataMap = call("unpack", QVariantList() << itemData).toMap();
539+
const auto dataMap = call("unpack", {itemData}).toMap();
544540
text.append( getTextData(dataMap) );
545541
}
546542
}
547543
}
548544

549-
const auto args = QVariantList()
550-
<< mimeText << text
551-
<< mimeHidden << "1";
545+
const QVariantList args{mimeText, text, mimeHidden, "1"};
552546
call("copy", args);
553547
call("copySelection", args);
554548
}
@@ -567,7 +561,7 @@ void ItemEncryptedScriptable::pasteEncryptedItems()
567561
copy('');
568562
copySelection('');
569563
)";
570-
call("eval", QVariantList() << script);
564+
call("eval", {script});
571565
}
572566

573567
QString ItemEncryptedScriptable::generateTestKeys()
@@ -829,17 +823,6 @@ ItemSaverPtr ItemEncryptedLoader::initializeTab(const QString &, QAbstractItemMo
829823
return createSaver();
830824
}
831825

832-
QObject *ItemEncryptedLoader::tests(const TestInterfacePtr &test) const
833-
{
834-
#ifdef HAS_TESTS
835-
QObject *tests = new ItemEncryptedTests(test);
836-
return tests;
837-
#else
838-
Q_UNUSED(test)
839-
return nullptr;
840-
#endif
841-
}
842-
843826
ItemScriptable *ItemEncryptedLoader::scriptableObject()
844827
{
845828
return new ItemEncryptedScriptable();

plugins/itemencrypted/itemencrypted.h

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -100,8 +100,6 @@ class ItemEncryptedLoader final : public QObject, public ItemLoaderInterface
100100

101101
ItemSaverPtr initializeTab(const QString &, QAbstractItemModel *model, int maxItems) override;
102102

103-
QObject *tests(const TestInterfacePtr &test) const override;
104-
105103
const QObject *signaler() const override { return this; }
106104

107105
ItemScriptable *scriptableObject() override;

plugins/itemfakevim/itemfakevim.cpp

Lines changed: 0 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,6 @@
33
#include "itemfakevim.h"
44
#include "ui_itemfakevimsettings.h"
55

6-
#include "tests/itemfakevimtests.h"
7-
#include "common/contenttype.h"
8-
96
#include "fakevim/fakevimhandler.h"
107

118
using namespace FakeVim::Internal;
@@ -784,21 +781,6 @@ QWidget *ItemFakeVimLoader::createSettingsWidget(QWidget *parent)
784781
return w;
785782
}
786783

787-
QObject *ItemFakeVimLoader::tests(const TestInterfacePtr &test) const
788-
{
789-
#ifdef HAS_TESTS
790-
QVariantMap settings;
791-
settings["really_enable"] = true;
792-
settings["source_file"] = QString(ItemFakeVimTests::fileNameToSource());
793-
QObject *tests = new ItemFakeVimTests(test);
794-
tests->setProperty("CopyQ_test_settings", settings);
795-
return tests;
796-
#else
797-
Q_UNUSED(test)
798-
return nullptr;
799-
#endif
800-
}
801-
802784
bool ItemFakeVimLoader::eventFilter(QObject *watched, QEvent *event)
803785
{
804786
if (event->type() == QEvent::Show)

plugins/itemfakevim/itemfakevim.h

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,8 +37,6 @@ class ItemFakeVimLoader final : public QObject, public ItemLoaderInterface
3737

3838
QWidget *createSettingsWidget(QWidget *parent) override;
3939

40-
QObject *tests(const TestInterfacePtr &test) const override;
41-
4240
bool eventFilter(QObject *watched, QEvent *event) override;
4341

4442
signals:

plugins/itemimage/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
set(copyq_plugin_itemimage_SOURCES
22
../../src/common/action.cpp
33
../../src/common/mimetypes.cpp
4+
../../src/common/process.cpp
45
../../src/common/temporaryfile.cpp
56
../../src/item/itemeditor.cpp
67
../../src/item/serialize.cpp

plugins/itemimage/itemimage.cpp

Lines changed: 0 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,6 @@
77
#include "item/itemeditor.h"
88
#include "gui/pixelratio.h"
99

10-
#ifdef HAS_TESTS
11-
# include "tests/itemimagetests.h"
12-
#endif
13-
1410
#include <QBuffer>
1511
#include <QHBoxLayout>
1612
#include <QModelIndex>
@@ -231,17 +227,6 @@ QStringList ItemImageLoader::formatsToSave() const
231227
};
232228
}
233229

234-
QObject *ItemImageLoader::tests(const TestInterfacePtr &test) const
235-
{
236-
#ifdef HAS_TESTS
237-
QObject *tests = new ItemImageTests(test);
238-
return tests;
239-
#else
240-
Q_UNUSED(test)
241-
return nullptr;
242-
#endif
243-
}
244-
245230
void ItemImageLoader::applySettings(QSettings &settings)
246231
{
247232
settings.setValue(configMaxImageWidth, ui->spinBoxImageWidth->value());

plugins/itemimage/itemimage.h

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -69,8 +69,6 @@ class ItemImageLoader final : public QObject, public ItemLoaderInterface
6969

7070
QStringList formatsToSave() const override;
7171

72-
QObject *tests(const TestInterfacePtr &test) const override;
73-
7472
void applySettings(QSettings &settings) override;
7573

7674
void loadSettings(const QSettings &settings) override;

0 commit comments

Comments
 (0)