Add an initial tests for dartdev that can execute and pass on the Dart build bots, as well as locally.
Change-Id: I92b24b7b5252d2f2dab97fe552406b7e97fc927c Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/132703 Reviewed-by: Devon Carew <devoncarew@google.com> Commit-Queue: Jaime Wren <jwren@google.com>
This commit is contained in:
committed by
commit-bot@chromium.org
parent
500822341e
commit
e9bd2595f4
@@ -2,65 +2,27 @@
|
||||
// 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:dartdev/dartdev.dart';
|
||||
import 'package:test/test.dart';
|
||||
|
||||
// TODO(jwren) move the following test utilities to a separate file
|
||||
import 'utils.dart';
|
||||
|
||||
// Files that end in _test.dart must have a main method to satisfy the dart2js
|
||||
// bots
|
||||
void main() {
|
||||
test('empty test for dart2js', () {
|
||||
assert(true == true);
|
||||
group('flag', flags);
|
||||
}
|
||||
|
||||
void flags() {
|
||||
TestProject p;
|
||||
tearDown(() => p?.dispose());
|
||||
test('--help', () {
|
||||
p = project();
|
||||
|
||||
var result = p.runSync('--help');
|
||||
|
||||
expect(result.exitCode, 0);
|
||||
expect(result.stdout, contains(DartdevRunner.dartdevDescription));
|
||||
expect(result.stdout, contains('Usage: dartdev <command> [arguments]'));
|
||||
expect(result.stdout, contains('Global options:'));
|
||||
expect(result.stdout, contains('Available commands:'));
|
||||
});
|
||||
}
|
||||
|
||||
TestProject project({String mainSrc}) => TestProject(mainSrc: mainSrc);
|
||||
|
||||
class TestProject {
|
||||
Directory dir;
|
||||
|
||||
static String get defaultProjectName => 'dartdev_temp';
|
||||
|
||||
String get name => defaultProjectName;
|
||||
|
||||
TestProject({String mainSrc}) {
|
||||
dir = Directory.systemTemp.createTempSync('dartdev');
|
||||
if (mainSrc != null) {
|
||||
file('lib/main.dart', 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() {
|
||||
dir.deleteSync(recursive: true);
|
||||
}
|
||||
|
||||
ProcessResult run(String command, [List<String> args]) {
|
||||
var arguments = [
|
||||
path.absolute(path.join(Directory.current.path, 'bin', 'dartdev.dart')),
|
||||
command
|
||||
];
|
||||
if (args != null && args.isNotEmpty) {
|
||||
arguments.addAll(args);
|
||||
}
|
||||
return Process.runSync(
|
||||
Platform.resolvedExecutable,
|
||||
arguments,
|
||||
workingDirectory: dir.path,
|
||||
);
|
||||
}
|
||||
|
||||
File findFile(String name) {
|
||||
var file = File(path.join(dir.path, name));
|
||||
return file.existsSync() ? file : null;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,71 @@
|
||||
// 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;
|
||||
|
||||
TestProject project({String mainSrc}) => TestProject(mainSrc: mainSrc);
|
||||
|
||||
class TestProject {
|
||||
Directory dir;
|
||||
|
||||
static String get defaultProjectName => 'dartdev_temp';
|
||||
|
||||
String get name => defaultProjectName;
|
||||
|
||||
TestProject({String mainSrc}) {
|
||||
dir = Directory.systemTemp.createTempSync('dartdev');
|
||||
if (mainSrc != null) {
|
||||
file('lib/main.dart', 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() {
|
||||
dir.deleteSync(recursive: true);
|
||||
}
|
||||
|
||||
ProcessResult runSync(String command, [List<String> args]) {
|
||||
var arguments = [
|
||||
absolutePathToDartdevFile,
|
||||
command,
|
||||
];
|
||||
|
||||
if (args != null && args.isNotEmpty) {
|
||||
arguments.addAll(args);
|
||||
}
|
||||
|
||||
return Process.runSync(
|
||||
Platform.resolvedExecutable,
|
||||
arguments,
|
||||
workingDirectory: 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;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user