From 2dac7583ecf4f5aa8f02108030ad9316b037f201 Mon Sep 17 00:00:00 2001 From: Travis Sanderson Date: Thu, 26 Feb 2015 15:42:26 -0600 Subject: [PATCH 1/2] Fixed issue where passing a particular test file did not work Fixed issue where test files in subdirectories were incorrectly marked as not in the test directory Added ability to pass a directory of test files, in which case the project path is assumed to be the current working directory --- bin/run_tests.dart | 17 ++++++-- lib/src/dart_project.dart | 86 +++++++++++++++++++++++++-------------- 2 files changed, 70 insertions(+), 33 deletions(-) diff --git a/bin/run_tests.dart b/bin/run_tests.dart index 416f58f..8e3818f 100644 --- a/bin/run_tests.dart +++ b/bin/run_tests.dart @@ -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 = "./"; } } diff --git a/lib/src/dart_project.dart b/lib/src/dart_project.dart index 1fde3e7..38fadbe 100644 --- a/lib/src/dart_project.dart +++ b/lib/src/dart_project.dart @@ -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) { @@ -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]. /// @@ -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 { @@ -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. From c114ed7da71f43b8fca55a1cde377c12e4796b33 Mon Sep 17 00:00:00 2001 From: Travis Sanderson Date: Thu, 26 Feb 2015 15:45:47 -0600 Subject: [PATCH 2/2] Updated contributing readme to point to correct repo for filing issues --- CONTRIBUTING.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 2fa84f6..5d51dd6 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -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.