Files
sdk/pkg/dartdev/test/experiment_util.dart
T
Janice Collins 5b3f387f4d Make dartdev test_all.dart test all and work.
This corrects some tests that just weren't working for myself and
others while disabling a small number that don't work anymore or
are blocked on a bug.

Bug: https://github.com/dart-lang/sdk/issues/51707
Change-Id: Ib537d210e80baa3bb80578f0fcccc063a2029173
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/288623
Auto-Submit: Janice Collins <jcollins@google.com>
Reviewed-by: Ben Konyi <bkonyi@google.com>
Commit-Queue: Janice Collins <jcollins@google.com>
2023-03-14 16:19:08 +00:00

64 lines
2.0 KiB
Dart

// Copyright (c) 2021, 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';
import 'package:path/path.dart' as path;
import 'package:pub_semver/pub_semver.dart';
import 'package:yaml/yaml.dart' as yaml;
/// Synchronously searches starting from the current working directory
/// for experimental_features.yaml, then caches it in this variable.
final experimentalFeaturesYaml = () {
var features = path.join('tools', 'experimental_features.yaml');
var searchDir = '.';
var root = path.canonicalize(path.separator);
do {
var tryPath = path.join(searchDir, features);
if (File(path.join(searchDir, features)).existsSync()) {
return tryPath;
}
searchDir = path.join(searchDir, '..');
} while (path.canonicalize(searchDir) != root);
throw 'experimental_features.yaml not found';
}();
/// The unexpired experiments from `experimental_features.yaml` that have an
/// associated `validation` program. Can not use async here as that will
/// break test_all.dart.
List<Experiment> experimentsWithValidation() {
final experiments = yaml.loadYaml(
File(experimentalFeaturesYaml).readAsStringSync(),
sourceUrl: path.toUri(experimentalFeaturesYaml));
return [
for (final e in experiments['features'].entries)
if (e.value['expired'] != true && e.value['validation'] != null)
Experiment(
e.key,
e.value['validation'],
tryParseVersion(e.value['enabledIn']),
tryParseVersion(e.value['experimentalReleaseVersion']),
)
];
}
Version? tryParseVersion(String? version) =>
version == null ? null : Version.parse(version);
class Experiment {
final String name;
final String validation;
final Version? enabledIn;
final Version? experimentalReleaseVersion;
Experiment(
this.name,
this.validation,
this.enabledIn,
this.experimentalReleaseVersion,
);
}