# 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 unittest
import mozpack.path as mozpath from mozunit import main
from mozbuild.frontend.context import (
FUNCTIONS,
SPECIAL_VARIABLES,
VARIABLES,
Context,
SourcePath,
) from mozbuild.frontend.reader import MozbuildSandbox, SandboxCalledError from mozbuild.frontend.sandbox import Sandbox, SandboxExecutionError, SandboxLoadError from mozbuild.test.common import MockConfig
def test_symbol_presence(self): # Ensure no discrepancies between the master symbol table and what's in # the sandbox.
sandbox = self.sandbox()
sandbox._context.add_source(sandbox.normalize_path("moz.build"))
# Access to an undefined substitution should return None.
self.assertNotIn("MISSING", sandbox["CONFIG"])
self.assertIsNone(sandbox["CONFIG"]["MISSING"])
# Should shouldn't be allowed to assign to the config. with self.assertRaises(Exception):
sandbox["CONFIG"]["FOO"] = ""
with self.assertRaises(SandboxLoadError) as sle:
sandbox.exec_file("moz.build")
self.assertIsNotNone(sle.exception.read_error)
def test_include_relative_from_child_dir(self): # A relative path from a subdirectory should be relative from that # child directory.
sandbox = self.sandbox(data_path="include-relative-from-child")
sandbox.exec_file("child/child.build")
self.assertEqual(sandbox["DIRS"], [sandbox.source_path("../foo")])
sandbox2 = self.sandbox(metadata={"templates": sandbox.templates})
source = """
TemplateError([ 'foo.cpp',
]) """ with self.assertRaises(SandboxExecutionError) as se:
sandbox2.exec_source(source, "foo.mozbuild")
e = se.exception
self.assertIsInstance(e.exc_value, KeyError)
e = se.exception.exc_value
self.assertEqual(e.args[0], "global_ns")
self.assertEqual(e.args[1], "set_unknown")
# TemplateGlobalVariable tries to access 'illegal' but that is expected # to throw.
sandbox2 = self.sandbox(metadata={"templates": sandbox.templates})
source = """
illegal = True
TemplateGlobalVariable() """ with self.assertRaises(SandboxExecutionError) as se:
sandbox2.exec_source(source, "foo.mozbuild")
e = se.exception
self.assertIsInstance(e.exc_value, NameError)
# TemplateGlobalUPPERVariable sets SOURCES with DIRS, but the context # used when running the template is not expected to access variables # from the global context.
sandbox2 = self.sandbox(metadata={"templates": sandbox.templates})
source = """
DIRS += ['foo']
TemplateGlobalUPPERVariable() """
sandbox2.exec_source(source, "foo.mozbuild")
self.assertEqual(
sandbox2._context,
{ "SOURCES": [], "DIRS": [sandbox2.source_path("foo")],
},
)
# However, the result of the template is mixed with the global # context.
sandbox2 = self.sandbox(metadata={"templates": sandbox.templates})
source = """
SOURCES += ['qux.cpp']
TemplateInherit([ 'bar.cpp', 'foo.cpp',
])
SOURCES += ['hoge.cpp'] """
sandbox2.exec_source(source, "foo.mozbuild")
# Template names must be CamelCase. Here, we can define the template # inline because the error happens before inspect.getsourcelines.
sandbox2 = self.sandbox(metadata={"templates": sandbox.templates})
source = """
@template def foo(): pass """
with self.assertRaises(SandboxExecutionError) as se:
sandbox2.exec_source(source, "foo.mozbuild")
e = se.exception
self.assertIsInstance(e.exc_value, NameError)
e = se.exception.exc_value
self.assertIn("Template function names must be CamelCase.", str(e))
# Template names must not already be registered.
sandbox2 = self.sandbox(metadata={"templates": sandbox.templates})
source = """
@template def Template(): pass """ with self.assertRaises(SandboxExecutionError) as se:
sandbox2.exec_source(source, "foo.mozbuild")
e = se.exception
self.assertIsInstance(e.exc_value, KeyError)
e = se.exception.exc_value
self.assertIn( 'A template named "Template" was already declared in %s.'
% sandbox.normalize_path("templates.mozbuild"),
str(e),
)
def test_function_args(self): class Foo(int): pass
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.