blob: 27578f57b34413a7b49707069414de2833292f72 [file] [log] [blame]
// Copyright (c) 2021, the Dart project authors. Please see the AUTHORS file
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.
import 'package:test/test.dart';
import 'test_client.dart';
import 'test_support.dart';
main() {
late DapTestSession dap;
setUp(() async {
dap = await DapTestSession.setUp();
tearDown(() => dap.tearDown());
group('debug mode', () {
test('prints messages from dart:developer log()', () async {
final testFile = dap.createTestFile(r'''
import 'dart:developer';
void main(List<String> args) async {
log('this is a test\nacross two lines');
log('this is a test', name: 'foo');
var outputEvents = await dap.client.collectOutput(file: testFile);
// Skip the first line because it's the VM Service connection info.
final output = outputEvents.skip(1).map((e) => e.output).join();
expectLines(output, [
'[log] this is a test',
' across two lines',
'[foo] this is a test',
test('prints long messages from dart:developer log()', () async {
// Make a long message that's more than 255 chars (where the VM truncates
// log strings by default).
final longMessage = 'this is a test' * 20;
final testFile = dap.createTestFile('''
import 'dart:developer';
void main(List<String> args) async {
// Prevent us exiting before the async log messages may have completed.
// The test will terminate the script early once the expectations are met.
await Future.delayed(const Duration(seconds: 30));
final expectedLogMessage = '[log] $longMessage\n';
final consoleOutputs = dap.client.outputEvents
.where((event) => event.category == 'console')
.map((event) => event.output);
await Future.wait([
expectLater(consoleOutputs, emitsThrough(expectedLogMessage)),
dap.client.start(file: testFile),
await dap.client.terminate();
// These tests can be slow due to starting up the external server process.
}, timeout: Timeout.none);