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

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: 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 /// Checks and if [update] is true, updates an autogenerated test file.
45 ///
46 /// This doesn't update an actual test expectation, that's done by executing the
47 /// files that we generate here.
48 bool checkAndMaybeUpdate(String filename, String contents,
49 bool update) {
50 var testFile = new File.fromUri(Platform.script.resolve(filename));
51 bool exists = testFile.existsSync();
52 var isUpToDate = exists && testFile.readAsStringSync() == contents;
53 if (isUpToDate) {
54 print('PASS: ${filename} is up to date.');
55 } else if (update) {
56 testFile.writeAsStringSync(contents);
57 print('INFO: ${filename} was updated.');
58 } else {
59 print("FAILED: ${filename} is ${exists ? 'out of date' : 'missing'}");
60 return true;
61 }
62 return false;
63 }
64
65 String generateUpdateAllFile(List<String> files) {
66 var lines = files.map((f) => "runTest('$f', update: true);");
67 return '''
68 // ---- AUTO-GENERATED -------------------
69 // This file was autogenerated by running:
70 //
71 // dart path/to/${Platform.script.pathSegments.last} update
72 //
73 // Do not edit this file by hand.
74 // ---------------------------------------
75
76 library tests.compiler.dart2js.cps_ir.update_all;
77
78 import 'runner.dart';
79
80 main(args) {
81 ${lines.join('\n ')}
82 }
83 ''';
84 }
85
86 String generateTestFile(String file) => '''
87 // ---- AUTO-GENERATED -------------------
88 // This file was autogenerated by running:
89 //
90 // dart path/to/${Platform.script.pathSegments.last} update
91 //
92 // Do not edit this file by hand.
93 // ---------------------------------------
94
95 library tests.compiler.dart2js.cps_ir.$file;
96
97 import 'runner.dart';
98
99 main(args) {
100 runTest("$file", update: args.length > 0 && args[0] == "update");
101 }
102 ''';
103
104
105 String get regenerateMessage {
106 var flags = Platform.packageRoot == null
107 ? '' : '--package-root=${Platform.packageRoot} ';
108 return '''
109
110 To regenerate the test files, please run:
111 dart $flags${Platform.script} update''';
112 }
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