Skip to content

Commit

Permalink
Check system() return values in testsuite
Browse files Browse the repository at this point in the history
test/testfolderwatcher.cpp: In function 'void touch(const QString&)':
test/testfolderwatcher.cpp:21:11: warning: ignoring return value of 'int system(const char*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   21 |     system(cmd.toLocal8Bit());
      |     ~~~~~~^~~~~~~~~~~~~~~~~~~
test/testfolderwatcher.cpp: In function 'void mkdir(const QString&)':
test/testfolderwatcher.cpp:33:11: warning: ignoring return value of 'int system(const char*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   33 |     system(cmd.toLocal8Bit());
      |     ~~~~~~^~~~~~~~~~~~~~~~~~~
test/testfolderwatcher.cpp: In function 'void rmdir(const QString&)':
test/testfolderwatcher.cpp:45:11: warning: ignoring return value of 'int system(const char*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   45 |     system(cmd.toLocal8Bit());
      |     ~~~~~~^~~~~~~~~~~~~~~~~~~
test/testfolderwatcher.cpp: In function 'void rm(const QString&)':
test/testfolderwatcher.cpp:56:11: warning: ignoring return value of 'int system(const char*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   56 |     system(cmd.toLocal8Bit());
      |     ~~~~~~^~~~~~~~~~~~~~~~~~~
test/testfolderwatcher.cpp: In function 'void mv(const QString&, const QString&)':
test/testfolderwatcher.cpp:67:11: warning: ignoring return value of 'int system(const char*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   67 |     system(cmd.toLocal8Bit());
      |     ~~~~~~^~~~~~~~~~~~~~~~~~~
test/testfolderwatcher.cpp: In member function 'void TestFolderWatcher::testACreate()':
test/testfolderwatcher.cpp:152:15: warning: ignoring return value of 'int system(const char*)' declared with attribute 'warn_unused_result' [-Wunused-result]
  152 |         system(cmd.toLocal8Bit());
      |         ~~~~~~^~~~~~~~~~~~~~~~~~~

test/testinotifywatcher.cpp: In member function 'void TestInotifyWatcher::cleanupTestCase()':
test/testinotifywatcher.cpp:67:18: warning: ignoring return value of 'int system(const char*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   67 |            system( QString("rm -rf %1").arg(_root).toLocal8Bit() );
      |            ~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

Signed-off-by: Christian Göttsche <cgzones@googlemail.com>
  • Loading branch information
cgzones committed Aug 10, 2024
1 parent 428910f commit 7fef8c4
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 7 deletions.
20 changes: 14 additions & 6 deletions test/testfolderwatcher.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,20 @@
*
*/

#include <QtGlobal>
#include <QtTest>

#include "folderwatcher.h"
#include "common/utility.h"
#include "logger.h"

#define CHECKED_SYSTEM(cmd_) \
do { \
int result_ = system(cmd_); \
Q_ASSERT(WIFEXITED(result_)); \
Q_ASSERT(WEXITSTATUS(result_) == 0); \
} while(0)

void touch(const QString &file)
{
#ifdef Q_OS_WIN
Expand All @@ -19,7 +27,7 @@ void touch(const QString &file)
QString cmd;
cmd = QString("touch %1").arg(file);
qDebug() << "Command: " << cmd;
system(cmd.toLocal8Bit());
CHECKED_SYSTEM(cmd.toLocal8Bit());
#endif
}

Expand All @@ -31,7 +39,7 @@ void mkdir(const QString &file)
#else
QString cmd = QString("mkdir %1").arg(file);
qDebug() << "Command: " << cmd;
system(cmd.toLocal8Bit());
CHECKED_SYSTEM(cmd.toLocal8Bit());
#endif
}

Expand All @@ -43,7 +51,7 @@ void rmdir(const QString &file)
#else
QString cmd = QString("rmdir %1").arg(file);
qDebug() << "Command: " << cmd;
system(cmd.toLocal8Bit());
CHECKED_SYSTEM(cmd.toLocal8Bit());
#endif
}

Expand All @@ -54,7 +62,7 @@ void rm(const QString &file)
#else
QString cmd = QString("rm %1").arg(file);
qDebug() << "Command: " << cmd;
system(cmd.toLocal8Bit());
CHECKED_SYSTEM(cmd.toLocal8Bit());
#endif
}

Expand All @@ -65,7 +73,7 @@ void mv(const QString &file1, const QString &file2)
#else
QString cmd = QString("mv %1 %2").arg(file1, file2);
qDebug() << "Command: " << cmd;
system(cmd.toLocal8Bit());
CHECKED_SYSTEM(cmd.toLocal8Bit());
#endif
}

Expand Down Expand Up @@ -160,7 +168,7 @@ private slots:
QString cmd;
cmd = QString("echo \"xyz\" > \"%1\"").arg(file);
qDebug() << "Command: " << cmd;
system(cmd.toLocal8Bit());
CHECKED_SYSTEM(cmd.toLocal8Bit());

QVERIFY(waitForPathChanged(file));
}
Expand Down
10 changes: 9 additions & 1 deletion test/testinotifywatcher.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,19 @@
* any purpose.
* */

#include <QtGlobal>
#include <QtTest>

#include "folderwatcher_linux.h"
#include "common/utility.h"

#define CHECKED_SYSTEM(cmd_) \
do { \
int result_ = system(cmd_); \
Q_ASSERT(WIFEXITED(result_)); \
Q_ASSERT(WEXITSTATUS(result_) == 0); \
} while(0)

using namespace OCC;

class TestInotifyWatcher: public FolderWatcherPrivate
Expand Down Expand Up @@ -62,7 +70,7 @@ private slots:

void cleanupTestCase() {
if( _root.startsWith(QDir::tempPath() )) {
system( QString("rm -rf %1").arg(_root).toLocal8Bit() );
CHECKED_SYSTEM( QString("rm -rf %1").arg(_root).toLocal8Bit() );
}
}
};
Expand Down

0 comments on commit 7fef8c4

Please sign in to comment.