summaryrefslogtreecommitdiffstats
path: root/python/mozbuild/mozbuild/test/backend/test_configenvironment.py
diff options
context:
space:
mode:
Diffstat (limited to 'python/mozbuild/mozbuild/test/backend/test_configenvironment.py')
-rw-r--r--python/mozbuild/mozbuild/test/backend/test_configenvironment.py73
1 files changed, 73 insertions, 0 deletions
diff --git a/python/mozbuild/mozbuild/test/backend/test_configenvironment.py b/python/mozbuild/mozbuild/test/backend/test_configenvironment.py
new file mode 100644
index 0000000000..7900cdd737
--- /dev/null
+++ b/python/mozbuild/mozbuild/test/backend/test_configenvironment.py
@@ -0,0 +1,73 @@
+# This Source Code Form is subject to the terms of the Mozilla Public
+# License, v. 2.0. If a copy of the MPL was not distributed with this
+# file, You can obtain one at http://mozilla.org/MPL/2.0/.
+
+import os
+import unittest
+
+import mozpack.path as mozpath
+from mozunit import main
+
+import mozbuild.backend.configenvironment as ConfigStatus
+from mozbuild.util import ReadOnlyDict
+
+
+class ConfigEnvironment(ConfigStatus.ConfigEnvironment):
+ def __init__(self, *args, **kwargs):
+ ConfigStatus.ConfigEnvironment.__init__(self, *args, **kwargs)
+ # Be helpful to unit tests
+ if "top_srcdir" not in self.substs:
+ if os.path.isabs(self.topsrcdir):
+ top_srcdir = self.topsrcdir.replace(os.sep, "/")
+ else:
+ top_srcdir = mozpath.relpath(self.topsrcdir, self.topobjdir).replace(
+ os.sep, "/"
+ )
+
+ d = dict(self.substs)
+ d["top_srcdir"] = top_srcdir
+ self.substs = ReadOnlyDict(d)
+
+
+class TestEnvironment(unittest.TestCase):
+ def test_auto_substs(self):
+ """Test the automatically set values of ACDEFINES, ALLSUBSTS
+ and ALLEMPTYSUBSTS.
+ """
+ env = ConfigEnvironment(
+ ".",
+ ".",
+ defines={"foo": "bar", "baz": "qux 42", "abc": "d'e'f"},
+ substs={
+ "FOO": "bar",
+ "FOOBAR": "",
+ "ABC": "def",
+ "bar": "baz qux",
+ "zzz": '"abc def"',
+ "qux": "",
+ },
+ )
+ # Original order of the defines need to be respected in ACDEFINES
+ self.assertEqual(
+ env.substs["ACDEFINES"],
+ """-Dabc='d'\\''e'\\''f' -Dbaz='qux 42' -Dfoo=bar""",
+ )
+ # Likewise for ALLSUBSTS, which also must contain ACDEFINES
+ self.assertEqual(
+ env.substs["ALLSUBSTS"],
+ '''ABC = def
+ACDEFINES = -Dabc='d'\\''e'\\''f' -Dbaz='qux 42' -Dfoo=bar
+FOO = bar
+bar = baz qux
+zzz = "abc def"''',
+ )
+ # ALLEMPTYSUBSTS contains all substs with no value.
+ self.assertEqual(
+ env.substs["ALLEMPTYSUBSTS"],
+ """FOOBAR =
+qux =""",
+ )
+
+
+if __name__ == "__main__":
+ main()