check method
Runs the stages 3 to 5 of the pipeline and missingTemplateTags for
contractCase, then, if render is on and they found no error, the
stages 7 and 8 and checkRendered.
Implementation
Future<ContractResult> check(ContractCase contractCase) async {
final environment = PipelineEnvironment(
_silentHost,
interactive: false,
skipExternalSetup: true,
);
final ResolverResult resolved;
try {
resolved = await resolve(
requested: contractCase.requested,
registry: registry,
environment: environment,
answers: {...contractCase.picks},
);
} on SmfUsageException catch (error) {
return ContractResult(contractCase, [SmfIssue(error.message)]);
}
final resolution = resolved.resolution;
if (resolution == null) {
return ContractResult(contractCase, resolved.issues);
}
final collection = collect(resolution, context);
final validation = validate(
registry: registry,
resolution: resolution,
collection: collection,
context: context,
interactive: environment.interactive,
skipExternalSetup: environment.skipExternalSetup,
);
final checked = ContractResult(
contractCase,
[
...resolved.issues,
...validation.issues,
...missingTemplateTags(
registry: registry,
resolution: resolution,
collection: collection,
),
..._copiedTemplateIssues(collection),
],
resolution: resolution,
collection: collection,
validation: validation,
);
if (!render || checked.errors.isNotEmpty) return checked;
final Map<Role, Object?> choices;
final RenderedApp app;
final options = {...roleOptions, ...contractCase.roleOptions};
final answering = _EnterPrompter();
// The choices of the roles that asked, which the harness answered.
final answered = <Role, Object?>{};
final Map<String, String> answers;
try {
choices = await chooseRoles(
registry: registry,
resolution: resolution,
collection: collection,
optionValues: options,
environment: PipelineEnvironment(
_answeringHost(answering),
interactive: true,
skipExternalSetup: true,
),
context: context,
onChoice: (role, choice) {
if (!answering.asked) return;
answering.asked = false;
answered[role] = choice;
},
);
final (options: given, :problems) = await _answersOf(
answered,
resolution: resolution,
collection: collection,
options: options,
);
if (problems.isNotEmpty) {
return checked._with(problems, choices: choices);
}
answers = given;
app = renderApp(
registry: registry,
resolution: resolution,
collection: collection,
context: context,
choices: choices,
pubspec: validation.pubspec,
);
} on SmfUsageException catch (error) {
return checked._with([SmfIssue(error.message)]);
} on GenerationFailedException catch (error) {
return checked._with([
if (error.issues.isEmpty) SmfIssue(error.message),
...error.issues,
]);
}
final rendered = checked._with(
const [],
choices: choices,
answers: answers,
app: app,
);
return rendered._with(checkRendered(rendered, app));
}