ensureExecutableUpToDate function

void ensureExecutableUpToDate(
  1. String executable, {
  2. bool node = false,
})

Throws a TestFailure if executable's compiled output isn't up-to-date relative to the pubspec or to source files in lib/ or bin/.

This is automatically run by start and executableArgs. However, it's presented as a separate function so that users can run it in setUpAll to get only a single error per file rather than many.

Implementation

void ensureExecutableUpToDate(String executable, {bool node = false}) {
  String path;
  if (node) {
    path = p.absolute("build/npm/$executable.js");
  } else {
    path = p.absolute("build/$executable.snapshot");
    if (!File(path).existsSync()) return;
  }

  if (!_executableUpToDateCache.contains(path)) {
    ensureUpToDate(
        path, "dart run grinder pkg-${node ? 'npm' : 'standalone'}-dev",
        dependencies: [executables.value[executable]]);

    // Only add this after ensuring that the executable is up-to-date, so that
    // running it multiple times for out-of-date inputs will cause multiple
    // errors.
    _executableUpToDateCache.add(path);
  }
}