Skip to content

Instantly share code, notes, and snippets.

@matanlurey
Created March 27, 2017 22:02
Show Gist options
  • Save matanlurey/5193a3b6e3d11aec354b386fd5533a0b to your computer and use it in GitHub Desktop.
Save matanlurey/5193a3b6e3d11aec354b386fd5533a0b to your computer and use it in GitHub Desktop.
/// Returns a future that completes when a [Resolver] for Dart [sourceCode].
///
/// ```
/// await resolveSource(r'''
/// import 'dart:collection';
///
/// Map createMap() => {};
/// ''')
/// ```
///
/// Used for extracting analysis results as a [Resolver] class, which in turn
/// can be used to test if certain references exist, or to run functional
/// testing on type-checks done in a build step.
///
/// ## Reading files from disk
///
/// By default [reader] uses a strategy depending on whether the test is being
/// run on a pub package (with a resolved `.packages` file) _or_ being run
/// within bazel.
///
/// ## Loading dependencies
///
/// To be able to resolve other source files, either by relative path or
/// `package:`, [srcs] is required to inform the build process what real files
/// should be loaded from disk and be made available:
///
/// ```
/// await resolveSource('...', srcs: {
/// // Load all .dart files in package:silly_monkey and make them available.
/// 'silly_monkey': ['lib/**/*.dart'],
/// })
/// ```
Future<Resolver> resolveSource(
String sourceCode, {
AssetReader reader,
Map<String, Glob> srcs: const {},
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment