fix: harden search and release safeguards
ci-release / verify (push) Successful in 34s
ci-release / publish-linux-amd64 (push) Has been skipped

This commit is contained in:
2026-07-25 21:04:54 +02:00
parent 918e081834
commit e0d7cbb29a
13 changed files with 680 additions and 234 deletions
+40
View File
@@ -0,0 +1,40 @@
#include "long_long_spin_box.h"
#include <QLineEdit>
#include <QtTest>
class LongLongSpinBoxTest final : public QObject {
Q_OBJECT
private slots:
void preservesValuesAboveTwoGigabytes()
{
LongLongSpinBox spin;
spin.setRange(0, std::numeric_limits<qint64>::max());
spin.setSuffix(QStringLiteral(" bytes"));
spin.setValue(5'000'000'000);
QCOMPARE(spin.value(), qint64(5'000'000'000));
QCOMPARE(spin.findChild<QLineEdit *>()->text(), QStringLiteral("5000000000 bytes"));
spin.stepUp();
QCOMPARE(spin.value(), qint64(5'000'000'001));
spin.findChild<QLineEdit *>()->setText(QStringLiteral("6000000000 bytes"));
QVERIFY(QMetaObject::invokeMethod(&spin, "editingFinished", Qt::DirectConnection));
QCOMPARE(spin.value(), qint64(6'000'000'000));
}
void clampsAtRangeEdges()
{
LongLongSpinBox spin;
spin.setRange(0, 10);
spin.setValue(10);
spin.stepUp();
QCOMPARE(spin.value(), qint64(10));
spin.setValue(-50);
QCOMPARE(spin.value(), qint64(0));
}
};
QTEST_MAIN(LongLongSpinBoxTest)
#include "long_long_spin_box_test.moc"
+20
View File
@@ -0,0 +1,20 @@
#!/usr/bin/env bash
set -euo pipefail
release_script="$(realpath "$1")"
test_directory="$(mktemp -d)"
trap 'rm -rf "$test_directory"' EXIT
git -C "$test_directory" init -q
git -C "$test_directory" config user.name "FolderScope Tests"
git -C "$test_directory" config user.email "tests@folderscope.invalid"
printf '9.9.9\n' > "$test_directory/VERSION"
printf '# Changelog\n\n## [9.9.9]\n' > "$test_directory/CHANGELOG.md"
git -C "$test_directory" add VERSION CHANGELOG.md
git -C "$test_directory" commit -q -m "test fixture"
touch "$test_directory/untracked"
if (cd "$test_directory" && "$release_script" 9.9.9 >/dev/null 2>&1); then
echo "release.sh accepted a repository with untracked files" >&2
exit 1
fi
+86
View File
@@ -0,0 +1,86 @@
#include "search_core.h"
#include <QCryptographicHash>
#include <QFile>
#include <QTemporaryDir>
#include <QtTest>
class SearchCoreTest final : public QObject {
Q_OBJECT
private slots:
void parsesPatternsAndExclusions()
{
QCOMPARE(patterns(QStringLiteral("/a; \"/b,with-comma\" , /c")),
QStringList({QStringLiteral("/a"), QStringLiteral("/b,with-comma"),
QStringLiteral("/c")}));
QCOMPARE(exclusionPatterns(QStringLiteral("tmp log *.bak")),
QStringList({QStringLiteral("*.tmp"), QStringLiteral("*.log"),
QStringLiteral("*.bak")}));
QVERIFY(wildcardMatch(QStringLiteral("Report.TXT"), {QStringLiteral("*.txt")},
Qt::CaseInsensitive));
QVERIFY(!wildcardMatch(QStringLiteral("Report.TXT"), {QStringLiteral("*.txt")},
Qt::CaseSensitive));
}
void parsesOptionalIsoDates()
{
qint64 seconds = -1;
QVERIFY(parseOptionalIsoDate(QString{}, seconds));
QCOMPARE(seconds, 0);
QVERIFY(parseOptionalIsoDate(QStringLiteral("2026-07-25T20:30:00"), seconds));
QVERIFY(seconds > 0);
QVERIFY(!parseOptionalIsoDate(QStringLiteral("2026-not-a-date"), seconds));
}
void searchesContentsAndHashes()
{
QTemporaryDir directory;
QVERIFY(directory.isValid());
const QString firstPath = directory.filePath(QStringLiteral("first.bin"));
const QString secondPath = directory.filePath(QStringLiteral("second.bin"));
const QString differentPath = directory.filePath(QStringLiteral("different.bin"));
const QByteArray content = QByteArray(1024 * 1024 - 2, 'x')
+ QByteArray("Alpha needle BETA");
QFile first(firstPath);
QVERIFY(first.open(QIODevice::WriteOnly));
QCOMPARE(first.write(content), content.size());
first.close();
QFile second(secondPath);
QVERIFY(second.open(QIODevice::WriteOnly));
QCOMPARE(second.write(content), content.size());
second.close();
QFile different(differentPath);
QVERIFY(different.open(QIODevice::WriteOnly));
QCOMPARE(different.write("different"), qint64(9));
different.close();
SearchOptions options;
options.contains = QStringLiteral("needle");
QVERIFY(fileContains(firstPath, options));
options.contains = QStringLiteral("alpha,beta");
options.multipleValues = true;
options.multipleAnd = true;
QVERIFY(fileContains(firstPath, options));
options.caseSensitive = true;
QVERIFY(!fileContains(firstPath, options));
options.binary = true;
options.multipleValues = false;
options.multipleAnd = false;
options.contains = QStringLiteral("41 6c 70 68 61");
QVERIFY(fileContains(firstPath, options));
options.contains = QStringLiteral("ABC");
QVERIFY(!fileContains(firstPath, options));
QVERIFY(filesEqual(firstPath, secondPath));
QVERIFY(!filesEqual(firstPath, differentPath));
QCOMPARE(sha256(firstPath), QCryptographicHash::hash(content, QCryptographicHash::Sha256));
}
};
QTEST_GUILESS_MAIN(SearchCoreTest)
#include "search_core_test.moc"