withIgnored method

  1. @useResult
LeakTesting withIgnored({
  1. Map<String, int?> notGCed = const {},
  2. bool allNotGCed = false,
  3. Map<String, int?> notDisposed = const {},
  4. bool allNotDisposed = false,
  5. List<String> classes = const [],
  6. bool createdByTestHelpers = false,
  7. List<RegExp> testHelperExceptions = const [],
})

Returns copy of settings with extended ignore lists.

In the result the ignored limit for a class is the maximum of two original ignored limits. Items in classes will be added to all ignore lists.

Setting createdByTestHelpers to true may cause significant performance impact on the test run, caused by conversion of creation call stack to String.

Implementation

@useResult
LeakTesting withIgnored({
  Map<String, int?> notGCed = const {},
  bool allNotGCed = false,
  Map<String, int?> notDisposed = const {},
  bool allNotDisposed = false,
  List<String> classes = const [],
  bool createdByTestHelpers = false,
  List<RegExp> testHelperExceptions = const [],
}) {
  Map<String, int?> addClassesToMap(
    Map<String, int?> map,
    List<String> classes,
  ) {
    return {
      ...map,
      for (final c in classes) c: null,
    };
  }

  return copyWith(
    ignoredLeaks: IgnoredLeaks(
      experimentalNotGCed: ignoredLeaks.experimentalNotGCed.merge(
        IgnoredLeaksSet(
          byClass: addClassesToMap(notGCed, classes),
          ignoreAll: allNotGCed,
        ),
      ),
      notDisposed: ignoredLeaks.notDisposed.merge(
        IgnoredLeaksSet(
          byClass: addClassesToMap(notDisposed, classes),
          ignoreAll: allNotDisposed,
        ),
      ),
      createdByTestHelpers:
          ignoredLeaks.createdByTestHelpers || createdByTestHelpers,
      testHelperExceptions: [
        ...ignoredLeaks.testHelperExceptions,
        ...testHelperExceptions,
      ],
    ),
  );
}