diff --git a/static_core/plugins/ets/tests/evaluate/ets/field_access/field_access.base.ets b/static_core/plugins/ets/tests/evaluate/ets/field_access/field_access.base.ets new file mode 100644 index 0000000000000000000000000000000000000000..48dc55369d644541477e840858cf62079dd5a093 --- /dev/null +++ b/static_core/plugins/ets/tests/evaluate/ets/field_access/field_access.base.ets @@ -0,0 +1,40 @@ +/* + * Copyright (c) 2024 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/*--- +params: + evaluate_line: 39 + disable_ast_comparison: True +---*/ + +export class A { + private a: int; + private b: double; + + private foo(val: int): int + { + return 100 * val; + } + + private goo(val: double): double + { + return 200 * val; + } +}; + +function main(): void { + let class_a = new A(); + console.log("Evaluate"); +} diff --git a/static_core/plugins/ets/tests/evaluate/ets/field_access/field_access.expected.ets b/static_core/plugins/ets/tests/evaluate/ets/field_access/field_access.expected.ets new file mode 100644 index 0000000000000000000000000000000000000000..85b16ffb8dfb622120a66c916937a71f8874d2c1 --- /dev/null +++ b/static_core/plugins/ets/tests/evaluate/ets/field_access/field_access.expected.ets @@ -0,0 +1,41 @@ +/* + * Copyright (c) 2024 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +class A { + public a: int; + public b: double; + + public foo(val: int): int + { + return 100 * val; + } + + public goo(val: double): double + { + return 200 * val; + } +}; + +function patch() { + let class_a: A = DebuggerAPI.getLocalObject(0) as A; + + console.log(class_a.a); + console.log(class_a.b); + + console.log(class_a.foo(100)); + console.log(class_a.goo(123.1)); + + DebuggerAPI.setLocalObject(0, class_a); +} diff --git a/static_core/plugins/ets/tests/evaluate/ets/field_access/field_access.patch.ets b/static_core/plugins/ets/tests/evaluate/ets/field_access/field_access.patch.ets new file mode 100644 index 0000000000000000000000000000000000000000..a4f9ef6f865e52c0d468aa62eefe821d71fec9ca --- /dev/null +++ b/static_core/plugins/ets/tests/evaluate/ets/field_access/field_access.patch.ets @@ -0,0 +1,22 @@ +/* + * Copyright (c) 2024 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +function patch() { + console.log(class_a.a); + console.log(class_a.b); + + console.log(class_a.foo(100)); + console.log(class_a.goo(123.1)); +} diff --git a/static_core/tests/tests-u-runner/runner/plugins/evaluate/test_evaluate.py b/static_core/tests/tests-u-runner/runner/plugins/evaluate/test_evaluate.py index 5716de0b72f14dc8677210d7f14114b9b9d132de..b25adf8bee793c0a40e57c8f780bcf4e765e49e4 100644 --- a/static_core/tests/tests-u-runner/runner/plugins/evaluate/test_evaluate.py +++ b/static_core/tests/tests-u-runner/runner/plugins/evaluate/test_evaluate.py @@ -91,6 +91,10 @@ class TestEvaluate(TestFileBased): def expected_file_imports_base(self) -> bool: return "expected_imports_base" in self.metadata.params and bool(self.metadata.params["expected_imports_base"]) + @property + def disable_ast_comparison(self) -> bool: + return "disable_ast_comparison" in self.metadata.params and bool(self.metadata.params["disable_ast_comparison"]) + # pylint: disable=too-many-return-statements def do_run(self) -> TestEvaluate: # NOTE(dslynko): must support cases with multiple context files @@ -123,9 +127,10 @@ class TestEvaluate(TestFileBased): if not self.passed: return self - self._compare_ast(patch_output, expected_output) - if not self.passed: - return self + if not self.disable_ast_comparison: + self._compare_ast(patch_output, expected_output) + if not self.passed: + return self self._compare_bytecode() return self @@ -287,6 +292,8 @@ class TestEvaluate(TestFileBased): """ Compares two bytecode files according to disasm output. """ + print("Compare bytecode") + with Path(self.patch_disasm).open() as patch: with Path(self.expected_disasm).open() as expected: prefix_to_delete = [f"{self.base_filename}.expected.", f"{self.base_filename}.base.", f"{self.base_filename}.patch."] @@ -366,10 +373,10 @@ class TestEvaluate(TestFileBased): es2panda_flags.append("--ets-module") if eval_options: es2panda_flags.extend([ - "--eval-mode=true", - f"--eval-context-panda-files={','.join(eval_options.panda_files_paths)}", - f"--eval-context-source={eval_options.source_path}", - f"--eval-context-line={self.evaluate_line}", + "--debugger-eval-mode=true", + f"--debugger-eval-panda-files={','.join(eval_options.panda_files_paths)}", + f"--debugger-eval-source={eval_options.source_path}", + f"--debugger-eval-line={self.evaluate_line}", ]) else: es2panda_flags.append("--debug-info")