summaryrefslogtreecommitdiffstats
path: root/tests/auto/corelib
diff options
context:
space:
mode:
authorIevgenii Meshcheriakov <ievgenii.meshcheriakov@qt.io>2021-10-14 15:14:00 +0200
committerIevgenii Meshcheriakov <ievgenii.meshcheriakov@qt.io>2021-11-07 01:53:44 +0100
commit5fc9c02a695edca23c0f8b2ec4c258e2c4212ea8 (patch)
tree67bed0f375fc5b05eeb34251574c21500ad8ff29 /tests/auto/corelib
parent7f8fd38931a86288bcf8dac7f4a249db259fd33e (diff)
QProcess: Distinguish between null and empty QProcessEnvironment
The documentation for QProcessEnvironment's default constructor says: This constructor creates an empty environment. If set on a QProcess, this will cause the current environment variables to be removed. This is not the case however, because setting such an environment for a process is equivalent to not setting an environment at all and the child process is executed with parent's environment. It is still possible starting from Qt 6.2.0 to create an empty environment by adding a variable to a null environment and removing it, but that's cumbersome, and the comparison operator says that it is equal to the null environment but it is obviously behaving in a different way. This change adds an additional constructor to QProcessEnvironment that can be used to construct a null environment, and changes the default constructor to produce an empty environment. The comparison operator is changed to correctly distinguish between such objects. This is a behavior change, but the current behavior is broken and this is unlikely to affect working code. [ChangeLog][QtCore][QProcessEnvironment] An additional constructor was added to explicitly create an object that when set on QProcess would cause it to inherit the environment from parent (this was formerly the behavior of a default-constructed QProcessEnvironment, which will now (as documented) actually give a process an environment with no variables set). A new method inheritsFromParent() was added to test for such objects. Fixes: QTBUG-58053 Change-Id: I15e20c6a5f01ebe2c736d5578c75dba1ee319320 Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
Diffstat (limited to 'tests/auto/corelib')
-rw-r--r--tests/auto/corelib/io/qprocessenvironment/tst_qprocessenvironment.cpp29
1 files changed, 29 insertions, 0 deletions
diff --git a/tests/auto/corelib/io/qprocessenvironment/tst_qprocessenvironment.cpp b/tests/auto/corelib/io/qprocessenvironment/tst_qprocessenvironment.cpp
index e0f598e32e..d1035cb8c2 100644
--- a/tests/auto/corelib/io/qprocessenvironment/tst_qprocessenvironment.cpp
+++ b/tests/auto/corelib/io/qprocessenvironment/tst_qprocessenvironment.cpp
@@ -36,6 +36,7 @@ class tst_QProcessEnvironment: public QObject
private slots:
void operator_eq();
void clearAndIsEmpty();
+ void clearAndInheritsFromParent();
void insert();
void emptyNull();
void toStringList();
@@ -58,6 +59,10 @@ void tst_QProcessEnvironment::operator_eq()
QProcessEnvironment e2;
QCOMPARE(e1, e2);
+ auto parentEnv = QProcessEnvironment(QProcessEnvironment::InheritFromParent);
+ QVERIFY(parentEnv != e2);
+ QVERIFY(e2 != parentEnv);
+
e1.clear();
QCOMPARE(e1, e2);
@@ -72,15 +77,39 @@ void tst_QProcessEnvironment::operator_eq()
e2.insert("FOO", "baz");
QVERIFY(e1 != e2);
+
+ QVERIFY(e2 != parentEnv);
+ QVERIFY(parentEnv != e2);
}
void tst_QProcessEnvironment::clearAndIsEmpty()
{
QProcessEnvironment e;
+ QVERIFY(e.isEmpty());
+ QVERIFY(!e.inheritsFromParent());
+ e.insert("FOO", "bar");
+ QVERIFY(!e.isEmpty());
+ QVERIFY(!e.inheritsFromParent());
+ e.clear();
+ QVERIFY(e.isEmpty());
+ QVERIFY(!e.inheritsFromParent());
+}
+
+void tst_QProcessEnvironment::clearAndInheritsFromParent()
+{
+ QProcessEnvironment e(QProcessEnvironment::InheritFromParent);
+ QVERIFY(e.isEmpty());
+ QVERIFY(e.inheritsFromParent());
+ // Clearing null environment keeps it null
+ e.clear();
+ QVERIFY(e.isEmpty());
+ QVERIFY(e.inheritsFromParent());
e.insert("FOO", "bar");
QVERIFY(!e.isEmpty());
+ QVERIFY(!e.inheritsFromParent());
e.clear();
QVERIFY(e.isEmpty());
+ QVERIFY(!e.inheritsFromParent());
}
void tst_QProcessEnvironment::insert()