1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
// Copyright 2014 The Flutter Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
// @dart = 2.8
import 'dart:async';
import 'dart:typed_data';
import 'package:file/memory.dart';
import 'package:file_testing/file_testing.dart';
import 'package:flutter_tools/src/base/common.dart';
import 'package:flutter_tools/src/base/file_system.dart';
import 'package:flutter_tools/src/base/terminal.dart';
import 'package:flutter_tools/src/cache.dart';
import 'package:flutter_tools/src/commands/symbolize.dart';
import 'package:flutter_tools/src/convert.dart';
import 'package:meta/meta.dart';
import 'package:test/fake.dart';
import '../../src/common.dart';
import '../../src/context.dart';
import '../../src/fakes.dart';
import '../../src/test_flutter_command_runner.dart';
void main() {
MemoryFileSystem fileSystem;
FakeStdio stdio;
setUpAll(() {
Cache.disableLocking();
});
setUp(() {
fileSystem = MemoryFileSystem.test();
stdio = FakeStdio();
});
testUsingContext('Regression test for type error in codec', () async {
final DwarfSymbolizationService symbolizationService = DwarfSymbolizationService.test();
final StreamController<List<int>> output = StreamController<List<int>>();
unawaited(symbolizationService.decode(
input: Stream<Uint8List>.fromIterable(<Uint8List>[
utf8.encode('Hello, World\n') as Uint8List,
]),
symbols: Uint8List(0),
output: IOSink(output.sink),
));
await expectLater(
output.stream.transform(utf8.decoder),
emits('Hello, World'),
);
});
testUsingContext('symbolize exits when --debug-info argument is missing', () async {
final SymbolizeCommand command = SymbolizeCommand(
stdio: stdio,
fileSystem: fileSystem,
dwarfSymbolizationService: DwarfSymbolizationService.test(),
);
final Future<void> result = createTestCommandRunner(command)
.run(const <String>['symbolize']);
expect(result, throwsToolExit(message: '"--debug-info" is required to symbolize stack traces.'));
}, overrides: <Type, Generator>{
OutputPreferences: () => OutputPreferences.test(),
});
testUsingContext('symbolize exits when --debug-info file is missing', () async {
final SymbolizeCommand command = SymbolizeCommand(
stdio: stdio,
fileSystem: fileSystem,
dwarfSymbolizationService: DwarfSymbolizationService.test(),
);
final Future<void> result = createTestCommandRunner(command)
.run(const <String>['symbolize', '--debug-info=app.debug']);
expect(result, throwsToolExit(message: 'app.debug does not exist.'));
}, overrides: <Type, Generator>{
OutputPreferences: () => OutputPreferences.test(),
});
testUsingContext('symbolize exits when --input file is missing', () async {
final SymbolizeCommand command = SymbolizeCommand(
stdio: stdio,
fileSystem: fileSystem,
dwarfSymbolizationService: DwarfSymbolizationService.test(),
);
fileSystem.file('app.debug').createSync();
final Future<void> result = createTestCommandRunner(command)
.run(const <String>['symbolize', '--debug-info=app.debug', '--input=foo.stack', '--output=results/foo.result']);
expect(result, throwsToolExit(message: ''));
}, overrides: <Type, Generator>{
OutputPreferences: () => OutputPreferences.test(),
});
testUsingContext('symbolize succeeds when DwarfSymbolizationService does not throw', () async {
final SymbolizeCommand command = SymbolizeCommand(
stdio: stdio,
fileSystem: fileSystem,
dwarfSymbolizationService: DwarfSymbolizationService.test(),
);
fileSystem.file('app.debug').writeAsBytesSync(<int>[1, 2, 3]);
fileSystem.file('foo.stack').writeAsStringSync('hello');
await createTestCommandRunner(command)
.run(const <String>['symbolize', '--debug-info=app.debug', '--input=foo.stack', '--output=results/foo.result']);
expect(fileSystem.file('results/foo.result'), exists);
expect(fileSystem.file('results/foo.result').readAsBytesSync(), <int>[104, 101, 108, 108, 111, 10]); // hello
}, overrides: <Type, Generator>{
OutputPreferences: () => OutputPreferences.test(),
});
testUsingContext('symbolize throws when DwarfSymbolizationService throws', () async {
final SymbolizeCommand command = SymbolizeCommand(
stdio: stdio,
fileSystem: fileSystem,
dwarfSymbolizationService: ThrowingDwarfSymbolizationService(),
);
fileSystem.file('app.debug').writeAsBytesSync(<int>[1, 2, 3]);
fileSystem.file('foo.stack').writeAsStringSync('hello');
expect(
createTestCommandRunner(command).run(const <String>[
'symbolize', '--debug-info=app.debug', '--input=foo.stack', '--output=results/foo.result']),
throwsToolExit(message: 'test'),
);
}, overrides: <Type, Generator>{
OutputPreferences: () => OutputPreferences.test(),
});
}
class ThrowingDwarfSymbolizationService extends Fake implements DwarfSymbolizationService {
@override
Future<void> decode({
@required Stream<List<int>> input,
@required IOSink output,
@required Uint8List symbols,
}) async {
throwToolExit('test');
}
}