941d2a7148
run.sh now records flutter's JSON results beside the log and prints a summary from tool/memwatch/summary.dart: one verdict line (pass/fail/skip counts, peak MB, duration, exit status), only failing tests with their error and app stack frames (framework frames dropped, per-test and total caps, tail of printed output), the tests still running when killed, and the log and JSON paths. Quiet is the default when stdout is not a terminal; MEMWATCH_OUTPUT=full also prints the whole log. The watchdog loop and exit status are unchanged. tool/analyze.sh bounds flutter analyze to a verdict line and the first 40 issues. Tests: test/tool/memwatch/summary_test.dart and the end-to-end tool/memwatch/quiet_test.sh over fixture suites.
121 lines
4.8 KiB
Dart
121 lines
4.8 KiB
Dart
import 'dart:convert';
|
|
|
|
import 'package:flutter_test/flutter_test.dart';
|
|
|
|
import '../../../tool/memwatch/summary.dart';
|
|
|
|
const _root = '/work/app';
|
|
|
|
String _event(Map<String, Object?> event) => jsonEncode(event);
|
|
|
|
List<String> _run({List<Map<String, Object?>> tests = const [], List<String> extra = const []}) => [
|
|
_event({'type': 'suite', 'suite': {'id': 0, 'path': '$_root/test/a_test.dart'}}),
|
|
for (final t in tests) ...[
|
|
_event({'type': 'testStart', 'test': {'id': t['id'], 'name': t['name'], 'suiteID': 0}}),
|
|
for (final p in (t['prints'] as List<String>? ?? const []))
|
|
_event({'type': 'print', 'testID': t['id'], 'message': p}),
|
|
if (t['error'] != null)
|
|
_event({'type': 'error', 'testID': t['id'], 'error': t['error'], 'stackTrace': t['stack'] ?? ''}),
|
|
if (t['done'] != false)
|
|
_event({
|
|
'type': 'testDone',
|
|
'testID': t['id'],
|
|
'result': t['error'] == null ? 'success' : 'failure',
|
|
'skipped': t['skipped'] ?? false,
|
|
'hidden': t['hidden'] ?? false,
|
|
}),
|
|
],
|
|
...extra,
|
|
];
|
|
|
|
String _summary(List<String> events, {int status = 1, List<String> logTail = const []}) => summarize(
|
|
events,
|
|
status: status,
|
|
peakMb: 812,
|
|
seconds: 9,
|
|
target: 'test/a',
|
|
logPath: '/tmp/memwatch/out.x',
|
|
jsonPath: '/tmp/memwatch/out.x.json',
|
|
logTail: logTail,
|
|
appPackage: 'pipelines_app',
|
|
appRoot: _root,
|
|
);
|
|
|
|
void main() {
|
|
test('a passing run is the verdict line and the log paths only', () {
|
|
final summary = _summary(
|
|
_run(tests: [
|
|
{'id': 1, 'name': 'loading $_root/test/a_test.dart', 'hidden': true},
|
|
{'id': 2, 'name': 'ok', 'prints': ['noise']},
|
|
{'id': 3, 'name': 'skip me', 'skipped': true},
|
|
]),
|
|
status: 0,
|
|
);
|
|
expect(summary.split('\n'), [
|
|
'memwatch: PASS: 1 passed, 0 failed, 1 skipped; peak 812 MB; 9s; exit 0 (test/a)',
|
|
'full output: /tmp/memwatch/out.x',
|
|
'json results: /tmp/memwatch/out.x.json',
|
|
]);
|
|
});
|
|
|
|
test('a failure shows its error and app frames, not framework frames', () {
|
|
final summary = _summary(_run(tests: [
|
|
{
|
|
'id': 2,
|
|
'name': 'group adds',
|
|
'error': "Expected: <2>\n Actual: <3>",
|
|
'stack': 'package:matcher expect\n'
|
|
'package:flutter_test/src/widget_tester.dart 473:18 expect\n'
|
|
'test/a_test.dart 11:5 main.<fn>\n',
|
|
},
|
|
]));
|
|
expect(summary, contains('memwatch: FAIL: 0 passed, 1 failed, 0 skipped'));
|
|
expect(summary, contains('FAILED test/a_test.dart: group adds'));
|
|
expect(summary, contains('Actual: <3>'));
|
|
expect(summary, contains('test/a_test.dart 11:5'));
|
|
expect(summary, isNot(contains('package:matcher')));
|
|
expect(summary, isNot(contains('widget_tester.dart')));
|
|
});
|
|
|
|
test('a flooding failure is bounded and keeps the exception before prints', () {
|
|
final flood = [for (var i = 0; i < 5000; i++) 'flood $i ${'y' * 500}'];
|
|
final exception = [
|
|
'══╡ EXCEPTION CAUGHT BY FLUTTER TEST FRAMEWORK ╞══',
|
|
'The following TestFailure was thrown running a test:',
|
|
'Expected: exactly one matching candidate',
|
|
for (var i = 0; i < 200; i++) '#$i frame (package:flutter/src/widgets/framework.dart:$i:1)',
|
|
'#201 main.<anonymous closure> (file://$_root/test/a_test.dart:20:5)',
|
|
].join('\n');
|
|
final summary = _summary(_run(tests: [
|
|
for (var id = 2; id < 52; id++)
|
|
{'id': id, 'name': 'fails $id', 'prints': [...flood, exception], 'error': 'Test failed. See exception logs above.'},
|
|
]));
|
|
expect(summary.length, lessThan(maxDetailChars + 4000));
|
|
expect(summary, contains('Expected: exactly one matching candidate'));
|
|
expect(summary, contains('(test/a_test.dart:20:5)'));
|
|
expect(summary, isNot(contains('framework.dart')));
|
|
expect(summary, contains('printed output (last 8 of 5000 lines):'));
|
|
expect(summary, contains('... and 20 more failures (see full log)'));
|
|
expect(summary.indexOf('EXCEPTION CAUGHT'), lessThan(summary.indexOf('printed output')));
|
|
});
|
|
|
|
test('a killed run names the tests still running', () {
|
|
final summary = _summary(
|
|
_run(tests: [
|
|
{'id': 2, 'name': 'finished'},
|
|
{'id': 3, 'name': 'runaway', 'done': false},
|
|
]),
|
|
status: 137,
|
|
);
|
|
expect(summary, startsWith('memwatch: KILLED: 1 passed, 0 failed'));
|
|
expect(summary, contains('RUNNING when killed: test/a_test.dart: runaway'));
|
|
});
|
|
|
|
test('a run without results shows the bounded log tail', () {
|
|
final summary = _summary(const [], logTail: ['Error: no test files', 'x' * 1000]);
|
|
expect(summary, contains('no test results were recorded; last log lines:'));
|
|
expect(summary, contains(' Error: no test files'));
|
|
expect(summary.length, lessThan(800));
|
|
});
|
|
}
|