Skip to content
This repository was archived by the owner on Feb 25, 2025. It is now read-only.

Commit d37e94f

Browse files
committed
fix sdk_rewriter_test.dart and ci/analyze.sh
1 parent fbfc59f commit d37e94f

File tree

4 files changed

+62
-24
lines changed

4 files changed

+62
-24
lines changed

ci/analyze.sh

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,11 @@ echo ""
7777
echo ""
7878

7979
# Check that dart libraries conform.
80-
echo "Checking web_ui api conformance..."
80+
echo "Checking the integrity of the Web SDK"
8181
(cd "$FLUTTER_DIR/web_sdk"; "$DART" pub get)
82-
(cd "$FLUTTER_DIR"; "$DART" "web_sdk/test/api_conform_test.dart")
83-
(cd "$FLUTTER_DIR"; "$DART" --enable-asserts "web_sdk/test/js_access_test.dart")
82+
WEB_SDK_TEST_FILES="$FLUTTER_DIR/web_sdk/test/*"
83+
for testFile in $WEB_SDK_TEST_FILES
84+
do
85+
echo "Running $testFile"
86+
(cd "$FLUTTER_DIR"; FLUTTER_DIR="$FLUTTER_DIR" "$DART" --enable-asserts $testFile)
87+
done

web_sdk/sdk_rewriter.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -154,7 +154,7 @@ void _validateEngineSource(String engineDartPath, String engineDartCode) {
154154
continue;
155155
}
156156

157-
if (line.startsWith('export ')) {
157+
if (line.startsWith('export')) {
158158
// Exports are OK
159159
continue;
160160
}

web_sdk/test/api_conform_test.dart

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -35,16 +35,17 @@ CompilationUnit _parseAndCheckDart(String path) {
3535
}
3636

3737
void main() {
38+
final String flutterDir = Platform.environment['FLUTTER_DIR']!;
3839
// These files just contain imports to the part files;
39-
final CompilationUnit uiUnit = _parseAndCheckDart('lib/ui/ui.dart');
40-
final CompilationUnit webUnit = _parseAndCheckDart('lib/web_ui/lib/ui.dart');
40+
final CompilationUnit uiUnit = _parseAndCheckDart('$flutterDir/lib/ui/ui.dart');
41+
final CompilationUnit webUnit = _parseAndCheckDart('$flutterDir/lib/web_ui/lib/ui.dart');
4142
final Map<String, ClassDeclaration> uiClasses = <String, ClassDeclaration>{};
4243
final Map<String, ClassDeclaration> webClasses = <String, ClassDeclaration>{};
4344

4445
// Gather all public classes from each library. For now we are skipping
4546
// other top level members.
46-
_collectPublicClasses(uiUnit, uiClasses, 'lib/ui/');
47-
_collectPublicClasses(webUnit, webClasses, 'lib/web_ui/lib/');
47+
_collectPublicClasses(uiUnit, uiClasses, '$flutterDir/lib/ui/');
48+
_collectPublicClasses(webUnit, webClasses, '$flutterDir/lib/web_ui/lib/');
4849

4950
if (uiClasses.isEmpty || webClasses.isEmpty) {
5051
print('Warning: did not resolve any classes.');

web_sdk/test/sdk_rewriter_test.dart

Lines changed: 49 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -7,40 +7,43 @@ import 'package:test/test.dart';
77
import '../sdk_rewriter.dart';
88

99
void main() {
10-
test('handles imports/exports correctly in the engine library file', () {
10+
test('handles exports correctly in the engine library file', () {
1111
const String source = '''
12-
library engine;
12+
// Comment 1
1313
14-
import '../ui.dart' as ui;
15-
import 'package:ui/ui.dart' as ui;
14+
library engine;
1615
17-
import 'package:some_package/some_package.dart';
16+
// Comment 2
1817
19-
import 'engine/file1.dart';
2018
export 'engine/file1.dart';
21-
22-
import'engine/file2.dart';
2319
export'engine/file2.dart';
24-
25-
import 'engine/file3.dart';
2620
export 'engine/file3.dart';
2721
''';
2822

2923
const String expected = '''
24+
// Comment 1
25+
26+
@JS()
3027
library dart._engine;
3128
32-
import 'dart:ui' as ui;
29+
import 'dart:async';
30+
import 'dart:collection';
31+
import 'dart:convert' hide Codec;
32+
import 'dart:developer' as developer;
33+
import 'dart:html' as html;
34+
import 'dart:js' as js;
35+
import 'dart:js_util' as js_util;
36+
import 'dart:_js_annotations';
37+
import 'dart:math' as math;
38+
import 'dart:svg' as svg;
39+
import 'dart:typed_data';
3340
import 'dart:ui' as ui;
3441
35-
import 'package:some_package/some_package.dart';
3642
43+
// Comment 2
3744
3845
part 'engine/file1.dart';
39-
40-
4146
part 'engine/file2.dart';
42-
43-
4447
part 'engine/file3.dart';
4548
''';
4649

@@ -53,6 +56,36 @@ part 'engine/file3.dart';
5356
expect(result, expected);
5457
});
5558

59+
test('complains about non-compliant engine.dart file', () {
60+
const String source = '''
61+
library engine;
62+
63+
import 'dart:something';
64+
export 'engine/file1.dart';
65+
export 'engine/file3.dart';
66+
''';
67+
68+
Object? caught;
69+
try {
70+
rewriteFile(
71+
source,
72+
filePath: '/path/to/lib/web_ui/lib/src/engine.dart',
73+
isUi: false,
74+
isEngine: true,
75+
);
76+
} catch(error) {
77+
caught = error;
78+
}
79+
expect(caught, isA<Exception>());
80+
expect(
81+
'$caught',
82+
'Exception: on line 3: unexpected code in /path/to/lib/web_ui/lib/src/engine.dart. '
83+
'This file may only contain comments and exports. Found:\n'
84+
'import \'dart:something\';',
85+
);
86+
});
87+
88+
5689
test('removes imports/exports from engine files', () {
5790
const String source = '''
5891
import 'package:some_package/some_package.dart';

0 commit comments

Comments
 (0)