-
Notifications
You must be signed in to change notification settings - Fork 82
Add experimental test fixtures and tests #1937
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
annagrin
merged 5 commits into
dart-lang:master
from
annagrin:annagrin/enable-experiment-in-tests
Feb 6, 2023
+215
−25
Merged
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
3c0ffbb
Validate only needed summaries in expression_compiler_service
16a5596
Merge branch 'master' of github.com:dart-lang/webdev
c3a99a8
Merge branch 'master' of github.com:dart-lang/webdev
3056911
Add experimental test features and tests
482c418
Addressed CR comments
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,133 @@ | ||
// Copyright (c) 2020, 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. | ||
|
||
@TestOn('vm') | ||
@Timeout(Duration(minutes: 2)) | ||
|
||
import 'package:dwds/src/connections/debug_connection.dart'; | ||
import 'package:dwds/src/services/chrome_proxy_service.dart'; | ||
import 'package:test/test.dart'; | ||
import 'package:vm_service/vm_service.dart'; | ||
|
||
import 'fixtures/context.dart'; | ||
import 'fixtures/logging.dart'; | ||
|
||
class TestSetup { | ||
TestContext context; | ||
|
||
TestSetup.sound() | ||
: context = TestContext.withSoundNullSafety( | ||
packageName: '_experimentSound', | ||
webAssetsPath: 'web', | ||
dartEntryFileName: 'main.dart', | ||
htmlEntryFileName: 'index.html', | ||
); | ||
|
||
ChromeProxyService get service => | ||
fetchChromeProxyService(context.debugConnection); | ||
} | ||
|
||
void main() async { | ||
// Enable verbose logging for debugging. | ||
final debug = false; | ||
|
||
for (var compilationMode in CompilationMode.values) { | ||
await _runTests( | ||
compilationMode: compilationMode, | ||
debug: debug, | ||
); | ||
} | ||
} | ||
|
||
Future<void> _runTests({ | ||
required CompilationMode compilationMode, | ||
required bool debug, | ||
}) async { | ||
final setup = TestSetup.sound(); | ||
final context = setup.context; | ||
late VmServiceInterface service; | ||
late Stream<Event> stream; | ||
late String isolateId; | ||
late ScriptRef mainScript; | ||
|
||
onBreakPoint(breakPointId, body) => _onBreakPoint( | ||
setup, | ||
stream, | ||
isolateId, | ||
mainScript, | ||
breakPointId, | ||
body, | ||
); | ||
|
||
group('$compilationMode |', () { | ||
setUpAll(() async { | ||
setCurrentLogWriter(debug: debug); | ||
await context.setUp( | ||
compilationMode: compilationMode, | ||
enableExpressionEvaluation: true, | ||
verboseCompiler: debug, | ||
experiments: ['records'], | ||
); | ||
service = setup.service; | ||
|
||
final vm = await service.getVM(); | ||
isolateId = vm.isolates!.first.id!; | ||
final scripts = await service.getScripts(isolateId); | ||
|
||
await service.streamListen('Debug'); | ||
stream = service.onEvent('Debug'); | ||
|
||
mainScript = scripts.scripts! | ||
.firstWhere((each) => each.uri!.contains('main.dart')); | ||
}); | ||
|
||
tearDownAll(context.tearDown); | ||
|
||
setUp(() => setCurrentLogWriter(debug: debug)); | ||
tearDown(() => service.resume(isolateId)); | ||
|
||
test('simple records', () async { | ||
await onBreakPoint('printSimpleLocal', (event) async { | ||
final frame = event.topFrame!.index!; | ||
final result = await service.evaluateInFrame( | ||
isolateId, | ||
frame, | ||
'record', | ||
); | ||
|
||
expect(result, isA<InstanceRef>()); | ||
return result as InstanceRef; | ||
}); | ||
}); | ||
}); | ||
} | ||
|
||
Future<void> _onBreakPoint( | ||
TestSetup setup, | ||
Stream<Event> stream, | ||
String isolateId, | ||
ScriptRef script, | ||
String breakPointId, | ||
Future<void> Function(Event event) body, | ||
) async { | ||
final context = setup.context; | ||
final service = setup.service; | ||
|
||
Breakpoint? bp; | ||
try { | ||
final line = | ||
await context.findBreakpointLine(breakPointId, isolateId, script); | ||
bp = await service.addBreakpointWithScriptUri(isolateId, script.uri!, line); | ||
|
||
final event = | ||
await stream.firstWhere((e) => e.kind == EventKind.kPauseBreakpoint); | ||
|
||
await body(event); | ||
} finally { | ||
// Remove breakpoint so it doesn't impact other tests or retries. | ||
if (bp != null) { | ||
await service.removeBreakpoint(isolateId, bp.id!); | ||
} | ||
} | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
name: _experiment | ||
version: 1.0.0 | ||
description: >- | ||
A fake package used for testing experimental language features. | ||
publish_to: none | ||
|
||
environment: | ||
sdk: ">=3.0.0-134.0.dev<4.0.0" | ||
|
||
dependencies: | ||
intl: ^0.17.0 | ||
path: ^1.8.2 | ||
|
||
dev_dependencies: | ||
build_runner: ^2.4.0 | ||
build_web_compilers: ^4.0.0 | ||
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
<html> | ||
|
||
<head> | ||
<script defer src="main.dart.js"></script> | ||
</head> | ||
|
||
</html> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
// Copyright (c) 2023, 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:async'; | ||
import 'dart:core'; | ||
import 'dart:html'; | ||
|
||
void main() { | ||
// for evaluation | ||
Timer.periodic(const Duration(seconds: 1), (_) { | ||
printSimpleLocal(); | ||
}); | ||
|
||
document.body!.appendText('Program is running!'); | ||
} | ||
|
||
void printSimpleLocal() { | ||
final record = (true, 3); | ||
print(record); // Breakpoint: printSimpleLocal | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I feel like this parameter makes more sense as part of the
TestContext
constructors since the experiments are tied to the package being usedThere was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I am not sure they are always tied to the package - I can imagine an experiment that does not need changes to the code, just the compilation of it. I'll ask Nick to confirm.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That makes sense!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Confirmed with Nick, indeed we can have experiments that work on the same code.