Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(176)

Side by Side Diff: tests/compiler/dart2js/cps_ir/up_to_date_test.dart

Issue 1576093003: cpsir unittests: move all unittests into individual files and test runners. (Closed) Base URL: git@github.com:dart-lang/sdk.git@master
Patch Set: add README and update analyzer_test Created 4 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(Empty)
1 // Copyright (c) 2016, 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 /// Test that cps_ir/update_all.dart and every cps_ir/*_test.dart file are up to
6 /// date. There should be a line in update_all and a file in the cps_ir folder
7 /// for each test file in the `input/` folder.
8 library tests.compiler.dart2js.cps_ir.up_to_date_test;
9
10 import 'dart:io';
11
12 main(args) {
13 bool update = args.length > 0 && args[0] == 'update';
14 var inputDir = new Directory.fromUri(Platform.script.resolve('input'));
15
16 bool errorsFound = false;
17
18 // Note: we create a test file per input file because invoking dart2js many
19 // times on a single test often makes test.py timeout.
20 //
21 // We tried using multi-tests for this, but it is unfortunately brittle. For
22 // example, multi-tests can't import code from one folder above the current
23 // directory, which prevents us from putting generated tests under a different
24 // folder than the rest of the helpers (like memory_compiler.dart)
25 var files = inputDir.listSync().map((f) => f.uri.pathSegments.last).toList();
26 files.sort();
27 for (var file in files) {
28 var testFilename = file.replaceAll('.dart', '_test.dart');
29 var contents = generateTestFile(file);
30 if (checkAndMaybeUpdate(testFilename, contents, update)) errorsFound = true;
31 }
32
33 var updateAllContents = generateUpdateAllFile(files);
34 if (checkAndMaybeUpdate('update_all.dart', updateAllContents, update)) {
35 errorsFound = true;
36 }
37
38 if (errorsFound) {
39 print(regenerateMessage);
40 exit(1);
41 }
42 }
43
44 bool checkAndMaybeUpdate(String filename, String contents,
45 bool update) {
46 var testFile = new File.fromUri(Platform.script.resolve(filename));
47 bool exists = testFile.existsSync();
48 var isUpToDate = exists && testFile.readAsStringSync() == contents;
49 if (isUpToDate) {
50 print('PASS: ${filename} is up to date.');
Kevin Millikin (Google) 2016/01/12 17:45:48 I think the focus of these messages should be on t
51 } else if (update) {
52 testFile.writeAsStringSync(contents);
53 print('INFO: ${filename} was updated.');
54 } else {
55 print("FAILED: ${filename} is ${exists ? 'out of date' : 'missing'}");
56 return true;
57 }
58 return false;
59 }
60
61 String generateUpdateAllFile(List<String> files) {
62 var lines = files.map((f) => "runTest('$f', update: true);");
63 return '''
64 // ---- AUTO-GENERATED -------------------
65 // This file was autogenerated by running:
66 //
67 // dart path/to/${Platform.script.pathSegments.last} update
68 //
69 // Do not edit this file by hand.
70 // ---------------------------------------
71
72 library tests.compiler.dart2js.cps_ir.update_all;
73
74 import 'runner.dart';
75
76 main(args) {
77 ${lines.join('\n ')}
78 }
79 ''';
80 }
81
82 String generateTestFile(String file) => '''
83 // ---- AUTO-GENERATED -------------------
84 // This file was autogenerated by running:
85 //
86 // dart path/to/${Platform.script.pathSegments.last} update
87 //
88 // Do not edit this file by hand.
89 // ---------------------------------------
90
91 library tests.compiler.dart2js.cps_ir.$file;
92
93 import 'runner.dart';
94
95 main(args) {
96 runTest("$file", update: args.length > 0 && args[0] == "update");
97 }
98 ''';
99
100
101 String get regenerateMessage {
102 var flags = Platform.packageRoot == null
103 ? '' : '--package-root=${Platform.packageRoot} ';
104 return '''
105
106 To regenerate the test files, please run:
107 dart $flags${Platform.script} update''';
108 }
OLDNEW
« no previous file with comments | « tests/compiler/dart2js/cps_ir/supercall_3_test.dart ('k') | tests/compiler/dart2js/cps_ir/update_all.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698