Unhandled exception
bsutton opened this issue · 6 comments
bsutton commented
I'm testing the package https://github.com/bsutton/dshell
pub run test_coverage
Precompiling executable... (1.1s)
Precompiled test_coverage:test_coverage.
Found 54 test files.
Generated test-all script in test/.test_coverage.dart. Please make sure it is added to .gitignore.
Unhandled exception:
Tests failed with exit code 255
#0 runTestsAndCollect (package:test_coverage/src/functions.dart:122:5)
<asynchronous suspension>
#1 main (file:///<home>/.pub-cache/hosted/pub.dartlang.org/test_coverage-0.4.3/bin/test_coverage.dart:60:9)
#2 _startIsolate.<anonymous closure> (dart:isolate-patch/isolate_patch.dart:299:32)
#3 _RawReceivePortImpl._handleMessage (dart:isolate-patch/isolate_patch.dart:168:12)
yusenD commented
have the same question, have you solve the problem?
BirjuVachhani commented
I am too getting this error. Any solution?
bsutton commented
I'm not going to have time to push this but one of the issues is that it doesn't print out errors:
I modified the functions.dart method runTestsAndCollect to output errors which Identified a problem in my unit test code:
Not the code that starts with:
process.stderr
Future<void> runTestsAndCollect(String packageRoot, String port,
{bool printOutput = false}) async {
final script = path.join(packageRoot, 'test', '.test_coverage.dart');
final dartArgs = [
'--pause-isolates-on-exit',
'--enable_asserts',
'--enable-vm-service=$port',
script
];
final process =
await Process.start('dart', dartArgs, workingDirectory: packageRoot);
final serviceUriCompleter = Completer<Uri>();
process.stdout
.transform(utf8.decoder)
.transform(const LineSplitter())
.listen((line) {
if (printOutput) print(line);
if (serviceUriCompleter.isCompleted) return;
final uri = _extractObservatoryUri(line);
if (uri != null) {
serviceUriCompleter.complete(uri);
} else {
serviceUriCompleter.completeError(line);
}
});
process.stderr
.transform(utf8.decoder)
.transform(const LineSplitter())
.listen((line) {
if (printOutput) print(line);
});
final serviceUri =
await serviceUriCompleter.future.catchError((Exception error) {
process.kill(ProcessSignal.sigkill);
});
if (serviceUri == null) {
throw StateError('Could not run tests with Observatory enabled. '
'Try setting a different port with --port option.');
}
Map<String, Map<int, int>> hitmap;
try {
final data = await coverage.collect(serviceUri, true, true, false, {});
hitmap =
coverage.createHitmap(data['coverage'] as List<Map<String, dynamic>>);
} finally {
// await process.stderr.drain<List<int>>();
}
final exitStatus = await process.exitCode;
if (exitStatus != 0) {
throw 'Tests failed with exit code $exitStatus';
}
final resolver = coverage.Resolver(
packagesPath: path.join(packageRoot, '.packages'),
);
final lcov = coverage.LcovFormatter(
resolver,
reportOn: ['lib${path.separator}'],
basePath: packageRoot,
);
final coverageData = await lcov.format(hitmap);
final coveragePath = path.join(packageRoot, 'coverage');
final coverageDir = Directory(coveragePath);
if (!coverageDir.existsSync()) {
coverageDir.createSync();
}
File(path.join(coveragePath, 'lcov.info')).writeAsStringSync(coverageData);
}
BirjuVachhani commented
Interestingly, when I removed all the assertions from my tests. It worked!
marcossevilla commented
hi! any update on this?
mzdm commented
Has anybody found some solution? /cc @marcossevilla