Chromium Code Reviews

Side by Side Diff: tests/fletch_tests/snapshot_stacktrace_tests.dart

Issue 1659163007: Rename fletch -> dartino (Closed) Base URL: https://github.com/dartino/sdk.git@master
Patch Set: address comments Created 4 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
View unified diff |
« no previous file with comments | « tests/fletch_tests/sentence_tests.dart ('k') | tests/fletch_tests/test_suite_consumer.dart » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 // Copyright (c) 2015, 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 'dart:async' show
6 Future,
7 Stream,
8 StreamController;
9
10 import 'dart:io' show
11 Directory,
12 File,
13 Process,
14 ProcessResult;
15
16 import 'dart:convert' show
17 UTF8;
18
19 import 'package:expect/expect.dart' show
20 Expect;
21
22 import '../fletchc/run.dart' show
23 export;
24
25 import 'package:fletchc/program_info.dart' as program_info;
26
27 import 'utils.dart' show
28 withTempDirectory;
29
30 const String buildDirectory =
31 const String.fromEnvironment('test.dart.build-dir');
32
33 const String buildArch =
34 const String.fromEnvironment('test.dart.build-arch');
35
36 const String buildSystem =
37 const String.fromEnvironment('test.dart.build-system');
38
39 final String fletchVM = '$buildDirectory/fletch-vm';
40
41 typedef Future NoArgFuture();
42
43 Future<Map<String, NoArgFuture>> listTests(
44 [bool write_golden_files = false]) async {
45 var tests = <String, NoArgFuture>{
46 'snapshot_stacktrace_tests/uncaught_exception':
47 () => runTest('uncaught_exception', write_golden_files),
48 'snapshot_stacktrace_tests/nsm_exception':
49 () => runTest('nsm_exception', write_golden_files),
50 'snapshot_stacktrace_tests/coroutine_exception':
51 () => runTest('coroutine_exception', write_golden_files),
52 };
53
54
55 // Dummy use of [main] to make analyzer happy.
56 main;
57
58 return tests;
59 }
60
61 Future runTest(String testName, bool write_golden_files) {
62 return withTempDirectory((Directory temp) async {
63 String snapshotFilename = '${temp.absolute.path}/test.snapshot';
64
65 // Part 1: Generate snapshot.
66 await export(
67 testFilename(testName), snapshotFilename, binaryProgramInfo: true);
68
69 // Part 2: Run VM.
70 ProcessResult result = await Process.run(fletchVM, [snapshotFilename]);
71 String expectationContent =
72 await new File(testExpectationFilename(testName)).readAsString();
73
74 // Part 3: Transform stdout via stack trace decoder.
75 var stdin = new Stream.fromIterable([UTF8.encode(result.stdout)]);
76 var stdout = new StreamController();
77 Future<List> stdoutBytes =
78 stdout.stream.fold([], (buffer, data) => buffer..addAll(data));
79 var arguments = [
80 buildArch.toLowerCase() == 'x64' ? '64' : '32',
81 buildSystem.toLowerCase() == 'lk' ? 'float' : 'double',
82 '${snapshotFilename}.info.bin',
83 ];
84 await program_info.decodeProgramMain(arguments, stdin, stdout);
85
86 // Part 4: Build expectation string
87 String stdoutString = UTF8.decode(await stdoutBytes);
88 String actualOutput =
89 '<STDOUT>:\n${stdoutString}\n'
90 '<STDERR>:\n${result.stderr}\n'
91 '<EXITCODE>:${result.exitCode}';
92
93 // Part 5: Compare actual/expected or write to golden files.
94 if (write_golden_files) {
95 // Create golden file directory (if it doesn't exist).
96 var dir = new Directory(testDirectory('_generated'));
97 if (!await dir.exists()) await dir.create(recursive: true);
98
99 // Copy test file.
100 var testFileContent =
101 await new File(await testFilename(testName)).readAsString();
102 await new File(testFilename(testName, '_generated'))
103 .writeAsString(testFileContent);
104
105 // Write actual expectation output.
106 await new File(testExpectationFilename(testName, '_generated'))
107 .writeAsString(actualOutput);
108 } else {
109 Expect.stringEquals(expectationContent, actualOutput);
110 }
111 });
112 }
113
114 String testFilename(String name, [String generated = ''])
115 => '${testDirectory(generated)}/${name}_test.dart';
116
117 String testExpectationFilename(String name, [String generated = ''])
118 => '${testDirectory(generated)}/${name}_expected.txt';
119
120 String testDirectory([String generated = ''])
121 => 'tests/snapshot_stacktrace_tests$generated';
122
123 main() async {
124 var tests = await listTests(true);
125 for (var name in tests.keys) {
126 await tests[name]();
127 }
128 }
OLDNEW
« no previous file with comments | « tests/fletch_tests/sentence_tests.dart ('k') | tests/fletch_tests/test_suite_consumer.dart » ('j') | no next file with comments »

Powered by Google App Engine