diff options
author | Matt A. Tobin <mattatobin@localhost.localdomain> | 2018-02-02 04:16:08 -0500 |
---|---|---|
committer | Matt A. Tobin <mattatobin@localhost.localdomain> | 2018-02-02 04:16:08 -0500 |
commit | 5f8de423f190bbb79a62f804151bc24824fa32d8 (patch) | |
tree | 10027f336435511475e392454359edea8e25895d /python/mozbuild/dumbmake/test | |
parent | 49ee0794b5d912db1f95dce6eb52d781dc210db5 (diff) | |
download | UXP-5f8de423f190bbb79a62f804151bc24824fa32d8.tar UXP-5f8de423f190bbb79a62f804151bc24824fa32d8.tar.gz UXP-5f8de423f190bbb79a62f804151bc24824fa32d8.tar.lz UXP-5f8de423f190bbb79a62f804151bc24824fa32d8.tar.xz UXP-5f8de423f190bbb79a62f804151bc24824fa32d8.zip |
Add m-esr52 at 52.6.0
Diffstat (limited to 'python/mozbuild/dumbmake/test')
-rw-r--r-- | python/mozbuild/dumbmake/test/__init__.py | 0 | ||||
-rw-r--r-- | python/mozbuild/dumbmake/test/test_dumbmake.py | 106 |
2 files changed, 106 insertions, 0 deletions
diff --git a/python/mozbuild/dumbmake/test/__init__.py b/python/mozbuild/dumbmake/test/__init__.py new file mode 100644 index 000000000..e69de29bb --- /dev/null +++ b/python/mozbuild/dumbmake/test/__init__.py diff --git a/python/mozbuild/dumbmake/test/test_dumbmake.py b/python/mozbuild/dumbmake/test/test_dumbmake.py new file mode 100644 index 000000000..1172117aa --- /dev/null +++ b/python/mozbuild/dumbmake/test/test_dumbmake.py @@ -0,0 +1,106 @@ +# 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/. +from __future__ import unicode_literals + +import unittest + +from mozunit import ( + main, +) + +from dumbmake.dumbmake import ( + add_extra_dependencies, + all_dependencies, + dependency_map, + indentation, +) + +class TestDumbmake(unittest.TestCase): + def test_indentation(self): + self.assertEqual(indentation(""), 0) + self.assertEqual(indentation("x"), 0) + self.assertEqual(indentation(" x"), 1) + self.assertEqual(indentation("\tx"), 1) + self.assertEqual(indentation(" \tx"), 2) + self.assertEqual(indentation("\t x"), 2) + self.assertEqual(indentation(" x "), 1) + self.assertEqual(indentation("\tx\t"), 1) + self.assertEqual(indentation(" x"), 2) + self.assertEqual(indentation(" x"), 4) + + def test_dependency_map(self): + self.assertEqual(dependency_map([]), {}) + self.assertEqual(dependency_map(["a"]), {"a": []}) + self.assertEqual(dependency_map(["a", "b"]), {"a": [], "b": []}) + self.assertEqual(dependency_map(["a", "b", "c"]), {"a": [], "b": [], "c": []}) + # indentation + self.assertEqual(dependency_map(["a", "\tb", "a", "\tc"]), {"a": [], "b": ["a"], "c": ["a"]}) + self.assertEqual(dependency_map(["a", "\tb", "\t\tc"]), {"a": [], "b": ["a"], "c": ["b", "a"]}) + self.assertEqual(dependency_map(["a", "\tb", "\t\tc", "\td", "\te", "f"]), {"a": [], "b": ["a"], "c": ["b", "a"], "d": ["a"], "e": ["a"], "f": []}) + # irregular indentation + self.assertEqual(dependency_map(["\ta", "b"]), {"a": [], "b": []}) + self.assertEqual(dependency_map(["a", "\t\t\tb", "\t\tc"]), {"a": [], "b": ["a"], "c": ["a"]}) + self.assertEqual(dependency_map(["a", "\t\tb", "\t\t\tc", "\t\td", "\te", "f"]), {"a": [], "b": ["a"], "c": ["b", "a"], "d": ["a"], "e": ["a"], "f": []}) + # repetitions + self.assertEqual(dependency_map(["a", "\tb", "a", "\tb"]), {"a": [], "b": ["a"]}) + self.assertEqual(dependency_map(["a", "\tb", "\t\tc", "b", "\td", "\t\te"]), {"a": [], "b": ["a"], "d": ["b"], "e": ["d", "b"], "c": ["b", "a"]}) + # cycles are okay + self.assertEqual(dependency_map(["a", "\tb", "\t\ta"]), {"a": ["b", "a"], "b": ["a"]}) + + def test_all_dependencies(self): + dm = {"a": [], "b": ["a"], "c": ["b", "a"], "d": ["a"], "e": ["a"], "f": []} + self.assertEqual(all_dependencies("a", dependency_map=dm), []) + self.assertEqual(all_dependencies("b", dependency_map=dm), ["a"]) + self.assertEqual(all_dependencies("c", "a", "b", dependency_map=dm), ["b", "a"]) + self.assertEqual(all_dependencies("d", dependency_map=dm), ["a"]) + self.assertEqual(all_dependencies("d", "f", "c", dependency_map=dm), ["b", "a"]) + self.assertEqual(all_dependencies("a", "b", dependency_map=dm), ["a"]) + self.assertEqual(all_dependencies("b", "b", dependency_map=dm), ["a"]) + + def test_missing_entry(self): + # a depends on b, which is missing + dm = {"a": ["b"]} + self.assertEqual(all_dependencies("a", dependency_map=dm), ["b"]) + self.assertEqual(all_dependencies("a", "b", dependency_map=dm), ["b"]) + self.assertEqual(all_dependencies("b", dependency_map=dm), []) + + def test_two_dependencies(self): + dm = {"a": ["c"], "b": ["c"], "c": []} + # suppose a and b both depend on c. Then we want to build a and b before c... + self.assertEqual(all_dependencies("a", "b", dependency_map=dm), ["c"]) + # ... but relative order is preserved. + self.assertEqual(all_dependencies("b", "a", dependency_map=dm), ["c"]) + + def test_nested_dependencies(self): + # a depends on b depends on c depends on d + dm = {"a": ["b", "c", "d"], "b": ["c", "d"], "c": ["d"]} + self.assertEqual(all_dependencies("b", "a", dependency_map=dm), ["b", "c", "d"]) + self.assertEqual(all_dependencies("c", "a", dependency_map=dm), ["b", "c", "d"]) + + def test_add_extra_dependencies(self): + # a depends on b depends on c depends on d + dm = {"a": ["b", "c", "d"], "b": ["c", "d"], "c": ["d"]} + # Edge cases. + self.assertEqual(list(add_extra_dependencies([], dependency_map=dm)), + []) + self.assertEqual(list(add_extra_dependencies([(None, "package")], dependency_map=dm)), + [(None, "package")]) + # Easy expansion. + self.assertEqual(list(add_extra_dependencies([("b", None)], dependency_map=dm)), + [("b", None), ("c", None), ("d", None)]) + # Expansion with two groups -- each group is handled independently. + self.assertEqual(list(add_extra_dependencies([("b", None), + (None, "package"), + ("c", None)], dependency_map=dm)), + [("b", None), (None, "package"), + ("c", None), ("d", None)]) + # Two groups, no duplicate dependencies in each group. + self.assertEqual(list(add_extra_dependencies([("a", None), ("b", None), + (None, "package"), (None, "install"), + ("c", None), ("d", None)], dependency_map=dm)), + [("a", None), ("b", None), (None, "package"), + (None, "install"), ("c", None), ("d", None)]) + +if __name__ == '__main__': + main() |