Files
sdk/pkg/front_end/test/testing_utils.dart
T
Jens Johansen 2bd74882e2 [package:testing] Various updates
* Delete unused stuff
 * rename 'path' to 'root'
 * accept 'includeEndsWith' as a plain text string so we often can avoid
   using regexp
 * accept 'subRoots' to filter to directories faster and more precisly
   than when using regexps in 'pattern'
 * make 'list' async instead of async* (no more yield stuff which we
   promptly turn into a list when actually using it)

Note that some changes in testing.json is not 100% semantic-preserving,
e.g. the "parser_all" suite previously had a pattern "/tests/.*\\.dart$"
which was probably meant to include all dart files in the "tests" folder
in the root, but in fact included all dart files in a "tests" folder
anywhere. The updated version does not.

Change-Id: Idd014274f86bf6214dee0753a7738ec80bc6a49e
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/358442
Reviewed-by: Johnni Winther <johnniwinther@google.com>
Commit-Queue: Jens Johansen <jensj@google.com>
Reviewed-by: Nicholas Shahan <nshahan@google.com>
2024-03-21 06:58:32 +00:00

54 lines
1.8 KiB
Dart

// 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.
import 'dart:io' show Directory, Process, ProcessResult;
import 'package:testing/testing.dart' show Chain, TestDescription;
Future<List<TestDescription>> filterList(
Chain suite, bool onlyInGit, List<TestDescription> base) async {
Set<Uri> gitFiles = {};
if (onlyInGit) {
for (Uri subRoot in suite.subRoots) {
gitFiles.addAll(await getGitFiles(subRoot));
}
}
List<TestDescription> result = [];
for (TestDescription description in base) {
if (onlyInGit && !gitFiles.contains(description.uri)) {
continue;
}
result.add(description);
}
return result;
}
Future<Set<Uri>> getGitFiles(Uri uri) async {
ProcessResult result = await Process.run("git", ["ls-files", "."],
workingDirectory: new Directory.fromUri(uri).absolute.path,
runInShell: true);
if (result.exitCode != 0) {
throw "Git returned non-zero error code (${result.exitCode}):\n\n"
"stdout: ${result.stdout}\n\n"
"stderr: ${result.stderr}";
}
String stdout = result.stdout;
return stdout
.split(new RegExp('^', multiLine: true))
.map((line) => uri.resolve(line.trimRight()))
.toSet();
}
void checkEnvironment(
Map<String, String> environment, Set<String> knownEnvironmentKeys) {
Set<String> environmentKeys = environment.keys.toSet();
environmentKeys.removeAll(knownEnvironmentKeys);
if (environmentKeys.isNotEmpty) {
throw "Unknown environment(s) given:"
"\n - ${environmentKeys.join("\n- ")}\n"
"Knows about these environment(s):"
"\n - ${knownEnvironmentKeys.join("\n - ")}";
}
}