4b8af9d734
Change-Id: Id11ac9e924ef5fab61961cbf1c9d293b62e954e5 Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/137141 Commit-Queue: Jaime Wren <jwren@google.com> Reviewed-by: Devon Carew <devoncarew@google.com>
85 lines
2.3 KiB
Dart
85 lines
2.3 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';
|
|
|
|
import 'package:path/path.dart' as path;
|
|
import 'package:test/test.dart';
|
|
|
|
Timeout defaultTimeout = Timeout(Duration(seconds: 15));
|
|
|
|
TestProject project({String mainSrc}) => TestProject(mainSrc: mainSrc);
|
|
|
|
class TestProject {
|
|
static String get defaultProjectName => 'dartdev_temp';
|
|
|
|
Directory dir;
|
|
|
|
String get dirPath => dir.path;
|
|
|
|
String get name => defaultProjectName;
|
|
|
|
String get relativeFilePath => 'lib/main.dart';
|
|
|
|
TestProject({String mainSrc}) {
|
|
dir = Directory.systemTemp.createTempSync('dartdev');
|
|
if (mainSrc != null) {
|
|
file(relativeFilePath, mainSrc);
|
|
}
|
|
file('pubspec.yaml', 'name: $name\ndev_dependencies:\n test: any\n');
|
|
}
|
|
|
|
void file(String name, String contents) {
|
|
var file = File(path.join(dir.path, name));
|
|
file.parent.createSync();
|
|
file.writeAsStringSync(contents);
|
|
}
|
|
|
|
void dispose() {
|
|
if (dir.existsSync()) {
|
|
dir.deleteSync(recursive: true);
|
|
}
|
|
}
|
|
|
|
ProcessResult runSync(
|
|
String command,
|
|
List<String> args, {
|
|
String workingDir,
|
|
}) {
|
|
var arguments = [
|
|
absolutePathToDartdevFile,
|
|
command,
|
|
];
|
|
|
|
if (args != null && args.isNotEmpty) {
|
|
arguments.addAll(args);
|
|
}
|
|
|
|
return Process.runSync(
|
|
Platform.resolvedExecutable,
|
|
arguments,
|
|
workingDirectory: workingDir ?? dir.path,
|
|
);
|
|
}
|
|
|
|
/// The path relative from `Directory.current.path` to `dartdev.dart` is
|
|
/// different when executing these tests locally versus on the Dart
|
|
/// buildbots, this if-else captures this change and branches for each case.
|
|
String get absolutePathToDartdevFile {
|
|
var dartdevFilePathOnBots = path.absolute(path.join(
|
|
Directory.current.path, 'pkg', 'dartdev', 'bin', 'dartdev.dart'));
|
|
if (File(dartdevFilePathOnBots).existsSync()) {
|
|
return dartdevFilePathOnBots;
|
|
} else {
|
|
return path
|
|
.absolute(path.join(Directory.current.path, 'bin', 'dartdev.dart'));
|
|
}
|
|
}
|
|
|
|
File findFile(String name) {
|
|
var file = File(path.join(dir.path, name));
|
|
return file.existsSync() ? file : null;
|
|
}
|
|
}
|