Revert "[ CLI ] Attempt to execute samples generated by 'dart create' templates"

This reverts commit e59f59d49a.

Reason for revert: Causing timeout failures on pkg-{mac,win}-release

Original change's description:
> [ CLI ] Attempt to execute samples generated by 'dart create' templates
>
> Fixes https://github.com/dart-lang/sdk/issues/47458
>
> Change-Id: Icf3c03c6d1f33ef9be30e4bf826813674e9e9fb7
> Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/220883
> Reviewed-by: Devon Carew <devoncarew@google.com>
> Commit-Queue: Ben Konyi <bkonyi@google.com>

TBR=mit@google.com,devoncarew@google.com,bkonyi@google.com

Change-Id: Id27c1f9ec124dad8556e1733220284180302b30e
No-Presubmit: true
No-Tree-Checks: true
No-Try: true
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/226561
Reviewed-by: Ben Konyi <bkonyi@google.com>
Commit-Queue: Ben Konyi <bkonyi@google.com>
This commit is contained in:
Ben Konyi 2022-01-05 17:43:15 +00:00 committed by Commit Bot
parent cd13938e5e
commit 7a7c36ab2f
3 changed files with 7 additions and 99 deletions

View file

@ -125,7 +125,7 @@ Response _rootHandler(Request req) {
}
Response _echoHandler(Request request) {
final message = request.params['message'];
final message = params(request, 'message');
return Response.ok('$message\n');
}

View file

@ -2,13 +2,9 @@
// 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:convert';
import 'dart:io';
import 'package:dartdev/src/commands/create.dart';
import 'package:dartdev/src/templates.dart';
import 'package:path/path.dart' as path;
import 'package:test/test.dart';
import '../utils.dart';
@ -27,22 +23,21 @@ void defineCreateTests() {
// Create tests for each template.
for (String templateId in CreateCommand.legalTemplateIds) {
test(templateId, () async {
const projectName = 'template_project';
p = project();
final templateGenerator = getGenerator(templateId);
ProcessResult createResult = await p.run([
'create',
'--force',
'--template',
templateId,
projectName,
'template_project',
]);
expect(createResult.exitCode, 0, reason: createResult.stderr);
// Validate that the project analyzes cleanly.
// TODO: Should we use --fatal-infos here?
ProcessResult analyzeResult =
await p.run(['analyze', '--fatal-infos', projectName]);
await p.run(['analyze'], workingDir: p.dir.path);
expect(analyzeResult.exitCode, 0, reason: analyzeResult.stdout);
// Validate that the code is well formatted.
@ -51,86 +46,9 @@ void defineCreateTests() {
'--output',
'none',
'--set-exit-if-changed',
projectName,
'template_project',
]);
expect(formatResult.exitCode, 0, reason: formatResult.stdout);
// Process the execution instructions provided by the template.
final runCommands = templateGenerator
.getInstallInstructions(
projectName,
projectName,
)
.split('\n')
// Remove directory change instructions.
.sublist(1)
.map((command) => command.trim())
.map((command) {
final commandParts = command.split(' ');
if (command.startsWith('dart ')) {
return commandParts.sublist(1);
}
return commandParts;
}).toList();
final isServerTemplate = templateGenerator.categories.contains('server');
final isWebTemplate = templateGenerator.categories.contains('web');
final workingDir = path.join(p.dirPath, projectName);
// Execute the templates run instructions.
for (int i = 0; i < runCommands.length; ++i) {
// The last command is always the command to execute the code generated
// by the template.
final isLastCommand = i == runCommands.length - 1;
final command = runCommands[i];
Process process;
if (isLastCommand && isWebTemplate) {
// The web template uses `webdev` to execute, not `dart`, so don't
// run the test through the project utility method.
process = await Process.start(
path.join(
p.pubCacheBinPath,
Platform.isWindows ? '${command.first}.bat' : command.first,
),
command.sublist(1),
workingDirectory: workingDir,
);
} else {
process = await p.start(
command,
workingDir: workingDir,
);
}
if (isLastCommand && (isServerTemplate || isWebTemplate)) {
final completer = Completer<void>();
StreamSubscription sub;
// Listen for well-known output from specific templates to determine
// if they've executed correctly. These templates won't exit on their
// own, so we'll need to terminate the process once we've verified it
// runs correctly.
sub = process.stdout.transform(utf8.decoder).listen((e) {
if ((isServerTemplate && e.contains('Server listening on port')) ||
(isWebTemplate && e.contains('Succeeded after'))) {
sub.cancel();
process.kill();
completer.complete();
}
});
await completer.future;
// Since we had to terminate the process manually, we aren't certain
// as to what the exit code will be on all platforms (should be -15
// for POSIX systems), so we'll just wait for the process to exit
// here.
await process.exitCode;
} else {
// If the sample should exit on its own, it should always result in
// an exit code of 0.
expect(await process.exitCode, 0);
}
}
});
}
}

View file

@ -39,10 +39,6 @@ class TestProject {
String get dirPath => dir.path;
String get pubCachePath => path.join(dirPath, 'pub_cache');
String get pubCacheBinPath => path.join(pubCachePath, 'bin');
String get mainPath => path.join(dirPath, relativeFilePath);
final String name;
@ -117,10 +113,7 @@ dev_dependencies:
...arguments,
],
workingDirectory: workingDir ?? dir.path,
environment: {
if (logAnalytics) '_DARTDEV_LOG_ANALYTICS': 'true',
'PUB_CACHE': pubCachePath
});
environment: {if (logAnalytics) '_DARTDEV_LOG_ANALYTICS': 'true'});
final stdoutContents = _process.stdout.transform(utf8.decoder).join();
final stderrContents = _process.stderr.transform(utf8.decoder).join();
final code = await _process.exitCode;
@ -143,10 +136,7 @@ dev_dependencies:
...arguments,
],
workingDirectory: workingDir ?? dir.path,
environment: {
if (logAnalytics) '_DARTDEV_LOG_ANALYTICS': 'true',
'PUB_CACHE': pubCachePath,
})
environment: {if (logAnalytics) '_DARTDEV_LOG_ANALYTICS': 'true'})
..then((p) => _process = p);
}