diff options
Diffstat (limited to 'python/mozbuild/mozbuild/test/action')
7 files changed, 378 insertions, 0 deletions
diff --git a/python/mozbuild/mozbuild/test/action/data/invalid/region.properties b/python/mozbuild/mozbuild/test/action/data/invalid/region.properties new file mode 100644 index 0000000000..d4d8109b69 --- /dev/null +++ b/python/mozbuild/mozbuild/test/action/data/invalid/region.properties @@ -0,0 +1,12 @@ +# A region.properties file with invalid unicode byte sequences. The +# sequences were cribbed from Markus Kuhn's "UTF-8 decoder capability +# and stress test", available at +# http://www.cl.cam.ac.uk/~mgk25/ucs/examples/UTF-8-test.txt + +# 3.5 Impossible bytes | +# | +# The following two bytes cannot appear in a correct UTF-8 string | +# | +# 3.5.1 fe = "þ" | +# 3.5.2 ff = "ÿ" | +# 3.5.3 fe fe ff ff = "þþÿÿ" | diff --git a/python/mozbuild/mozbuild/test/action/data/node/node-test-script.js b/python/mozbuild/mozbuild/test/action/data/node/node-test-script.js new file mode 100644 index 0000000000..f6dbfcc594 --- /dev/null +++ b/python/mozbuild/mozbuild/test/action/data/node/node-test-script.js @@ -0,0 +1,11 @@ +#! /usr/bin/env node +"use strict"; + +/* eslint-disable no-console */ + +let args = process.argv.slice(2); + +for (let arg of args) { + console.log(`dep:${arg}`); +} + diff --git a/python/mozbuild/mozbuild/test/action/data/valid-zh-CN/region.properties b/python/mozbuild/mozbuild/test/action/data/valid-zh-CN/region.properties new file mode 100644 index 0000000000..d4d7fcfee5 --- /dev/null +++ b/python/mozbuild/mozbuild/test/action/data/valid-zh-CN/region.properties @@ -0,0 +1,37 @@ +# 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/. + +# Default search engine +browser.search.defaultenginename=百度 + +# Search engine order (order displayed in the search bar dropdown)s +browser.search.order.1=百度 +browser.search.order.2=Google + +# This is the default set of web based feed handlers shown in the reader +# selection UI +browser.contentHandlers.types.0.title=Bloglines +browser.contentHandlers.types.0.uri=http://www.bloglines.com/login?r=/sub/%s + +# increment this number when anything gets changed in the list below. This will +# cause Firefox to re-read these prefs and inject any new handlers into the +# profile database. Note that "new" is defined as "has a different URL"; this +# means that it's not possible to update the name of existing handler, so +# don't make any spelling errors here. +gecko.handlerService.defaultHandlersVersion=3 + +# The default set of protocol handlers for webcal: +gecko.handlerService.schemes.webcal.0.name=30 Boxes +gecko.handlerService.schemes.webcal.0.uriTemplate=https://30boxes.com/external/widget?refer=ff&url=%s + +# The default set of protocol handlers for mailto: +gecko.handlerService.schemes.mailto.0.name=Yahoo! 邮件 +gecko.handlerService.schemes.mailto.0.uriTemplate=https://compose.mail.yahoo.com/?To=%s +gecko.handlerService.schemes.mailto.1.name=Gmail +gecko.handlerService.schemes.mailto.1.uriTemplate=https://mail.google.com/mail/?extsrc=mailto&url=%s + +# This is the default set of web based feed handlers shown in the reader +# selection UI +browser.contentHandlers.types.0.title=My Yahoo! +browser.contentHandlers.types.0.uri=http://www.bloglines.com/login?r=/sub/%s diff --git a/python/mozbuild/mozbuild/test/action/test_buildlist.py b/python/mozbuild/mozbuild/test/action/test_buildlist.py new file mode 100644 index 0000000000..4ec4bbcb66 --- /dev/null +++ b/python/mozbuild/mozbuild/test/action/test_buildlist.py @@ -0,0 +1,98 @@ +# 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 absolute_import, print_function + +import unittest + +import os +import os.path +from tempfile import mkdtemp +from shutil import rmtree +import mozunit + +from mozbuild.action.buildlist import addEntriesToListFile + + +class TestBuildList(unittest.TestCase): + """ + Unit tests for buildlist.py + """ + + def setUp(self): + self.tmpdir = mkdtemp() + + def tearDown(self): + rmtree(self.tmpdir) + + # utility methods for tests + def touch(self, file, dir=None): + if dir is None: + dir = self.tmpdir + f = os.path.join(dir, file) + open(f, "w").close() + return f + + def assertFileContains(self, filename, l): + """Assert that the lines in the file |filename| are equal + to the contents of the list |l|, in order.""" + l = l[:] + f = open(filename, "r") + lines = [line.rstrip() for line in f.readlines()] + f.close() + for line in lines: + self.assert_( + len(l) > 0, + "ran out of expected lines! (expected '{0}', got '{1}')".format( + l, lines + ), + ) + self.assertEqual(line, l.pop(0)) + self.assert_( + len(l) == 0, + "not enough lines in file! (expected '{0}'," " got '{1}'".format(l, lines), + ) + + def test_basic(self): + "Test that addEntriesToListFile works when file doesn't exist." + testfile = os.path.join(self.tmpdir, "test.list") + l = ["a", "b", "c"] + addEntriesToListFile(testfile, l) + self.assertFileContains(testfile, l) + # ensure that attempting to add the same entries again doesn't change it + addEntriesToListFile(testfile, l) + self.assertFileContains(testfile, l) + + def test_append(self): + "Test adding new entries." + testfile = os.path.join(self.tmpdir, "test.list") + l = ["a", "b", "c"] + addEntriesToListFile(testfile, l) + self.assertFileContains(testfile, l) + l2 = ["x", "y", "z"] + addEntriesToListFile(testfile, l2) + l.extend(l2) + self.assertFileContains(testfile, l) + + def test_append_some(self): + "Test adding new entries mixed with existing entries." + testfile = os.path.join(self.tmpdir, "test.list") + l = ["a", "b", "c"] + addEntriesToListFile(testfile, l) + self.assertFileContains(testfile, l) + addEntriesToListFile(testfile, ["a", "x", "c", "z"]) + self.assertFileContains(testfile, ["a", "b", "c", "x", "z"]) + + def test_add_multiple(self): + """Test that attempting to add the same entry multiple times results in + only one entry being added.""" + testfile = os.path.join(self.tmpdir, "test.list") + addEntriesToListFile(testfile, ["a", "b", "a", "a", "b"]) + self.assertFileContains(testfile, ["a", "b"]) + addEntriesToListFile(testfile, ["c", "a", "c", "b", "c"]) + self.assertFileContains(testfile, ["a", "b", "c"]) + + +if __name__ == "__main__": + mozunit.main() diff --git a/python/mozbuild/mozbuild/test/action/test_langpack_manifest.py b/python/mozbuild/mozbuild/test/action/test_langpack_manifest.py new file mode 100644 index 0000000000..9cab012b34 --- /dev/null +++ b/python/mozbuild/mozbuild/test/action/test_langpack_manifest.py @@ -0,0 +1,70 @@ +# -*- coding: utf-8 -*- + +# Any copyright is dedicated to the Public Domain. +# http://creativecommons.org/publicdomain/zero/1.0/ + +from __future__ import absolute_import, print_function + +import unittest +import json + +import mozunit + +import mozbuild.action.langpack_manifest as langpack_manifest +from mozbuild.preprocessor import Context + + +class TestGenerateManifest(unittest.TestCase): + """ + Unit tests for langpack_manifest.py. + """ + + def test_manifest(self): + ctx = Context() + ctx["MOZ_LANG_TITLE"] = "Finnish" + ctx["MOZ_LANGPACK_CREATOR"] = "Suomennosprojekti" + ctx[ + "MOZ_LANGPACK_CONTRIBUTORS" + ] = """ + <em:contributor>Joe Smith</em:contributor> + <em:contributor>Mary White</em:contributor> + """ + manifest = langpack_manifest.create_webmanifest( + "fi", + "57.0", + "57.0.*", + "Firefox", + "/var/vcs/l10n-central", + "langpack-fi@firefox.mozilla.og", + ctx, + {}, + ) + + data = json.loads(manifest) + self.assertEquals(data["name"], "Finnish Language Pack") + self.assertEquals( + data["author"], "Suomennosprojekti (contributors: Joe Smith, Mary White)" + ) + + def test_manifest_without_contributors(self): + ctx = Context() + ctx["MOZ_LANG_TITLE"] = "Finnish" + ctx["MOZ_LANGPACK_CREATOR"] = "Suomennosprojekti" + manifest = langpack_manifest.create_webmanifest( + "fi", + "57.0", + "57.0.*", + "Firefox", + "/var/vcs/l10n-central", + "langpack-fi@firefox.mozilla.og", + ctx, + {}, + ) + + data = json.loads(manifest) + self.assertEquals(data["name"], "Finnish Language Pack") + self.assertEquals(data["author"], "Suomennosprojekti") + + +if __name__ == "__main__": + mozunit.main() diff --git a/python/mozbuild/mozbuild/test/action/test_node.py b/python/mozbuild/mozbuild/test/action/test_node.py new file mode 100644 index 0000000000..29134e68fc --- /dev/null +++ b/python/mozbuild/mozbuild/test/action/test_node.py @@ -0,0 +1,82 @@ +# -*- coding: utf-8 -*- + +# Any copyright is dedicated to the Public Domain. +# http://creativecommons.org/publicdomain/zero/1.0/ + +from __future__ import absolute_import, unicode_literals, print_function + +import buildconfig +import os +import unittest +import mozunit + +from mozbuild.action.node import generate, SCRIPT_ALLOWLIST +from mozbuild.nodeutil import find_node_executable +import mozpack.path as mozpath + + +test_data_path = mozpath.abspath(mozpath.dirname(__file__)) +test_data_path = mozpath.join(test_data_path, "data", "node") + + +def data(name): + return os.path.join(test_data_path, name) + + +TEST_SCRIPT = data("node-test-script.js") +NONEXISTENT_TEST_SCRIPT = data("non-existent-test-script.js") + + +class TestNode(unittest.TestCase): + """ + Tests for node.py. + """ + + def setUp(self): + if not buildconfig.substs.get("NODEJS"): + buildconfig.substs["NODEJS"] = find_node_executable()[0] + SCRIPT_ALLOWLIST.append(TEST_SCRIPT) + + def tearDown(self): + try: + SCRIPT_ALLOWLIST.remove(TEST_SCRIPT) + except Exception: + pass + + def test_generate_no_returned_deps(self): + deps = generate("dummy_argument", TEST_SCRIPT) + + self.assertSetEqual(deps, set([])) + + def test_generate_returns_passed_deps(self): + deps = generate("dummy_argument", TEST_SCRIPT, "a", "b") + + self.assertSetEqual(deps, set(["a", "b"])) + + def test_called_process_error_handled(self): + SCRIPT_ALLOWLIST.append(NONEXISTENT_TEST_SCRIPT) + + with self.assertRaises(SystemExit) as cm: + generate("dummy_arg", NONEXISTENT_TEST_SCRIPT) + + self.assertEqual(cm.exception.code, 1) + SCRIPT_ALLOWLIST.remove(NONEXISTENT_TEST_SCRIPT) + + def test_nodejs_not_set(self): + buildconfig.substs["NODEJS"] = None + + with self.assertRaises(SystemExit) as cm: + generate("dummy_arg", TEST_SCRIPT) + + self.assertEqual(cm.exception.code, 1) + + def test_generate_missing_allowlist_entry_exit_code(self): + SCRIPT_ALLOWLIST.remove(TEST_SCRIPT) + with self.assertRaises(SystemExit) as cm: + generate("dummy_arg", TEST_SCRIPT) + + self.assertEqual(cm.exception.code, 1) + + +if __name__ == "__main__": + mozunit.main() diff --git a/python/mozbuild/mozbuild/test/action/test_process_install_manifest.py b/python/mozbuild/mozbuild/test/action/test_process_install_manifest.py new file mode 100644 index 0000000000..929f90cbab --- /dev/null +++ b/python/mozbuild/mozbuild/test/action/test_process_install_manifest.py @@ -0,0 +1,68 @@ +# -*- coding: utf-8 -*- + +# Any copyright is dedicated to the Public Domain. +# http://creativecommons.org/publicdomain/zero/1.0/ + +from __future__ import absolute_import, print_function + +import os + +import mozunit + +from mozpack.manifests import InstallManifest +from mozpack.test.test_files import TestWithTmpDir + +import mozbuild.action.process_install_manifest as process_install_manifest + + +class TestGenerateManifest(TestWithTmpDir): + """ + Unit tests for process_install_manifest.py. + """ + + def test_process_manifest(self): + source = self.tmppath("source") + os.mkdir(source) + os.mkdir("%s/base" % source) + os.mkdir("%s/base/foo" % source) + os.mkdir("%s/base2" % source) + + with open("%s/base/foo/file1" % source, "a"): + pass + + with open("%s/base/foo/file2" % source, "a"): + pass + + with open("%s/base2/file3" % source, "a"): + pass + + m = InstallManifest() + m.add_pattern_link("%s/base" % source, "**", "") + m.add_link("%s/base2/file3" % source, "foo/file3") + + p = self.tmppath("m") + m.write(path=p) + + dest = self.tmppath("dest") + track = self.tmppath("track") + + for i in range(2): + process_install_manifest.process_manifest(dest, [p], track) + + self.assertTrue(os.path.exists(self.tmppath("dest/foo/file1"))) + self.assertTrue(os.path.exists(self.tmppath("dest/foo/file2"))) + self.assertTrue(os.path.exists(self.tmppath("dest/foo/file3"))) + + m = InstallManifest() + m.write(path=p) + + for i in range(2): + process_install_manifest.process_manifest(dest, [p], track) + + self.assertFalse(os.path.exists(self.tmppath("dest/foo/file1"))) + self.assertFalse(os.path.exists(self.tmppath("dest/foo/file2"))) + self.assertFalse(os.path.exists(self.tmppath("dest/foo/file3"))) + + +if __name__ == "__main__": + mozunit.main() |