brintos

brintos / llvm-project-archived public Read only

0
0
Text · 2.2 KiB · 0c242d5 Raw
58 lines · python
1"""2Test importing the 'std' C++ module and evaluate expressions with it.3"""4 5from lldbsuite.test.decorators import *6from lldbsuite.test.lldbtest import *7from lldbsuite.test import lldbutil8 9 10class ImportStdModule(TestBase):11    @add_test_categories(["libc++"])12    @skipIf(compiler=no_match("clang"))13    @skipIf(macos_version=["<", "15.0"])14    def test(self):15        self.build()16 17        lldbutil.run_to_source_breakpoint(18            self, "// Set break point at this line.", lldb.SBFileSpec("main.cpp")19        )20 21        # Activate importing of std module.22        self.runCmd("settings set target.import-std-module true")23        # Calling some normal std functions that return non-template types.24        self.expect_expr("std::abs(-42)", result_type="int", result_value="42")25        self.expect_expr(26            "std::minmax<int>(1, 2).first", result_type="const int", result_value="1"27        )28        self.expect_expr("std::div(2, 1).quot", result_type="int", result_value="2")29        # Using types from std.30        self.expect_expr(31            "(std::size_t)33U", result_type="std::size_t", result_value="33"32        )33        # Calling templated functions that return non-template types.34        self.expect_expr(35            "char char_a = 'b'; char char_b = 'a'; std::swap(char_a, char_b); char_a",36            result_type="char",37            result_value="'a'",38        )39 40    @add_test_categories(["libc++"])41    @skipIf(compiler=no_match("clang"))42    @skipIf(macos_version=["<", "15.0"])43    def test_non_cpp_language(self):44        self.build()45 46        lldbutil.run_to_source_breakpoint(47            self, "// Set break point at this line.", lldb.SBFileSpec("main.cpp")48        )49 50        # Activate importing of std module.51        self.runCmd("settings set target.import-std-module true")52        # These languages don't support C++ modules, so they shouldn't53        # be able to evaluate the expression.54        self.expect("expr -l C -- std::minmax<int>(1, 2).first", error=True)55        self.expect("expr -l C99 -- std::minmax<int>(1, 2).first", error=True)56        self.expect("expr -l C11 -- std::minmax<int>(1, 2).first", error=True)57        self.expect("expr -l ObjC -- std::minmax<int>(1, 2).first", error=True)58