 // MARK: - Build helpers
 extension IncrementalCompilationTests {
   @discardableResult
-  fileprivate func doABuild(_ message: String,
-                checkDiagnostics: Bool,
-                extraArguments: [String],
-                expecting expectations: [[Diagnostic.Message]],
-                whenAutolinking autolinkExpectations: [Diagnostic.Message]
+  fileprivate func doABuild(
+    _ message: String,
+    checkDiagnostics: Bool,
+    extraArguments: [String],
+    whenAutolinking autolinkExpectedDiags: [Diagnostic.Message],
+    @DiagsBuilder expecting expectedDiags: () -> [Diagnostic.Message]
   ) throws -> Driver {
     print("*** starting build \(message) ***", to: &stderrStream); stderrStream.flush()
 

    let extraArguments = removeInputFromInvocation
    ? [] : [inputPath(basename: removedInput).pathString]
    let inputs = ["main", "other"] + (removeInputFromInvocation ? [] : [removedInput])
    let expectations: [[Diagnostic.Message]]
    switch (removeInputFromInvocation, removeSwiftDepsFile, afterRestoringBadPriors) {
    case
      (false, false, false),
      (false, true,  false),
      (false, false, true ),
      (true,  false, true ),
      (true,  true,  true ),
      (false, true,  true ):
      expectations = [
        .readGraphAndSkipAll(inputs)
      ]
    case
      (true, false, false),
      (true, true,  false):
      expectations = [
        .createdGraphFromSwiftdeps,
        .enablingCrossModule,
        .skippingAll(inputs),
      ]
    }

    let graph = try doABuild(
      "restoring incrementality after removal of \(removedInput)",
      checkDiagnostics: true,
      extraArguments: extraArguments,
      expecting: expectations,
      whenAutolinking: autolinkLifecycleExpectations)
      .moduleDependencyGraph()

    graph.verifyGraph()
    if removeInputFromInvocation {
      if afterRestoringBadPriors {

      "initial",
      checkDiagnostics: checkDiagnostics,
      extraArguments: extraArguments,
      whenAutolinking: autolinkLifecycleExpectedDiags
    ) {
      // Leave off the part after the colon because it varies on Linux:
      // MacOS: The operation could not be completed. (TSCBasic.FileSystemError error 3.).
      // Linux: The operation couldn’t be completed. (TSCBasic.FileSystemError error 3.)
      enablingCrossModule
      cannotReadBuildRecord
      disablingIncrementalCannotReadBuildRecord
      createdGraphFromSwiftdeps
      findingBatchingCompiling("main", "other")
      schedLinking
    }
  }

  /// Try a build with no changes.
