[dds] Fix deserialisation of env vars in DAP

Change-Id: Ia3da6d4abdfd41b4b4f6631fd82d8680ee1727b8
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/239309
Reviewed-by: Ben Konyi <bkonyi@google.com>
Commit-Queue: Ben Konyi <bkonyi@google.com>
This commit is contained in:
Danny Tuppeny 2022-03-29 18:39:29 +00:00 committed by Commit Bot
parent 0640f6e1e3
commit 8e90d6ac15
2 changed files with 37 additions and 1 deletions

View file

@ -217,7 +217,7 @@ class DartCommonLaunchAttachRequestArguments extends RequestArguments {
: restart = obj['restart'],
name = obj['name'] as String?,
cwd = obj['cwd'] as String?,
env = obj['env'] as Map<String, String>?,
env = (obj['env'] as Map<String, Object?>?)?.cast<String, String>(),
additionalProjectPaths =
(obj['additionalProjectPaths'] as List?)?.cast<String>(),
debugSdkLibraries = obj['debugSdkLibraries'] as bool?,

View file

@ -0,0 +1,36 @@
// Copyright (c) 2022, 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 'dart:convert';
import 'package:dds/dap.dart';
import 'package:test/test.dart';
main() {
group('DartLaunchRequestArguments', () {
test('handles only required arguments', () async {
final json = '{"program":"a"}';
final decoded = DartLaunchRequestArguments.fromJson(jsonDecode(json));
expect(decoded.program, 'a');
final encoded = jsonEncode(decoded.toJson());
expect(encoded, json);
});
test('handles env variables map', () async {
final json = '{"env":{"a":"b"},"program":"a"}';
final decoded = DartLaunchRequestArguments.fromJson(jsonDecode(json));
expect(decoded.env!['a'], 'b');
final encoded = jsonEncode(decoded.toJson());
expect(encoded, json);
});
test('handles additional project paths list', () async {
final json = '{"additionalProjectPaths":["a","b"],"program":"a"}';
final decoded = DartLaunchRequestArguments.fromJson(jsonDecode(json));
expect(decoded.additionalProjectPaths, ['a', 'b']);
final encoded = jsonEncode(decoded.toJson());
expect(encoded, json);
});
});
}