dart-sdk/pkg/vm_service/test/evaluate_with_scope_test.dart
pq a6e3008ded fix sort_directives violations
See: https://dart-review.googlesource.com/c/sdk/+/196026

TEST=Code cleanup exclusively (sorting imports); no new tests.


Change-Id: Ib07a82ff418138c542d6a83cfab9aabbb285f866
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/196180
Auto-Submit: Phil Quitslund <pquitslund@google.com>
Reviewed-by: Phil Quitslund <pquitslund@google.com>
Reviewed-by: Brian Wilkerson <brianwilkerson@google.com>
Reviewed-by: Ben Konyi <bkonyi@google.com>
Reviewed-by: Bob Nystrom <rnystrom@google.com>
Commit-Queue: Phil Quitslund <pquitslund@google.com>
2021-04-20 22:21:28 +00:00

71 lines
2.2 KiB
Dart

// Copyright (c) 2019, 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 'package:vm_service/vm_service.dart';
import 'common/test_helper.dart';
int? thing1;
int? thing2;
testeeMain() {
thing1 = 3;
thing2 = 4;
}
Future evaluate(VmService service, isolate, target, x, y) async =>
await service.evaluate(isolate!.id!!, target.id!, 'x + y',
scope: {'x': x.id!, 'y': y.id!});
final tests = <IsolateTest>[
(VmService service, IsolateRef isolateRef) async {
final isolateId = isolateRef.id!;
final isolate = await service.getIsolate(isolateId);
final Library lib =
(await service.getObject(isolateId, isolate.rootLib!.id!)) as Library;
final Field field1 = (await service.getObject(isolateId,
lib.variables!.singleWhere((v) => v.name == 'thing1').id!)) as Field;
final thing1 =
(await service.getObject(isolateId, field1.staticValue!.id!));
final Field field2 = (await service.getObject(isolateId,
lib.variables!.singleWhere((v) => v.name == 'thing2').id!)) as Field;
final thing2 =
(await service.getObject(isolateId, field2.staticValue!.id!));
var result = await evaluate(service, isolate, lib, thing1, thing2);
expect(result.valueAsString, equals('7'));
bool didThrow = false;
try {
result = await evaluate(service, isolate, lib, lib, lib);
print(result);
} catch (e) {
didThrow = true;
expect(e.toString(),
contains("Cannot evaluate against a VM-internal object"));
}
expect(didThrow, isTrue);
didThrow = false;
try {
result = await service.evaluate(isolateId, lib.id!, "x + y",
scope: <String, String>{"not&an&id!entifier": thing1.id!});
print(result);
} catch (e) {
didThrow = true;
expect(e.toString(), contains("invalid 'scope' parameter"));
}
expect(didThrow, isTrue);
}
];
main([args = const <String>[]]) => runIsolateTests(
args,
tests,
'evaluate_with_scope_test.dart',
testeeBefore: testeeMain,
);