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

Commit 370fb4b

Browse files
clean up test file
1 parent 95175b4 commit 370fb4b

File tree

1 file changed

+98
-115
lines changed

1 file changed

+98
-115
lines changed

tools/const_finder/test/const_finder_test.dart

Lines changed: 98 additions & 115 deletions
Original file line numberDiff line numberDiff line change
@@ -38,8 +38,8 @@ void expectInstances(dynamic value, dynamic expected, Compiler compiler) {
3838
equality = const DeepCollectionEquality();
3939
}
4040
if (!equality.equals(value, expected)) {
41-
stderr.writeln('Expected: ${const JsonEncoder.withIndent(' ').convert(expected)}');
42-
stderr.writeln('Actual: ${const JsonEncoder.withIndent(' ').convert(value)}');
41+
stderr.writeln('Expected: ${jsonEncode(expected)}');
42+
stderr.writeln('Actual: ${jsonEncode(value)}');
4343
exitCode = -1;
4444
}
4545
}
@@ -114,6 +114,7 @@ void _checkConsts(String dillPath, Compiler compiler) {
114114
);
115115
}
116116

117+
// Verify constants declared in a class specified in ignoredClasses will be ignored.
117118
void _checkDenyList(String dillPath, Compiler compiler) {
118119
stdout.writeln('Checking constant instances in a denylist are ignored with $compiler');
119120
final ConstFinder finder = ConstFinder(
@@ -239,6 +240,11 @@ void checkProcessResult(ProcessResult result) {
239240
expect(result.exitCode, 0);
240241
}
241242

243+
final String basePath =
244+
path.canonicalize(path.join(path.dirname(Platform.script.toFilePath()), '..'));
245+
final String fixtures = path.join(basePath, 'test', 'fixtures');
246+
final String packageConfig = path.join(fixtures, '.dart_tool', 'package_config.json');
247+
242248
Future<void> main(List<String> args) async {
243249
if (args.length != 3) {
244250
stderr.writeln('The first argument must be the path to the frontend server dill.');
@@ -247,128 +253,105 @@ Future<void> main(List<String> args) async {
247253
exit(-1);
248254
}
249255

250-
TestRunner(
251-
frontendServer: args[0],
252-
sdkRoot: args[1],
253-
librariesSpec: args[2],
254-
).test();
255-
}
256-
257-
final String basePath =
258-
path.canonicalize(path.join(path.dirname(Platform.script.toFilePath()), '..'));
259-
final String fixtures = path.join(basePath, 'test', 'fixtures');
260-
final String packageConfig = path.join(fixtures, '.dart_tool', 'package_config.json');
261-
262-
class TestRunner {
263-
TestRunner({
264-
required this.frontendServer,
265-
required this.sdkRoot,
266-
required this.librariesSpec,
267-
});
268-
269-
//static final String box = path.join(fixtures, 'lib', 'box.dart');
270-
//static final String consts = path.join(fixtures, 'lib', 'consts.dart');
271-
//static final String constsAndNon = path.join(fixtures, 'lib', 'consts_and_non.dart');
272-
273-
final String frontendServer;
274-
final String sdkRoot;
275-
final String librariesSpec;
276-
277-
void test() {
278-
final List<_Test> tests = <_Test>[
279-
_Test(
280-
name: 'box_frontend',
281-
dartSource: path.join(fixtures, 'lib', 'box.dart'),
282-
frontendServer: frontendServer,
283-
sdkRoot: sdkRoot,
284-
librariesSpec: librariesSpec,
285-
verify: _checkRecursion,
286-
compiler: Compiler.frontendServer,
287-
),
288-
_Test(
289-
name: 'box_web',
290-
dartSource: path.join(fixtures, 'lib', 'box.dart'),
291-
frontendServer: frontendServer,
292-
sdkRoot: sdkRoot,
293-
librariesSpec: librariesSpec,
294-
verify: _checkRecursion,
295-
compiler: Compiler.dart2js,
296-
),
297-
_Test(
298-
name: 'consts_frontend',
299-
dartSource: path.join(fixtures, 'lib', 'consts.dart'),
300-
frontendServer: frontendServer,
301-
sdkRoot: sdkRoot,
302-
librariesSpec: librariesSpec,
303-
verify: _checkConsts,
304-
compiler: Compiler.frontendServer,
305-
),
306-
_Test(
307-
name: 'consts_web',
308-
dartSource: path.join(fixtures, 'lib', 'consts.dart'),
309-
frontendServer: frontendServer,
310-
sdkRoot: sdkRoot,
311-
librariesSpec: librariesSpec,
312-
verify: _checkConsts,
313-
compiler: Compiler.dart2js,
314-
),
315-
_Test(
316-
name: 'consts_and_non_frontend',
317-
dartSource: path.join(fixtures, 'lib', 'consts_and_non.dart'),
318-
frontendServer: frontendServer,
319-
sdkRoot: sdkRoot,
320-
librariesSpec: librariesSpec,
321-
verify: _checkNonConstsFrontend,
322-
compiler: Compiler.frontendServer,
323-
),
324-
_Test(
325-
name: 'consts_and_non_web',
326-
dartSource: path.join(fixtures, 'lib', 'consts_and_non.dart'),
327-
frontendServer: frontendServer,
328-
sdkRoot: sdkRoot,
329-
librariesSpec: librariesSpec,
330-
verify: _checkNonConstsWeb,
331-
compiler: Compiler.dart2js,
332-
),
333-
_Test(
334-
name: 'denylist_frontend',
335-
dartSource: path.join(fixtures, 'lib', 'denylist.dart'),
336-
frontendServer: frontendServer,
337-
sdkRoot: sdkRoot,
338-
librariesSpec: librariesSpec,
339-
verify: _checkDenyList,
340-
compiler: Compiler.frontendServer,
341-
),
342-
_Test(
343-
name: 'denylist_web',
344-
dartSource: path.join(fixtures, 'lib', 'denylist.dart'),
345-
frontendServer: frontendServer,
346-
sdkRoot: sdkRoot,
347-
librariesSpec: librariesSpec,
348-
verify: _checkDenyList,
349-
compiler: Compiler.dart2js,
350-
),
351-
];
256+
final String frontendServer = args[0];
257+
final String sdkRoot = args[1];
258+
final String librariesSpec = args[2];
259+
260+
final List<_Test> tests = <_Test>[
261+
_Test(
262+
name: 'box_frontend',
263+
dartSource: path.join(fixtures, 'lib', 'box.dart'),
264+
frontendServer: frontendServer,
265+
sdkRoot: sdkRoot,
266+
librariesSpec: librariesSpec,
267+
verify: _checkRecursion,
268+
compiler: Compiler.frontendServer,
269+
),
270+
_Test(
271+
name: 'box_web',
272+
dartSource: path.join(fixtures, 'lib', 'box.dart'),
273+
frontendServer: frontendServer,
274+
sdkRoot: sdkRoot,
275+
librariesSpec: librariesSpec,
276+
verify: _checkRecursion,
277+
compiler: Compiler.dart2js,
278+
),
279+
_Test(
280+
name: 'consts_frontend',
281+
dartSource: path.join(fixtures, 'lib', 'consts.dart'),
282+
frontendServer: frontendServer,
283+
sdkRoot: sdkRoot,
284+
librariesSpec: librariesSpec,
285+
verify: _checkConsts,
286+
compiler: Compiler.frontendServer,
287+
),
288+
_Test(
289+
name: 'consts_web',
290+
dartSource: path.join(fixtures, 'lib', 'consts.dart'),
291+
frontendServer: frontendServer,
292+
sdkRoot: sdkRoot,
293+
librariesSpec: librariesSpec,
294+
verify: _checkConsts,
295+
compiler: Compiler.dart2js,
296+
),
297+
_Test(
298+
name: 'consts_and_non_frontend',
299+
dartSource: path.join(fixtures, 'lib', 'consts_and_non.dart'),
300+
frontendServer: frontendServer,
301+
sdkRoot: sdkRoot,
302+
librariesSpec: librariesSpec,
303+
verify: _checkNonConstsFrontend,
304+
compiler: Compiler.frontendServer,
305+
),
306+
_Test(
307+
name: 'consts_and_non_web',
308+
dartSource: path.join(fixtures, 'lib', 'consts_and_non.dart'),
309+
frontendServer: frontendServer,
310+
sdkRoot: sdkRoot,
311+
librariesSpec: librariesSpec,
312+
verify: _checkNonConstsWeb,
313+
compiler: Compiler.dart2js,
314+
),
315+
_Test(
316+
name: 'denylist_frontend',
317+
dartSource: path.join(fixtures, 'lib', 'denylist.dart'),
318+
frontendServer: frontendServer,
319+
sdkRoot: sdkRoot,
320+
librariesSpec: librariesSpec,
321+
verify: _checkDenyList,
322+
compiler: Compiler.frontendServer,
323+
),
324+
_Test(
325+
name: 'denylist_web',
326+
dartSource: path.join(fixtures, 'lib', 'denylist.dart'),
327+
frontendServer: frontendServer,
328+
sdkRoot: sdkRoot,
329+
librariesSpec: librariesSpec,
330+
verify: _checkDenyList,
331+
compiler: Compiler.dart2js,
332+
),
333+
];
334+
try {
335+
stdout.writeln('Generating kernel fixtures...');
336+
337+
for (final _Test test in tests) {
338+
test.run();
339+
}
340+
} finally {
352341
try {
353-
stdout.writeln('Generating kernel fixtures...');
354-
355342
for (final _Test test in tests) {
356-
test.run();
343+
test.dispose();
357344
}
358345
} finally {
359-
try {
360-
for (final _Test test in tests) {
361-
test.dispose();
362-
}
363-
} finally {
364-
stdout.writeln('Tests ${exitCode == 0 ? 'succeeded' : 'failed'} - exit code: $exitCode');
365-
}
346+
stdout.writeln('Tests ${exitCode == 0 ? 'succeeded' : 'failed'} - exit code: $exitCode');
366347
}
367348
}
368349
}
369350

370351
enum Compiler {
352+
// Uses TFA tree-shaking.
371353
frontendServer,
354+
// Does not have TFA tree-shaking.
372355
dart2js,
373356
}
374357

@@ -395,7 +378,7 @@ class _Test {
395378
final List<String> resourcesToDispose = <String>[];
396379

397380
void run() {
398-
stdout.writeln('Compiling $dartSource to $dillPath');
381+
stdout.writeln('Compiling $dartSource to $dillPath with $compiler');
399382

400383
if (compiler == Compiler.frontendServer) {
401384
_compileTFADill();

0 commit comments

Comments
 (0)