OLD | NEW |
1 // Copyright (c) 2015, the Dart project authors. Please see the AUTHORS file | 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 | 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. | 3 // BSD-style license that can be found in the LICENSE file. |
4 | 4 |
5 library analyzer_cli.test.utils; | 5 library analyzer_cli.test.utils; |
6 | 6 |
7 import 'dart:collection'; | |
8 import 'dart:io'; | 7 import 'dart:io'; |
9 import 'dart:mirrors'; | 8 import 'dart:mirrors'; |
10 | 9 |
11 import 'package:analyzer/analyzer.dart'; | 10 import 'package:analyzer/analyzer.dart'; |
12 import 'package:analyzer/src/generated/java_io.dart'; | 11 import 'package:analyzer/src/generated/java_io.dart'; |
13 import 'package:path/path.dart' as pathos; | 12 import 'package:path/path.dart' as pathos; |
14 import 'package:path/path.dart' as path; | 13 import 'package:path/path.dart' as path; |
15 import 'package:typed_mock/typed_mock.dart'; | |
16 import 'package:unittest/unittest.dart'; | 14 import 'package:unittest/unittest.dart'; |
17 | 15 |
18 /// Gets the test directory in a way that works with | 16 /// Gets the test directory in a way that works with |
19 /// package:test and package:unittest. | 17 /// package:test and package:unittest. |
20 /// See <https://github.com/dart-lang/test/issues/110> for more info. | 18 /// See <https://github.com/dart-lang/test/issues/110> for more info. |
21 final String testDirectory = pathos.dirname( | 19 final String testDirectory = pathos.dirname( |
22 pathos.fromUri((reflectClass(_TestUtils).owner as LibraryMirror).uri)); | 20 pathos.fromUri((reflectClass(_TestUtils).owner as LibraryMirror).uri)); |
23 | 21 |
24 /// Returns the string representation of the [AnalyzerErrorGroup] thrown when | 22 /// Returns the string representation of the [AnalyzerErrorGroup] thrown when |
25 /// parsing [contents] as a Dart file. If [contents] doesn't throw any errors, | 23 /// parsing [contents] as a Dart file. If [contents] doesn't throw any errors, |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
58 dynamic withTempDir(fn(String path)) { | 56 dynamic withTempDir(fn(String path)) { |
59 var tempDir = Directory.systemTemp.createTempSync('analyzer_').path; | 57 var tempDir = Directory.systemTemp.createTempSync('analyzer_').path; |
60 try { | 58 try { |
61 return fn(tempDir); | 59 return fn(tempDir); |
62 } finally { | 60 } finally { |
63 new Directory(tempDir).deleteSync(recursive: true); | 61 new Directory(tempDir).deleteSync(recursive: true); |
64 } | 62 } |
65 } | 63 } |
66 | 64 |
67 class _TestUtils {} | 65 class _TestUtils {} |
68 | |
69 /** | |
70 * A [Stdin] mock. | |
71 */ | |
72 class TestStdinStream extends TypedMock implements Stdin { | |
73 final pendingBytes = new Queue<int>(); | |
74 | |
75 // Adds all the input bytes to this stream. | |
76 void addInputBytes(List<int> bytes) { | |
77 pendingBytes.addAll(bytes); | |
78 } | |
79 | |
80 @override | |
81 int readByteSync() { | |
82 if (pendingBytes.isEmpty) { | |
83 return -1; | |
84 } else { | |
85 return pendingBytes.removeFirst(); | |
86 } | |
87 } | |
88 } | |
89 | |
90 /** | |
91 * A [Stdout] mock. | |
92 */ | |
93 class TestStdoutStream extends TypedMock implements Stdout { | |
94 final writes = <List<int>>[]; | |
95 | |
96 @override | |
97 void add(List<int> bytes) { | |
98 super.add(bytes); | |
99 writes.add(bytes); | |
100 } | |
101 } | |
OLD | NEW |