Fix warnings about unused return values

Change-Id: I9682c6b5a0bba400050e91fe89b2883f7bb6465f
Reviewed-by: Christian Stenger <christian.stenger@qt.io>
This commit is contained in:
Christian Kandeler
2025-01-20 16:27:27 +01:00
parent 2dbd2fb674
commit ea7b16cb70
34 changed files with 84 additions and 74 deletions

View File

@@ -949,7 +949,8 @@ bool DesktopDeviceFileAccess::ensureExistingFile(const FilePath &filePath) const
QFile f(filePath.path()); QFile f(filePath.path());
if (f.exists()) if (f.exists())
return true; return true;
f.open(QFile::WriteOnly); if (!f.open(QFile::WriteOnly))
return false;
f.close(); f.close();
return f.exists(); return f.exists();
} }

View File

@@ -558,7 +558,7 @@ MimeType MimeDatabasePrivate::mimeTypeForFileNameAndData(const QString &fileName
return matchOnContent(device); return matchOnContent(device);
QFile fallbackFile(fileName); QFile fallbackFile(fileName);
fallbackFile.open(QIODevice::ReadOnly); // error handling: matchOnContent() will check isOpen() (void) fallbackFile.open(QIODevice::ReadOnly); // error handling: matchOnContent() will check isOpen()
return matchOnContent(&fallbackFile); return matchOnContent(&fallbackFile);
} }

View File

@@ -608,7 +608,8 @@ bool AndroidBuildApkWidget::isOpenSslLibsIncluded()
Utils::FilePath projectPath = appProjectFilePath(); Utils::FilePath projectPath = appProjectFilePath();
const QString searchStr = openSslIncludeFileContent(projectPath); const QString searchStr = openSslIncludeFileContent(projectPath);
QFile projectFile(projectPath.toFSPathString()); QFile projectFile(projectPath.toFSPathString());
projectFile.open(QIODevice::ReadOnly); if (!projectFile.open(QIODevice::ReadOnly))
return false;
QTextStream textStream(&projectFile); QTextStream textStream(&projectFile);
QString fileContent = textStream.readAll(); QString fileContent = textStream.readAll();
projectFile.close(); projectFile.close();

View File

@@ -54,7 +54,7 @@ void CMakeModificationFile::read()
void CMakeModificationFile::write() const void CMakeModificationFile::write() const
{ {
QFile out(nativePath()); QFile out(nativePath());
out.open(QIODevice::WriteOnly | QIODevice::Text); QTC_CHECK(out.open(QIODevice::WriteOnly | QIODevice::Text));
QTextStream outStream(&out); QTextStream outStream(&out);
for (QString &line : defaultModificationFile()) { for (QString &line : defaultModificationFile()) {

View File

@@ -161,7 +161,7 @@ void CocoCMakeSettings::writeToolchainFile(const QString &internalPath)
const Utils::FilePath projectDirectory = buildConfig()->project()->projectDirectory(); const Utils::FilePath projectDirectory = buildConfig()->project()->projectDirectory();
QFile internalFile{internalPath}; QFile internalFile{internalPath};
internalFile.open(QIODeviceBase::ReadOnly); QTC_CHECK(internalFile.open(QIODeviceBase::ReadOnly));
const QByteArray internalContent = internalFile.readAll(); const QByteArray internalContent = internalFile.readAll();
const QString fileName = Utils::FilePath::fromString(internalPath).fileName(); const QString fileName = Utils::FilePath::fromString(internalPath).fileName();
@@ -170,7 +170,7 @@ void CocoCMakeSettings::writeToolchainFile(const QString &internalPath)
if (toolchainPath.exists()) { if (toolchainPath.exists()) {
QFile currentFile{toolchainNative}; QFile currentFile{toolchainNative};
currentFile.open(QIODeviceBase::ReadOnly); QTC_CHECK(currentFile.open(QIODeviceBase::ReadOnly));
QByteArray currentContent = currentFile.readAll(); QByteArray currentContent = currentFile.readAll();
if (internalContent == currentContent) if (internalContent == currentContent)
@@ -181,7 +181,7 @@ void CocoCMakeSettings::writeToolchainFile(const QString &internalPath)
logSilently(Tr::tr("Write file %1").arg(maybeQuote(toolchainNative))); logSilently(Tr::tr("Write file %1").arg(maybeQuote(toolchainNative)));
QFile out{toolchainNative}; QFile out{toolchainNative};
out.open(QIODeviceBase::WriteOnly); QTC_CHECK(out.open(QIODeviceBase::WriteOnly));
out.write(internalContent); out.write(internalContent);
out.close(); out.close();
} }

View File

@@ -49,7 +49,7 @@ QStringList ModificationFile::defaultModificationFile() const
QStringList ModificationFile::contentOf(const Utils::FilePath &filePath) const QStringList ModificationFile::contentOf(const Utils::FilePath &filePath) const
{ {
QFile resource(filePath.nativePath()); QFile resource(filePath.nativePath());
resource.open(QIODevice::ReadOnly | QIODevice::Text); QTC_CHECK(resource.open(QIODevice::ReadOnly | QIODevice::Text));
QTextStream inStream(&resource); QTextStream inStream(&resource);
QStringList result; QStringList result;

View File

@@ -63,7 +63,7 @@ void QMakeFeatureFile::read()
void QMakeFeatureFile::write() const void QMakeFeatureFile::write() const
{ {
QFile out(nativePath()); QFile out(nativePath());
out.open(QIODevice::WriteOnly | QIODevice::Text); QTC_CHECK(out.open(QIODevice::WriteOnly | QIODevice::Text));
QTextStream outStream(&out); QTextStream outStream(&out);
for (QString &line : defaultModificationFile()) { for (QString &line : defaultModificationFile()) {

View File

@@ -4,19 +4,16 @@
#include "compileroptionsbuilder_test.h" #include "compileroptionsbuilder_test.h"
#include "compileroptionsbuilder.h" #include "compileroptionsbuilder.h"
#include "projectinfo.h"
#include "projectpart.h" #include "projectpart.h"
#include <projectexplorer/headerpath.h> #include <projectexplorer/headerpath.h>
#include <projectexplorer/project.h>
#include <projectexplorer/projectexplorerconstants.h> #include <projectexplorer/projectexplorerconstants.h>
#include <utils/algorithm.h> #include <utils/algorithm.h>
#include <utils/qtcassert.h>
#include <utils/temporarydirectory.h> #include <utils/temporarydirectory.h>
#include <QtTest> #include <QtTest>
#include <memory>
using namespace ProjectExplorer; using namespace ProjectExplorer;
namespace CppEditor::Internal { namespace CppEditor::Internal {
@@ -28,7 +25,7 @@ public:
const ProjectPart &finalize() const ProjectPart &finalize()
{ {
QFile pchFile(pchFileNativePath()); QFile pchFile(pchFileNativePath());
pchFile.open(QIODevice::WriteOnly); QTC_CHECK(pchFile.open(QIODevice::WriteOnly));
RawProjectPart rpp; RawProjectPart rpp;
rpp.setPreCompiledHeaders({pchFileNativePath()}); rpp.setPreCompiledHeaders({pchFileNativePath()});
rpp.setMacros({Macro{"projectFoo", "projectBar"}}); rpp.setMacros({Macro{"projectFoo", "projectBar"}});

View File

@@ -272,13 +272,12 @@ namespace CppEditor::Internal {
static inline QString _(const QByteArray &ba) { return QString::fromLatin1(ba, ba.size()); } static inline QString _(const QByteArray &ba) { return QString::fromLatin1(ba, ba.size()); }
static void createTempFile(const FilePath &filePath) static bool createTempFile(const FilePath &filePath)
{ {
QString fileName = filePath.toUrlishString(); QString fileName = filePath.toUrlishString();
QFile file(fileName); QFile file(fileName);
QDir(QFileInfo(fileName).absolutePath()).mkpath(_(".")); QDir(QFileInfo(fileName).absolutePath()).mkpath(_("."));
file.open(QFile::WriteOnly); return file.open(QFile::WriteOnly);
file.close();
} }
static QString baseTestDir() static QString baseTestDir()
@@ -309,8 +308,8 @@ void HeaderSourceTest::test()
const QDir path = QDir(temporaryDir.path() + QLatin1Char('/') + _(QTest::currentDataTag())); const QDir path = QDir(temporaryDir.path() + QLatin1Char('/') + _(QTest::currentDataTag()));
const FilePath sourcePath = FilePath::fromString(path.absoluteFilePath(sourceFileName)); const FilePath sourcePath = FilePath::fromString(path.absoluteFilePath(sourceFileName));
const FilePath headerPath = FilePath::fromString(path.absoluteFilePath(headerFileName)); const FilePath headerPath = FilePath::fromString(path.absoluteFilePath(headerFileName));
createTempFile(sourcePath); QVERIFY2(createTempFile(sourcePath), qPrintable(sourcePath.toUserOutput()));
createTempFile(headerPath); QVERIFY2(createTempFile(headerPath), qPrintable(headerPath.toUserOutput()));
bool wasHeader; bool wasHeader;
clearHeaderSourceCache(); clearHeaderSourceCache();

View File

@@ -113,7 +113,7 @@ void DebuggerRunTool::startCoreFileSetupIfNeededAndContinueStartup()
{ {
TemporaryFile tmp("tmpcore-XXXXXX"); TemporaryFile tmp("tmpcore-XXXXXX");
tmp.open(); QTC_CHECK(tmp.open());
d->m_tempCoreFilePath = FilePath::fromString(tmp.fileName()); d->m_tempCoreFilePath = FilePath::fromString(tmp.fileName());
} }
@@ -139,7 +139,7 @@ void DebuggerRunTool::startCoreFileSetupIfNeededAndContinueStartup()
if (coreFile.endsWith(".gz")) { if (coreFile.endsWith(".gz")) {
d->m_tempCoreFile.setFileName(d->m_tempCoreFilePath.path()); d->m_tempCoreFile.setFileName(d->m_tempCoreFilePath.path());
d->m_tempCoreFile.open(QFile::WriteOnly); QTC_CHECK(d->m_tempCoreFile.open(QFile::WriteOnly));
connect(&d->m_coreUnpackProcess, &Process::readyReadStandardOutput, this, [this] { connect(&d->m_coreUnpackProcess, &Process::readyReadStandardOutput, this, [this] {
d->m_tempCoreFile.write(d->m_coreUnpackProcess.readAllRawStandardOutput()); d->m_tempCoreFile.write(d->m_coreUnpackProcess.readAllRawStandardOutput());
}); });

View File

@@ -2855,7 +2855,7 @@ static void handleShowModuleSymbols(const DebuggerResponse &response,
if (response.resultClass == ResultDone) { if (response.resultClass == ResultDone) {
Symbols symbols; Symbols symbols;
QFile file(fileName); QFile file(fileName);
file.open(QIODevice::ReadOnly); QTC_CHECK(file.open(QIODevice::ReadOnly));
// Object file /opt/dev/qt/lib/libQtNetworkMyns.so.4: // Object file /opt/dev/qt/lib/libQtNetworkMyns.so.4:
// [ 0] A 0x16bd64 _DYNAMIC moc_qudpsocket.cpp // [ 0] A 0x16bd64 _DYNAMIC moc_qudpsocket.cpp
// [12] S 0xe94680 _ZN4myns5QFileC1Ev section .plt myns::QFile::QFile() // [12] S 0xe94680 _ZN4myns5QFileC1Ev section .plt myns::QFile::QFile()

View File

@@ -6345,7 +6345,8 @@ bool FakeVimHandler::Private::handleExWriteCommand(const ExCommand &cmd)
} }
// Check result by reading back. // Check result by reading back.
QFile file3(fileName); QFile file3(fileName);
file3.open(QIODevice::ReadOnly); if (!file3.open(QIODevice::ReadOnly))
return false;
QByteArray ba = file3.readAll(); QByteArray ba = file3.readAll();
showMessage(MessageInfo, Tr::tr("\"%1\" %2 %3L, %4C written.") showMessage(MessageInfo, Tr::tr("\"%1\" %2 %3L, %4C written.")
.arg(fileName).arg(exists ? QString(" ") : Tr::tr(" [New] ")) .arg(fileName).arg(exists ? QString(" ") : Tr::tr(" [New] "))
@@ -6375,7 +6376,8 @@ bool FakeVimHandler::Private::handleExReadCommand(const ExCommand &cmd)
m_currentFileName = replaceTildeWithHome(cmd.args); m_currentFileName = replaceTildeWithHome(cmd.args);
QFile file(m_currentFileName); QFile file(m_currentFileName);
file.open(QIODevice::ReadOnly); if (!file.open(QIODevice::ReadOnly))
return false;
QTextStream ts(&file); QTextStream ts(&file);
QString data = ts.readAll(); QString data = ts.readAll();
insertText(data); insertText(data);

View File

@@ -84,7 +84,7 @@ StdIOClientInterface::StdIOClientInterface()
: m_logFile("lspclient.XXXXXX.log") : m_logFile("lspclient.XXXXXX.log")
{ {
m_logFile.setAutoRemove(false); m_logFile.setAutoRemove(false);
m_logFile.open(); QTC_CHECK(m_logFile.open());
} }
StdIOClientInterface::~StdIOClientInterface() StdIOClientInterface::~StdIOClientInterface()

View File

@@ -206,7 +206,10 @@ static Group installRecipe(
{ {
QTemporaryFile tempFile(QDir::tempPath() + "/XXXXXX" + ext); QTemporaryFile tempFile(QDir::tempPath() + "/XXXXXX" + ext);
tempFile.setAutoRemove(false); tempFile.setAutoRemove(false);
tempFile.open(); if (!tempFile.open()) {
emitResult(Tr::tr("Cannot open temporary file."));
return SetupResult::StopWithError;
}
(*storage).setFileName(tempFile.fileName()); (*storage).setFileName(tempFile.fileName());
} }

View File

@@ -165,7 +165,7 @@ public:
m_readCallback = {}; m_readCallback = {};
QFile f(":/lua/scripts/ilua.lua"); QFile f(":/lua/scripts/ilua.lua");
f.open(QIODevice::ReadOnly); QTC_CHECK(f.open(QIODevice::ReadOnly));
const auto ilua = QString::fromUtf8(f.readAll()); const auto ilua = QString::fromUtf8(f.readAll());
m_luaState = runScript(ilua, "ilua.lua", [this](sol::state &lua) { m_luaState = runScript(ilua, "ilua.lua", [this](sol::state &lua) {
lua["print"] = [this](sol::variadic_args va) { lua["print"] = [this](sol::variadic_args va) {

View File

@@ -74,7 +74,8 @@ QString McuPackageXmlVersionDetector::parseVersion(const FilePath &packagePath)
const auto files = QDir(packagePath.toUrlishString(), m_filePattern).entryInfoList(); const auto files = QDir(packagePath.toUrlishString(), m_filePattern).entryInfoList();
for (const auto &xmlFile : files) { for (const auto &xmlFile : files) {
QFile sdkXmlFile = QFile(xmlFile.absoluteFilePath()); QFile sdkXmlFile = QFile(xmlFile.absoluteFilePath());
sdkXmlFile.open(QFile::OpenModeFlag::ReadOnly); if (!sdkXmlFile.open(QFile::OpenModeFlag::ReadOnly))
return {};
QXmlStreamReader xmlReader(&sdkXmlFile); QXmlStreamReader xmlReader(&sdkXmlFile);
while (xmlReader.readNext()) { while (xmlReader.readNext()) {
if (xmlReader.name() == m_versionElement) { if (xmlReader.name() == m_versionElement) {

View File

@@ -47,11 +47,8 @@ template<typename T>
inline std::optional<T> load(const QString &jsonFile) inline std::optional<T> load(const QString &jsonFile)
{ {
QFile js(jsonFile); QFile js(jsonFile);
js.open(QIODevice::ReadOnly | QIODevice::Text); if (js.open(QIODevice::ReadOnly | QIODevice::Text))
if (js.isOpen()) { return load<T>(QJsonDocument::fromJson(js.readAll()));
auto data = js.readAll();
return load<T>(QJsonDocument::fromJson(data));
}
return std::nullopt; return std::nullopt;
} }

View File

@@ -82,7 +82,7 @@ private slots:
{ {
// With unconfigured project // With unconfigured project
QTemporaryFile introFile; QTemporaryFile introFile;
introFile.open(); QVERIFY(introFile.open());
const auto tool = findMeson(); const auto tool = findMeson();
QVERIFY(tool.has_value()); QVERIFY(tool.has_value());
const MesonToolWrapper meson("name", *tool); const MesonToolWrapper meson("name", *tool);

View File

@@ -245,7 +245,7 @@ QVariantMap JsonWizardFactory::loadDefaultValues(const QString &fileName)
+ "\n"); + "\n");
if (current.pathAppended(fileName).exists()) { if (current.pathAppended(fileName).exists()) {
QFile configFile(current.pathAppended(fileName).toUrlishString()); QFile configFile(current.pathAppended(fileName).toUrlishString());
configFile.open(QIODevice::ReadOnly); QTC_CHECK(configFile.open(QIODevice::ReadOnly));
QJsonParseError error; QJsonParseError error;
const QByteArray fileData = configFile.readAll(); const QByteArray fileData = configFile.readAll();
const QJsonDocument json = QJsonDocument::fromJson(fileData, &error); const QJsonDocument json = QJsonDocument::fromJson(fileData, &error);

View File

@@ -183,7 +183,7 @@ void QmlProfilerDetailsRewriterTest::seedRewriter()
lPaths, m_modelManager, false); lPaths, m_modelManager, false);
QFile file(filename); QFile file(filename);
file.open(QFile::ReadOnly | QFile::Text); QTC_CHECK(file.open(QFile::ReadOnly | QFile::Text));
const QString content = QString::fromUtf8(file.readAll()); const QString content = QString::fromUtf8(file.readAll());
file.close(); file.close();

View File

@@ -267,7 +267,7 @@ void CMakeGenerator::readQmlDir(const Utils::FilePath &filePath, NodePtr &node)
node->type = Node::Type::Module; node->type = Node::Type::Module;
QFile f(filePath.toUrlishString()); QFile f(filePath.toUrlishString());
f.open(QIODevice::ReadOnly); QTC_CHECK(f.open(QIODevice::ReadOnly));
QTextStream stream(&f); QTextStream stream(&f);
Utils::FilePath dir = filePath.parentDir(); Utils::FilePath dir = filePath.parentDir();

View File

@@ -101,7 +101,8 @@ CMakeWriter::Version CMakeWriter::versionFromIgnoreFile(const Utils::FilePath &p
QString CMakeWriter::readTemplate(const QString &templatePath) QString CMakeWriter::readTemplate(const QString &templatePath)
{ {
QFile templatefile(templatePath); QFile templatefile(templatePath);
templatefile.open(QIODevice::ReadOnly | QIODevice::Text); if (!templatefile.open(QIODevice::ReadOnly | QIODevice::Text))
return {};
QTextStream stream(&templatefile); QTextStream stream(&templatefile);
QString content = stream.readAll(); QString content = stream.readAll();
templatefile.close(); templatefile.close();

View File

@@ -65,8 +65,7 @@ bool QmlProjectFileGenerator::execute()
.arg(contentEntry, imageEntry, jsEntry, assetEntry, importPaths); .arg(contentEntry, imageEntry, jsEntry, assetEntry, importPaths);
QFile file(m_targetFile.toUrlishString()); QFile file(m_targetFile.toUrlishString());
file.open(QIODevice::WriteOnly); if (!file.open(QIODevice::WriteOnly))
if (!file.isOpen())
return false; return false;
file.reset(); file.reset();

View File

@@ -46,7 +46,7 @@ public:
setWindowTitle(Tr::tr("Record Screen")); setWindowTitle(Tr::tr("Record Screen"));
StyleHelper::setPanelWidget(this); StyleHelper::setPanelWidget(this);
m_recordFile.open(); QTC_CHECK(m_recordFile.open());
m_recordWidget = new RecordWidget(FilePath::fromString(m_recordFile.fileName())); m_recordWidget = new RecordWidget(FilePath::fromString(m_recordFile.fileName()));
m_cropAndTrimStatusWidget = new CropAndTrimWidget; m_cropAndTrimStatusWidget = new CropAndTrimWidget;

View File

@@ -592,7 +592,7 @@ void SquishTools::setupAndStartRecorder()
args << "--suitedir" << m_suitePath.toUserOutput(); args << "--suitedir" << m_suitePath.toUserOutput();
Utils::TemporaryFile tmp("squishsnippetfile-XXXXXX"); // quick and dirty Utils::TemporaryFile tmp("squishsnippetfile-XXXXXX"); // quick and dirty
tmp.open(); QTC_CHECK(tmp.open());
m_currentRecorderSnippetFile = Utils::FilePath::fromUserInput(tmp.fileName()); m_currentRecorderSnippetFile = Utils::FilePath::fromUserInput(tmp.fileName());
args << "--outfile" << m_currentRecorderSnippetFile.toUserOutput(); args << "--outfile" << m_currentRecorderSnippetFile.toUserOutput();
tmp.close(); tmp.close();

View File

@@ -383,7 +383,8 @@ static expected_str<void> loadXFCE4ColorScheme(const FilePath &path)
arr->replace(';', ','); arr->replace(';', ',');
QTemporaryFile f; QTemporaryFile f;
f.open(); if (!f.open())
return make_unexpected(f.errorString());
f.write(*arr); f.write(*arr);
f.close(); f.close();

View File

@@ -189,7 +189,7 @@ void tst_CppSelectionChanger::initTestCase()
// Read cpp file contents into QTextDocument and CppEditor::Document::Ptr. // Read cpp file contents into QTextDocument and CppEditor::Document::Ptr.
QString fileName(SRCDIR "/testCppFile.cpp"); QString fileName(SRCDIR "/testCppFile.cpp");
QFile file(fileName); QFile file(fileName);
file.open(QIODevice::ReadOnly | QIODevice::Text); QVERIFY2(file.open(QIODevice::ReadOnly | QIODevice::Text), qPrintable(fileName));
QTextStream s(&file); QTextStream s(&file);
cppFileString = s.readAll(); cppFileString = s.readAll();
file.close(); file.close();

View File

@@ -63,7 +63,7 @@ static bool generateEnvironmentSettings(Utils::Environment &env,
QString tempOutFile; QString tempOutFile;
QTemporaryFile* pVarsTempFile = new QTemporaryFile(QDir::tempPath() + "/XXXXXX.txt"); QTemporaryFile* pVarsTempFile = new QTemporaryFile(QDir::tempPath() + "/XXXXXX.txt");
pVarsTempFile->setAutoRemove(false); pVarsTempFile->setAutoRemove(false);
pVarsTempFile->open(); QTC_CHECK(pVarsTempFile->open());
pVarsTempFile->close(); pVarsTempFile->close();
tempOutFile = pVarsTempFile->fileName(); tempOutFile = pVarsTempFile->fileName();
delete pVarsTempFile; delete pVarsTempFile;
@@ -1372,7 +1372,7 @@ void tst_Dumpers::cleanup()
{ {
if (!t->buildTemp.autoRemove()) { if (!t->buildTemp.autoRemove()) {
QFile logger(t->buildPath + "/input.txt"); QFile logger(t->buildPath + "/input.txt");
logger.open(QIODevice::ReadWrite); QTC_CHECK(logger.open(QIODevice::ReadWrite));
logger.write(t->input.toUtf8()); logger.write(t->input.toUtf8());
} }
delete t; delete t;
@@ -1839,7 +1839,7 @@ void tst_Dumpers::dumper()
} else if (m_debuggerEngine == LldbEngine) { } else if (m_debuggerEngine == LldbEngine) {
QFile fullLldb(t->buildPath + "/lldbcommand.txt"); QFile fullLldb(t->buildPath + "/lldbcommand.txt");
fullLldb.setPermissions(QFile::ReadOwner|QFile::WriteOwner|QFile::ExeOwner|QFile::ReadGroup|QFile::ReadOther); fullLldb.setPermissions(QFile::ReadOwner|QFile::WriteOwner|QFile::ExeOwner|QFile::ReadGroup|QFile::ReadOther);
fullLldb.open(QIODevice::WriteOnly); QVERIFY2(fullLldb.open(QIODevice::WriteOnly), qPrintable(fullLldb.fileName()));
fullLldb.write((exe + ' ' + args.join(' ') + '\n').toUtf8()); fullLldb.write((exe + ' ' + args.join(' ') + '\n').toUtf8());
#ifdef Q_OS_WIN #ifdef Q_OS_WIN
@@ -1894,7 +1894,7 @@ void tst_Dumpers::dumper()
if (keepTemp()) { if (keepTemp()) {
QFile logger(t->buildPath + "/output.txt"); QFile logger(t->buildPath + "/output.txt");
logger.open(QIODevice::ReadWrite); QVERIFY2(logger.open(QIODevice::ReadWrite), qPrintable(logger.fileName()));
logger.write("=== STDOUT ===\n"); logger.write("=== STDOUT ===\n");
logger.write(output); logger.write(output);
logger.write("\n=== STDERR ===\n"); logger.write("\n=== STDERR ===\n");

View File

@@ -1508,7 +1508,7 @@ void tst_Json::fromJsonErrors()
void tst_Json::fromBinary() void tst_Json::fromBinary()
{ {
QFile file(testDataDir + QLatin1String("/test.json")); QFile file(testDataDir + QLatin1String("/test.json"));
file.open(QFile::ReadOnly); QVERIFY2(file.open(QFile::ReadOnly), qPrintable(file.fileName()));
std::string testJson = file.readAll().data(); std::string testJson = file.readAll().data();
JsonDocument doc = JsonDocument::fromJson(testJson); JsonDocument doc = JsonDocument::fromJson(testJson);
@@ -1524,7 +1524,7 @@ void tst_Json::fromBinary()
// b1file.close(); // b1file.close();
QFile bfile(testDataDir + QLatin1String("/test.bjson")); QFile bfile(testDataDir + QLatin1String("/test.bjson"));
bfile.open(QFile::ReadOnly); QVERIFY2(bfile.open(QFile::ReadOnly), qPrintable(bfile.fileName()));
std::string binary = bfile.readAll().toStdString(); std::string binary = bfile.readAll().toStdString();
JsonDocument bdoc = JsonDocument::fromBinaryData(binary); JsonDocument bdoc = JsonDocument::fromBinaryData(binary);
@@ -1722,7 +1722,7 @@ void tst_Json::parseDuplicateKeys()
void tst_Json::testParser() void tst_Json::testParser()
{ {
QFile file(testDataDir + QLatin1String("/test.json")); QFile file(testDataDir + QLatin1String("/test.json"));
file.open(QFile::ReadOnly); QVERIFY2(file.open(QFile::ReadOnly), qPrintable(file.fileName()));
std::string testJson = file.readAll().data(); std::string testJson = file.readAll().data();
JsonDocument doc = JsonDocument::fromJson(testJson); JsonDocument doc = JsonDocument::fromJson(testJson);
@@ -1828,7 +1828,7 @@ void tst_Json::validation()
QFile file2(testDataDir + QLatin1String("/test3.json")); QFile file2(testDataDir + QLatin1String("/test3.json"));
file2.open(QFile::ReadOnly); QVERIFY2(file2.open(QFile::ReadOnly), qPrintable(file2.fileName()));
testJson = file2.readAll().data(); testJson = file2.readAll().data();
QVERIFY(!testJson.empty()); QVERIFY(!testJson.empty());
@@ -2207,7 +2207,7 @@ void tst_Json::arrayEquals()
void tst_Json::bom() void tst_Json::bom()
{ {
QFile file(testDataDir + QLatin1String("/bom.json")); QFile file(testDataDir + QLatin1String("/bom.json"));
file.open(QFile::ReadOnly); QVERIFY2(file.open(QFile::ReadOnly), qPrintable(file.fileName()));
std::string json = file.readAll().data(); std::string json = file.readAll().data();
// Import json document into a JsonDocument // Import json document into a JsonDocument

View File

@@ -107,7 +107,7 @@ void tst_Check::test()
Snapshot snapshot = mm->snapshot(); Snapshot snapshot = mm->snapshot();
Document::MutablePtr doc = Document::create(pathPath, Dialect::Qml); Document::MutablePtr doc = Document::create(pathPath, Dialect::Qml);
QFile file(doc->fileName().toUrlishString()); QFile file(doc->fileName().toUrlishString());
file.open(QFile::ReadOnly | QFile::Text); QVERIFY2(file.open(QFile::ReadOnly | QFile::Text), qPrintable(file.fileName()));
doc->setSource(QString::fromUtf8(file.readAll())); doc->setSource(QString::fromUtf8(file.readAll()));
file.close(); file.close();
doc->parse(); doc->parse();

View File

@@ -26,6 +26,8 @@
#include <extensionsystem/pluginmanager.h> #include <extensionsystem/pluginmanager.h>
#include <utils/filepath.h> #include <utils/filepath.h>
#include <optional>
using namespace QmlJS; using namespace QmlJS;
using namespace QmlJS::AST; using namespace QmlJS::AST;
using namespace QmlJS::StaticAnalysis; using namespace QmlJS::StaticAnalysis;
@@ -49,9 +51,10 @@ struct TestData
const int staticMessages; const int staticMessages;
}; };
static TestData testData(const QString &path) { static std::optional<TestData> testData(const QString &path) {
QFile file(path); QFile file(path);
file.open(QFile::ReadOnly | QFile::Text); if (!file.open(QFile::ReadOnly | QFile::Text))
return {};
const QString content = QString::fromUtf8(file.readAll()); const QString content = QString::fromUtf8(file.readAll());
file.close(); file.close();
@@ -129,10 +132,11 @@ void tst_Dependencies::test()
ModelManagerInterface::importScan(ModelManagerInterface::workingCopy(), lPaths, ModelManagerInterface::importScan(ModelManagerInterface::workingCopy(), lPaths,
ModelManagerInterface::instance(), false); ModelManagerInterface::instance(), false);
ModelManagerInterface::instance()->test_joinAllThreads(); ModelManagerInterface::instance()->test_joinAllThreads();
TestData data = testData(filename); const auto data = testData(filename);
Document::MutablePtr doc = data.doc; QVERIFY(data);
int nExpectedSemanticMessages = data.semanticMessages; Document::MutablePtr doc = data->doc;
int nExpectedStaticMessages = data.staticMessages; int nExpectedSemanticMessages = data->semanticMessages;
int nExpectedStaticMessages = data->staticMessages;
QVERIFY(!doc->source().isEmpty()); QVERIFY(!doc->source().isEmpty());
Snapshot snapshot = modelManager->snapshot(); Snapshot snapshot = modelManager->snapshot();

View File

@@ -68,7 +68,7 @@ void tst_Reformatter::test()
Document::MutablePtr doc = Document::create(fPath, ModelManagerInterface::guessLanguageOfFile(fPath)); Document::MutablePtr doc = Document::create(fPath, ModelManagerInterface::guessLanguageOfFile(fPath));
QFile file(doc->fileName().toUrlishString()); QFile file(doc->fileName().toUrlishString());
file.open(QFile::ReadOnly | QFile::Text); QVERIFY2(file.open(QFile::ReadOnly | QFile::Text), qPrintable(file.fileName()));
QString source = QString::fromUtf8(file.readAll()); QString source = QString::fromUtf8(file.readAll());
doc->setSource(source); doc->setSource(source);
file.close(); file.close();

View File

@@ -135,12 +135,15 @@ private:
QString exeExt; QString exeExt;
}; };
static void touch(const QDir &dir, const QString &filename, bool fill, bool executable = false) static bool touch(const QDir &dir, const QString &filename, bool fill, bool executable = false)
{ {
QFile file(dir.absoluteFilePath(filename)); QFile file(dir.absoluteFilePath(filename));
file.open(QIODevice::WriteOnly); if (!file.open(QIODevice::WriteOnly))
if (executable) return false;
file.setPermissions(file.permissions() | QFileDevice::ExeUser); if (executable) {
if (!file.setPermissions(file.permissions() | QFileDevice::ExeUser))
return false;
}
if (fill) { if (fill) {
QRandomGenerator *random = QRandomGenerator::global(); QRandomGenerator *random = QRandomGenerator::global();
@@ -148,6 +151,7 @@ static void touch(const QDir &dir, const QString &filename, bool fill, bool exec
file.write(QString::number(random->generate(), 16).toUtf8()); file.write(QString::number(random->generate(), 16).toUtf8());
} }
file.close(); file.close();
return true;
} }
void tst_filepath::initTestCase() void tst_filepath::initTestCase()
@@ -160,13 +164,13 @@ void tst_filepath::initTestCase()
dir.mkpath("a/x/y/z"); dir.mkpath("a/x/y/z");
dir.mkpath("a/b/x/y/z"); dir.mkpath("a/b/x/y/z");
dir.mkpath("x/y/z"); dir.mkpath("x/y/z");
touch(dir, "a/b/c/d/file1.txt", false); QVERIFY(touch(dir, "a/b/c/d/file1.txt", false));
touch(dir, "a/x/y/z/file2.txt", false); QVERIFY(touch(dir, "a/x/y/z/file2.txt", false));
touch(dir, "a/file3.txt", false); QVERIFY(touch(dir, "a/file3.txt", false));
touch(dir, "x/y/file4.txt", false); QVERIFY(touch(dir, "x/y/file4.txt", false));
// initialize test for tst_filepath::asyncLocalCopy() // initialize test for tst_filepath::asyncLocalCopy()
touch(dir, "x/y/fileToCopy.txt", true); QVERIFY(touch(dir, "x/y/fileToCopy.txt", true));
// initialize test for tst_filepath::searchIn() // initialize test for tst_filepath::searchIn()
#ifdef Q_OS_WIN #ifdef Q_OS_WIN
@@ -175,8 +179,8 @@ void tst_filepath::initTestCase()
dir.mkpath("s/1"); dir.mkpath("s/1");
dir.mkpath("s/2"); dir.mkpath("s/2");
touch(dir, "s/1/testexe" + exeExt, false, true); QVERIFY(touch(dir, "s/1/testexe" + exeExt, false, true));
touch(dir, "s/2/testexe" + exeExt, false, true); QVERIFY(touch(dir, "s/2/testexe" + exeExt, false, true));
} }
void tst_filepath::searchInWithFilter() void tst_filepath::searchInWithFilter()
@@ -1550,7 +1554,7 @@ void tst_filepath::isSameFile_data()
<< false; << false;
QDir dir(tempDir.path()); QDir dir(tempDir.path());
touch(dir, "target-file", false); QVERIFY(touch(dir, "target-file", false));
QFile file(dir.absoluteFilePath("target-file")); QFile file(dir.absoluteFilePath("target-file"));
if (file.link(dir.absoluteFilePath("source-file"))) { if (file.link(dir.absoluteFilePath("source-file"))) {

View File

@@ -120,7 +120,7 @@ void tst_CodeSize::cleanup()
{ {
if (!t->buildTemp.autoRemove()) { if (!t->buildTemp.autoRemove()) {
QFile logger(t->buildPath + QLatin1String("/input.txt")); QFile logger(t->buildPath + QLatin1String("/input.txt"));
logger.open(QIODevice::ReadWrite); QVERIFY2(logger.open(QIODevice::ReadWrite), qPrintable(logger.fileName()));
logger.write(t->input); logger.write(t->input);
} }
delete t; delete t;