Skip to content

Commit ce62ad2

Browse files
stereotype441commit-bot@chromium.org
authored andcommitted
Migration: test "add hint" functionality, and fix a path problem on Windows
Change-Id: I6373a20ef3e3e74c77c4a1b9108317996256b831 Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/146820 Reviewed-by: Samuel Rawlins <[email protected]> Commit-Queue: Paul Berry <[email protected]>
1 parent 8636312 commit ce62ad2

File tree

3 files changed

+47
-3
lines changed

3 files changed

+47
-3
lines changed

pkg/nnbd_migration/lib/src/front_end/path_mapper.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,6 @@ class PathMapper {
2727

2828
/// Returns the local filesystem path corresponding to the given [uri].
2929
String reverseMap(Uri uri) {
30-
return provider.pathContext.fromUri(uri);
30+
return provider.pathContext.fromUri(uri.replace(scheme: 'file'));
3131
}
3232
}

pkg/nnbd_migration/lib/src/preview/preview_site.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -240,7 +240,7 @@ class PreviewSite extends Site
240240
// Update the code on disk.
241241
//
242242
var params = uri.queryParameters;
243-
var path = Uri.parse(uri.path).toFilePath();
243+
var path = pathMapper.reverseMap(uri);
244244
var offset = int.parse(params['offset']);
245245
var end = int.parse(params['end']);
246246
var replacement = params['replacement'];

pkg/nnbd_migration/test/migration_cli_test.dart

Lines changed: 45 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,21 @@ mixin _MigrationCliTestMethods on _MigrationCliTestBase {
7979
return stderrText;
8080
}
8181

82+
void assertHttpSuccess(http.Response response) {
83+
if (response.statusCode == 500) {
84+
try {
85+
var decodedResponse = jsonDecode(response.body);
86+
print('Exception: ${decodedResponse['exception']}');
87+
print('Stack trace:');
88+
print(decodedResponse['stackTrace']);
89+
} catch (_) {
90+
print(response.body);
91+
}
92+
fail('HTTP request failed');
93+
}
94+
expect(response.statusCode, 200);
95+
}
96+
8297
Future<String> assertParseArgsFailure(List<String> args) async {
8398
var cli = _createCli();
8499
await cli.run(args);
@@ -97,7 +112,7 @@ mixin _MigrationCliTestMethods on _MigrationCliTestBase {
97112

98113
Future assertPreviewServerResponsive(String url) async {
99114
var response = await http.get(url);
100-
expect(response.statusCode, 200);
115+
assertHttpSuccess(response);
101116
}
102117

103118
void assertProjectContents(String projectDir, Map<String, String> expected) {
@@ -332,6 +347,35 @@ int? f() => null
332347
assertProjectContents(projectDir, projectContents);
333348
}
334349

350+
test_lifecycle_preview_add_hint() async {
351+
var projectContents = simpleProject(sourceText: 'int x;');
352+
var projectDir = await createProjectDir(projectContents);
353+
var cli = _createCli();
354+
await runWithPreviewServer(cli, [projectDir], (url) async {
355+
expect(
356+
logger.stdoutBuffer.toString(), contains('No analysis issues found'));
357+
await assertPreviewServerResponsive(url);
358+
var uri = Uri.parse(url);
359+
var authToken = uri.queryParameters['authToken'];
360+
var response = await http.post(
361+
uri.replace(
362+
path: resourceProvider.pathContext
363+
.toUri(resourceProvider.pathContext
364+
.join(projectDir, 'lib', 'test.dart'))
365+
.path,
366+
queryParameters: {
367+
'offset': '3',
368+
'end': '3',
369+
'replacement': '/*!*/',
370+
'authToken': authToken
371+
}),
372+
headers: {'Content-Type': 'application/json; charset=UTF-8'});
373+
assertHttpSuccess(response);
374+
assertProjectContents(
375+
projectDir, simpleProject(sourceText: 'int/*!*/ x;'));
376+
});
377+
}
378+
335379
test_lifecycle_preview_extra_forward_slash() async {
336380
var projectDir = await createProjectDir(simpleProject());
337381
var cli = _createCli();

0 commit comments

Comments
 (0)