Skip to content
This repository was archived by the owner on Feb 22, 2018. It is now read-only.
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ Test Runner for Dart is an open source project. It is licensed using the
[BSD 3-Clause License](LICENSE).
We appreciate pull requests, here are our guidelines:

1. File a bug at https://github.com/dart-lang/test_runner/issues (if there
1. File a bug at https://github.com/google/test_runner.dart/issues (if there
isn’t one already). If your patch is going to be large it might be a good idea
to get the discussion started early. We are happy to discuss it in a new issue
beforehand.
Expand Down
17 changes: 14 additions & 3 deletions bin/run_tests.dart
Original file line number Diff line number Diff line change
Expand Up @@ -130,11 +130,22 @@ void runTests(
"directory or a list of test files.\n"));
exit(2);
} else if (!allDartFiles && projectOrTests.length == 1) {
projectPath = projectOrTests[0];
bool isProjectPath = false;
try {
isProjectPath = DartProject.isProjectPath(projectOrTests[0]);
} on ArgumentError catch(e) {
isProjectPath = false;
}

if (isProjectPath) {
projectPath = projectOrTests[0];
} else {
testPaths = projectOrTests;
projectPath = "./";
}
} else {
testPaths = projectOrTests;
projectPath = projectOrTests[0].substring(0,
projectOrTests[0].lastIndexOf("test/") + 5);
projectPath = "./";
}
}

Expand Down
86 changes: 56 additions & 30 deletions lib/src/dart_project.dart
Original file line number Diff line number Diff line change
Expand Up @@ -47,29 +47,16 @@ class DartProject {
/// Check if a Dart project can be found in [projectPath] and loads its
/// pubspec.yaml values into [pubSpecYaml].
void checkProject() {
var projPathType = FileSystemEntity.typeSync(projectPath);

if (projPathType == FileSystemEntityType.NOT_FOUND) {
throw new ArgumentError('The "${new File(projectPath).absolute.path}" '
'directory does not exist.');
}

if (projPathType != FileSystemEntityType.DIRECTORY) {
throw new ArgumentError("\"$projectPath\" is not a directory.");
if (!DartProject.isProjectPath(projectPath)) {
throw new StateError("$projectPath is not a valid project path");
}

// Save the absolute directory and path.
Directory projectDirectory = new Directory(projectPath);

projectPath = projectDirectory.path;

var pubSpecFile = new File(p.join(projectPath, 'pubspec.yaml'));

if (!pubSpecFile.existsSync()) {
throw new ArgumentError('"$projectPath" is not a Dart project directory.'
' Could not find the "pubspec.yaml" file.');
}

try {
pubSpecYaml = loadYaml(pubSpecFile.readAsStringSync());
} catch (e) {
Expand All @@ -82,6 +69,28 @@ class DartProject {
p.join(projectPath, 'packages')) == FileSystemEntityType.DIRECTORY;
}

static bool isProjectPath(String path) {
var projPathType = FileSystemEntity.typeSync(path);

if (projPathType == FileSystemEntityType.NOT_FOUND) {
throw new ArgumentError('The "${new File(path).absolute.path}" '
'directory does not exist.');
}

if (projPathType != FileSystemEntityType.DIRECTORY) {
throw new ArgumentError("\"$path\" is not a directory.");
}

var pubSpecFile = new File(p.join(path, 'pubspec.yaml'));

if (!pubSpecFile.existsSync()) {
throw new ArgumentError('"$path" is not a Dart project directory.'
' Could not find the "pubspec.yaml" file.');
}

return true;
}

/// Finds all the tests in the project and reads their configuration and lists
/// them in [tests].
///
Expand Down Expand Up @@ -111,22 +120,20 @@ class DartProject {
// Special case if the user has manually specified a list of tests to run.
if (testPaths.length != 0) {
for (String testPath in testPaths) {
if (!testPath.endsWith(TEST_FILE_SUFFIX)) {
throw new ArgumentError('The "$testPath" file does not seem to be a'
' test Dart file. Test Dart files should have a "_test.dart" '
'suffix');
} else if (FileSystemEntity.isFileSync(testPath)) {
File testFile = new File(testPath);
if (!FileSystemEntity.identicalSync(
testFile.parent.path, testDirectory.path)) {
throw new ArgumentError('The "$testPath" test file is not located'
" in the current Dart project's test directory: " +
testDirectory.path);
} else {
files.add(testFile);
}
if (FileSystemEntity.isDirectorySync(testPath)) {
new Directory(testPath)
.listSync(recursive: true, followLinks: false)
.forEach((FileSystemEntity entity) {
if (entity is File) {
if (entity.path.endsWith(TEST_FILE_SUFFIX)) {
files.add(_checkTestPath(entity.path));
} else {
print('\nNotice: ignoring non-test file ${entity.path}');
}
}
});
} else {
throw new ArgumentError('The "$testPath" file does not exist.');
files.add(_checkTestPath(testPath));
}
}
} else {
Expand All @@ -151,6 +158,25 @@ class DartProject {
return controller.stream;
}

File _checkTestPath(String testPath) {
if (!testPath.endsWith(TEST_FILE_SUFFIX)) {
throw new ArgumentError('The "$testPath" file does not seem to be a'
' test Dart file. Test Dart files should have a "_test.dart" '
'suffix');
} else if (FileSystemEntity.isFileSync(testPath)) {
File testFile = new File(testPath);
if (testFile.absolute.path.indexOf(testDirectory.absolute.path) != 0) {
throw new ArgumentError('The "$testPath" test file is not located'
" in the current Dart project's test directory: " +
testDirectory.path);
} else {
return testFile;
}
} else {
throw new ArgumentError('The "$testPath" file does not exist.');
}
}

/// Extracts the given test [file]'s configuration. If the [file] is not a
/// test [null] is returned.
// TODO: add annotation extraction to configure tests.
Expand Down