runScript method
Generate bridges and run a D4rt script file, capturing results.
- Runs the bridge generator in-memory with
config, producing bridge files and the test runner into projectPath. - Compiles and runs the test runner with
--test <scriptFile>. - Returns a D4rtTestResult with captured output, exceptions, and timeout status.
The scriptFile path is relative to projectPath or absolute.
The timeout overrides defaultTimeout for this execution.
If bridge generation fails, returns a D4rtTestResult with the generation errors in D4rtTestResult.exceptions.
Example:
final result = await tester.runScript(
config,
'scripts/test_cli_api.dart',
timeout: Duration(seconds: 5),
);
expect(result.success, isTrue);
expect(result.processOutput, contains('All verifications passed'));
Implementation
Future<D4rtTestResult> runScript(
BridgeConfig config,
String scriptFile, {
Duration? timeout,
}) async {
// Generate and compile bridges
final ok = await prepareBridges(config);
if (!ok) {
return D4rtTestResult(
timedOut: false,
exceptions: _lastGenerationErrors!,
exitCode: -1,
);
}
// Run using compiled binary
return _runBinary(['--test', scriptFile], timeout ?? defaultTimeout);
}