runPluginConformance function
- Flutter3dPlugin create(), {
- PluginHarness harness = const PluginHarness(),
Registers the plugin checks as tests: one per check, and one per backend for the backends check, named "plugin.backends on webgl".
A declined check is reported as skipped with its reason, as
runDeviceConformance reports a backend that declines: never as a pass.
Writes <package>.conformance.json (f3d.conformance, the
conformanceReport of what ran) beside the pubspec of the package the
suite runs in, once its checks are done: the one record of whether the
plugin earns the badge, judged by earnsBadge and read by
flutter3d_build's plugin.report and the plugin catalogue. A suite
that calls this more than once (under two profiles, say) writes one
file holding every outcome, and earns the badge only if every call
would. A check left out by --name is not run, so the file of a
partial run earns nothing. In a browser nothing is written.
Implementation
void runPluginConformance(
Flutter3dPlugin Function() create, {
PluginHarness harness = const PluginHarness(),
}) {
final session = PluginSession(create, harness);
final found = <String, List<PluginCheckOutcome>>{};
tearDownAll(() {
for (final check in pluginChecks) {
_reported.addAll(found[check.name] ?? const <PluginCheckOutcome>[]);
}
found.clear();
final plugin = session.manifest.id;
// The render suite's outcomes, if it ran first, stay beside these.
final merged = mergedOutcomes(
plugin,
_reported,
isOurs: (o) => !o.check.startsWith('render.'),
);
writeConformanceReportFile(plugin, () => conformanceReport(plugin, merged));
});
final declared = session.manifest.backends.toList();
for (final check in pluginChecks) {
List<PluginCheckOutcome> outcomes() =>
found.putIfAbsent(check.name, () => check.run(session));
void report(PluginCheckOutcome? outcome) {
if (outcome == null) {
fail('${check.name} reported nothing');
}
if (outcome.declined) {
markTestSkipped(outcome.says);
return;
}
if (!outcome.passed) fail(outcome.says);
}
if (check.name != 'plugin.backends') {
test(check.name, () => report(outcomes().firstOrNull));
continue;
}
// The backends are known before anything runs — from the manifest — so
// each gets a test of its own, and the one the plugin does not declare
// is whichever the check picks, reported under the last name.
final backends = <String?>[
...(declared.isEmpty ? everyBackend : declared),
if (declared.isNotEmpty) 'undeclared',
];
for (var i = 0; i < backends.length; i++) {
test('plugin.backends on ${backends[i] ?? 'no backend'}', () {
final all = outcomes();
report(i < all.length ? all[i] : null);
});
}
}
}