def test_contents(self): target_cfg = self.get_pkg("three") package_path = [self.get_linker_files_dir("three-deps")] pkg_cfg = packaging.build_config(self.root, target_cfg, packagepath=package_path) deps = packaging.get_deps_for_targets(pkg_cfg, [target_cfg.name, "addon-sdk"]) addon_sdk_dir = pkg_cfg.packages["addon-sdk"].lib[0] m = manifest.build_manifest(target_cfg, pkg_cfg, deps, scan_tests=False) used_files = list(m.get_used_files()) here = up(os.path.abspath(__file__)) def absify(*parts): fn = os.path.join(here, "linker-files", *parts) return os.path.abspath(fn) expected = [absify(*parts) for parts in [("three", "lib", "main.js"), ("three-deps", "three-a", "lib", "main.js"), ("three-deps", "three-a", "lib", "subdir", "subfile.js"), ("three", "data", "msg.txt"), ("three", "data", "subdir", "submsg.txt"), ("three-deps", "three-b", "lib", "main.js"), ("three-deps", "three-c", "lib", "main.js"), ("three-deps", "three-c", "lib", "sub", "foo.js") ]] add_addon_sdk= lambda path: os.path.join(addon_sdk_dir, path) expected.extend([add_addon_sdk(module) for module in [ os.path.join("sdk", "self.js"), os.path.join("sdk", "core", "promise.js"), os.path.join("sdk", "net", "url.js"), os.path.join("sdk", "util", "object.js") ]]) missing = set(expected) - set(used_files) extra = set(used_files) - set(expected) self.failUnlessEqual(list(missing), []) self.failUnlessEqual(list(extra), []) used_deps = m.get_used_packages() build = packaging.generate_build_for_target(pkg_cfg, target_cfg.name, used_deps, include_tests=False) options = {'main': target_cfg.main} options.update(build) basedir = self.make_basedir() xpi_name = os.path.join(basedir, "contents.xpi") xpi.build_xpi(template_root_dir=xpi_template_path, manifest=fake_manifest, xpi_path=xpi_name, harness_options=options, limit_to=used_files) x = zipfile.ZipFile(xpi_name, "r") names = x.namelist() expected = ["components/", "components/harness.js", # the real template also has 'bootstrap.js', but the fake # one in tests/static-files/xpi-template doesn't "harness-options.json", "install.rdf", "defaults/preferences/prefs.js", "resources/", "resources/addon-sdk/", "resources/addon-sdk/data/", "resources/addon-sdk/lib/", "resources/addon-sdk/lib/sdk/", "resources/addon-sdk/lib/sdk/self.js", "resources/addon-sdk/lib/sdk/core/", "resources/addon-sdk/lib/sdk/util/", "resources/addon-sdk/lib/sdk/net/", "resources/addon-sdk/lib/sdk/core/promise.js", "resources/addon-sdk/lib/sdk/util/object.js", "resources/addon-sdk/lib/sdk/net/url.js", "resources/three/", "resources/three/lib/", "resources/three/lib/main.js", "resources/three/data/", "resources/three/data/msg.txt", "resources/three/data/subdir/", "resources/three/data/subdir/submsg.txt", "resources/three-a/", "resources/three-a/lib/", "resources/three-a/lib/main.js", "resources/three-a/lib/subdir/", "resources/three-a/lib/subdir/subfile.js", "resources/three-b/", "resources/three-b/lib/", "resources/three-b/lib/main.js", "resources/three-c/", "resources/three-c/lib/", "resources/three-c/lib/main.js", "resources/three-c/lib/sub/", "resources/three-c/lib/sub/foo.js", # notably absent: three-a/lib/unused.js "locale/", "locale/fr-FR.json", "locales.json", ] # showing deltas makes failures easier to investigate missing = set(expected) - set(names) extra = set(names) - set(expected) self.failUnlessEqual((list(missing), list(extra)), ([], [])) self.failUnlessEqual(sorted(names), sorted(expected)) # check locale files localedata = json.loads(x.read("locales.json")) self.failUnlessEqual(sorted(localedata["locales"]), sorted(["fr-FR"])) content = x.read("locale/fr-FR.json") locales = json.loads(content) # Locale files are merged into one. # Conflicts are silently resolved by taking last package translation, # so that we get "No" translation from three-c instead of three-b one. self.failUnlessEqual(locales, json.loads(u''' { "No": "Nein", "one": "un", "What?": "Quoi?", "Yes": "Oui", "plural": { "other": "other", "one": "one" }, "uft8_value": "\u00e9" }'''))
def get_linker_files_dir(self, name): return os.path.join(up(os.path.abspath(__file__)), "linker-files", name)
def test_contents(self): target_cfg = self.get_pkg("three") package_path = [self.get_linker_files_dir("three-deps")] pkg_cfg = packaging.build_config(self.root, target_cfg, packagepath=package_path) deps = packaging.get_deps_for_targets(pkg_cfg, [target_cfg.name, "addon-kit"]) m = manifest.build_manifest(target_cfg, pkg_cfg, deps, "P/", scan_tests=False) used_files = list(m.get_used_files()) here = up(os.path.abspath(__file__)) def absify(*parts): fn = os.path.join(here, "linker-files", *parts) return os.path.abspath(fn) expected = [ absify(*parts) for parts in [ ("three", "lib", "main.js"), ("three-deps", "three-a", "lib", "main.js"), ("three-deps", "three-b", "lib", "main.js"), ("three-deps", "three-c", "lib", "main.js"), ("three-deps", "three-c", "lib", "sub", "foo.js"), ] ] self.failUnlessEqual(sorted(used_files), sorted(expected)) used_deps = m.get_used_packages() build = packaging.generate_build_for_target(pkg_cfg, target_cfg.name, used_deps, prefix="p-", include_tests=False) options = {'main': target_cfg.main} options.update(build) basedir = self.make_basedir() xpi_name = os.path.join(basedir, "contents.xpi") xpi.build_xpi(template_root_dir=xpi_template_path, manifest=fake_manifest, xpi_name=xpi_name, harness_options=options, limit_to=used_files) x = zipfile.ZipFile(xpi_name, "r") names = x.namelist() expected = [ "components/harness.js", # the real template also has 'bootstrap.js', but the fake # one in tests/static-files/xpi-template doesn't "harness-options.json", "install.rdf", "resources/p-api-utils-data/", "resources/p-api-utils-lib/", "resources/p-three-lib/", "resources/p-three-lib/main.js", "resources/p-three-a-lib/", "resources/p-three-a-lib/main.js", "resources/p-three-b-lib/", "resources/p-three-b-lib/main.js", "resources/p-three-c-lib/", "resources/p-three-c-lib/main.js", "resources/p-three-c-lib/sub/foo.js", # notably absent: p-three-a-lib/unused.js ] # showing deltas makes failures easier to investigate missing = set(expected) - set(names) self.failUnlessEqual(list(missing), []) extra = set(names) - set(expected) self.failUnlessEqual(list(extra), []) self.failUnlessEqual(sorted(names), sorted(expected))
def setUp(self): self.root = up(os.path.abspath(__file__), 4)
def test_contents(self): target_cfg = self.get_pkg("three") package_path = [self.get_linker_files_dir("three-deps")] pkg_cfg = packaging.build_config(self.root, target_cfg, packagepath=package_path) deps = packaging.get_deps_for_targets(pkg_cfg, [target_cfg.name, "addon-kit"]) m = manifest.build_manifest(target_cfg, pkg_cfg, deps, scan_tests=False) used_files = list(m.get_used_files()) here = up(os.path.abspath(__file__)) def absify(*parts): fn = os.path.join(here, "linker-files", *parts) return os.path.abspath(fn) expected = [absify(*parts) for parts in [("three", "lib", "main.js"), ("three-deps", "three-a", "lib", "main.js"), ("three-deps", "three-a", "lib", "subdir", "subfile.js"), ("three-deps", "three-a", "data", "msg.txt"), ("three-deps", "three-a", "data", "subdir", "submsg.txt"), ("three-deps", "three-b", "lib", "main.js"), ("three-deps", "three-c", "lib", "main.js"), ("three-deps", "three-c", "lib", "sub", "foo.js"), ]] missing = set(expected) - set(used_files) extra = set(used_files) - set(expected) self.failUnlessEqual((list(missing), list(extra)), ([], [])) used_deps = m.get_used_packages() build = packaging.generate_build_for_target(pkg_cfg, target_cfg.name, used_deps, include_tests=False) options = {'main': target_cfg.main} options.update(build) basedir = self.make_basedir() xpi_name = os.path.join(basedir, "contents.xpi") xpi.build_xpi(template_root_dir=xpi_template_path, manifest=fake_manifest, xpi_path=xpi_name, harness_options=options, limit_to=used_files) x = zipfile.ZipFile(xpi_name, "r") names = x.namelist() expected = ["components/", "components/harness.js", # the real template also has 'bootstrap.js', but the fake # one in tests/static-files/xpi-template doesn't "harness-options.json", "install.rdf", "resources/", "resources/api-utils/", "resources/api-utils/data/", "resources/api-utils/lib/", "resources/three/", "resources/three/lib/", "resources/three/lib/main.js", "resources/three-a/", "resources/three-a/data/", "resources/three-a/data/msg.txt", "resources/three-a/data/subdir/", "resources/three-a/data/subdir/submsg.txt", "resources/three-a/lib/", "resources/three-a/lib/main.js", "resources/three-a/lib/subdir/", "resources/three-a/lib/subdir/subfile.js", "resources/three-b/", "resources/three-b/lib/", "resources/three-b/lib/main.js", "resources/three-c/", "resources/three-c/lib/", "resources/three-c/lib/main.js", "resources/three-c/lib/sub/", "resources/three-c/lib/sub/foo.js", # notably absent: three-a/lib/unused.js ] # showing deltas makes failures easier to investigate missing = set(expected) - set(names) extra = set(names) - set(expected) self.failUnlessEqual((list(missing), list(extra)), ([], [])) self.failUnlessEqual(sorted(names), sorted(expected))