summaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
authorThiago Macieira <thiago.macieira@intel.com>2020-04-08 14:26:50 -0300
committerThiago Macieira <thiago.macieira@intel.com>2020-04-09 10:55:25 -0300
commit7cd2d2b7516211d233f657edd98903911536b1ff (patch)
treeb3b49851371198bf77d3a20a026d2fd1b4906f25 /tests
parentf0ec2eb151f5e3d9a26ce86a1ba86d41f1fe24c4 (diff)
tst_QFileInfo: fix running with systems without /etc/passwd
Clear Linux containers running as root may have no /etc/passwd. But they'll have /etc/machine-id because systemd creates that. Also test /proc/version (a Linux-specific file) because that isn't writeable even by root. Take the opportunity to check with access() instead of assuming root and only root can write to the file. Change-Id: Ibdc95e9af7bd456a94ecfffd1603e8359604752b Reviewed-by: Volker Hilsheimer <volker.hilsheimer@qt.io>
Diffstat (limited to 'tests')
-rw-r--r--tests/auto/corelib/io/qfileinfo/tst_qfileinfo.cpp9
1 files changed, 5 insertions, 4 deletions
diff --git a/tests/auto/corelib/io/qfileinfo/tst_qfileinfo.cpp b/tests/auto/corelib/io/qfileinfo/tst_qfileinfo.cpp
index 09ef0ea44f..1788c04494 100644
--- a/tests/auto/corelib/io/qfileinfo/tst_qfileinfo.cpp
+++ b/tests/auto/corelib/io/qfileinfo/tst_qfileinfo.cpp
@@ -1887,10 +1887,11 @@ void tst_QFileInfo::isWritable()
#if defined (Q_OS_QNX) // On QNX /etc is usually on a read-only filesystem
QVERIFY(!QFileInfo("/etc/passwd").isWritable());
#elif defined (Q_OS_UNIX) && !defined(Q_OS_VXWORKS) // VxWorks does not have users/groups
- if (::getuid() == 0)
- QVERIFY(QFileInfo("/etc/passwd").isWritable());
- else
- QVERIFY(!QFileInfo("/etc/passwd").isWritable());
+ for (const char *attempt : { "/etc/passwd", "/etc/machine-id", "/proc/version" }) {
+ if (access(attempt, F_OK) == -1)
+ continue;
+ QCOMPARE(QFileInfo(attempt).isWritable(), ::access(attempt, W_OK) == 0);
+ }
#endif
}