From 83322f5cce9376f5ca2decb12ce61ea818a7acc6 Mon Sep 17 00:00:00 2001 From: ozerovnikita Date: Mon, 7 Aug 2023 19:40:57 +0300 Subject: [PATCH] [es2panda] System ArkTS. Add ets-warning-tests target in u-runner Signed-off-by: ozerovnikita Signed-off-by: lirismankarina --- Test.ets | 14 +++ plugins/ets/tests/CMakeLists.txt | 12 +++ .../tests/ets_warnings_tests/CMakeLists.txt | 45 +++++++++ .../all_warnings_tests/1-expected.txt | 1 + .../all_warnings_tests/1.ets | 24 +++++ .../all_warnings_tests/CMakeLists.txt | 29 ++++++ .../CMakeLists.txt | 29 ++++++ .../boost_equal_statements_1-expected.txt | 1 + .../boost_equal_statements_1.ets | 18 ++++ .../boost_equal_statements_2-expected.txt | 5 + .../boost_equal_statements_2.ets | 39 ++++++++ .../CMakeLists.txt | 29 ++++++ .../boxing-expected.txt | 42 ++++++++ .../implicit_boxing_unboxing_tests/boxing.ets | 98 +++++++++++++++++++ .../CMakeLists.txt | 29 ++++++ ...ohibit_top_level_statements_1-expected.txt | 4 + .../prohibit_top_level_statements_1.ets | 21 ++++ ...ohibit_top_level_statements_2-expected.txt | 5 + .../prohibit_top_level_statements_2.ets | 41 ++++++++ .../remove_async_tests/1-expected.txt | 1 + .../remove_async_tests/1.ets | 24 +++++ .../remove_async_tests/CMakeLists.txt | 29 ++++++ .../remove_async_tests/async-expected.txt | 2 + .../remove_async_tests/async.ets | 44 +++++++++ .../remove_lambda_tests/CMakeLists.txt | 29 ++++++ .../remove_lambda_tests/lambda-expected.txt | 1 + .../remove_lambda_tests/lambda.ets | 19 ++++ .../remove_lambda_tests/lambda_1-expected.txt | 3 + .../remove_lambda_tests/lambda_1.ets | 24 +++++ .../suggest_final_tests/CMakeLists.txt | 29 ++++++ .../suggest_final_for_classes_1-expected.txt | 1 + .../suggest_final_for_classes_1.ets | 17 ++++ .../suggest_final_for_classes_2-expected.txt | 1 + .../suggest_final_for_classes_2.ets | 25 +++++ ...nal_for_classes_and_methods_1-expected.txt | 6 ++ ...uggest_final_for_classes_and_methods_1.ets | 36 +++++++ ...nal_for_classes_and_methods_2-expected.txt | 6 ++ ...uggest_final_for_classes_and_methods_2.ets | 36 +++++++ .../suggest_final_for_methods_1-expected.txt | 0 .../suggest_final_for_methods_1.ets | 29 ++++++ .../suggest_final_for_methods_2-expected.txt | 0 .../suggest_final_for_methods_2.ets | 40 ++++++++ .../warnings_suppresion_tests/CMakeLists.txt | 29 ++++++ ...ings_suppression_all_warnings-expected.txt | 0 .../warnings_suppression_all_warnings.ets | 84 ++++++++++++++++ ...nings_suppression_begin_end_1-expected.txt | 0 .../warnings_suppression_begin_end_1.ets | 85 ++++++++++++++++ ...nings_suppression_begin_end_2-expected.txt | 13 +++ .../warnings_suppression_begin_end_2.ets | 85 ++++++++++++++++ ...warnings_suppression_nextline-expected.txt | 0 .../warnings_suppression_nextline.ets | 22 +++++ .../werror_tests/CMakeLists.txt | 31 ++++++ .../werror_tests/werror-expected.txt | 1 + .../werror_tests/werror.ets | 36 +++++++ .../runner/options/cli_options.py | 6 ++ .../runner/options/options_es2panda.py | 16 ++- .../runner/plugins/ets/runner_ets.py | 2 + .../runner/plugins/parser/runner_js_parser.py | 13 +++ .../runner/plugins/parser/test_js_parser.py | 10 +- 59 files changed, 1315 insertions(+), 6 deletions(-) create mode 100644 Test.ets create mode 100644 plugins/ets/tests/ets_warnings_tests/CMakeLists.txt create mode 100644 plugins/ets/tests/ets_warnings_tests/all_warnings_tests/1-expected.txt create mode 100644 plugins/ets/tests/ets_warnings_tests/all_warnings_tests/1.ets create mode 100644 plugins/ets/tests/ets_warnings_tests/all_warnings_tests/CMakeLists.txt create mode 100644 plugins/ets/tests/ets_warnings_tests/boost_equal_statements_tests/CMakeLists.txt create mode 100644 plugins/ets/tests/ets_warnings_tests/boost_equal_statements_tests/boost_equal_statements_1-expected.txt create mode 100644 plugins/ets/tests/ets_warnings_tests/boost_equal_statements_tests/boost_equal_statements_1.ets create mode 100644 plugins/ets/tests/ets_warnings_tests/boost_equal_statements_tests/boost_equal_statements_2-expected.txt create mode 100644 plugins/ets/tests/ets_warnings_tests/boost_equal_statements_tests/boost_equal_statements_2.ets create mode 100644 plugins/ets/tests/ets_warnings_tests/implicit_boxing_unboxing_tests/CMakeLists.txt create mode 100644 plugins/ets/tests/ets_warnings_tests/implicit_boxing_unboxing_tests/boxing-expected.txt create mode 100644 plugins/ets/tests/ets_warnings_tests/implicit_boxing_unboxing_tests/boxing.ets create mode 100644 plugins/ets/tests/ets_warnings_tests/prohibit_top_level_statements_tests/CMakeLists.txt create mode 100644 plugins/ets/tests/ets_warnings_tests/prohibit_top_level_statements_tests/prohibit_top_level_statements_1-expected.txt create mode 100644 plugins/ets/tests/ets_warnings_tests/prohibit_top_level_statements_tests/prohibit_top_level_statements_1.ets create mode 100644 plugins/ets/tests/ets_warnings_tests/prohibit_top_level_statements_tests/prohibit_top_level_statements_2-expected.txt create mode 100644 plugins/ets/tests/ets_warnings_tests/prohibit_top_level_statements_tests/prohibit_top_level_statements_2.ets create mode 100644 plugins/ets/tests/ets_warnings_tests/remove_async_tests/1-expected.txt create mode 100644 plugins/ets/tests/ets_warnings_tests/remove_async_tests/1.ets create mode 100644 plugins/ets/tests/ets_warnings_tests/remove_async_tests/CMakeLists.txt create mode 100644 plugins/ets/tests/ets_warnings_tests/remove_async_tests/async-expected.txt create mode 100644 plugins/ets/tests/ets_warnings_tests/remove_async_tests/async.ets create mode 100644 plugins/ets/tests/ets_warnings_tests/remove_lambda_tests/CMakeLists.txt create mode 100644 plugins/ets/tests/ets_warnings_tests/remove_lambda_tests/lambda-expected.txt create mode 100644 plugins/ets/tests/ets_warnings_tests/remove_lambda_tests/lambda.ets create mode 100644 plugins/ets/tests/ets_warnings_tests/remove_lambda_tests/lambda_1-expected.txt create mode 100644 plugins/ets/tests/ets_warnings_tests/remove_lambda_tests/lambda_1.ets create mode 100644 plugins/ets/tests/ets_warnings_tests/suggest_final_tests/CMakeLists.txt create mode 100644 plugins/ets/tests/ets_warnings_tests/suggest_final_tests/suggest_final_for_classes_1-expected.txt create mode 100644 plugins/ets/tests/ets_warnings_tests/suggest_final_tests/suggest_final_for_classes_1.ets create mode 100644 plugins/ets/tests/ets_warnings_tests/suggest_final_tests/suggest_final_for_classes_2-expected.txt create mode 100644 plugins/ets/tests/ets_warnings_tests/suggest_final_tests/suggest_final_for_classes_2.ets create mode 100644 plugins/ets/tests/ets_warnings_tests/suggest_final_tests/suggest_final_for_classes_and_methods_1-expected.txt create mode 100644 plugins/ets/tests/ets_warnings_tests/suggest_final_tests/suggest_final_for_classes_and_methods_1.ets create mode 100644 plugins/ets/tests/ets_warnings_tests/suggest_final_tests/suggest_final_for_classes_and_methods_2-expected.txt create mode 100644 plugins/ets/tests/ets_warnings_tests/suggest_final_tests/suggest_final_for_classes_and_methods_2.ets create mode 100644 plugins/ets/tests/ets_warnings_tests/suggest_final_tests/suggest_final_for_methods_1-expected.txt create mode 100644 plugins/ets/tests/ets_warnings_tests/suggest_final_tests/suggest_final_for_methods_1.ets create mode 100644 plugins/ets/tests/ets_warnings_tests/suggest_final_tests/suggest_final_for_methods_2-expected.txt create mode 100644 plugins/ets/tests/ets_warnings_tests/suggest_final_tests/suggest_final_for_methods_2.ets create mode 100644 plugins/ets/tests/ets_warnings_tests/warnings_suppresion_tests/CMakeLists.txt create mode 100644 plugins/ets/tests/ets_warnings_tests/warnings_suppresion_tests/warnings_suppression_all_warnings-expected.txt create mode 100644 plugins/ets/tests/ets_warnings_tests/warnings_suppresion_tests/warnings_suppression_all_warnings.ets create mode 100644 plugins/ets/tests/ets_warnings_tests/warnings_suppresion_tests/warnings_suppression_begin_end_1-expected.txt create mode 100644 plugins/ets/tests/ets_warnings_tests/warnings_suppresion_tests/warnings_suppression_begin_end_1.ets create mode 100644 plugins/ets/tests/ets_warnings_tests/warnings_suppresion_tests/warnings_suppression_begin_end_2-expected.txt create mode 100644 plugins/ets/tests/ets_warnings_tests/warnings_suppresion_tests/warnings_suppression_begin_end_2.ets create mode 100644 plugins/ets/tests/ets_warnings_tests/warnings_suppresion_tests/warnings_suppression_nextline-expected.txt create mode 100644 plugins/ets/tests/ets_warnings_tests/warnings_suppresion_tests/warnings_suppression_nextline.ets create mode 100644 plugins/ets/tests/ets_warnings_tests/werror_tests/CMakeLists.txt create mode 100644 plugins/ets/tests/ets_warnings_tests/werror_tests/werror-expected.txt create mode 100644 plugins/ets/tests/ets_warnings_tests/werror_tests/werror.ets diff --git a/Test.ets b/Test.ets new file mode 100644 index 000000000..3f597d122 --- /dev/null +++ b/Test.ets @@ -0,0 +1,14 @@ +abstract class B { + abstract foo(): B; +} + +class B1 extends B { + override foo(): B1 { + return new B1(); + } +} + +function main() { + let c: B = new B1(); + c.foo(); +} \ No newline at end of file diff --git a/plugins/ets/tests/CMakeLists.txt b/plugins/ets/tests/CMakeLists.txt index d501b238c..2692e9666 100644 --- a/plugins/ets/tests/CMakeLists.txt +++ b/plugins/ets/tests/CMakeLists.txt @@ -452,6 +452,18 @@ if(PANDA_TEST_COMPILE_STDLIB) add_dependencies(ets_tests ets-compile-stdlib) endif() +set(ETS_WARNINGS_TEST_DEPENDENCIES es2panda verifier) +if(NOT CMAKE_CROSSCOMPILING) + if(PANDA_WITH_ETS) + add_custom_target(ets-warnings-tests DEPENDS ${ETS_WARNINGS_TEST_DEPENDENCIES}) + set (ETS_WARNINGS_RESULT_FOLDER ${CMAKE_BINARY_DIR}/tests/ets-warnings-tests) + set (ETS_WARNINGS_TEST_FOLDER ${CMAKE_SOURCE_DIR}/plugins/ets/tests/ets_warnings_tests) + add_subdirectory(ets_warnings_tests) + add_dependencies(ets_tests ets-warnings-tests) + endif() +endif() + + add_subdirectory(common) add_subdirectory(lookup_by_name) add_subdirectory(ets_test_suite) diff --git a/plugins/ets/tests/ets_warnings_tests/CMakeLists.txt b/plugins/ets/tests/ets_warnings_tests/CMakeLists.txt new file mode 100644 index 000000000..a64e48045 --- /dev/null +++ b/plugins/ets/tests/ets_warnings_tests/CMakeLists.txt @@ -0,0 +1,45 @@ +# Copyright (c) 2021-2022 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. + +if(PANDA_TARGET_ARM32 OR PANDA_ARM64_TESTS_WITH_SANITIZER) + return() +endif() + +set(OPTIONS --parser + --processes=1 + --ets-warnings-tests + ) + +if(PANDA_TARGET_ARM64) + set(OPTIONS --test-list-arch=arm64 ${OPTIONS}) + if(PANDA_QEMU_BUILD) + set(OPTIONS --arm64-qemu ${OPTIONS}) + endif() +endif() + +if(PANDA_TARGET_ARM32) + set(OPTIONS --test-list-arch=arm32 ${OPTIONS}) + if(PANDA_QEMU_BUILD) + set(OPTIONS --arm32-qemu ${OPTIONS}) + endif() +endif() + +add_subdirectory(all_warnings_tests) +add_subdirectory(remove_async_tests) +add_subdirectory(implicit_boxing_unboxing_tests) +add_subdirectory(remove_lambda_tests) +add_subdirectory(boost_equal_statements_tests) +add_subdirectory(suggest_final_tests) +add_subdirectory(prohibit_top_level_statements_tests) +add_subdirectory(werror_tests) +add_subdirectory(warnings_suppresion_tests) \ No newline at end of file diff --git a/plugins/ets/tests/ets_warnings_tests/all_warnings_tests/1-expected.txt b/plugins/ets/tests/ets_warnings_tests/all_warnings_tests/1-expected.txt new file mode 100644 index 000000000..7cdc586d5 --- /dev/null +++ b/plugins/ets/tests/ets_warnings_tests/all_warnings_tests/1-expected.txt @@ -0,0 +1 @@ +ETS Warning: Replace asynchronous function with coroutine. [1.ets:21:1] diff --git a/plugins/ets/tests/ets_warnings_tests/all_warnings_tests/1.ets b/plugins/ets/tests/ets_warnings_tests/all_warnings_tests/1.ets new file mode 100644 index 000000000..856cc0b36 --- /dev/null +++ b/plugins/ets/tests/ets_warnings_tests/all_warnings_tests/1.ets @@ -0,0 +1,24 @@ +/* + * Copyright (c) 2023 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 main() +{ + +} + +async function foo() : Promise +{ + return 5 +} diff --git a/plugins/ets/tests/ets_warnings_tests/all_warnings_tests/CMakeLists.txt b/plugins/ets/tests/ets_warnings_tests/all_warnings_tests/CMakeLists.txt new file mode 100644 index 000000000..d68372258 --- /dev/null +++ b/plugins/ets/tests/ets_warnings_tests/all_warnings_tests/CMakeLists.txt @@ -0,0 +1,29 @@ +# Copyright (c) 2021-2022 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. + + +set (TESTS_RESULT_FOLDER ${ETS_WARNINGS_RESULT_FOLDER}/all-warnings-tests) +set (TESTS_FOLDER ${ETS_WARNINGS_TEST_FOLDER}/all_warnings_tests) +set (ETS_WARNING_FLAG --es2panda-args=--ets-warnings-all) + +add_custom_target(all-warnings-tests DEPENDS ${ETS_WARNINGS_TEST_DEPENDENCIES} + WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR} + COMMAND ${ETS_RUNNER} + ${CMAKE_SOURCE_DIR} + ${OPTIONS} + ${ETS_WARNING_FLAG} + --work-dir ${TESTS_RESULT_FOLDER} + --test-root ${TESTS_FOLDER} + --build-dir ${CMAKE_BINARY_DIR} +) +add_dependencies(ets-warnings-tests all-warnings-tests) \ No newline at end of file diff --git a/plugins/ets/tests/ets_warnings_tests/boost_equal_statements_tests/CMakeLists.txt b/plugins/ets/tests/ets_warnings_tests/boost_equal_statements_tests/CMakeLists.txt new file mode 100644 index 000000000..46296e0db --- /dev/null +++ b/plugins/ets/tests/ets_warnings_tests/boost_equal_statements_tests/CMakeLists.txt @@ -0,0 +1,29 @@ +# Copyright (c) 2021-2022 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. + + +set (TESTS_RESULT_FOLDER ${ETS_WARNINGS_RESULT_FOLDER}/boost-equal-statements-tests) +set (TESTS_FOLDER ${ETS_WARNINGS_TEST_FOLDER}/boost_equal_statements_tests) +set (ETS_WARNING_FLAG --es2panda-args=--ets-boost-equality-statement) + +add_custom_target(boost-equal-statements-tests DEPENDS ${ETS_WARNINGS_TEST_DEPENDENCIES} + WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR} + COMMAND ${ETS_RUNNER} + ${CMAKE_SOURCE_DIR} + ${OPTIONS} + ${ETS_WARNING_FLAG} + --work-dir ${TESTS_RESULT_FOLDER} + --test-root ${TESTS_FOLDER} + --build-dir ${CMAKE_BINARY_DIR} +) +add_dependencies(ets-warnings-tests boost-equal-statements-tests) \ No newline at end of file diff --git a/plugins/ets/tests/ets_warnings_tests/boost_equal_statements_tests/boost_equal_statements_1-expected.txt b/plugins/ets/tests/ets_warnings_tests/boost_equal_statements_tests/boost_equal_statements_1-expected.txt new file mode 100644 index 000000000..edd435dcd --- /dev/null +++ b/plugins/ets/tests/ets_warnings_tests/boost_equal_statements_tests/boost_equal_statements_1-expected.txt @@ -0,0 +1 @@ +ETS Warning: Boost Equality Statement. Change sides of binary expression. [boost_equal_statements_1.ets:18:21] diff --git a/plugins/ets/tests/ets_warnings_tests/boost_equal_statements_tests/boost_equal_statements_1.ets b/plugins/ets/tests/ets_warnings_tests/boost_equal_statements_tests/boost_equal_statements_1.ets new file mode 100644 index 000000000..7cec9de62 --- /dev/null +++ b/plugins/ets/tests/ets_warnings_tests/boost_equal_statements_tests/boost_equal_statements_1.ets @@ -0,0 +1,18 @@ +/* + * Copyright (c) 2023 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. + */ + +let x: Int = new Int(5); + +let flag: boolean = x == null; // Suggest switch sides \ No newline at end of file diff --git a/plugins/ets/tests/ets_warnings_tests/boost_equal_statements_tests/boost_equal_statements_2-expected.txt b/plugins/ets/tests/ets_warnings_tests/boost_equal_statements_tests/boost_equal_statements_2-expected.txt new file mode 100644 index 000000000..357d2dd32 --- /dev/null +++ b/plugins/ets/tests/ets_warnings_tests/boost_equal_statements_tests/boost_equal_statements_2-expected.txt @@ -0,0 +1,5 @@ +ETS Warning: Boost Equality Statement. Change sides of binary expression. [boost_equal_statements_2.ets:18:21] +ETS Warning: Boost Equality Statement. Change sides of binary expression. [boost_equal_statements_2.ets:20:5] +ETS Warning: Boost Equality Statement. Change sides of binary expression. [boost_equal_statements_2.ets:25:25] +ETS Warning: Boost Equality Statement. Change sides of binary expression. [boost_equal_statements_2.ets:27:9] +ETS Warning: Boost Equality Statement. Change sides of binary expression. [boost_equal_statements_2.ets:35:13] diff --git a/plugins/ets/tests/ets_warnings_tests/boost_equal_statements_tests/boost_equal_statements_2.ets b/plugins/ets/tests/ets_warnings_tests/boost_equal_statements_tests/boost_equal_statements_2.ets new file mode 100644 index 000000000..c6ae02b96 --- /dev/null +++ b/plugins/ets/tests/ets_warnings_tests/boost_equal_statements_tests/boost_equal_statements_2.ets @@ -0,0 +1,39 @@ +/* + * Copyright (c) 2023 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. + */ + +let x: Int = new Int(5); + +let flag: boolean = x == null; // Suggest switch sides + +if (x == null) { // Suggest switch sides + console.println("Hello, World!"); +} + +function foo(): void { + let flag: boolean = x == null; // Suggest switch sides + + if (x == null) { // Suggest switch sides + console.println("Hello, World!"); + } +} + +class A { + flag: boolean = null == null; // Not (!!!) suggest switch sides, both are 'null' + greeting(): void { + if (x == null) { // Suggest switch sides + console.println("Hello, World!"); + } + } +} \ No newline at end of file diff --git a/plugins/ets/tests/ets_warnings_tests/implicit_boxing_unboxing_tests/CMakeLists.txt b/plugins/ets/tests/ets_warnings_tests/implicit_boxing_unboxing_tests/CMakeLists.txt new file mode 100644 index 000000000..8098e6b5b --- /dev/null +++ b/plugins/ets/tests/ets_warnings_tests/implicit_boxing_unboxing_tests/CMakeLists.txt @@ -0,0 +1,29 @@ +# Copyright (c) 2021-2022 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. + + +set (TESTS_RESULT_FOLDER ${ETS_WARNINGS_RESULT_FOLDER}/implicit-boxing-unboxing-tests) +set (TESTS_FOLDER ${ETS_WARNINGS_TEST_FOLDER}/implicit_boxing_unboxing_tests) +set (ETS_WARNING_FLAG --es2panda-args=--ets-implicit-boxing-unboxing) + +add_custom_target(implicit-boxing-unboxing-tests DEPENDS ${ETS_WARNINGS_TEST_DEPENDENCIES} + WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR} + COMMAND ${ETS_RUNNER} + ${CMAKE_SOURCE_DIR} + ${OPTIONS} + ${ETS_WARNING_FLAG} + --work-dir ${TESTS_RESULT_FOLDER} + --test-root ${TESTS_FOLDER} + --build-dir ${CMAKE_BINARY_DIR} +) +add_dependencies(ets-warnings-tests implicit-boxing-unboxing-tests) \ No newline at end of file diff --git a/plugins/ets/tests/ets_warnings_tests/implicit_boxing_unboxing_tests/boxing-expected.txt b/plugins/ets/tests/ets_warnings_tests/implicit_boxing_unboxing_tests/boxing-expected.txt new file mode 100644 index 000000000..56ecb1790 --- /dev/null +++ b/plugins/ets/tests/ets_warnings_tests/implicit_boxing_unboxing_tests/boxing-expected.txt @@ -0,0 +1,42 @@ +ETS Warning: Implicit Boxing to Int in Assignment Expression. [boxing.ets:26:9] +ETS Warning: Implicit Unboxing to int in Binary Expression. [boxing.ets:26:9] +ETS Warning: Implicit Boxing to Int in Assignment Expression. [boxing.ets:27:9] +ETS Warning: Implicit Unboxing to int in Binary Expression. [boxing.ets:27:9] +ETS Warning: Implicit Boxing to Char in Variable Declaration. [boxing.ets:33:15] +ETS Warning: Implicit Boxing to Float in Variable Declaration. [boxing.ets:34:21] +ETS Warning: Implicit Boxing to Double in Variable Declaration. [boxing.ets:35:22] +ETS Warning: Implicit Boxing to Short in Variable Declaration. [boxing.ets:36:21] +ETS Warning: Implicit Boxing to Long in Variable Declaration. [boxing.ets:37:20] +ETS Warning: Implicit Boxing to Int in Variable Declaration. [boxing.ets:38:19] +ETS Warning: Implicit Boxing to Byte in Variable Declaration. [boxing.ets:39:20] +ETS Warning: Implicit Boxing to Boolean in Variable Declaration. [boxing.ets:40:23] +ETS Warning: Implicit Unboxing to char in Variable Declaration. [boxing.ets:42:20] +ETS Warning: Implicit Unboxing to float in Variable Declaration. [boxing.ets:43:22] +ETS Warning: Implicit Unboxing to double in Variable Declaration. [boxing.ets:44:23] +ETS Warning: Implicit Unboxing to short in Variable Declaration. [boxing.ets:45:22] +ETS Warning: Implicit Unboxing to long in Variable Declaration. [boxing.ets:46:21] +ETS Warning: Implicit Unboxing to int in Variable Declaration. [boxing.ets:47:20] +ETS Warning: Implicit Unboxing to byte in Variable Declaration. [boxing.ets:48:21] +ETS Warning: Implicit Unboxing to boolean in Variable Declaration. [boxing.ets:49:24] +ETS Warning: Implicit Unboxing to int in Assignment Expression. [boxing.ets:54:11] +ETS Warning: Implicit Boxing to Int in Call Method/Function. [boxing.ets:54:15] +ETS Warning: Implicit Unboxing to int in Assignment Expression. [boxing.ets:56:11] +ETS Warning: Implicit Boxing to Int in Call Method/Function. [boxing.ets:56:17] +ETS Warning: Implicit Unboxing to int in Switch-case Statement. [boxing.ets:58:12] +ETS Warning: Implicit Boxing to Int in Variable Declaration. [boxing.ets:66:21] +ETS Warning: Implicit Unboxing to int in Unary Expression. [boxing.ets:66:22] +ETS Warning: Implicit Unboxing to double in Assignment Expression. [boxing.ets:68:11] +ETS Warning: Implicit Boxing to Double in Assignment Expression. [boxing.ets:69:10] +ETS Warning: Implicit Boxing to Int in Update Expression. [boxing.ets:71:5] +ETS Warning: Implicit Unboxing to int in Update Expression. [boxing.ets:71:5] +ETS Warning: Implicit Boxing to Int in Update Expression. [boxing.ets:72:5] +ETS Warning: Implicit Unboxing to int in Update Expression. [boxing.ets:72:5] +ETS Warning: Implicit Unboxing to int in Assignment Expression. [boxing.ets:73:5] +ETS Warning: Implicit Unboxing to int in Assignment Expression. [boxing.ets:74:5] +ETS Warning: Implicit Unboxing to int in Member Expression. [boxing.ets:76:9] +ETS Warning: Implicit Unboxing to int in Binary Expression. [boxing.ets:78:5] +ETS Warning: Implicit Unboxing to int in Binary Expression. [boxing.ets:81:8] +ETS Warning: Implicit Unboxing to int in Binary Expression. [boxing.ets:82:5] +ETS Warning: Implicit Unboxing to int in Binary Expression. [boxing.ets:83:13] +ETS Warning: Implicit Boxing to Int in Update Expression. [boxing.ets:83:22] +ETS Warning: Implicit Unboxing to int in Update Expression. [boxing.ets:83:22] diff --git a/plugins/ets/tests/ets_warnings_tests/implicit_boxing_unboxing_tests/boxing.ets b/plugins/ets/tests/ets_warnings_tests/implicit_boxing_unboxing_tests/boxing.ets new file mode 100644 index 000000000..2c64a12dd --- /dev/null +++ b/plugins/ets/tests/ets_warnings_tests/implicit_boxing_unboxing_tests/boxing.ets @@ -0,0 +1,98 @@ +/* + * Copyright (c) 2023 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 +{ + a(b : Int) : Int + { + return b + } +} + +function foo(a : Int) : Int +{ + a = a + 1; + a = a - 1; + return a +} + +function main() +{ +let i: Char = 15 as char + let i1: Float = 5.0 + let i2: Double = 5.0 + let i3: Short = 5 + let i4: Long = 5 as long + let i5: Int = 5 + let i6: Byte = 5 as byte + let i7: Boolean = true + + let ui: char = i + let ui1: float = i1 + let ui2: double = i2 + let ui3: short = i3 + let ui4: long = i4 + let ui5: int = i5 + let ui6: byte = i6 + let ui7: boolean = i7 + + + + + ui5 = foo(ui5) + let a_1 : A = new A + ui5 = a_1.a(ui5) + console.println(ui5) + switch(i5) + { + case 5: + break; + default: + break; + } + + let uni1: Int = ~i5 + + ui2 = i2 + i2 = ui2 + + i5++ + i5-- + i5 += 1 + i5 *= 1 + let ar1: int[] = [1, 2, 3, 4, 5, 6, 7] + ar1[i5] + + i5 << 1 + i5 as int + + if(i5 > 3) + i5 & 1 + for(i5; i5 < 10; i5++) + { + + } + + switch((i5 as int)) + { + case 5: + break; + default: + break; + } + + let ni5 : Int = 5 as Int + let nui5 : int = ni5 as int +} diff --git a/plugins/ets/tests/ets_warnings_tests/prohibit_top_level_statements_tests/CMakeLists.txt b/plugins/ets/tests/ets_warnings_tests/prohibit_top_level_statements_tests/CMakeLists.txt new file mode 100644 index 000000000..43a95bed1 --- /dev/null +++ b/plugins/ets/tests/ets_warnings_tests/prohibit_top_level_statements_tests/CMakeLists.txt @@ -0,0 +1,29 @@ +# Copyright (c) 2021-2022 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. + + +set (TESTS_RESULT_FOLDER ${ETS_WARNINGS_RESULT_FOLDER}/prohibit-top-level-statements-tests) +set (TESTS_FOLDER ${ETS_WARNINGS_TEST_FOLDER}/prohibit_top_level_statements_tests) +set (ETS_WARNING_FLAG --es2panda-args=--ets-phohibit-top-level-statements) + +add_custom_target(prohibit-top-level-statements-tests DEPENDS ${ETS_WARNINGS_TEST_DEPENDENCIES} + WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR} + COMMAND ${ETS_RUNNER} + ${CMAKE_SOURCE_DIR} + ${OPTIONS} + ${ETS_WARNING_FLAG} + --work-dir ${TESTS_RESULT_FOLDER} + --test-root ${TESTS_FOLDER} + --build-dir ${CMAKE_BINARY_DIR} +) +add_dependencies(ets-warnings-tests prohibit-top-level-statements-tests) \ No newline at end of file diff --git a/plugins/ets/tests/ets_warnings_tests/prohibit_top_level_statements_tests/prohibit_top_level_statements_1-expected.txt b/plugins/ets/tests/ets_warnings_tests/prohibit_top_level_statements_tests/prohibit_top_level_statements_1-expected.txt new file mode 100644 index 000000000..a3bcda497 --- /dev/null +++ b/plugins/ets/tests/ets_warnings_tests/prohibit_top_level_statements_tests/prohibit_top_level_statements_1-expected.txt @@ -0,0 +1,4 @@ +ETS Warning: Prohibit top-level statements. [prohibit_top_level_statements_1.ets:16:1] +ETS Warning: Prohibit top-level statements. [prohibit_top_level_statements_1.ets:18:5] +ETS Warning: Prohibit top-level statements. [prohibit_top_level_statements_1.ets:19:1] +ETS Warning: Prohibit top-level statements. [prohibit_top_level_statements_1.ets:21:5] diff --git a/plugins/ets/tests/ets_warnings_tests/prohibit_top_level_statements_tests/prohibit_top_level_statements_1.ets b/plugins/ets/tests/ets_warnings_tests/prohibit_top_level_statements_tests/prohibit_top_level_statements_1.ets new file mode 100644 index 000000000..612bcb839 --- /dev/null +++ b/plugins/ets/tests/ets_warnings_tests/prohibit_top_level_statements_tests/prohibit_top_level_statements_1.ets @@ -0,0 +1,21 @@ +/* + * Copyright (c) 2023 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. + */ + +console.println("Hello, World!"); + +let x: int = 5; +x+=2 + +let z: float = 3.0; \ No newline at end of file diff --git a/plugins/ets/tests/ets_warnings_tests/prohibit_top_level_statements_tests/prohibit_top_level_statements_2-expected.txt b/plugins/ets/tests/ets_warnings_tests/prohibit_top_level_statements_tests/prohibit_top_level_statements_2-expected.txt new file mode 100644 index 000000000..a6ba5e3f2 --- /dev/null +++ b/plugins/ets/tests/ets_warnings_tests/prohibit_top_level_statements_tests/prohibit_top_level_statements_2-expected.txt @@ -0,0 +1,5 @@ +ETS Warning: Prohibit top-level statements. [prohibit_top_level_statements_2.ets:16:5] +ETS Warning: Prohibit top-level statements. [prohibit_top_level_statements_2.ets:18:5] +ETS Warning: Prohibit top-level statements. [prohibit_top_level_statements_2.ets:20:1] +ETS Warning: Prohibit top-level statements. [prohibit_top_level_statements_2.ets:24:1] +ETS Warning: Prohibit top-level statements. [prohibit_top_level_statements_2.ets:28:1] diff --git a/plugins/ets/tests/ets_warnings_tests/prohibit_top_level_statements_tests/prohibit_top_level_statements_2.ets b/plugins/ets/tests/ets_warnings_tests/prohibit_top_level_statements_tests/prohibit_top_level_statements_2.ets new file mode 100644 index 000000000..cfcf75c3a --- /dev/null +++ b/plugins/ets/tests/ets_warnings_tests/prohibit_top_level_statements_tests/prohibit_top_level_statements_2.ets @@ -0,0 +1,41 @@ +/* + * Copyright (c) 2023 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. + */ + +let x: int = 5; + +let z: float = 3.0; + +while (x < 10) { + x = x + 1; +} + +for (z = 3.0; z < 10; z++) { + console.println("Hello!"); +} + +if (x == z) { + x += 4; +} + +class A { + k: float = 5.0; + foo(): int { + return 10; + } +} + +function main(): int { + return 0; +} \ No newline at end of file diff --git a/plugins/ets/tests/ets_warnings_tests/remove_async_tests/1-expected.txt b/plugins/ets/tests/ets_warnings_tests/remove_async_tests/1-expected.txt new file mode 100644 index 000000000..7cdc586d5 --- /dev/null +++ b/plugins/ets/tests/ets_warnings_tests/remove_async_tests/1-expected.txt @@ -0,0 +1 @@ +ETS Warning: Replace asynchronous function with coroutine. [1.ets:21:1] diff --git a/plugins/ets/tests/ets_warnings_tests/remove_async_tests/1.ets b/plugins/ets/tests/ets_warnings_tests/remove_async_tests/1.ets new file mode 100644 index 000000000..856cc0b36 --- /dev/null +++ b/plugins/ets/tests/ets_warnings_tests/remove_async_tests/1.ets @@ -0,0 +1,24 @@ +/* + * Copyright (c) 2023 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 main() +{ + +} + +async function foo() : Promise +{ + return 5 +} diff --git a/plugins/ets/tests/ets_warnings_tests/remove_async_tests/CMakeLists.txt b/plugins/ets/tests/ets_warnings_tests/remove_async_tests/CMakeLists.txt new file mode 100644 index 000000000..7284b8888 --- /dev/null +++ b/plugins/ets/tests/ets_warnings_tests/remove_async_tests/CMakeLists.txt @@ -0,0 +1,29 @@ +# Copyright (c) 2021-2022 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. + + +set (TESTS_RESULT_FOLDER ${ETS_WARNINGS_RESULT_FOLDER}/remove-async-tests) +set (TESTS_FOLDER ${ETS_WARNINGS_TEST_FOLDER}/remove_async_tests) +set (ETS_WARNING_FLAG --es2panda-args=--ets-remove-async) + +add_custom_target(remove-async-tests DEPENDS ${ETS_WARNINGS_TEST_DEPENDENCIES} + WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR} + COMMAND ${ETS_RUNNER} + ${CMAKE_SOURCE_DIR} + ${OPTIONS} + ${ETS_WARNING_FLAG} + --work-dir ${TESTS_RESULT_FOLDER} + --test-root ${TESTS_FOLDER} + --build-dir ${CMAKE_BINARY_DIR} +) +add_dependencies(ets-warnings-tests remove-async-tests) \ No newline at end of file diff --git a/plugins/ets/tests/ets_warnings_tests/remove_async_tests/async-expected.txt b/plugins/ets/tests/ets_warnings_tests/remove_async_tests/async-expected.txt new file mode 100644 index 000000000..473857d0e --- /dev/null +++ b/plugins/ets/tests/ets_warnings_tests/remove_async_tests/async-expected.txt @@ -0,0 +1,2 @@ +ETS Warning: Replace asynchronous function with coroutine. [async.ets:26:1] +ETS Warning: Replace asynchronous function with coroutine. [async.ets:20:5] diff --git a/plugins/ets/tests/ets_warnings_tests/remove_async_tests/async.ets b/plugins/ets/tests/ets_warnings_tests/remove_async_tests/async.ets new file mode 100644 index 000000000..cc4808845 --- /dev/null +++ b/plugins/ets/tests/ets_warnings_tests/remove_async_tests/async.ets @@ -0,0 +1,44 @@ +/* + * Copyright (c) 2023 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. + */ + +let num_of_cycles = 1 + +class A +{ + async foo() : Promise + { + return "5" + } +} + +async function foo_1() : Promise +{ + return "5" +} + +function bench_body() : void +{ + let a = new A + for(let i = 0; i < num_of_cycles; i++) + { + let promise = a.foo() + promise = foo_1() + } +} + +function main() +{ + bench_body() +} diff --git a/plugins/ets/tests/ets_warnings_tests/remove_lambda_tests/CMakeLists.txt b/plugins/ets/tests/ets_warnings_tests/remove_lambda_tests/CMakeLists.txt new file mode 100644 index 000000000..3a4eb0be4 --- /dev/null +++ b/plugins/ets/tests/ets_warnings_tests/remove_lambda_tests/CMakeLists.txt @@ -0,0 +1,29 @@ +# Copyright (c) 2021-2022 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. + + +set (TESTS_RESULT_FOLDER ${ETS_WARNINGS_RESULT_FOLDER}/remove-lambda-tests) +set (TESTS_FOLDER ${ETS_WARNINGS_TEST_FOLDER}/remove_lambda_tests) +set (ETS_WARNING_FLAG --es2panda-args=--ets-remove-lambda) + +add_custom_target(remove-lambda-tests DEPENDS ${ETS_WARNINGS_TEST_DEPENDENCIES} + WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR} + COMMAND ${ETS_RUNNER} + ${CMAKE_SOURCE_DIR} + ${OPTIONS} + ${ETS_WARNING_FLAG} + --work-dir ${TESTS_RESULT_FOLDER} + --test-root ${TESTS_FOLDER} + --build-dir ${CMAKE_BINARY_DIR} +) +add_dependencies(ets-warnings-tests remove-lambda-tests) \ No newline at end of file diff --git a/plugins/ets/tests/ets_warnings_tests/remove_lambda_tests/lambda-expected.txt b/plugins/ets/tests/ets_warnings_tests/remove_lambda_tests/lambda-expected.txt new file mode 100644 index 000000000..ab8d7f6fa --- /dev/null +++ b/plugins/ets/tests/ets_warnings_tests/remove_lambda_tests/lambda-expected.txt @@ -0,0 +1 @@ +ETS Warning: Replace the lambda function with a regular function. [lambda.ets:18:11] diff --git a/plugins/ets/tests/ets_warnings_tests/remove_lambda_tests/lambda.ets b/plugins/ets/tests/ets_warnings_tests/remove_lambda_tests/lambda.ets new file mode 100644 index 000000000..054d3c867 --- /dev/null +++ b/plugins/ets/tests/ets_warnings_tests/remove_lambda_tests/lambda.ets @@ -0,0 +1,19 @@ +/* + * Copyright (c) 2023 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 main() { + let foo: (i : int) => int + foo = (i : int): int => {return i+1} +} diff --git a/plugins/ets/tests/ets_warnings_tests/remove_lambda_tests/lambda_1-expected.txt b/plugins/ets/tests/ets_warnings_tests/remove_lambda_tests/lambda_1-expected.txt new file mode 100644 index 000000000..ae3ea311a --- /dev/null +++ b/plugins/ets/tests/ets_warnings_tests/remove_lambda_tests/lambda_1-expected.txt @@ -0,0 +1,3 @@ +ETS Warning: Replace the lambda function with a regular function. [lambda_1.ets:18:11] +ETS Warning: Replace the lambda function with a regular function. [lambda_1.ets:20:11] +ETS Warning: Replace the lambda function with a regular function. [lambda_1.ets:22:11] diff --git a/plugins/ets/tests/ets_warnings_tests/remove_lambda_tests/lambda_1.ets b/plugins/ets/tests/ets_warnings_tests/remove_lambda_tests/lambda_1.ets new file mode 100644 index 000000000..cc510fa06 --- /dev/null +++ b/plugins/ets/tests/ets_warnings_tests/remove_lambda_tests/lambda_1.ets @@ -0,0 +1,24 @@ +/* + * Copyright (c) 2023 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 main() { + let foo: (i : int) => int + foo = (i : int): int => {return i+1} + + foo = (i : int): int => {return i+1} + + foo = (i : int): int => {return i+1} + +} diff --git a/plugins/ets/tests/ets_warnings_tests/suggest_final_tests/CMakeLists.txt b/plugins/ets/tests/ets_warnings_tests/suggest_final_tests/CMakeLists.txt new file mode 100644 index 000000000..cd5356408 --- /dev/null +++ b/plugins/ets/tests/ets_warnings_tests/suggest_final_tests/CMakeLists.txt @@ -0,0 +1,29 @@ +# Copyright (c) 2021-2022 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. + + +set (TESTS_RESULT_FOLDER ${ETS_WARNINGS_RESULT_FOLDER}/suggest-final-tests) +set (TESTS_FOLDER ${ETS_WARNINGS_TEST_FOLDER}/suggest_final_tests) +set (ETS_WARNING_FLAG --es2panda-args=--ets-suggest-final) + +add_custom_target(suggest-final-tests DEPENDS ${ETS_WARNINGS_TEST_DEPENDENCIES} + WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR} + COMMAND ${ETS_RUNNER} + ${CMAKE_SOURCE_DIR} + ${OPTIONS} + ${ETS_WARNING_FLAG} + --work-dir ${TESTS_RESULT_FOLDER} + --test-root ${TESTS_FOLDER} + --build-dir ${CMAKE_BINARY_DIR} +) +add_dependencies(ets-warnings-tests suggest-final-tests) \ No newline at end of file diff --git a/plugins/ets/tests/ets_warnings_tests/suggest_final_tests/suggest_final_for_classes_1-expected.txt b/plugins/ets/tests/ets_warnings_tests/suggest_final_tests/suggest_final_for_classes_1-expected.txt new file mode 100644 index 000000000..85835c19e --- /dev/null +++ b/plugins/ets/tests/ets_warnings_tests/suggest_final_tests/suggest_final_for_classes_1-expected.txt @@ -0,0 +1 @@ +ETS Warning: Suggest 'final' modifier for class. [suggest_final_for_classes_1.ets:15:7] diff --git a/plugins/ets/tests/ets_warnings_tests/suggest_final_tests/suggest_final_for_classes_1.ets b/plugins/ets/tests/ets_warnings_tests/suggest_final_tests/suggest_final_for_classes_1.ets new file mode 100644 index 000000000..10a8fba25 --- /dev/null +++ b/plugins/ets/tests/ets_warnings_tests/suggest_final_tests/suggest_final_for_classes_1.ets @@ -0,0 +1,17 @@ +/* + * Copyright (c) 2023 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 I { // Suggest final + +} \ No newline at end of file diff --git a/plugins/ets/tests/ets_warnings_tests/suggest_final_tests/suggest_final_for_classes_2-expected.txt b/plugins/ets/tests/ets_warnings_tests/suggest_final_tests/suggest_final_for_classes_2-expected.txt new file mode 100644 index 000000000..07ba2ee83 --- /dev/null +++ b/plugins/ets/tests/ets_warnings_tests/suggest_final_tests/suggest_final_for_classes_2-expected.txt @@ -0,0 +1 @@ +ETS Warning: Suggest 'final' modifier for class. [suggest_final_for_classes_2.ets:21:7] diff --git a/plugins/ets/tests/ets_warnings_tests/suggest_final_tests/suggest_final_for_classes_2.ets b/plugins/ets/tests/ets_warnings_tests/suggest_final_tests/suggest_final_for_classes_2.ets new file mode 100644 index 000000000..27c0ceffd --- /dev/null +++ b/plugins/ets/tests/ets_warnings_tests/suggest_final_tests/suggest_final_for_classes_2.ets @@ -0,0 +1,25 @@ +/* + * Copyright (c) 2023 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 I { // No final - inheritance +} + +final class A extends I { // No final - is final already +} + +class B { // Suggest final +} + +abstract class K { // No final - abstract +} \ No newline at end of file diff --git a/plugins/ets/tests/ets_warnings_tests/suggest_final_tests/suggest_final_for_classes_and_methods_1-expected.txt b/plugins/ets/tests/ets_warnings_tests/suggest_final_tests/suggest_final_for_classes_and_methods_1-expected.txt new file mode 100644 index 000000000..b5b9c7ac9 --- /dev/null +++ b/plugins/ets/tests/ets_warnings_tests/suggest_final_tests/suggest_final_for_classes_and_methods_1-expected.txt @@ -0,0 +1,6 @@ +ETS Warning: Suggest 'final' modifier for class. [suggest_final_for_classes_and_methods_1.ets:21:7] +ETS Warning: Suggest 'final' modifier for method. [suggest_final_for_classes_and_methods_1.ets:22:14] +ETS Warning: Suggest 'final' modifier for method. [suggest_final_for_classes_and_methods_1.ets:23:16] +ETS Warning: Suggest 'final' modifier for class. [suggest_final_for_classes_and_methods_1.ets:28:7] +ETS Warning: Suggest 'final' modifier for method. [suggest_final_for_classes_and_methods_1.ets:29:8] +ETS Warning: Suggest 'final' modifier for class. [suggest_final_for_classes_and_methods_1.ets:34:7] diff --git a/plugins/ets/tests/ets_warnings_tests/suggest_final_tests/suggest_final_for_classes_and_methods_1.ets b/plugins/ets/tests/ets_warnings_tests/suggest_final_tests/suggest_final_for_classes_and_methods_1.ets new file mode 100644 index 000000000..f98b67163 --- /dev/null +++ b/plugins/ets/tests/ets_warnings_tests/suggest_final_tests/suggest_final_for_classes_and_methods_1.ets @@ -0,0 +1,36 @@ +/* + * Copyright (c) 2023 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 I { // No final - inheritance + fn(): String { // No final - overridden + return "hehe" + }; +} + +class A extends I { // Suggest final + something(): void {} // Suggest final + override fn(): String { // Suggest final + return ""; + } +} + +class B { // Suggest final + yoo(): String { // Suggest final + return "yo"; + } +} + +class K { // Suggest final + final koko(): void {} // No final - already final +} \ No newline at end of file diff --git a/plugins/ets/tests/ets_warnings_tests/suggest_final_tests/suggest_final_for_classes_and_methods_2-expected.txt b/plugins/ets/tests/ets_warnings_tests/suggest_final_tests/suggest_final_for_classes_and_methods_2-expected.txt new file mode 100644 index 000000000..61a861722 --- /dev/null +++ b/plugins/ets/tests/ets_warnings_tests/suggest_final_tests/suggest_final_for_classes_and_methods_2-expected.txt @@ -0,0 +1,6 @@ +ETS Warning: Suggest 'final' modifier for class. [suggest_final_for_classes_and_methods_2.ets:21:7] +ETS Warning: Suggest 'final' modifier for method. [suggest_final_for_classes_and_methods_2.ets:22:14] +ETS Warning: Suggest 'final' modifier for method. [suggest_final_for_classes_and_methods_2.ets:23:17] +ETS Warning: Suggest 'final' modifier for class. [suggest_final_for_classes_and_methods_2.ets:28:7] +ETS Warning: Suggest 'final' modifier for method. [suggest_final_for_classes_and_methods_2.ets:29:8] +ETS Warning: Suggest 'final' modifier for class. [suggest_final_for_classes_and_methods_2.ets:34:7] diff --git a/plugins/ets/tests/ets_warnings_tests/suggest_final_tests/suggest_final_for_classes_and_methods_2.ets b/plugins/ets/tests/ets_warnings_tests/suggest_final_tests/suggest_final_for_classes_and_methods_2.ets new file mode 100644 index 000000000..d7b7d9394 --- /dev/null +++ b/plugins/ets/tests/ets_warnings_tests/suggest_final_tests/suggest_final_for_classes_and_methods_2.ets @@ -0,0 +1,36 @@ +/* + * Copyright (c) 2023 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 I { // No final - inheritance + fn(): String { // No final - overridden + return "hehe" + }; +} + +class A extends I { // Suggest final + something(): void {} // Suggest final + override fn(): String { + return ""; + } +} + +class B { // Suggest final + yoo(): String { // Suggest final + return "yo"; + } +} + +class K { // Suggest final + final koko(): void {} // No final - already final +} \ No newline at end of file diff --git a/plugins/ets/tests/ets_warnings_tests/suggest_final_tests/suggest_final_for_methods_1-expected.txt b/plugins/ets/tests/ets_warnings_tests/suggest_final_tests/suggest_final_for_methods_1-expected.txt new file mode 100644 index 000000000..e69de29bb diff --git a/plugins/ets/tests/ets_warnings_tests/suggest_final_tests/suggest_final_for_methods_1.ets b/plugins/ets/tests/ets_warnings_tests/suggest_final_tests/suggest_final_for_methods_1.ets new file mode 100644 index 000000000..c8ce44213 --- /dev/null +++ b/plugins/ets/tests/ets_warnings_tests/suggest_final_tests/suggest_final_for_methods_1.ets @@ -0,0 +1,29 @@ +/* + * Copyright (c) 2023 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 I { // No final - inheritance + aaa(): String { // No final - overrided + return "a" + }; +} + +final class A extends I { // No final - is already final + override aaa(): String { // No final - methods of final class are already final + return ""; + } +} + +function main(): int { // No final - ETSGLBAL + return 0; +} \ No newline at end of file diff --git a/plugins/ets/tests/ets_warnings_tests/suggest_final_tests/suggest_final_for_methods_2-expected.txt b/plugins/ets/tests/ets_warnings_tests/suggest_final_tests/suggest_final_for_methods_2-expected.txt new file mode 100644 index 000000000..e69de29bb diff --git a/plugins/ets/tests/ets_warnings_tests/suggest_final_tests/suggest_final_for_methods_2.ets b/plugins/ets/tests/ets_warnings_tests/suggest_final_tests/suggest_final_for_methods_2.ets new file mode 100644 index 000000000..e44a75f2f --- /dev/null +++ b/plugins/ets/tests/ets_warnings_tests/suggest_final_tests/suggest_final_for_methods_2.ets @@ -0,0 +1,40 @@ +/* + * Copyright (c) 2023 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 I { // No final - inheritance + aaa(): String { // No final - overrided + return "a"; + }; +} + +final class A extends I { // No final - is already final + something(): void {}; // // No final - methods of final class are already final + override aaa(): String { // // No final - methods of final class are already final + return ""; + } +} + +final class K { // No final - is already final + static foo(): int { // No final - static, methods of final class are already final + return 10; + }; +} + +interface H { + fee(): void {}; // No final - abstract +} + +function main(): int { // No final - ETSGLOBAL + return 0; +} \ No newline at end of file diff --git a/plugins/ets/tests/ets_warnings_tests/warnings_suppresion_tests/CMakeLists.txt b/plugins/ets/tests/ets_warnings_tests/warnings_suppresion_tests/CMakeLists.txt new file mode 100644 index 000000000..3776d2cfa --- /dev/null +++ b/plugins/ets/tests/ets_warnings_tests/warnings_suppresion_tests/CMakeLists.txt @@ -0,0 +1,29 @@ +# Copyright (c) 2021-2022 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. + + +set (TESTS_RESULT_FOLDER ${ETS_WARNINGS_RESULT_FOLDER}/warnings-suppresion-tests) +set (TESTS_FOLDER ${ETS_WARNINGS_TEST_FOLDER}/warnings_suppresion_tests) +set (ETS_WARNING_FLAG --es2panda-args=--ets-warnings-all) + +add_custom_target(warnings-suppresion-tests DEPENDS ${ETS_WARNINGS_TEST_DEPENDENCIES} + WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR} + COMMAND ${ETS_RUNNER} + ${CMAKE_SOURCE_DIR} + ${OPTIONS} + ${ETS_WARNING_FLAG} + --work-dir ${TESTS_RESULT_FOLDER} + --test-root ${TESTS_FOLDER} + --build-dir ${CMAKE_BINARY_DIR} +) +add_dependencies(ets-warnings-tests warnings-suppresion-tests) \ No newline at end of file diff --git a/plugins/ets/tests/ets_warnings_tests/warnings_suppresion_tests/warnings_suppression_all_warnings-expected.txt b/plugins/ets/tests/ets_warnings_tests/warnings_suppresion_tests/warnings_suppression_all_warnings-expected.txt new file mode 100644 index 000000000..e69de29bb diff --git a/plugins/ets/tests/ets_warnings_tests/warnings_suppresion_tests/warnings_suppression_all_warnings.ets b/plugins/ets/tests/ets_warnings_tests/warnings_suppresion_tests/warnings_suppression_all_warnings.ets new file mode 100644 index 000000000..c6309cc65 --- /dev/null +++ b/plugins/ets/tests/ets_warnings_tests/warnings_suppresion_tests/warnings_suppression_all_warnings.ets @@ -0,0 +1,84 @@ +/* + * Copyright (c) 2023 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. + */ + +// ETSNOLINT-NEXTLINE(ets-phohibit-top-level-statements) +let num_of_cycles = 1 + +if (num_of_cycles == 1) { // ETSNOLINT(ets-suggest-final,ets-phohibit-top-level-statements) + num_of_cycles += 1; +} + +class A // ETSNOLINT(ets-suggest-final) +{ + async foo() : Promise // ETSNOLINT(ets-remove-async) + { + return "5"; + } +} + + +async function foo_1() : Promise // ETSNOLINT(ets-remove-async) +{ + return "5"; +} + +function bench_body() : void +{ + let a = new A; + for(let i = 0; i < num_of_cycles; i++) + { + let promise = a.foo(); + promise = foo_1(); + } +} + +let ref: Int = new Int(3); // ETSNOLINT(ets-phohibit-top-level-statements) +class AA { // ETSNOLINT(ets-suggest-final) + s: String = "Hello, World!"; + foo(): void { // ETSNOLINT(ets-suggest-final) + console.println(this.s); + } +} + + +function main() +{ + bench_body() + let a : Number[] = new Number[1000000] + let x : Number = 5.0 // ETSNOLINT(ets-implicit-boxing-unboxing) + for (let x : Number of a) { + } + + let foo: (i : int) => int + foo = (i : int): int => {return i+1} // ETSNOLINT(ets-remove-lambda) + + let TOTAL_NUMBER = 30000000 + + let tmp = 0 + for (let i = 0; i < TOTAL_NUMBER; i++) { + tmp = foo(tmp) + } + + for (let aa : int = 1; aa < 1000000; aa++) { + if (ref == null) { // ETSNOLINT(ets-boost-equality-statement) + ref = ref + 1; // ETSNOLINT(ets-implicit-boxing-unboxing) + } + + let new_ref: AA = new AA(); + if (new_ref == null) { // ETSNOLINT(ets-boost-equality-statement) + ref = ref + 3; // ETSNOLINT(ets-implicit-boxing-unboxing) + } + } +} diff --git a/plugins/ets/tests/ets_warnings_tests/warnings_suppresion_tests/warnings_suppression_begin_end_1-expected.txt b/plugins/ets/tests/ets_warnings_tests/warnings_suppresion_tests/warnings_suppression_begin_end_1-expected.txt new file mode 100644 index 000000000..e69de29bb diff --git a/plugins/ets/tests/ets_warnings_tests/warnings_suppresion_tests/warnings_suppression_begin_end_1.ets b/plugins/ets/tests/ets_warnings_tests/warnings_suppresion_tests/warnings_suppression_begin_end_1.ets new file mode 100644 index 000000000..8c441074f --- /dev/null +++ b/plugins/ets/tests/ets_warnings_tests/warnings_suppresion_tests/warnings_suppression_begin_end_1.ets @@ -0,0 +1,85 @@ +/* + * Copyright (c) 2023 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. + */ + +// ETSNOLINT-BEGIN +let num_of_cycles = 1 + +if (num_of_cycles == 1) { + num_of_cycles += 1; +} + +class A +{ + async foo() : Promise + { + return "5"; + } +} + + +async function foo_1() : Promise +{ + return "5"; +} + +function bench_body() : void +{ + let a = new A; + for(let i = 0; i < num_of_cycles; i++) + { + let promise = a.foo(); + promise = foo_1(); + } +} + +let ref: Int = new Int(3); +class AA { + s: String = "Hello, World!"; + foo(): void { + console.println(this.s); + } +} + + +function main() +{ + bench_body() + let a : Number[] = new Number[1000000] + let x : Number = 5.0 + for (let x : Number of a) { + } + + let foo: (i : int) => int + foo = (i : int): int => {return i+1} + + let TOTAL_NUMBER = 30000000 + + let tmp = 0 + for (let i = 0; i < TOTAL_NUMBER; i++) { + tmp = foo(tmp) + } + + for (let aa : int = 1; aa < 1000000; aa++) { + if (ref == null) { + ref = ref + 1; + } + + let new_ref: AA = new AA(); + if (new_ref == null) { + ref = ref + 3; + } + } +} +// ETSNOLINT-END diff --git a/plugins/ets/tests/ets_warnings_tests/warnings_suppresion_tests/warnings_suppression_begin_end_2-expected.txt b/plugins/ets/tests/ets_warnings_tests/warnings_suppresion_tests/warnings_suppression_begin_end_2-expected.txt new file mode 100644 index 000000000..1c9c1dff6 --- /dev/null +++ b/plugins/ets/tests/ets_warnings_tests/warnings_suppresion_tests/warnings_suppression_begin_end_2-expected.txt @@ -0,0 +1,13 @@ +ETS Warning: Prohibit top-level statements. [warnings_suppression_begin_end_2.ets:17:5] +ETS Warning: Prohibit top-level statements. [warnings_suppression_begin_end_2.ets:19:1] +ETS Warning: Prohibit top-level statements. [warnings_suppression_begin_end_2.ets:47:5] +ETS Warning: Boost Equality Statement. Change sides of binary expression. [warnings_suppression_begin_end_2.ets:75:13] +ETS Warning: Boost Equality Statement. Change sides of binary expression. [warnings_suppression_begin_end_2.ets:80:13] +ETS Warning: Replace asynchronous function with coroutine. [warnings_suppression_begin_end_2.ets:32:1] +ETS Warning: Replace asynchronous function with coroutine. [warnings_suppression_begin_end_2.ets:25:5] +ETS Warning: Replace the lambda function with a regular function. [warnings_suppression_begin_end_2.ets:65:11] +ETS Warning: Implicit Boxing to Double in Variable Declaration. [warnings_suppression_begin_end_2.ets:60:22] +ETS Warning: Implicit Boxing to Int in Assignment Expression. [warnings_suppression_begin_end_2.ets:76:19] +ETS Warning: Implicit Unboxing to int in Binary Expression. [warnings_suppression_begin_end_2.ets:76:19] +ETS Warning: Implicit Boxing to Int in Assignment Expression. [warnings_suppression_begin_end_2.ets:81:19] +ETS Warning: Implicit Unboxing to int in Binary Expression. [warnings_suppression_begin_end_2.ets:81:19] diff --git a/plugins/ets/tests/ets_warnings_tests/warnings_suppresion_tests/warnings_suppression_begin_end_2.ets b/plugins/ets/tests/ets_warnings_tests/warnings_suppresion_tests/warnings_suppression_begin_end_2.ets new file mode 100644 index 000000000..0773b5f16 --- /dev/null +++ b/plugins/ets/tests/ets_warnings_tests/warnings_suppresion_tests/warnings_suppression_begin_end_2.ets @@ -0,0 +1,85 @@ +/* + * Copyright (c) 2023 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. + */ + +// ETSNOLINT-BEGIN(ets-suggest-final) +let num_of_cycles = 1 + +if (num_of_cycles == 1) { + num_of_cycles += 1; +} + +class A +{ + async foo() : Promise + { + return "5"; + } +} + + +async function foo_1() : Promise +{ + return "5"; +} + +function bench_body() : void +{ + let a = new A; + for(let i = 0; i < num_of_cycles; i++) + { + let promise = a.foo(); + promise = foo_1(); + } +} + +let ref: Int = new Int(3); +class AA { + s: String = "Hello, World!"; + foo(): void { + console.println(this.s); + } +} + + +function main() +{ + bench_body() + let a : Number[] = new Number[1000000] + let x : Number = 5.0 + for (let x : Number of a) { + } + + let foo: (i : int) => int + foo = (i : int): int => {return i+1} + + let TOTAL_NUMBER = 30000000 + + let tmp = 0 + for (let i = 0; i < TOTAL_NUMBER; i++) { + tmp = foo(tmp) + } + + for (let aa : int = 1; aa < 1000000; aa++) { + if (ref == null) { + ref = ref + 1; + } + + let new_ref: AA = new AA(); + if (new_ref == null) { + ref = ref + 3; + } + } +} +// ETSNOLINT-END(ets-suggest-final) diff --git a/plugins/ets/tests/ets_warnings_tests/warnings_suppresion_tests/warnings_suppression_nextline-expected.txt b/plugins/ets/tests/ets_warnings_tests/warnings_suppresion_tests/warnings_suppression_nextline-expected.txt new file mode 100644 index 000000000..e69de29bb diff --git a/plugins/ets/tests/ets_warnings_tests/warnings_suppresion_tests/warnings_suppression_nextline.ets b/plugins/ets/tests/ets_warnings_tests/warnings_suppresion_tests/warnings_suppression_nextline.ets new file mode 100644 index 000000000..0b4880ff9 --- /dev/null +++ b/plugins/ets/tests/ets_warnings_tests/warnings_suppresion_tests/warnings_suppression_nextline.ets @@ -0,0 +1,22 @@ +/* + * Copyright (c) 2023 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. + */ + +// ETSNOLINT-NEXTLINE(ets-phohibit-top-level-statements) +let num_of_cycles = 1 + +function main() +{ + num_of_cycles += 1 +} diff --git a/plugins/ets/tests/ets_warnings_tests/werror_tests/CMakeLists.txt b/plugins/ets/tests/ets_warnings_tests/werror_tests/CMakeLists.txt new file mode 100644 index 000000000..d82aa62bb --- /dev/null +++ b/plugins/ets/tests/ets_warnings_tests/werror_tests/CMakeLists.txt @@ -0,0 +1,31 @@ +# Copyright (c) 2021-2022 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. + + +set (TESTS_RESULT_FOLDER ${ETS_WARNINGS_RESULT_FOLDER}/werror-tests) +set (TESTS_FOLDER ${ETS_WARNINGS_TEST_FOLDER}/werror_tests) +set (ETS_WARNING_FLAG --es2panda-args=--ets-warnings-all) +set (ETS_WERROR_FLAG --es2panda-args=--ets-werror) + +add_custom_target(werror-tests DEPENDS ${ETS_WARNINGS_TEST_DEPENDENCIES} + WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR} + COMMAND ${ETS_RUNNER} + ${CMAKE_SOURCE_DIR} + ${OPTIONS} + ${ETS_WARNING_FLAG} + ${ETS_WERROR_FLAG} + --work-dir ${TESTS_RESULT_FOLDER} + --test-root ${TESTS_FOLDER} + --build-dir ${CMAKE_BINARY_DIR} +) +add_dependencies(ets-warnings-tests werror-tests) \ No newline at end of file diff --git a/plugins/ets/tests/ets_warnings_tests/werror_tests/werror-expected.txt b/plugins/ets/tests/ets_warnings_tests/werror_tests/werror-expected.txt new file mode 100644 index 000000000..8c14436ac --- /dev/null +++ b/plugins/ets/tests/ets_warnings_tests/werror_tests/werror-expected.txt @@ -0,0 +1 @@ +System ArkTS: warning treated as error.: Suggest 'final' modifier for class [werror.ets:21:7] diff --git a/plugins/ets/tests/ets_warnings_tests/werror_tests/werror.ets b/plugins/ets/tests/ets_warnings_tests/werror_tests/werror.ets new file mode 100644 index 000000000..f98b67163 --- /dev/null +++ b/plugins/ets/tests/ets_warnings_tests/werror_tests/werror.ets @@ -0,0 +1,36 @@ +/* + * Copyright (c) 2023 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 I { // No final - inheritance + fn(): String { // No final - overridden + return "hehe" + }; +} + +class A extends I { // Suggest final + something(): void {} // Suggest final + override fn(): String { // Suggest final + return ""; + } +} + +class B { // Suggest final + yoo(): String { // Suggest final + return "yo"; + } +} + +class K { // Suggest final + final koko(): void {} // No final - already final +} \ No newline at end of file diff --git a/tests/tests-u-runner/runner/options/cli_options.py b/tests/tests-u-runner/runner/options/cli_options.py index fe3ff6fa7..00e0a8a97 100644 --- a/tests/tests-u-runner/runner/options/cli_options.py +++ b/tests/tests-u-runner/runner/options/cli_options.py @@ -212,6 +212,12 @@ def get_args(): # pylint: disable=too-many-statements '--arktsconfig', action='store', dest='arktsconfig', type=is_file, default=None, help='path to arktsconfig file') + parser.add_argument( + '--es2panda-args', action='append', dest='es2panda_args', default=None, + help='Additional arguments that will be passed to es2panda') + parser.add_argument( + '--ets-warnings-tests', action='store_true', dest='ets_warnings_tests', default=None, + help='Modified --parser to enable ets-warnings-tests') # Verifier options parser.add_argument( diff --git a/tests/tests-u-runner/runner/options/options_es2panda.py b/tests/tests-u-runner/runner/options/options_es2panda.py index 9ef16fdef..c5fee33d2 100644 --- a/tests/tests-u-runner/runner/options/options_es2panda.py +++ b/tests/tests-u-runner/runner/options/options_es2panda.py @@ -1,8 +1,8 @@ from dataclasses import dataclass from functools import cached_property -from typing import Dict, Optional +from typing import Dict, Optional, List -from runner.options.decorator_value import value, _to_int, _to_str, _to_path +from runner.options.decorator_value import value, _to_int, _to_str, _to_path, _to_bool @dataclass @@ -19,6 +19,8 @@ class Es2PandaOptions: "opt-level": self.opt_level, "custom-path": self.custom_path, "arktsconfig": self.arktsconfig, + "es2panda-args": self.es2panda_args, + "ets_warnings_tests": self.ets_warnings_tests } @cached_property @@ -41,6 +43,16 @@ class Es2PandaOptions: def arktsconfig(self) -> Optional[str]: return None + @cached_property + @value(yaml_path="es2panda.es2panda-args", cli_name="es2panda_args") + def es2panda_args(self) -> List[str]: + return [] + + @cached_property + @value(yaml_path="es2panda.ets_warnings_tests", cli_name="ets_warnings_tests", cast_to_type=_to_bool) + def ets_warnings_tests(self) -> bool: + return False + def get_command_line(self) -> str: options = [ f'--es2panda-timeout={self.timeout}' if self.timeout != Es2PandaOptions.__DEFAULT_TIMEOUT else '', diff --git a/tests/tests-u-runner/runner/plugins/ets/runner_ets.py b/tests/tests-u-runner/runner/plugins/ets/runner_ets.py index 4b00734bd..55f45a337 100644 --- a/tests/tests-u-runner/runner/plugins/ets/runner_ets.py +++ b/tests/tests-u-runner/runner/plugins/ets/runner_ets.py @@ -37,6 +37,8 @@ class RunnerETS(RunnerFileBased): "--extension=ets", f"--opt-level={self.config.es2panda.opt_level}" ]) + self.test_env.es2panda_args.extend(self.config.es2panda.es2panda_args) + load_runtime_ets = [f"--boot-panda-files={self.stdlib_path}", "--load-runtimes=ets"] self.test_env.runtime_args.extend(load_runtime_ets) self.test_env.verifier_args.extend(load_runtime_ets) diff --git a/tests/tests-u-runner/runner/plugins/parser/runner_js_parser.py b/tests/tests-u-runner/runner/plugins/parser/runner_js_parser.py index 87663cdda..1ce700bc9 100644 --- a/tests/tests-u-runner/runner/plugins/parser/runner_js_parser.py +++ b/tests/tests-u-runner/runner/plugins/parser/runner_js_parser.py @@ -26,6 +26,19 @@ class RunnerJSParser(RunnerJS): self.collect_excluded_test_lists() self.collect_ignored_test_lists() + ets_flags = [ + "--extension=ets", + "--output=/dev/null", + f"--arktsconfig={self.arktsconfig}" + ] + ets_flags.extend(config.es2panda.es2panda_args) + + if config.es2panda.ets_warnings_tests: + self.add_directory("", "ets", flags=ets_flags) + else: + self.add_directory("compiler/ets", "ets", flags=ets_flags) + self.add_directory("parser/ets", "ets", flags=ets_flags) + if self.config.general.with_js: self.add_directory("ark_tests/parser/js", "js", flags=["--parse-only"]) diff --git a/tests/tests-u-runner/runner/plugins/parser/test_js_parser.py b/tests/tests-u-runner/runner/plugins/parser/test_js_parser.py index 323ab3b64..edc76e27e 100644 --- a/tests/tests-u-runner/runner/plugins/parser/test_js_parser.py +++ b/tests/tests-u-runner/runner/plugins/parser/test_js_parser.py @@ -15,11 +15,13 @@ class TestJSParser(TestFileBased): def do_run(self): desc = Descriptor(self.path).get_descriptor() + es2panda_flags = [] + if "ets_warnings_tests" not in self.path: + if 'flags' in desc and 'dynamic-ast' in desc['flags']: + es2panda_flags = ["--dump-dynamic-ast"] + else: + es2panda_flags = ["--dump-ast"] - if 'flags' in desc and 'dynamic-ast' in desc['flags']: - es2panda_flags = ["--dump-dynamic-ast"] - else: - es2panda_flags = ["--dump-ast"] es2panda_flags.extend(self.flags) if 'flags' in desc and 'module' in desc['flags']: es2panda_flags.append("--module") -- Gitee