stack_trace_test.dart 1.72 KB
Newer Older
1 2 3 4 5 6 7
// Copyright 2016 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

import 'package:flutter/foundation.dart';
import 'package:test/test.dart';

8 9
import 'platform_helper.dart';

10
void main() {
11 12
  // TODO(8128): These tests and the filtering mechanism should be revisited to account for causal async stack traces.

13 14
  final String dividerRegExp = pathSeparatorForRegExp;

15
  test('FlutterError.defaultStackFilter', () {
16
    final List<String> filtered = FlutterError.defaultStackFilter(StackTrace.current.toString().trimRight().split('\n')).toList();
17
    expect(filtered.length, greaterThanOrEqualTo(4));
18
    expect(filtered[0], matches(r'^#0 +main\.<anonymous closure> \(.*stack_trace_test\.dart:[0-9]+:[0-9]+\)$'));
19
    expect(filtered[1], matches(r'^#1 +Declarer\.test\.<anonymous closure>.<anonymous closure> \(package:test' + dividerRegExp + r'.+:[0-9]+:[0-9]+\)$'));
20 21
    expect(filtered[2], equals('<asynchronous suspension>'));
    expect(filtered.last, matches(r'^\(elided [1-9][0-9]+ frames from package dart:async, package dart:async-patch, and package stack_trace\)$'));
22 23 24
  });

  test('FlutterError.defaultStackFilter (async test body)', () async {
25
    final List<String> filtered = FlutterError.defaultStackFilter(StackTrace.current.toString().trimRight().split('\n')).toList();
26
    expect(filtered.length, greaterThanOrEqualTo(3));
27
    expect(filtered[0], matches(r'^#0 +main\.<anonymous closure> \(.*stack_trace_test\.dart:[0-9]+:[0-9]+\)$'));
28 29
    expect(filtered[1], equals('<asynchronous suspension>'));
    expect(filtered.last, matches(r'^\(elided [1-9][0-9]+ frames from package dart:async, package dart:async-patch, and package stack_trace\)$'));
30 31
  });
}