diff --git a/static_core/plugins/ets/tests/ets-templates/13.compilation_units/02.import_directives/01.bind_all_with_qualified_access/modules/mod1.ets b/static_core/plugins/ets/tests/ets-templates/13.compilation_units/02.import_directives/01.bind_all_with_qualified_access/modules/mod1.ets index 187bcc0379f8929788b79009a284aa65c440178e..c2d73815bb850e5f82dad9603ed35dfd8a8de1a2 100644 --- a/static_core/plugins/ets/tests/ets-templates/13.compilation_units/02.import_directives/01.bind_all_with_qualified_access/modules/mod1.ets +++ b/static_core/plugins/ets/tests/ets-templates/13.compilation_units/02.import_directives/01.bind_all_with_qualified_access/modules/mod1.ets @@ -28,4 +28,4 @@ export class C { foo(): int { return 3 } -} +} \ No newline at end of file diff --git a/static_core/plugins/ets/tests/ets-templates/13.compilation_units/02.import_directives/02.default_import_binding/default_import_const_var_binding.ets b/static_core/plugins/ets/tests/ets-templates/13.compilation_units/02.import_directives/02.default_import_binding/default_import_const_var_binding.ets index ac03e52b47a6a944c2f0084a74fb3e5f2967a4ba..c4d9e3065e48b73f14131fd8ca6eb7e5097b4323 100644 --- a/static_core/plugins/ets/tests/ets-templates/13.compilation_units/02.import_directives/02.default_import_binding/default_import_const_var_binding.ets +++ b/static_core/plugins/ets/tests/ets-templates/13.compilation_units/02.import_directives/02.default_import_binding/default_import_const_var_binding.ets @@ -23,4 +23,4 @@ import {default as const_var} from "../../05.top-level_declarations/01.exported_ function main(): void { arktest.assertEQ(const_var, 2); -} +} \ No newline at end of file diff --git a/static_core/plugins/ets/tests/ets-templates/13.compilation_units/02.import_directives/02.default_import_binding/default_import_const_var_binding_neg.ets b/static_core/plugins/ets/tests/ets-templates/13.compilation_units/02.import_directives/02.default_import_binding/default_import_const_var_binding_neg.ets index 44ac1386a2dec7c0a390077a55ab0400caaff024..f98e302b54c98528e5e8f9b33754a136ef1d9ae0 100644 --- a/static_core/plugins/ets/tests/ets-templates/13.compilation_units/02.import_directives/02.default_import_binding/default_import_const_var_binding_neg.ets +++ b/static_core/plugins/ets/tests/ets-templates/13.compilation_units/02.import_directives/02.default_import_binding/default_import_const_var_binding_neg.ets @@ -24,4 +24,4 @@ import {default as const_var} from "../../05.top-level_declarations/01.exported_ function main(): void { const_var = 3 -} +} \ No newline at end of file diff --git a/static_core/plugins/ets/tests/ets-templates/16.concurrency/03.asynchronous_api/01.async_functions/return_type_is_promise/no_input_params/predefined_types/async_function_returns_promise_predefined0.ets b/static_core/plugins/ets/tests/ets-templates/16.concurrency/03.asynchronous_api/01.async_functions/return_type_is_promise/no_input_params/predefined_types/async_function_returns_promise_predefined0.ets new file mode 100644 index 0000000000000000000000000000000000000000..399c3bb6055cfb19f5b63328991e09bdc8890b39 --- /dev/null +++ b/static_core/plugins/ets/tests/ets-templates/16.concurrency/03.asynchronous_api/01.async_functions/return_type_is_promise/no_input_params/predefined_types/async_function_returns_promise_predefined0.ets @@ -0,0 +1,19 @@ +/* + * Copyright (c) 2024-2025 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. + */ + +{% from 'ets-templates/16.concurrency/03.asynchronous_api/predefined_types.jinja' import numeric_types_cases, boolean_types_cases, symbol_types_cases, no_value_types_cases %} +{% from 'ets-templates/16.concurrency/03.asynchronous_api/async_returns_predefined0.base.jinja' import generate_complete_test %} + +{{ generate_complete_test(numeric_types_cases + boolean_types_cases + symbol_types_cases + no_value_types_cases, 'function') }} diff --git a/static_core/plugins/ets/tests/ets-templates/16.concurrency/03.asynchronous_api/03.async_methods/ameth.ets b/static_core/plugins/ets/tests/ets-templates/16.concurrency/03.asynchronous_api/03.async_methods/ameth.ets index 432e6534f7ea6d6d2b0fb649e4eb5dba96f82ce6..689fa321b6630330dc2f10cdc6f1a604b1b7c504 100644 --- a/static_core/plugins/ets/tests/ets-templates/16.concurrency/03.asynchronous_api/03.async_methods/ameth.ets +++ b/static_core/plugins/ets/tests/ets-templates/16.concurrency/03.asynchronous_api/03.async_methods/ameth.ets @@ -20,7 +20,13 @@ desc: The method async is an implicit coroutine that can be called as a regular {{c.decl}} -function main() { +async function startTest() { {{c.use|indent}} } + + +function main(){ + waitForCompletion(startTest); +} + {% endfor %} diff --git a/static_core/plugins/ets/tests/ets-templates/16.concurrency/03.asynchronous_api/03.async_methods/ameth.params.yaml b/static_core/plugins/ets/tests/ets-templates/16.concurrency/03.asynchronous_api/03.async_methods/ameth.params.yaml index acb7bf76fe3c6bf6eea860526ca2ff840f48350b..2f2b4277864e57144e40f6ad3d8ae715b85489fc 100644 --- a/static_core/plugins/ets/tests/ets-templates/16.concurrency/03.asynchronous_api/03.async_methods/ameth.params.yaml +++ b/static_core/plugins/ets/tests/ets-templates/16.concurrency/03.asynchronous_api/03.async_methods/ameth.params.yaml @@ -20,7 +20,7 @@ cases: use: |- // Promise of void let r = new A().foo() - arktest.assertTrue((await r) == undefined) + arktest.assertEQ((await r), undefined) - decl: |- class A { @@ -30,7 +30,7 @@ cases: } use: |- // Promise of primitive - arktest.assertTrue((await new A().foo(42)) == 84) + arktest.assertEQ((await new A().foo(42)), 84) - decl: |- class A { @@ -40,7 +40,7 @@ cases: } use: |- // Promise of primitive - arktest.assertTrue((await new A().foo(42)) == 84) + arktest.assertEQ((await new A().foo(42)), 84) - decl: |- class A { @@ -50,7 +50,7 @@ cases: } use: |- // Promise of boxed - arktest.assertTrue((await new A().foo(new Double(42.0))) == 84.0) + arktest.assertEQ((await new A().foo(new Double(42.0))), 84.0) - decl: |- class A { @@ -60,7 +60,7 @@ cases: } use: |- // Promise of boxed - arktest.assertTrue((await new A().foo(new Double(42.0))) == 84.0) + arktest.assertEQ((await new A().foo(new Double(42.0))), 84.0) - decl: |- class A { @@ -71,7 +71,7 @@ cases: use: |- // Promise of string let r = new A().foo(42) - arktest.assertTrue((await r) == '42') + arktest.assertEQ((await r), '42') - decl: |- class A { @@ -82,7 +82,7 @@ cases: use: |- // Promise of string let r = new A().foo(42) - arktest.assertTrue((await r) == '4242') + arktest.assertEQ((await r), '4242') - decl: |- class A { @@ -132,7 +132,7 @@ cases: } use: |- // Promise of nullish - arktest.assertTrue((await new A().foo(42)) == 43) + arktest.assertEQ((await new A().foo(42)), 43) - decl: |- class A { @@ -142,7 +142,7 @@ cases: } use: |- // Promise of nullish - arktest.assertTrue((await new A().foo(42)) == 43) + arktest.assertEQ((await new A().foo(42)), 43) - decl: |- class A { @@ -152,7 +152,7 @@ cases: } use: |- // Promise of nullish - arktest.assertTrue((await new A().foo(42)) == 43) + arktest.assertEQ((await new A().foo(42)), 43) - decl: |- class A { @@ -162,7 +162,7 @@ cases: } use: |- // Promise of nullish - arktest.assertTrue((await new A().foo(42)) == 43) + arktest.assertEQ((await new A().foo(42)), 43) - decl: |- class A { @@ -172,7 +172,7 @@ cases: } use: |- // Promise of nullish - arktest.assertTrue((await new A().foo(42)) == 43) + arktest.assertEQ((await new A().foo(42)), 43) - decl: |- class A { @@ -185,7 +185,7 @@ cases: } use: |- // Promise of nullish - arktest.assertTrue((await new A().foo(42)) == 43) + arktest.assertEQ((await new A().foo(42)), 43) - decl: |- class A { @@ -199,7 +199,7 @@ cases: } use: |- // Promise of promise - arktest.assertTrue((await new A().bar('A')) == 'AA') + arktest.assertEQ((await new A().bar('A')), 'AA') - decl: |- class A { @@ -213,7 +213,7 @@ cases: } use: |- // Promise of promise - arktest.assertTrue((await new A().bar('A')) == 'AA') + arktest.assertEQ((await new A().bar('A')), 'AA') - decl: |- class A { @@ -224,7 +224,10 @@ cases: use: |- // Promise of array let q: int[] = await new A().foo() - arktest.assertTrue(q[0] == 1 && q[1] == 2 && q[2] == 3) + //arktest.assertTrue(q[0] == 1 && q[1] == 2 && q[2] == 3) + arktest.assertEQ(q[0], 1) + arktest.assertEQ(q[1], 2) + arktest.assertEQ(q[2], 3) - decl: |- class A { @@ -235,7 +238,12 @@ cases: use: |- // Promise of array let q: int[] = await new A().foo() - arktest.assertTrue(q[0] == 1 && q[1] == 2 && q[2] == 3) + //arktest.assertTrue(q[0] == 1 && q[1] == 2 && q[2] == 3) + arktest.assertEQ(q[0], 1) + arktest.assertEQ(q[1], 2) + arktest.assertEQ(q[2], 3) + arktest.assertEQ(q.length, 3) + - decl: |- class A { @@ -245,7 +253,7 @@ cases: } use: |- // Promise of function - arktest.assertTrue((await new A().foo())('A') == 'AA') + arktest.assertEQ((await new A().foo())('A'), 'AA') - decl: |- type FT = (p: string) => string @@ -257,7 +265,7 @@ cases: } use: |- // Promise of function - arktest.assertTrue((await new A().foo())('A') == 'AA') + arktest.assertEQ((await new A().foo())('A'), 'AA') - decl: |- type UT = number | string | boolean @@ -269,7 +277,7 @@ cases: use: |- // Promise of union let q: boolean|number|string = await new A().foo(-1) - arktest.assertTrue(q as string == '-1') + arktest.assertEQ(q as string, '-1') - decl: |- type UT = number | string | boolean @@ -282,7 +290,7 @@ cases: use: |- // Promise of union let q: boolean|number|string = await new A().foo(-1) - arktest.assertTrue(q as string == '-1') + arktest.assertEQ(q as string, '-1') - decl: |- class A { @@ -293,7 +301,9 @@ cases: use: |- // Promise of tuple let q: [Boolean, Error] = await new A().foo(42) - arktest.assertTrue(q[0] && (q[1] instanceof Error)) + arktest.assertEQ(q[0], true) + arktest.assertTrue(q[1] instanceof Error) + - decl: |- class A { @@ -304,7 +314,8 @@ cases: use: |- // Promise of tuple let q: [Boolean, Error] = await new A().foo(42) - arktest.assertTrue(q[0] && (q[1] instanceof Error)) + arktest.assertEQ(q[0], true) + arktest.assertTrue(q[1] instanceof Error) - decl: |- class A { @@ -315,7 +326,7 @@ cases: use: |- // Promise of BigInt let q: BigInt = await new A().foo('123456789012345678901234567890') - arktest.assertTrue(q == 123456789012345678901234567890n) + arktest.assertEQ(q, 123456789012345678901234567890n) - decl: |- class A { @@ -326,7 +337,7 @@ cases: use: |- // Promise of BigInt let q: BigInt = await new A().foo('123456789012345678901234567890') - arktest.assertTrue(q == 123456789012345678901234567890n) + arktest.assertEQ(q, 123456789012345678901234567890n) - decl: |- class A { @@ -337,7 +348,7 @@ cases: use: |- // Promise of bigint let q: bigint = await new A().foo(123456789012345678901234567890n) - arktest.assertTrue(q == 123456789012345678901234567890n) + arktest.assertEQ(q, 123456789012345678901234567890n) - decl: |- class A { @@ -348,7 +359,7 @@ cases: use: |- // Promise of bigint let q: bigint = await new A().foo(123456789012345678901234567890n) - arktest.assertTrue(q == 123456789012345678901234567890n) + arktest.assertEQ(q, 123456789012345678901234567890n) - decl: |- class B { @@ -374,7 +385,7 @@ cases: ] let cnt = 0.0 for (let v of arr) cnt += (await v) - arktest.assertTrue(cnt == 90.0) + arktest.assertEQ(cnt, 90.0) - decl: |- class A { @@ -398,7 +409,7 @@ cases: ] let cnt = 0.0 for (let v of arr) cnt += (await v) - arktest.assertTrue(cnt == 90.0) + arktest.assertEQ(cnt, 90.0) - decl: |- enum Color { Red, Green, Blue } @@ -409,7 +420,7 @@ cases: } use: |- // Promise of enum - arktest.assertTrue((await new A().foo(42)) == Color.Green) + arktest.assertEQ((await new A().foo(42)), Color.Green) - decl: |- enum Color { Red, Green, Blue } @@ -420,7 +431,7 @@ cases: } use: |- // Promise of enum - arktest.assertTrue((await new A().foo(42)) == Color.Green) + arktest.assertEQ((await new A().foo(42)), Color.Green) - decl: |- enum Color { R="red", G="green", B="blue" } @@ -431,7 +442,7 @@ cases: } use: |- // Promise of string-based enum - arktest.assertTrue((await new A().foo(-42)) == Color.B) + arktest.assertEQ((await new A().foo(-42)), Color.B) - decl: |- enum Color { R="red", G="green", B="blue" } @@ -442,7 +453,7 @@ cases: } use: |- // Promise of string-based enum - arktest.assertTrue((await new A().foo(-42)) == Color.B) + arktest.assertEQ((await new A().foo(-42)), Color.B) - decl: |- class B { @@ -463,7 +474,7 @@ cases: use: |- // Promise of T let a: A = new A("abc") - arktest.assertTrue(a.meth() == "abc") + arktest.assertEQ(a.meth(), "abc") - decl: |- class B { @@ -487,7 +498,7 @@ cases: use: |- // Promise of T let a: A = new A("abc") - arktest.assertTrue(a.meth() == "abc") + arktest.assertEQ(a.meth(), "abc") - decl: |- class A { @@ -501,7 +512,7 @@ cases: use: |- // Promise in object literal let a: A = { fld: new B().foo(42.0) } - arktest.assertTrue((await a.fld!) == '42') + arktest.assertEQ((await a.fld!), '42') - decl: |- class A { @@ -515,7 +526,7 @@ cases: use: |- // Promise in object literal let a: A = { fld: B.foo(42.0) } - arktest.assertTrue((await a.fld!) == '42') + arktest.assertEQ((await a.fld!), '42') - decl: |- let s = 'ABC' @@ -527,7 +538,7 @@ cases: use: |- // Launch in argument lambda let r = await new A().foo((): Promise => (async (): Promise => s)()) - arktest.assertTrue(r == 'ABC') + arktest.assertEQ(r, 'ABC') - decl: |- let s = 'ABC' @@ -539,7 +550,7 @@ cases: use: |- // Launch in argument lambda let r = await new A().foo((): Promise => (async (): Promise => s)()) - arktest.assertTrue(r == 'ABC') + arktest.assertEQ(r, 'ABC') - decl: |- let s = 'ABC' @@ -551,7 +562,7 @@ cases: use: |- // Launch in trailing lambda let r = await new A().foo(async (): Promise => s) - arktest.assertTrue(r == 'ABC') + arktest.assertEQ(r, 'ABC') - decl: |- let s = 'ABC' @@ -563,7 +574,7 @@ cases: use: |- // Launch in trailing lambda let r = await A.foo(async (): Promise => s) - arktest.assertTrue(r == 'ABC') + arktest.assertEQ(r, 'ABC') - decl: |- let s = 'A' @@ -578,7 +589,7 @@ cases: .then((p: string): string => p + p) .then((p: string): string => p + p) - arktest.assertTrue((await r) == 'AAAAAAAA') + arktest.assertEQ((await r), 'AAAAAAAA') - decl: |- type EN = Error|null @@ -598,7 +609,7 @@ cases: .catch((p: EN): string => p!.message) .then((p: string): string => p + p) - arktest.assertTrue((await r) == 'EE') + arktest.assertEQ((await r), 'EE') - decl: |- type EN = Error|null @@ -614,7 +625,7 @@ cases: .then((p: string): string => { throw new Error(p) }) .catch((p: EN): string => p!.message + p!.message) - arktest.assertTrue((await r) == 'AAAA') + arktest.assertEQ((await r), 'AAAA') - decl: |- type EN = Error|null @@ -635,8 +646,8 @@ cases: .catch((p: EN): string => { throw p! }) try { await r + arktest.assertTrue(false) } catch (e) { - arktest.assertTrue((e as Error).message == 'E') - return + arktest.assertEQ((e as Error).message, 'E') } - arktest.assertTrue(false) + \ No newline at end of file diff --git a/static_core/plugins/ets/tests/ets-templates/16.concurrency/03.asynchronous_api/03.async_methods/async_method23.ets b/static_core/plugins/ets/tests/ets-templates/16.concurrency/03.asynchronous_api/03.async_methods/ameth_48_old.ets old mode 100644 new mode 100755 similarity index 50% rename from static_core/plugins/ets/tests/ets-templates/16.concurrency/03.asynchronous_api/03.async_methods/async_method23.ets rename to static_core/plugins/ets/tests/ets-templates/16.concurrency/03.asynchronous_api/03.async_methods/ameth_48_old.ets index f28ee0bd26afea4ee664ac420fcb6bc1d94ebdba..2d682e6af5c7ec8ff15d2d5480d0b95a7d290752 --- a/static_core/plugins/ets/tests/ets-templates/16.concurrency/03.asynchronous_api/03.async_methods/async_method23.ets +++ b/static_core/plugins/ets/tests/ets-templates/16.concurrency/03.asynchronous_api/03.async_methods/ameth_48_old.ets @@ -14,26 +14,31 @@ */ /*--- -desc: Test cases for various usage scenarios of asynchronous method. - Using loops in asynchronous methods. +desc: Throw error in chained catch await is forbidden for non-async function ---*/ -class MethodWithLoop { - async methodWithLoop(): Promise { - let sum = 0.0; - for (let i = 1; i <= 5; i++) { - sum += i; +type EN = Error|null +let s = 'A' +class A { + async foo(p: string): Promise { + if (p == 'A') { + throw new Error('E') } - return sum; + return 'X' } } - -async function startTest() { - const example = new MethodWithLoop(); - const result = await example.methodWithLoop(); - arktest.assertEQ(result, 15); +//old test +function main() { + // Throw error in chained catch + // await is forbidden for non-async function + let r = new A().foo(s) + .then((p: string): string => p + p) + .catch((p: EN): string => { throw p! }) + try { + await r + } catch (e) { + arktest.assertEQ((e as Error).message, 'E') + return + } + arktest.assertTrue(false) } - -function main(): void { - startTest(); -} \ No newline at end of file diff --git a/static_core/plugins/ets/tests/ets-templates/16.concurrency/03.asynchronous_api/03.async_methods/async_method0.ets b/static_core/plugins/ets/tests/ets-templates/16.concurrency/03.asynchronous_api/03.async_methods/async_method0.ets deleted file mode 100644 index d2079dabd8203d8a27be183c4c30092813da4cd0..0000000000000000000000000000000000000000 --- a/static_core/plugins/ets/tests/ets-templates/16.concurrency/03.asynchronous_api/03.async_methods/async_method0.ets +++ /dev/null @@ -1,35 +0,0 @@ -/* - * Copyright (c) 2025 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. - */ - -/*--- -desc: Test cases for various usage scenarios of asynchronous method. - The asynchronous method returns a string. ----*/ - -class MethodReturnString { - async methodReturnString(): Promise { - return "Hello, World!"; - } -} - -async function startTest() { - const example = new MethodReturnString(); - const result = await example.methodReturnString(); - arktest.assertEQ(result, "Hello, World!"); -} - -function main(): void { - waitForCompletion(startTest); -} \ No newline at end of file diff --git a/static_core/plugins/ets/tests/ets-templates/16.concurrency/03.asynchronous_api/03.async_methods/async_method10.ets b/static_core/plugins/ets/tests/ets-templates/16.concurrency/03.asynchronous_api/03.async_methods/async_method10.ets index 90022474dbc234d0c02393c7474359d8cf9076c7..08d5008148776519b135dcde7059d329884f5a24 100644 --- a/static_core/plugins/ets/tests/ets-templates/16.concurrency/03.asynchronous_api/03.async_methods/async_method10.ets +++ b/static_core/plugins/ets/tests/ets-templates/16.concurrency/03.asynchronous_api/03.async_methods/async_method10.ets @@ -28,7 +28,7 @@ class MethodWithErrorHandling { await this.methodThrowError(); return "Success"; } catch (error) { - return `Caught error: ${error as string}`; + return `Caught error: ${(error as Error).message}`; } } } @@ -40,5 +40,5 @@ async function startTest() { } function main(): void { - startTest(); + waitForCompletion(startTest); } \ No newline at end of file diff --git a/static_core/plugins/ets/tests/ets-templates/16.concurrency/03.asynchronous_api/03.async_methods/async_method12.ets b/static_core/plugins/ets/tests/ets-templates/16.concurrency/03.asynchronous_api/03.async_methods/async_method12.ets deleted file mode 100644 index bb58d7954c3a27fc9ea1cd3e9d2830c6c43d952d..0000000000000000000000000000000000000000 --- a/static_core/plugins/ets/tests/ets-templates/16.concurrency/03.asynchronous_api/03.async_methods/async_method12.ets +++ /dev/null @@ -1,35 +0,0 @@ -/* - * Copyright (c) 2025 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. - */ - -/*--- -desc: Test cases for various usage scenarios of asynchronous method. - Asynchronous method returns undefined. ----*/ - -class MethodReturnUndefined { - async methodReturnUndefined(): Promise { - return undefined; - } -} - -async function startTest() { - const example = new MethodReturnUndefined(); - const result = await example.methodReturnUndefined(); - arktest.assertEQ(result === undefined, true) -} - -function main(): void { - startTest(); -} \ No newline at end of file diff --git a/static_core/plugins/ets/tests/ets-templates/16.concurrency/03.asynchronous_api/03.async_methods/async_method15.ets b/static_core/plugins/ets/tests/ets-templates/16.concurrency/03.asynchronous_api/03.async_methods/async_method15.ets index 3ffec03f060cda3195a97ade3c5013ffd9f8733e..ccd70e04ac4395e5143e9204e165d1f3dcce58c9 100644 --- a/static_core/plugins/ets/tests/ets-templates/16.concurrency/03.asynchronous_api/03.async_methods/async_method15.ets +++ b/static_core/plugins/ets/tests/ets-templates/16.concurrency/03.asynchronous_api/03.async_methods/async_method15.ets @@ -36,10 +36,10 @@ class MethodReturnObject { async function startTest() { const example = new MethodReturnObject(); const result = await example.methodReturnObject(); - arktest.assertEQ(result.name === "Alice", true); - arktest.assertEQ(result.age === 25, true); + arktest.assertEQ(result.name, "Alice"); + arktest.assertEQ(result.age, 25); } function main(): void { - startTest(); + waitForCompletion(startTest); } \ No newline at end of file diff --git a/static_core/plugins/ets/tests/ets-templates/16.concurrency/03.asynchronous_api/03.async_methods/async_method16.ets b/static_core/plugins/ets/tests/ets-templates/16.concurrency/03.asynchronous_api/03.async_methods/async_method16.ets deleted file mode 100644 index b90e10f278fabfc1e8d7405e3269a0669677c3a6..0000000000000000000000000000000000000000 --- a/static_core/plugins/ets/tests/ets-templates/16.concurrency/03.asynchronous_api/03.async_methods/async_method16.ets +++ /dev/null @@ -1,36 +0,0 @@ -/* - * Copyright (c) 2025 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. - */ - -/*--- -desc: Test cases for various usage scenarios of asynchronous method. - Asynchronous method returns array. ----*/ - -class MethodReturnArray { - async methodReturnArray(): Promise> { - return new Array(1, 2, 3); - } -} - -async function startTest() { - const example = new MethodReturnArray(); - const result = await example.methodReturnArray(); - const resTemp = new Array(1, 2, 3); - arktest.assertEQ(result === resTemp, true); -} - -function main(): void { - startTest(); -} \ No newline at end of file diff --git a/static_core/plugins/ets/tests/ets-templates/16.concurrency/03.asynchronous_api/03.async_methods/async_method17.ets b/static_core/plugins/ets/tests/ets-templates/16.concurrency/03.asynchronous_api/03.async_methods/async_method17.ets index 935e807c09f896c9e7cd897ceb1d26b0794acec8..7c50398774e1c3c83a9132f5305037630c690ee2 100644 --- a/static_core/plugins/ets/tests/ets-templates/16.concurrency/03.asynchronous_api/03.async_methods/async_method17.ets +++ b/static_core/plugins/ets/tests/ets-templates/16.concurrency/03.asynchronous_api/03.async_methods/async_method17.ets @@ -27,22 +27,26 @@ class MethodConcurrentExecution { return 42.0; } - async methodConcurrentExecution(): Promise>> { - const result = await Promise.all( new Array>( + async methodConcurrentExecution(): Promise>> { + const result = await Promise.all( new Array>( this.methodReturnString(), this.methodReturnNumber(), )); - return result as Array>; + return result; } } async function startTest() { const example = new MethodConcurrentExecution(); const result = await example.methodConcurrentExecution(); - const resTemp = new Array("Hello", 42); - arktest.assertEQ(result === resTemp, true); + + arktest.assertTrue(Array.isArray(result)); + arktest.assertEQ(result.length, 2); + arktest.assertEQ(result[0], "Hello"); + arktest.assertEQ(result[1], 42.0); + } function main(): void { - startTest(); + waitForCompletion(startTest); } \ No newline at end of file diff --git a/static_core/plugins/ets/tests/ets-templates/16.concurrency/03.asynchronous_api/03.async_methods/async_method18.ets b/static_core/plugins/ets/tests/ets-templates/16.concurrency/03.asynchronous_api/03.async_methods/async_method18.ets index c54fd1daa5245f9c6ba5b64876639cc24b27ecd9..79d5df5b8e56495d486fb365396c0e043b43b9a2 100644 --- a/static_core/plugins/ets/tests/ets-templates/16.concurrency/03.asynchronous_api/03.async_methods/async_method18.ets +++ b/static_core/plugins/ets/tests/ets-templates/16.concurrency/03.asynchronous_api/03.async_methods/async_method18.ets @@ -41,5 +41,5 @@ async function startTest() { } function main(): void { - startTest(); + waitForCompletion(startTest); } \ No newline at end of file diff --git a/static_core/plugins/ets/tests/ets-templates/16.concurrency/03.asynchronous_api/03.async_methods/async_method19.ets b/static_core/plugins/ets/tests/ets-templates/16.concurrency/03.asynchronous_api/03.async_methods/async_method19.ets index b82bf1d8225cfefc8f583668f065fa291f93cef1..6e341e457db31b58e092f99f3c3ecf49e42a388e 100644 --- a/static_core/plugins/ets/tests/ets-templates/16.concurrency/03.asynchronous_api/03.async_methods/async_method19.ets +++ b/static_core/plugins/ets/tests/ets-templates/16.concurrency/03.asynchronous_api/03.async_methods/async_method19.ets @@ -29,10 +29,10 @@ async function startTest() { try { await example.methodReturnReject(); } catch (error) { - arktest.assertEQ(error as string, "Rejected!"); + arktest.assertEQ((error as Error).message, "Rejected!"); } } function main(): void { - startTest(); + waitForCompletion(startTest); } \ No newline at end of file diff --git a/static_core/plugins/ets/tests/ets-templates/16.concurrency/03.asynchronous_api/03.async_methods/async_method20.ets b/static_core/plugins/ets/tests/ets-templates/16.concurrency/03.asynchronous_api/03.async_methods/async_method20.ets index 57a2a11bc80f73ec5ec5f6b5808f9f08ef3379db..197f7928ee5be4ba0987d2b10b5d03ee97704ab2 100644 --- a/static_core/plugins/ets/tests/ets-templates/16.concurrency/03.asynchronous_api/03.async_methods/async_method20.ets +++ b/static_core/plugins/ets/tests/ets-templates/16.concurrency/03.asynchronous_api/03.async_methods/async_method20.ets @@ -32,5 +32,5 @@ async function startTest() { } function main(): void { - startTest(); + waitForCompletion(startTest); } \ No newline at end of file diff --git a/static_core/plugins/ets/tests/ets-templates/16.concurrency/03.asynchronous_api/03.async_methods/async_method21.ets b/static_core/plugins/ets/tests/ets-templates/16.concurrency/03.asynchronous_api/03.async_methods/async_method21.ets index d3ea286091dc919b7a95ec04e375d8be09aa352d..7d163cfebde7d6588a4023be60d3cdbf77f5edc6 100644 --- a/static_core/plugins/ets/tests/ets-templates/16.concurrency/03.asynchronous_api/03.async_methods/async_method21.ets +++ b/static_core/plugins/ets/tests/ets-templates/16.concurrency/03.asynchronous_api/03.async_methods/async_method21.ets @@ -32,9 +32,9 @@ class MethodAwaitReject { async function startTest() { const example = new MethodAwaitReject(); const result = await example.methodAwaitReject(); - arktest.assertEQ(result, "Rejected!"); + arktest.assertEQ(result, "Caught error: Rejected!"); } function main(): void { - startTest(); + waitForCompletion(startTest); } \ No newline at end of file diff --git a/static_core/plugins/ets/tests/ets-templates/16.concurrency/03.asynchronous_api/03.async_methods/async_method22.ets b/static_core/plugins/ets/tests/ets-templates/16.concurrency/03.asynchronous_api/03.async_methods/async_method22.ets index 38edd61934839c05fd6d3fd2f7ddbd57014a5ee0..6dea9ce2e44aec9494bd6251ee788f0ce17edb24 100644 --- a/static_core/plugins/ets/tests/ets-templates/16.concurrency/03.asynchronous_api/03.async_methods/async_method22.ets +++ b/static_core/plugins/ets/tests/ets-templates/16.concurrency/03.asynchronous_api/03.async_methods/async_method22.ets @@ -37,5 +37,5 @@ async function startTest() { } function main(): void { - startTest(); + waitForCompletion(startTest); } \ No newline at end of file diff --git a/static_core/plugins/ets/tests/ets-templates/16.concurrency/03.asynchronous_api/03.async_methods/async_method24.ets b/static_core/plugins/ets/tests/ets-templates/16.concurrency/03.asynchronous_api/03.async_methods/async_method24.ets index 2d9a2cd454d65a9e53af0cd1ac212eedc511ab3b..3150bfd0727fd27f3bbaae10218fa46bc270dd46 100644 --- a/static_core/plugins/ets/tests/ets-templates/16.concurrency/03.asynchronous_api/03.async_methods/async_method24.ets +++ b/static_core/plugins/ets/tests/ets-templates/16.concurrency/03.asynchronous_api/03.async_methods/async_method24.ets @@ -34,5 +34,5 @@ async function startTest() { } function main(): void { - startTest(); + waitForCompletion(startTest); } \ No newline at end of file diff --git a/static_core/plugins/ets/tests/ets-templates/16.concurrency/03.asynchronous_api/03.async_methods/async_method25.ets b/static_core/plugins/ets/tests/ets-templates/16.concurrency/03.asynchronous_api/03.async_methods/async_method25.ets index ede876a1454012f2d2afe4f2ea64a747ca296cb7..2e8c894f4de0d996e6ab43133829b985fe4f8655 100644 --- a/static_core/plugins/ets/tests/ets-templates/16.concurrency/03.asynchronous_api/03.async_methods/async_method25.ets +++ b/static_core/plugins/ets/tests/ets-templates/16.concurrency/03.asynchronous_api/03.async_methods/async_method25.ets @@ -34,5 +34,5 @@ async function startTest() { } function main(): void { - startTest(); + waitForCompletion(startTest); } \ No newline at end of file diff --git a/static_core/plugins/ets/tests/ets-templates/16.concurrency/03.asynchronous_api/03.async_methods/async_method26.ets b/static_core/plugins/ets/tests/ets-templates/16.concurrency/03.asynchronous_api/03.async_methods/async_method26.ets index fc716944ccaba63268723c97dc3d15601535e35c..f8d7dc1e2b6bd9d3792a912f488f064a492829d3 100644 --- a/static_core/plugins/ets/tests/ets-templates/16.concurrency/03.asynchronous_api/03.async_methods/async_method26.ets +++ b/static_core/plugins/ets/tests/ets-templates/16.concurrency/03.asynchronous_api/03.async_methods/async_method26.ets @@ -44,5 +44,5 @@ async function startTest() { } function main(): void { - startTest(); + waitForCompletion(startTest); } \ No newline at end of file diff --git a/static_core/plugins/ets/tests/ets-templates/16.concurrency/03.asynchronous_api/03.async_methods/async_method27.ets b/static_core/plugins/ets/tests/ets-templates/16.concurrency/03.asynchronous_api/03.async_methods/async_method27.ets index ccf9fcd59920c22ce7874278146849e157403d29..a3f67771228b2884b688e1f0650277ba3e102960 100644 --- a/static_core/plugins/ets/tests/ets-templates/16.concurrency/03.asynchronous_api/03.async_methods/async_method27.ets +++ b/static_core/plugins/ets/tests/ets-templates/16.concurrency/03.asynchronous_api/03.async_methods/async_method27.ets @@ -31,9 +31,12 @@ class MethodWithAllSettled { async function startTest() { const example = new MethodWithAllSettled(); const result = await example.methodWithAllSettled(); - arktest.assertEQ(result, '[{"status":"fulfilled","value":"Resolved!"},{"status":"rejected","reason":{}}]'); + + //redo it... + let expected = '[{"status":"fulfilled","value":"Resolved!"},{"status":"rejected","reason":{"name_":"Error","message_":"Rejected!","stackLines":[{"className":"escompat.Error","methodName":"","sourceFileName":"Error.ets","lineNumber":56,"colNumber":0},{"className":"escompat.Error","methodName":"","sourceFileName":"Error.ets","lineNumber":57,"colNumber":0},{"className":"escompat.Error","methodName":"","sourceFileName":"Error.ets","lineNumber":56,"colNumber":0},{"className":"async_method27.MethodWithAllSettled","methodName":"%%async-methodWithAllSettled","sourceFileName":"async_method27.ets","lineNumber":22,"colNumber":0}],"code_":0}}]'; + arktest.assertEQ(result, expected); } function main(): void { - startTest(); + waitForCompletion(startTest); } \ No newline at end of file diff --git a/static_core/plugins/ets/tests/ets-templates/16.concurrency/03.asynchronous_api/03.async_methods/async_method28.ets b/static_core/plugins/ets/tests/ets-templates/16.concurrency/03.asynchronous_api/03.async_methods/async_method28.ets index 08cba5ada97eea33c30b218a5dde715d64d69d37..1543dabfc44b84d7169a1ba6aad6cc9fd399f7de 100644 --- a/static_core/plugins/ets/tests/ets-templates/16.concurrency/03.asynchronous_api/03.async_methods/async_method28.ets +++ b/static_core/plugins/ets/tests/ets-templates/16.concurrency/03.asynchronous_api/03.async_methods/async_method28.ets @@ -43,5 +43,5 @@ async function startTest() { } function main(): void { - startTest(); + waitForCompletion(startTest); } \ No newline at end of file diff --git a/static_core/plugins/ets/tests/ets-templates/16.concurrency/03.asynchronous_api/03.async_methods/async_method29.ets b/static_core/plugins/ets/tests/ets-templates/16.concurrency/03.asynchronous_api/03.async_methods/async_method29.ets index 1929ddd08677080b2ae9f19fe5887b9ceb881c4d..b409491dff54e016f5f33d9719d32462da14d911 100644 --- a/static_core/plugins/ets/tests/ets-templates/16.concurrency/03.asynchronous_api/03.async_methods/async_method29.ets +++ b/static_core/plugins/ets/tests/ets-templates/16.concurrency/03.asynchronous_api/03.async_methods/async_method29.ets @@ -32,5 +32,5 @@ async function startTest() { } function main(): void { - startTest(); + waitForCompletion(startTest); } \ No newline at end of file diff --git a/static_core/plugins/ets/tests/ets-templates/16.concurrency/03.asynchronous_api/03.async_methods/async_method3.ets b/static_core/plugins/ets/tests/ets-templates/16.concurrency/03.asynchronous_api/03.async_methods/async_method3.ets deleted file mode 100644 index 4d044796fdd011c70ab59fec20a84d7a653532c0..0000000000000000000000000000000000000000 --- a/static_core/plugins/ets/tests/ets-templates/16.concurrency/03.asynchronous_api/03.async_methods/async_method3.ets +++ /dev/null @@ -1,36 +0,0 @@ -/* - * Copyright (c) 2025 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. - */ - -/*--- -desc: Test cases for various usage scenarios of asynchronous method. - The asynchronous method returns a void. ----*/ - -class MethodReturnVoid { - value: number = 0; - async methodReturnVoid(): Promise { - this.value = 1; - arktest.assertEQ(this.value, 1); - } -} - -async function startTest() { - const example = new MethodReturnVoid(); - await example.methodReturnVoid(); -} - -function main(): void { - waitForCompletion(startTest); -} \ No newline at end of file diff --git a/static_core/plugins/ets/tests/ets-templates/16.concurrency/03.asynchronous_api/03.async_methods/async_method30.ets b/static_core/plugins/ets/tests/ets-templates/16.concurrency/03.asynchronous_api/03.async_methods/async_method30.ets index d11e45994cd09470ba9ed44805628f38919f9d2b..5b1954a4463d1ed28477ee1f833a37148d7900b0 100644 --- a/static_core/plugins/ets/tests/ets-templates/16.concurrency/03.asynchronous_api/03.async_methods/async_method30.ets +++ b/static_core/plugins/ets/tests/ets-templates/16.concurrency/03.asynchronous_api/03.async_methods/async_method30.ets @@ -33,5 +33,5 @@ async function startTest() { } function main(): void { - startTest(); + waitForCompletion(startTest); } \ No newline at end of file diff --git a/static_core/plugins/ets/tests/ets-templates/16.concurrency/03.asynchronous_api/03.async_methods/async_method4.ets b/static_core/plugins/ets/tests/ets-templates/16.concurrency/03.asynchronous_api/03.async_methods/async_method4.ets index 7e1802f09e6ff5eb763b0f5e47021e577cf98f32..e3b3e16a15b4647b350c9dddf20c5dcdd8c3c88c 100644 --- a/static_core/plugins/ets/tests/ets-templates/16.concurrency/03.asynchronous_api/03.async_methods/async_method4.ets +++ b/static_core/plugins/ets/tests/ets-templates/16.concurrency/03.asynchronous_api/03.async_methods/async_method4.ets @@ -32,5 +32,5 @@ async function startTest() { } function main(): void { - startTest(); + waitForCompletion(startTest); } \ No newline at end of file diff --git a/static_core/plugins/ets/tests/ets-templates/16.concurrency/03.asynchronous_api/03.async_methods/async_method5.ets b/static_core/plugins/ets/tests/ets-templates/16.concurrency/03.asynchronous_api/03.async_methods/async_method5.ets index b8da6aa2763c370cd5fbb588972550b5748b9f05..c7d725ebcdf9458e73ab6e45fa83f4dc024736ec 100644 --- a/static_core/plugins/ets/tests/ets-templates/16.concurrency/03.asynchronous_api/03.async_methods/async_method5.ets +++ b/static_core/plugins/ets/tests/ets-templates/16.concurrency/03.asynchronous_api/03.async_methods/async_method5.ets @@ -32,5 +32,5 @@ async function startTest() { } function main(): void { - startTest(); + waitForCompletion(startTest); } \ No newline at end of file diff --git a/static_core/plugins/ets/tests/ets-templates/16.concurrency/03.asynchronous_api/03.async_methods/async_method6.ets b/static_core/plugins/ets/tests/ets-templates/16.concurrency/03.asynchronous_api/03.async_methods/async_method6.ets index d9d83f75ea5178653f729dd5fb36225760c6fdf1..a60ed1b699ecdfb7ec4d8efdebb5f057f28ad92a 100644 --- a/static_core/plugins/ets/tests/ets-templates/16.concurrency/03.asynchronous_api/03.async_methods/async_method6.ets +++ b/static_core/plugins/ets/tests/ets-templates/16.concurrency/03.asynchronous_api/03.async_methods/async_method6.ets @@ -31,5 +31,5 @@ async function startTest() { } function main(): void { - startTest(); + waitForCompletion(startTest); } \ No newline at end of file diff --git a/static_core/plugins/ets/tests/ets-templates/16.concurrency/03.asynchronous_api/03.async_methods/async_method7.ets b/static_core/plugins/ets/tests/ets-templates/16.concurrency/03.asynchronous_api/03.async_methods/async_method7.ets index 4b7e6fc3e82aa02dd46a1c2fd8c3bd7cc54b87eb..406504a2f6bf4e9f77810e84b126b2bb8e861e2a 100644 --- a/static_core/plugins/ets/tests/ets-templates/16.concurrency/03.asynchronous_api/03.async_methods/async_method7.ets +++ b/static_core/plugins/ets/tests/ets-templates/16.concurrency/03.asynchronous_api/03.async_methods/async_method7.ets @@ -29,10 +29,10 @@ async function startTest() { try { await example.methodThrowError(); } catch (error) { - arktest.assertEQ(error as string, "Something went wrong!"); + arktest.assertEQ((error as Error).message, "Something went wrong!"); } } function main(): void { - startTest(); + waitForCompletion(startTest); } \ No newline at end of file diff --git a/static_core/plugins/ets/tests/ets-templates/16.concurrency/03.asynchronous_api/03.async_methods/async_method8.ets b/static_core/plugins/ets/tests/ets-templates/16.concurrency/03.asynchronous_api/03.async_methods/async_method8.ets index c368d91cdb5b58d0b13f016f73e972c9199d0e49..8a29056ebbd874b3a9dd2440ac6ca565240c16e3 100644 --- a/static_core/plugins/ets/tests/ets-templates/16.concurrency/03.asynchronous_api/03.async_methods/async_method8.ets +++ b/static_core/plugins/ets/tests/ets-templates/16.concurrency/03.asynchronous_api/03.async_methods/async_method8.ets @@ -35,5 +35,5 @@ async function startTest() { } function main(): void { - startTest(); + waitForCompletion(startTest); } \ No newline at end of file diff --git a/static_core/plugins/ets/tests/ets-templates/16.concurrency/03.asynchronous_api/03.async_methods/async_method9.ets b/static_core/plugins/ets/tests/ets-templates/16.concurrency/03.asynchronous_api/03.async_methods/async_method9.ets index 268d28a8cfdfc273801495914101707ba3cd5f62..e320e917ada6bbf473ee5a9239f650fde19fb584 100644 --- a/static_core/plugins/ets/tests/ets-templates/16.concurrency/03.asynchronous_api/03.async_methods/async_method9.ets +++ b/static_core/plugins/ets/tests/ets-templates/16.concurrency/03.asynchronous_api/03.async_methods/async_method9.ets @@ -41,5 +41,5 @@ async function startTest() { } function main(): void { - startTest(); + waitForCompletion(startTest); } \ No newline at end of file diff --git a/static_core/plugins/ets/tests/ets-templates/16.concurrency/03.asynchronous_api/03.async_methods/return_type_is_promise/no_input_params/predefined_types/async_method_returns_promise_predefined0.ets b/static_core/plugins/ets/tests/ets-templates/16.concurrency/03.asynchronous_api/03.async_methods/return_type_is_promise/no_input_params/predefined_types/async_method_returns_promise_predefined0.ets new file mode 100644 index 0000000000000000000000000000000000000000..b6d8e578c8a0e954362032c8146f3ba4462fbf5d --- /dev/null +++ b/static_core/plugins/ets/tests/ets-templates/16.concurrency/03.asynchronous_api/03.async_methods/return_type_is_promise/no_input_params/predefined_types/async_method_returns_promise_predefined0.ets @@ -0,0 +1,19 @@ +/* + * Copyright (c) 2025 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. + */ + +{% from 'ets-templates/16.concurrency/03.asynchronous_api/predefined_types.jinja' import numeric_types_cases, boolean_types_cases, symbol_types_cases, no_value_types_cases %} +{% from 'ets-templates/16.concurrency/03.asynchronous_api/async_returns_predefined0.base.jinja' import generate_complete_test %} + +{{ generate_complete_test(numeric_types_cases + boolean_types_cases + symbol_types_cases + no_value_types_cases, 'method') }} \ No newline at end of file diff --git a/static_core/plugins/ets/tests/ets-templates/16.concurrency/03.asynchronous_api/03.async_methods/return_type_is_promise/no_input_params/predefined_types/async_method_returns_promise_predefined1.ets b/static_core/plugins/ets/tests/ets-templates/16.concurrency/03.asynchronous_api/03.async_methods/return_type_is_promise/no_input_params/predefined_types/async_method_returns_promise_predefined1.ets new file mode 100644 index 0000000000000000000000000000000000000000..064722c4f15c232862ab37d31f7dcf90b8f52b20 --- /dev/null +++ b/static_core/plugins/ets/tests/ets-templates/16.concurrency/03.asynchronous_api/03.async_methods/return_type_is_promise/no_input_params/predefined_types/async_method_returns_promise_predefined1.ets @@ -0,0 +1,19 @@ +/* + * Copyright (c) 2025 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. + */ + +{% from 'ets-templates/16.concurrency/03.asynchronous_api/predefined_types.jinja' import numeric_types_cases, boolean_types_cases, symbol_types_cases %} +{% from 'ets-templates/16.concurrency/03.asynchronous_api/async_returns_predefined1.base.jinja' import generate_complete_test %} + +{{ generate_complete_test(numeric_types_cases + boolean_types_cases + symbol_types_cases, 'method') }} \ No newline at end of file diff --git a/static_core/plugins/ets/tests/ets-templates/16.concurrency/03.asynchronous_api/03.async_methods/async_method11.ets b/static_core/plugins/ets/tests/ets-templates/16.concurrency/03.asynchronous_api/03.async_methods/return_type_is_promise/no_input_params/predefined_types/async_method_returns_void.ets similarity index 33% rename from static_core/plugins/ets/tests/ets-templates/16.concurrency/03.asynchronous_api/03.async_methods/async_method11.ets rename to static_core/plugins/ets/tests/ets-templates/16.concurrency/03.asynchronous_api/03.async_methods/return_type_is_promise/no_input_params/predefined_types/async_method_returns_void.ets index dcf299b5c83fcfb8e1e23338259d49269ba24383..8dafcedba4ce3ceb1fbd93049d6753d5b0c83058 100644 --- a/static_core/plugins/ets/tests/ets-templates/16.concurrency/03.asynchronous_api/03.async_methods/async_method11.ets +++ b/static_core/plugins/ets/tests/ets-templates/16.concurrency/03.asynchronous_api/03.async_methods/return_type_is_promise/no_input_params/predefined_types/async_method_returns_void.ets @@ -13,27 +13,52 @@ * limitations under the License. */ -/*--- -desc: Test cases for various usage scenarios of asynchronous method. - Asynchronous methods return a promise.. ----*/ - -class MethodReturnNestedPromise { - async methodReturnString(): Promise { - return "Hello, World!"; +{% set cases = [ + { + 'body': 'console.log("Hello")', + 'return_type': '', + 'description': 'The return type of an async method must be Promise.' + }, + { + 'body': 'console.log("Hello")', + 'return_type': ':Promise', + 'description': 'No-argument return statement can be added implicitly as the last statement of the method + body if there is no explicit return statement in a method with the return Promise.' + }, + { + 'body': 'return', + 'return_type': ':Promise', + 'description': 'Using return statement without an expression is allowed if the return type is Promise.' } + ] %} - async methodReturnNestedPromise(): Promise> { - return this.methodReturnString(); +{% macro generate_method(body, return_type) %} +class AsyncMethodClass{ + async noParams(){{return_type}}{ + {{body}} } } +{% endmacro %} + +{% for c in cases %} + + /*--- +desc: {{c.description}} +---*/ + +{{ generate_method(c.body, c.return_type) }} + +async function startTest(){ + + let obj = new AsyncMethodClass() + let result = obj.noParams() + arktest.assertTrue(result instanceof Promise) + let awaited_result = await result + arktest.assertTrue(awaited_result instanceof undefined) +} -async function startTest() { - const example = new MethodReturnNestedPromise(); - const result = await example.methodReturnNestedPromise(); - arktest.assertEQ(result, "Hello, World!") +function main(){ + waitForCompletion(startTest) } -function main(): void { - startTest(); -} \ No newline at end of file +{% endfor %} \ No newline at end of file diff --git a/static_core/plugins/ets/tests/ets-templates/16.concurrency/03.asynchronous_api/03.async_methods/async_method14.ets b/static_core/plugins/ets/tests/ets-templates/16.concurrency/03.asynchronous_api/03.async_methods/return_type_is_promise/no_input_params/predefined_types/async_method_with_promise_with_return.ets similarity index 69% rename from static_core/plugins/ets/tests/ets-templates/16.concurrency/03.asynchronous_api/03.async_methods/async_method14.ets rename to static_core/plugins/ets/tests/ets-templates/16.concurrency/03.asynchronous_api/03.async_methods/return_type_is_promise/no_input_params/predefined_types/async_method_with_promise_with_return.ets index 1cbb4ece9d3389fcaf82710880323bad6d17256e..0b9fb2aca2a28870be34727f94c95b850d61f19a 100644 --- a/static_core/plugins/ets/tests/ets-templates/16.concurrency/03.asynchronous_api/03.async_methods/async_method14.ets +++ b/static_core/plugins/ets/tests/ets-templates/16.concurrency/03.asynchronous_api/03.async_methods/return_type_is_promise/no_input_params/predefined_types/async_method_with_promise_with_return.ets @@ -14,22 +14,21 @@ */ /*--- -desc: Test cases for various usage scenarios of asynchronous method. - Asynchronous method returns boolean. +desc: Test cases for various usage scenarios of asynchronous method. With 'Promise', With 'return' ---*/ -class MethodReturnBoolean { - async methodReturnBoolean(): Promise { - return true; - } +class MethodConcurrentExecution { + async methodReturnVoid(): Promise{ + return; + } } async function startTest() { - const example = new MethodReturnBoolean(); - const result = await example.methodReturnBoolean(); - arktest.assertEQ(result === true, true) + const example = new MethodConcurrentExecution(); + const result = await example.methodReturnVoid(); + arktest.assertTrue(result instanceof undefined) } function main(): void { - startTest(); + waitForCompletion(startTest); } \ No newline at end of file diff --git a/static_core/plugins/ets/tests/ets-templates/16.concurrency/03.asynchronous_api/03.async_methods/async_method2.ets b/static_core/plugins/ets/tests/ets-templates/16.concurrency/03.asynchronous_api/03.async_methods/return_type_is_promise/no_input_params/predefined_types/async_method_with_promise_without_return.ets similarity index 69% rename from static_core/plugins/ets/tests/ets-templates/16.concurrency/03.asynchronous_api/03.async_methods/async_method2.ets rename to static_core/plugins/ets/tests/ets-templates/16.concurrency/03.asynchronous_api/03.async_methods/return_type_is_promise/no_input_params/predefined_types/async_method_with_promise_without_return.ets index 19ee73ade2e4f995c7fb13eca1fa6d4cee4ede51..ebcf1a0b6cd1bed2237a32c119fb5ce51d3a9dd0 100644 --- a/static_core/plugins/ets/tests/ets-templates/16.concurrency/03.asynchronous_api/03.async_methods/async_method2.ets +++ b/static_core/plugins/ets/tests/ets-templates/16.concurrency/03.asynchronous_api/03.async_methods/return_type_is_promise/no_input_params/predefined_types/async_method_with_promise_without_return.ets @@ -14,22 +14,20 @@ */ /*--- -desc: Test cases for various usage scenarios of asynchronous method. - The asynchronous method returns a double. +desc: Test cases for various usage scenarios of asynchronous method. With 'Promise', Without 'return' ---*/ -class MethodReturnDouble { - async methodReturnDouble(): Promise { - return 10.0; - } +class MethodConcurrentExecution { + async methodReturnVoid(): Promise{ + } } async function startTest() { - const example = new MethodReturnDouble(); - const result = await example.methodReturnDouble(); - arktest.assertEQ(result, 10.0); + const example = new MethodConcurrentExecution(); + const result = await example.methodReturnVoid(); + arktest.assertTrue(result instanceof undefined) } function main(): void { - waitForCompletion(startTest); + waitForCompletion(startTest); } \ No newline at end of file diff --git a/static_core/plugins/ets/tests/ets-templates/16.concurrency/03.asynchronous_api/03.async_methods/async_method1.ets b/static_core/plugins/ets/tests/ets-templates/16.concurrency/03.asynchronous_api/03.async_methods/return_type_is_promise/no_input_params/predefined_types/async_method_without_promise_with_return.ets similarity index 70% rename from static_core/plugins/ets/tests/ets-templates/16.concurrency/03.asynchronous_api/03.async_methods/async_method1.ets rename to static_core/plugins/ets/tests/ets-templates/16.concurrency/03.asynchronous_api/03.async_methods/return_type_is_promise/no_input_params/predefined_types/async_method_without_promise_with_return.ets index 9190c8cb29d232a44fdef2dd93a0a7bce2bf73cb..e996e6378dbb18a81b8b653575f394bb795cc067 100644 --- a/static_core/plugins/ets/tests/ets-templates/16.concurrency/03.asynchronous_api/03.async_methods/async_method1.ets +++ b/static_core/plugins/ets/tests/ets-templates/16.concurrency/03.asynchronous_api/03.async_methods/return_type_is_promise/no_input_params/predefined_types/async_method_without_promise_with_return.ets @@ -14,22 +14,21 @@ */ /*--- -desc: Test cases for various usage scenarios of asynchronous method. - The asynchronous method returns a int. +desc: Test cases for various usage scenarios of asynchronous method. Without 'Promise', With 'return' ---*/ -class MethodReturnInt { - async methodReturnInt(): Promise { - return 10; - } +class MethodConcurrentExecution { + async methodReturnVoid(){ + return; + } } async function startTest() { - const example = new MethodReturnInt(); - const result = await example.methodReturnInt(); - arktest.assertEQ(result, 10); + const example = new MethodConcurrentExecution(); + const result = await example.methodReturnVoid(); + arktest.assertTrue(result instanceof undefined) } function main(): void { - waitForCompletion(startTest); + waitForCompletion(startTest); } \ No newline at end of file diff --git a/static_core/plugins/ets/tests/ets-templates/16.concurrency/03.asynchronous_api/03.async_methods/async_method13.ets b/static_core/plugins/ets/tests/ets-templates/16.concurrency/03.asynchronous_api/03.async_methods/return_type_is_promise/no_input_params/predefined_types/async_method_without_promise_without_return.ets similarity index 71% rename from static_core/plugins/ets/tests/ets-templates/16.concurrency/03.asynchronous_api/03.async_methods/async_method13.ets rename to static_core/plugins/ets/tests/ets-templates/16.concurrency/03.asynchronous_api/03.async_methods/return_type_is_promise/no_input_params/predefined_types/async_method_without_promise_without_return.ets index 04a715d4ce4e2fbafc3481308ecee8ea7478388a..61eda1746c2c81a7deb44b52af89c86daa72e8c5 100644 --- a/static_core/plugins/ets/tests/ets-templates/16.concurrency/03.asynchronous_api/03.async_methods/async_method13.ets +++ b/static_core/plugins/ets/tests/ets-templates/16.concurrency/03.asynchronous_api/03.async_methods/return_type_is_promise/no_input_params/predefined_types/async_method_without_promise_without_return.ets @@ -14,22 +14,20 @@ */ /*--- -desc: Test cases for various usage scenarios of asynchronous method. - Asynchronous method returns null. +desc: Test cases for various usage scenarios of asynchronous method. Without 'Promise', Without 'return' ---*/ -class MethodReturnNull { - async methodReturnNull(): Promise { - return null; - } +class MethodConcurrentExecution { + async methodReturnVoid(){ + } } async function startTest() { - const example = new MethodReturnNull(); - const result = await example.methodReturnNull(); - arktest.assertEQ(result === null, true) + const example = new MethodConcurrentExecution(); + const result = await example.methodReturnVoid(); + arktest.assertTrue(result instanceof undefined) } function main(): void { - startTest(); + waitForCompletion(startTest); } \ No newline at end of file diff --git a/static_core/plugins/ets/tests/ets-templates/16.concurrency/03.asynchronous_api/async_returns_predefined0.base.jinja b/static_core/plugins/ets/tests/ets-templates/16.concurrency/03.asynchronous_api/async_returns_predefined0.base.jinja new file mode 100644 index 0000000000000000000000000000000000000000..143bd3188ae4fab3e63e6823aec20c47fa9b0b18 --- /dev/null +++ b/static_core/plugins/ets/tests/ets-templates/16.concurrency/03.asynchronous_api/async_returns_predefined0.base.jinja @@ -0,0 +1,73 @@ +/** + * Copyright (c) 2025 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. + */ + +{% macro generate_complete_test(cases, declaration_type='function') %} +{% for c in cases %} +{% for type_name in [c.type, c.alias] | select %} + +/*--- +desc: The return type of an async function must be Promise<{{type_name}}>. +---*/ + +{% if declaration_type == 'function' %} +async function noParams(): Promise<{{type_name}}> { +{% elif declaration_type == 'lambda' %} +const noParams = async (): Promise<{{type_name}}> => { +{% elif declaration_type == 'method' %} +class AsyncMethodReturnClass { + async noParams(): Promise<{{type_name}}> { +{% endif %} + + {% if type_name in ['Byte', 'Short'] %} + const value: {{type_name}} = new {{type_name}}({{c.value}}) + {% else %} + const value: {{type_name}} = {{c.value}} + {% endif %} + return value + +} + +{% if declaration_type == 'method' %} +} {# Closing brace of class #} +{% endif %} + +async function startTest(){ + + + {% if declaration_type == 'method' %} + let obj = new AsyncMethodReturnClass() + let result = obj.noParams() + {% else %} + let result = noParams() + {% endif %} + + arktest.assertTrue(result instanceof Promise) + let awaited_result = await result + arktest.assertTrue(awaited_result instanceof {{type_name}}) + {% if type_name in ['Byte', 'Short'] %} + arktest.assertEQ({{type_name}}.valueOf(awaited_result), {{c.value}}) + {% else %} + arktest.assertEQ(awaited_result, {{c.value}}) + + {% endif %} +} + +function main(){ + waitForCompletion(startTest) +} + +{% endfor %} +{% endfor %} +{% endmacro %} \ No newline at end of file diff --git a/static_core/plugins/ets/tests/ets-templates/16.concurrency/03.asynchronous_api/async_returns_predefined1.base.jinja b/static_core/plugins/ets/tests/ets-templates/16.concurrency/03.asynchronous_api/async_returns_predefined1.base.jinja new file mode 100644 index 0000000000000000000000000000000000000000..a0dc61efb95f0dbcb8ca1da68bc5f30c9b4b62f8 --- /dev/null +++ b/static_core/plugins/ets/tests/ets-templates/16.concurrency/03.asynchronous_api/async_returns_predefined1.base.jinja @@ -0,0 +1,72 @@ +/** + * Copyright (c) 2025 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. + */ + + +{% macro generate_type_name(array_type, content_type) -%} +{%- if array_type == 'Array' or array_type == 'FixedArray' -%} +{{array_type}}<{{content_type}}> +{%- else -%} +{{content_type}}[] +{%- endif -%} +{%- endmacro %} + +{% macro generate_complete_test(cases, declaration_type='function') %} +{% for c in cases %} +{% for arr_type in ['Array', 'FixedArray', '[]'] %} +{% set type_name = generate_type_name(arr_type, c.type) %} + +/*--- +desc: The return type of an async function must be Promise<{{type_name}}>. +---*/ + +{% if declaration_type == 'function' %} +async function noParams(): Promise<{{type_name}}> { +{% elif declaration_type == 'lambda' %} +const noParams = async (): Promise<{{type_name}}> => { +{% elif declaration_type == 'method' %} +class AsyncMethodReturnClass { + async noParams(): Promise<{{type_name}}> { +{% endif %} + const value: {{type_name}} = [{{c.value}}] + return value +} +{% if declaration_type == 'method' %} +} {# Closing brace of class #} +{% endif %} + +async function startTest(){ + + {% if declaration_type == 'method' %} + let obj = new AsyncMethodReturnClass() + let result = obj.noParams() + {% else %} + let result = noParams() + {% endif %} + arktest.assertTrue(result instanceof Promise) + let awaited_result = await result + arktest.assertTrue(Array.isArray(awaited_result)) + arktest.assertEQ(awaited_result[0], {{c.value}}) + {%- if array_type == 'FixedArray' -%} + arktest.assertTrue(awaited_result instanceof FixedArray) + {% endif %} +} + +function main(){ + waitForCompletion(startTest) +} + +{% endfor %} +{% endfor %} +{% endmacro %} \ No newline at end of file diff --git a/static_core/plugins/ets/tests/ets-templates/16.concurrency/03.asynchronous_api/predefined_types.jinja b/static_core/plugins/ets/tests/ets-templates/16.concurrency/03.asynchronous_api/predefined_types.jinja new file mode 100644 index 0000000000000000000000000000000000000000..886b50b105cacf829ec82704bc696c0aa219df1c --- /dev/null +++ b/static_core/plugins/ets/tests/ets-templates/16.concurrency/03.asynchronous_api/predefined_types.jinja @@ -0,0 +1,98 @@ +/** + * Copyright (c) 2025 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 numeric_types_cases = [ + {'type': 'int', 'alias': 'Int', 'value': '42'}, + {'type': 'number', 'alias': 'Number', 'value': '42.0'}, + {'type': 'byte', 'alias': 'Byte', 'value': '127'}, + {'type': 'short', 'alias': 'Short', 'value': '32767'}, + {'type': 'long', 'alias': 'Long', 'value': '9223372036854775807'}, + {'type': 'float', 'alias': 'Float', 'value': '3.14f'}, + {'type': 'double', 'alias': 'Double', 'value': '3.141592653589793'}, + {'type': 'bigint', 'alias': 'BigInt', 'value': '123456789012345678901234567890n'} +] %} + +{% set boolean_types_cases = [ + {'type': 'boolean', 'alias': 'Boolean', 'value': 'true'}, +] %} + +{% set symbol_types_cases = [ + {'type': 'string', 'alias': 'String', 'value': '"Hello, ArkTS!"'}, + {'type': 'char', 'alias': 'Char', 'value': "c'A'"}, +] %} + +{% set non_return_types_cases = [ + {'type': 'never', 'value': 'undefined'}, + {'type': 'void', 'value': 'undefined'} +] %} + +{% set no_value_types_cases = [ + {'type': 'undefined', 'value': 'undefined'}, + {'type': 'null', 'value': 'null'} +] %} + +{% set base_types_cases = [ + {'type': 'Any', 'value': '"Any value"'}, + {'type': 'Object', 'alias': 'object', 'value': 'new Object()'}, +]%} + +{% set resizable_array_types_cases = [ + {'type': 'int[]', 'value': '[1, 2, 3]'}, + {'type': 'number[]', 'value': '[1.0, 2.5, 3.7]'}, + {'type': 'string[]', 'value': '["Hello", "ArkTS", "World"]'}, + {'type': 'boolean[]', 'value': '[true, false, true]'}, + {'type': 'byte[]', 'value': '[127, -128, 0]'}, + {'type': 'short[]', 'value': '[32767, -32768, 0]'}, + {'type': 'long[]', 'value': '[9223372036854775807, 0]'}, + {'type': 'float[]', 'value': '[3.14f, -2.71f, 0.0f]'}, + {'type': 'double[]', 'value': '[3.141592653589793, 0.0]'}, + {'type': 'bigint[]', 'value': '[123456789012345678901234567890n]'}, + {'type': 'char[]', 'value': "[c'A', c'B', c'C']"}, + {'type': 'Any[]', 'value': '["mixed", 42, true]'}, + {'type': 'Object[]', 'value': '[new Object(), new Object()]'} +] %} + +{% set generic_array_types_cases = [ + {'type': 'Array', 'value': '[1, 2, 3]'}, + {'type': 'Array', 'value': '[1.0, 2.5, 3.7]'}, + {'type': 'Array', 'value': '["Hello", "ArkTS"]'}, + {'type': 'Array', 'value': '[true, false]'}, + {'type': 'Array', 'value': '["mixed", 42]'}, + {'type': 'Array', 'value': '[new Object(), new Object()]'} +] %} + +{% set fixed_array_types_cases = [ + {'type': 'FixedArray', 'value': '[1, 2, 3]'}, + {'type': 'FixedArray', 'value': '[1.0, 2.5, 3.7]'}, + {'type': 'FixedArray', 'value': '["Hello", "ArkTS"]'}, + {'type': 'FixedArray', 'value': '[true, false]'}, + {'type': 'FixedArray', 'value': '[127, -128]'}, + {'type': 'FixedArray', 'value': "[c'A', c'B']"} +] %} + +{% set multidimensional_array_types_cases = [ + {'type': 'int[][]', 'value': '[[1, 2], [3, 4]]'}, + {'type': 'string[][]', 'value': '[["Hello", "World"], ["ArkTS", "Test"]]'}, + {'type': 'Array>', 'value': '[[1, 2], [3, 4]]'}, + {'type': 'Array>', 'value': '[["Hello", "World"], ["ArkTS", "Test"]]'}, + {'type': 'FixedArray>', 'value': '[[1, 2], [3, 4]]'}, + {'type': 'FixedArray>', 'value': '[["A", "B"], ["C", "D"]]'} +] %} + +{% set empty_array_types_cases = [ + {'type': 'int[]', 'value': '[]'}, + {'type': 'Array', 'value': '[]'}, + {'type': 'FixedArray', 'value': '[]'} +] %} \ No newline at end of file diff --git a/static_core/plugins/ets/tests/test-lists/ets-cts/ets-cts-ignored.txt b/static_core/plugins/ets/tests/test-lists/ets-cts/ets-cts-ignored.txt index 0aa140820d31f2c7b23db81807c669f9aad40eb5..45809354ca910b852052ceafaf458fb8a6dc15f0 100644 --- a/static_core/plugins/ets/tests/test-lists/ets-cts/ets-cts-ignored.txt +++ b/static_core/plugins/ets/tests/test-lists/ets-cts/ets-cts-ignored.txt @@ -1479,6 +1479,7 @@ 09.classes/06.field_declarations/05.fields_with_late_initialization/fields_with_late_initialization_rte_153.ets 09.classes/06.field_declarations/05.fields_with_late_initialization/fields_with_late_initialization_rte_154.ets 09.classes/06.field_declarations/05.fields_with_late_initialization/fields_with_late_initialization_rte_155.ets +16.concurrency/03.asynchronous_api/03.async_methods/return_type_is_promise/no_input_params/predefined_types/async_method_without_promise_with_return.ets #29302 09.classes/06.field_declarations/05.fields_with_late_initialization/fields_with_late_initialization_decl_247.ets @@ -2866,6 +2867,7 @@ #2160 14.ambient_declarations/06.namespace_declarations/01.impl_ambient_namespace/negative/namespace_usage_n_5.ets + #29727 10.interfaces/06.interface_inheritance/multi_layer_interface/complex_inheritance/complex_inheritance_12.ets 10.interfaces/06.interface_inheritance/multi_layer_interface/complex_inheritance/complex_inheritance_22.ets @@ -2877,3 +2879,6 @@ 13.compilation_units/02.import_directives/05.import_path/file/import_path_file_global_0.ets 13.compilation_units/02.import_directives/05.import_path/file/import_path_file_global_1.ets +#29982 +16.concurrency/03.asynchronous_api/03.async_methods/async_method17.ets + diff --git a/static_core/tests/tests-u-runner/runner/plugins/ets/ets_templates/template.py b/static_core/tests/tests-u-runner/runner/plugins/ets/ets_templates/template.py index 9576a0583e19de739cd2fd1a466c67063e51e7e9..0cde48a09798dd79d537900734bb50e0d2ffb3cc 100644 --- a/static_core/tests/tests-u-runner/runner/plugins/ets/ets_templates/template.py +++ b/static_core/tests/tests-u-runner/runner/plugins/ets/ets_templates/template.py @@ -1,7 +1,7 @@ #!/usr/bin/env python3 # -*- coding: utf-8 -*- -# Copyright (c) 2021-2024 Huawei Device Co., Ltd. +# Copyright (c) 2021-2025 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 @@ -21,7 +21,7 @@ from pathlib import Path from typing import Dict, Any, List, Tuple import yaml -from jinja2 import Environment, select_autoescape, TemplateSyntaxError +from jinja2 import Environment, select_autoescape, TemplateSyntaxError, FileSystemLoader from runner.plugins.ets.utils.constants import META_COPYRIGHT, META_START_STRING, \ META_END_STRING, META_START_COMMENT, META_END_COMMENT from runner.plugins.ets.utils.exceptions import \ @@ -29,6 +29,8 @@ from runner.plugins.ets.utils.exceptions import \ from runner.utils import read_file ROOT_PATH = Path(os.path.realpath(os.path.dirname(__file__))) +PROJECT_ROOT = ROOT_PATH.parent.parent.parent.parent.parent.parent.parent +ETS_TESTS_ROOT = PROJECT_ROOT / "static_core" / "plugins" / "ets" / "tests" BENCH_PATH = ROOT_PATH / "test_template.tpl" COPYRIGHT_PATH = ROOT_PATH / "copyright.txt" @@ -44,7 +46,10 @@ class Template: self.test_path = str(test_path) self.text = read_file(test_path) self.__params = params - self.__jinja_env = Environment(autoescape=select_autoescape()) + self.__jinja_env = Environment( + loader=FileSystemLoader([str(test_path.parent), str(ETS_TESTS_ROOT)]), + autoescape=select_autoescape() + ) if self.is_copyright: self.__copyright = read_file(COPYRIGHT_PATH)