Skip to content

Commit

Permalink
increase coverage?
Browse files Browse the repository at this point in the history
  • Loading branch information
Renan Araujo committed May 20, 2022
1 parent b5368cf commit 7733842
Show file tree
Hide file tree
Showing 2 changed files with 117 additions and 16 deletions.
27 changes: 11 additions & 16 deletions lib/src/cli/flutter_cli.dart
Original file line number Diff line number Diff line change
Expand Up @@ -465,23 +465,18 @@ extension on String {
String? _getTraceLocation({
required String stackTrace,
}) {
try {
final trace = Trace.parse(stackTrace);

if (trace.frames.isEmpty) {
return null;
}
final trace = Trace.parse(stackTrace);
if (trace.frames.isEmpty) {
return null;
}

final lastFrame = trace.frames.last;
final lastFrame = trace.frames.last;

final library = lastFrame.library;
final line = lastFrame.line;
final column = lastFrame.column;
final library = lastFrame.library;
final line = lastFrame.line;
final column = lastFrame.column;

if (line == null) return library;
if (column == null) return '$library:$line';
return '$library:$line:$column';
} on FormatException {
return null;
}
if (line == null) return library;
if (column == null) return '$library:$line';
return '$library:$line:$column';
}
106 changes: 106 additions & 0 deletions test/src/cli/flutter_cli_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,32 @@ void main() {
});
}''';

const registerExceptionNoStackTraceContents = '''
import 'package:test/test.dart';
import 'package:stack_trace/stack_trace.dart' as stack_trace;
void main() {
test('example', () {
print('EXCEPTION');
registerException(
'fake error',
stack_trace.Chain(<stack_trace.Trace>[]),
);
});
}''';

String registerExceptionCustomStackTraceContents(String stackTrace) => '''
import 'package:test/test.dart';
import 'package:stack_trace/stack_trace.dart' as stack_trace;
void main() {
test('example', () {
print('EXCEPTION');
registerException(
'fake error',
stack_trace.Trace.parse('$stackTrace'),
);
});
}''';

const skippedTestContents = '''
import 'package:test/test.dart';
void main() {
Expand Down Expand Up @@ -545,6 +571,86 @@ void main() {
).called(1);
});

test(
'completes when there is a test directory (exception w/o trace)',
() async {
final directory = Directory.systemTemp.createTempSync();
final testDirectory = Directory(p.join(directory.path, 'test'))
..createSync();
File(p.join(directory.path, 'pubspec.yaml'))
.writeAsStringSync(pubspec);
File(
p.join(testDirectory.path, 'example_test.dart'),
).writeAsStringSync(registerExceptionNoStackTraceContents);
await expectLater(
Flutter.test(
cwd: directory.path,
stdout: logger.write,
stderr: logger.err,
),
completion(equals([ExitCode.unavailable.code])),
);
verify(
() => logger.write(
any(
that: contains(
'Running "flutter test" in ${p.dirname(directory.path)}',
),
),
),
).called(1);
verify(() => logger.err(any(that: contains('EXCEPTION')))).called(1);
verify(
() => logger.write(any(that: contains('-1: Some tests failed.'))),
).called(1);
verify(
() => logger.err(any(that: contains('- [ERROR] fake error'))),
).called(1);
},
);

test(
'completes when there is a test directory (exception w/ custom trace)',
() async {
final directory = Directory.systemTemp.createTempSync();
final testDirectory = Directory(p.join(directory.path, 'test'))
..createSync();
File(p.join(directory.path, 'pubspec.yaml'))
.writeAsStringSync(pubspec);
File(
p.join(testDirectory.path, 'example_test.dart'),
).writeAsStringSync(
registerExceptionCustomStackTraceContents(
'test/example_test.dart 4 main',
),
);
await expectLater(
Flutter.test(
cwd: directory.path,
stdout: logger.write,
stderr: logger.err,
),
completion(equals([ExitCode.unavailable.code])),
);
verify(
() => logger.write(
any(
that: contains(
'Running "flutter test" in ${p.dirname(directory.path)}',
),
),
),
).called(1);
verify(() => logger.err(any(that: contains('EXCEPTION')))).called(1);
verify(
() => logger.write(any(that: contains('-1: Some tests failed.'))),
).called(1);
verify(
() => logger.err(any(that: contains('- [ERROR] test/example_test.dart:4'))),
).called(1);
},
);

test('completes and truncates really long test name', () async {
final directory = Directory.systemTemp.createTempSync();
final testDirectory = Directory(p.join(directory.path, 'test'))
Expand Down

0 comments on commit 7733842

Please sign in to comment.