copyResourceInto function

void copyResourceInto(
  1. String path,
  2. Directory dir,
  3. {String prefix = _defaultPrefix}
)

Copies the test resource at the specified path into the provided Directory as a File with the same filename as the original.

"Test resources" are files stored (by default) under the test/resources/ directory of the project root. This prefix may be changed, using the prefix argument.

Arguments

  • String path - the relative path (from the prefix by default).
  • Directory dir - the directory where the file is to be copied.
  • String prefix - the path prefix from the project root (defaults to test/resources).

Implementation

void copyResourceInto(
  String path,
  Directory dir, {
  String prefix = _defaultPrefix,
}) {
  final sourceFile = resourceFile(path, prefix: prefix);

  if (!sourceFile.existsSync()) {
    throw Exception('Resource file ($path) does not exist.');
  }

  if (!dir.existsSync()) {
    dir.createSync(recursive: true);
  }

  sourceFile.copySync('${dir.path}/${sourceFile.uri.pathSegments.last}');
}