Skip to content

Commit d58b002

Browse files
sigmundchCommit Queue
authored andcommitted
[dyn_modules] add more test cases.
This includes: * tests extending non-base class * tests for applying mixins * generalization of top-level test to include methods and gettters * tests for annotating entities indirectly (reexport, hidden implementation) * test for using core libraries and core language features. Change-Id: I2ff928c15794547368d2871f5b982685593ef662 Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/396105 Reviewed-by: Alexander Markov <[email protected]> Commit-Queue: Sigmund Cherem <[email protected]>
1 parent c18e243 commit d58b002

File tree

20 files changed

+420
-7
lines changed

20 files changed

+420
-7
lines changed
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
# Copyright (c) 2024, the Dart project authors. Please see the AUTHORS file
2+
# for details. All rights reserved. Use of this source code is governed by a
3+
# BSD-style license that can be found in the LICENSE file.
4+
extendable:
5+
- library: 'shared/shared.dart'
6+
class: 'A'
7+
- library: 'shared/shared.dart'
8+
class: 'M'
9+
# TODO(sigmund): This should be included by default
10+
- library: 'dart:core'
11+
class: 'Object'
12+
13+
callable:
14+
# TODO(sigmund): This should be included by default
15+
- library: 'dart:core'
16+
class: 'Object'
17+
- library: 'dart:core'
18+
class: 'int'
19+
- library: 'dart:core'
20+
class: 'String'
21+
- library: 'dart:core'
22+
class: 'pragma'
23+
member: '_'
24+
- library: 'dart:core'
25+
member: 'override'
26+
- library: 'shared/shared.dart'
27+
class: 'M'
28+
29+
can-be-overridden:
30+
- library: 'shared/shared.dart'
31+
class: 'A'
32+
- library: 'shared/shared.dart'
33+
class: 'M'

pkg/dynamic_modules/test/data/update_top_level/main.dart renamed to pkg/dynamic_modules/test/data/apply_mixin/main.dart

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,12 @@
55
import '../../common/testing.dart' as helper;
66
import 'package:expect/expect.dart';
77

8-
import 'shared/shared.dart' show topLevel;
8+
import 'shared/shared.dart' show M;
99

10-
/// A top-level setter can be invoked from a dynamic module.
10+
/// A dynamic module can apply an exposed mixin.
1111
main() async {
12-
Expect.equals('original', topLevel);
13-
await helper.load('entry1.dart');
14-
Expect.equals('updated', topLevel);
12+
final o = (await helper.load('entry1.dart')) as M;
13+
Expect.equals(3, o.method1());
14+
Expect.equals('*3 2', o.method2());
1515
helper.done();
1616
}
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
// Copyright (c) 2024, the Dart project authors. Please see the AUTHORS file
2+
// for details. All rights reserved. Use of this source code is governed by a
3+
// BSD-style license that can be found in the LICENSE file.
4+
5+
import '../shared/shared.dart';
6+
7+
class RealA implements A {
8+
@override
9+
int method1() => 3;
10+
}
11+
12+
class Child extends RealA with M {
13+
@override
14+
String method2() => '*${super.method2()}';
15+
}
16+
17+
@pragma('dyn-module:entry-point')
18+
Object? dynamicModuleEntrypoint() => Child();

pkg/dynamic_modules/test/data/update_top_level/shared/shared.dart renamed to pkg/dynamic_modules/test/data/apply_mixin/shared/shared.dart

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,10 @@
22
// for details. All rights reserved. Use of this source code is governed by a
33
// BSD-style license that can be found in the LICENSE file.
44

5-
String topLevel = 'original';
5+
abstract interface class A {
6+
int method1();
7+
}
8+
9+
mixin M on A {
10+
String method2() => '${super.method1()} 2';
11+
}
Lines changed: 90 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,90 @@
1+
# Copyright (c) 2024, the Dart project authors. Please see the AUTHORS file
2+
# for details. All rights reserved. Use of this source code is governed by a
3+
# BSD-style license that can be found in the LICENSE file.
4+
callable:
5+
# Mentioned in the code, however core types should be included by default
6+
- library: 'package:expect/expect.dart'
7+
class: 'Expect'
8+
member: 'equals'
9+
- library: 'dart:async'
10+
class: 'Future'
11+
- library: 'dart:core'
12+
class: 'String'
13+
- library: 'dart:core'
14+
class: 'int'
15+
- library: 'dart:core'
16+
class: 'bool'
17+
- library: 'dart:core'
18+
class: 'List'
19+
- library: 'dart:core'
20+
class: 'Iterable'
21+
22+
# TODO(sigmund): This should be included by default
23+
- library: 'dart:core'
24+
class: 'pragma'
25+
member: '_'
26+
27+
# Needed to support for-in loops
28+
- library: 'dart:core'
29+
class: 'Iterator'
30+
member: 'moveNext'
31+
- library: 'dart:core'
32+
class: 'Iterator'
33+
member: 'get:current'
34+
- library: 'dart:core'
35+
class: 'Iterator'
36+
- library: 'dart:core'
37+
38+
# Needed to support creating list literals
39+
- library: 'dart:core'
40+
class: '_GrowableList'
41+
- library: 'dart:core'
42+
class: '_GrowableList'
43+
member: '_literal1'
44+
- library: 'dart:core'
45+
class: '_GrowableList'
46+
member: '_literal2'
47+
- library: 'dart:core'
48+
class: '_GrowableList'
49+
member: '_literal3'
50+
- library: 'dart:core'
51+
class: '_GrowableList'
52+
member: '_literal4'
53+
- library: 'dart:core'
54+
class: '_GrowableList'
55+
member: '_literal5'
56+
- library: 'dart:core'
57+
class: '_GrowableList'
58+
member: '_literal6'
59+
- library: 'dart:core'
60+
class: '_GrowableList'
61+
member: '_literal7'
62+
- library: 'dart:core'
63+
class: '_GrowableList'
64+
member: '_literal8'
65+
- library: 'dart:core'
66+
class: '_GrowableList'
67+
member: ''
68+
- library: 'dart:core'
69+
class: '_GrowableList'
70+
member: 'empty'
71+
- library: 'dart:core'
72+
class: '_GrowableList'
73+
member: 'filled'
74+
- library: 'dart:core'
75+
class: '_GrowableList'
76+
member: 'generate'
77+
- library: 'dart:core'
78+
class: '_List'
79+
- library: 'dart:core'
80+
class: '_List'
81+
member: ''
82+
- library: 'dart:core'
83+
class: '_List'
84+
member: 'empty'
85+
- library: 'dart:core'
86+
class: '_List'
87+
member: 'filled'
88+
- library: 'dart:core'
89+
class: '_List'
90+
member: 'generate'
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
// Copyright (c) 2024, the Dart project authors. Please see the AUTHORS file
2+
// for details. All rights reserved. Use of this source code is governed by a
3+
// BSD-style license that can be found in the LICENSE file.
4+
5+
import '../../common/testing.dart' as helper;
6+
import 'package:expect/expect.dart';
7+
8+
/// A dynamic module can use core libraries and language features.
9+
main() async {
10+
final result = await helper.load('entry1.dart');
11+
Expect.isTrue(result);
12+
helper.done();
13+
}
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
// Copyright (c) 2024, the Dart project authors. Please see the AUTHORS file
2+
// for details. All rights reserved. Use of this source code is governed by a
3+
// BSD-style license that can be found in the LICENSE file.
4+
5+
import 'package:expect/expect.dart';
6+
7+
@pragma('dyn-module:entry-point')
8+
Future<bool> dynamicModuleEntrypoint() async {
9+
final list = ['1','2','3'];
10+
list.add('4');
11+
final list2 = list.map((e) => 'item $e').toList().reversed.toList();
12+
final list3 = <Future>[];
13+
for (var e in list2) {
14+
list3.add(Future.value(e));
15+
}
16+
Expect.equals('item 2', await list3[2]);
17+
return true;
18+
}
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
# Copyright (c) 2024, the Dart project authors. Please see the AUTHORS file
2+
# for details. All rights reserved. Use of this source code is governed by a
3+
# BSD-style license that can be found in the LICENSE file.
4+
extendable:
5+
- library: 'shared/shared.dart'
6+
class: 'Base'
7+
8+
can-be-overridden:
9+
- library: 'shared/shared.dart'
10+
class: 'Base'
11+
member: 'method2'
12+
13+
# TODO(sigmund): consider implying this for all extendable types.
14+
callable:
15+
- library: 'shared/shared.dart'
16+
class: 'Base'
17+
member: ''
18+
# TODO(sigmund): This should be included by default
19+
- library: 'dart:core'
20+
class: 'Object'
21+
- library: 'dart:core'
22+
class: 'int'
23+
- library: 'dart:core'
24+
class: 'pragma'
25+
member: '_'
26+
- library: 'dart:core'
27+
member: 'override'
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
// Copyright (c) 2024, the Dart project authors. Please see the AUTHORS file
2+
// for details. All rights reserved. Use of this source code is governed by a
3+
// BSD-style license that can be found in the LICENSE file.
4+
5+
import '../../common/testing.dart' as helper;
6+
import 'package:expect/expect.dart';
7+
8+
import 'shared/shared.dart' show Base, Child1;
9+
10+
class Child extends Base {
11+
@override
12+
int method2() => 4;
13+
}
14+
15+
/// A dynamic module is allowed to extend a class in the dynamic interface and
16+
/// override its members.
17+
///
18+
/// This is similar to the `extend_class` test case, but includes more nuance,
19+
/// like extending a non-leaf class that already was used in the program, since
20+
/// that may affect dispatch logic based on some backends.
21+
main() async {
22+
Base o = Child1();
23+
Expect.equals(1, o.method1());
24+
Expect.equals(3, o.method2());
25+
Expect.equals(3, indirect(o));
26+
Expect.equals(4, indirect(Child()));
27+
o = (await helper.load('entry1.dart')) as Base;
28+
Expect.equals(1, o.method1());
29+
Expect.equals(2, o.method2());
30+
Expect.equals(2, indirect(o));
31+
helper.done();
32+
}
33+
34+
@pragma('vm:never-inline')
35+
int indirect(Base a) => a.method2();
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
// Copyright (c) 2024, the Dart project authors. Please see the AUTHORS file
2+
// for details. All rights reserved. Use of this source code is governed by a
3+
// BSD-style license that can be found in the LICENSE file.
4+
5+
import '../shared/shared.dart';
6+
7+
class Child2 extends Base {
8+
@override
9+
int method2() => 2;
10+
}
11+
12+
@pragma('dyn-module:entry-point')
13+
Object? dynamicModuleEntrypoint() => Child2();

0 commit comments

Comments
 (0)