Files
sdk/runtime/observatory/tests/service/eval_test.dart
T
Ben Konyi f247613737 Reland "[ VM / Service ] Migrated Observatory service tests from package:unittest to package:test and package:expect."
This reverts commit 32ed244f63.

Reason for revert: Hopefully clear up bot failures

Original change's description:
> Revert "Reland "[ VM / Service ] Migrated Observatory service tests from package:unittest to package:test and package:expect.""
> 
> This reverts commit d03b7ea721.
> 
> Reason for revert: Hitting assert in VM (https://logs.chromium.org/logs/dart/buildbucket/cr-buildbucket.appspot.com/8885275470407956944/+/steps/test_results/0/logs/new_test_failures__logs_/0)
> 
> Original change's description:
> > Reland "[ VM / Service ] Migrated Observatory service tests from package:unittest to package:test and package:expect."
> > 
> > This reverts commit 01dc1756c4.
> > 
> > Change-Id: I1c9186947af2368ff48c02a392da9ced85770335
> > Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/140254
> > Commit-Queue: Ben Konyi <bkonyi@google.com>
> > Reviewed-by: Ryan Macnak <rmacnak@google.com>
> 
> TBR=bkonyi@google.com,rmacnak@google.com
> 
> Change-Id: I640adf8e96672476f46fc1f4580a7231b5cfd8fe
> No-Presubmit: true
> No-Tree-Checks: true
> No-Try: true
> Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/140379
> Reviewed-by: Ben Konyi <bkonyi@google.com>
> Commit-Queue: Ben Konyi <bkonyi@google.com>

TBR=bkonyi@google.com,rmacnak@google.com

Change-Id: I3127f2f39e64e87daa5ae0c02e14cd24cb586f5f
No-Presubmit: true
No-Tree-Checks: true
No-Try: true
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/140480
Reviewed-by: Ben Konyi <bkonyi@google.com>
Commit-Queue: Ben Konyi <bkonyi@google.com>
2020-03-21 06:28:36 +00:00

107 lines
2.9 KiB
Dart

// Copyright (c) 2015, 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:developer';
import 'package:observatory/service_io.dart';
import 'package:test/test.dart';
import 'service_test_common.dart';
import 'test_helper.dart';
int globalVar = 100;
class MyClass {
static int staticVar = 1000;
static void method(int value) {
debugger();
}
}
class _MyClass {
void foo() {
debugger();
}
}
void testFunction() {
int i = 0;
while (true) {
if (++i % 100000000 == 0) {
MyClass.method(10000);
(new _MyClass()).foo();
}
}
}
var tests = <IsolateTest>[
hasStoppedAtBreakpoint,
// Evaluate against library, class, and instance.
(Isolate isolate) async {
ServiceMap stack = await isolate.getStack();
// Make sure we are in the right place.
expect(stack.type, equals('Stack'));
expect(stack['frames'].length, greaterThanOrEqualTo(2));
expect(stack['frames'][0].function.name, equals('method'));
expect(stack['frames'][0].function.dartOwner.name, equals('MyClass'));
var lib = isolate.rootLibrary;
var cls = stack['frames'][0].function.dartOwner;
var instance = stack['frames'][0].variables[0]['value'];
dynamic result = await lib.evaluate('globalVar + 5');
print(result);
expect(result.valueAsString, equals('105'));
await expectError(() => lib.evaluate('globalVar + staticVar + 5'));
result = await cls.evaluate('globalVar + staticVar + 5');
print(result);
expect(result.valueAsString, equals('1105'));
await expectError(() => cls.evaluate('this + 5'));
result = await instance.evaluate('this + 5');
print(result);
expect(result.valueAsString, equals('10005'));
await expectError(() => instance.evaluate('this + frog'));
},
resumeIsolate,
hasStoppedAtBreakpoint,
(Isolate isolate) async {
ServiceMap stack = await isolate.getStack();
// Make sure we are in the right place.
expect(stack.type, equals('Stack'));
expect(stack['frames'].length, greaterThanOrEqualTo(2));
expect(stack['frames'][0].function.name, equals('foo'));
expect(stack['frames'][0].function.dartOwner.name, equals('_MyClass'));
var cls = stack['frames'][0].function.dartOwner;
dynamic result = await cls.evaluate("1+1");
print(result);
expect(result.valueAsString, equals("2"));
}
];
expectError(func) async {
bool gotException = false;
dynamic result;
try {
result = await func();
expect(result.type, equals('Error')); // dart1 semantics
} on ServerRpcException catch (e) {
expect(e.code, equals(ServerRpcException.kExpressionCompilationError));
gotException = true;
}
if (result?.type != 'Error') {
expect(gotException, true); // dart2 semantics
}
}
main(args) => runIsolateTests(args, tests, testeeConcurrent: testFunction);