diff --git a/changelog.md b/changelog.md index 9508d762..a5dd6293 100644 --- a/changelog.md +++ b/changelog.md @@ -1,5 +1,8 @@ # grinder.dart changes +## 0.7.1+1 (2015/5/19) +- Add a `files` param to `TestRunner.test`. + ## 0.7.1 (2015/5/19) - `Dart.run` now takes an optional `vmArgs`, a list of arguments passed to the Dart VM. - Added `downgrade` method do `Pub`. diff --git a/lib/grinder_sdk.dart b/lib/grinder_sdk.dart index 4ad97046..51a45c74 100644 --- a/lib/grinder_sdk.dart +++ b/lib/grinder_sdk.dart @@ -13,6 +13,7 @@ import 'package:which/which.dart'; import 'grinder.dart'; import 'src/run.dart' as run_lib; import 'src/run_utils.dart'; +import 'src/utils.dart'; bool _sdkOnPath; @@ -305,7 +306,7 @@ class Analyzer { List args = []; if (packageRoot != null) args.add('--package-root=${packageRoot.path}'); if (fatalWarnings) args.add('--fatal-warnings'); - args.addAll(_coerceToPathList(fileOrPaths)); + args.addAll(coerceToPathList(fileOrPaths)); run_lib.run(_sdkBin('dartanalyzer'), arguments: args); } @@ -316,7 +317,7 @@ class Analyzer { List args = []; if (packageRoot != null) args.add('--package-root=${packageRoot.path}'); if (fatalWarnings) args.add('--fatal-warnings'); - args.addAll(_coerceToPathList(files)); + args.addAll(coerceToPathList(files)); run_lib.run(_sdkBin('dartanalyzer'), arguments: args); } @@ -331,13 +332,13 @@ class DartFmt { /// Run the `dartfmt` command with the `--overwrite` option. Format a file, a /// directory or a list of files or directories in place. static void format(fileOrPath) { - _run('--overwrite', _coerceToPathList(fileOrPath)); + _run('--overwrite', coerceToPathList(fileOrPath)); } /// Run the `dartfmt` command with the `--dry-run` option. Return `true` if /// any files would be changed by running the formatter. static bool dryRun(fileOrPath) { - String results = _run('--dry-run', _coerceToPathList(fileOrPath)); + String results = _run('--dry-run', coerceToPathList(fileOrPath)); return results.trim().isNotEmpty; } @@ -535,12 +536,3 @@ class _PubLocalApp extends PubApp { script: script, arguments: arguments, runOptions: runOptions); } } - -List _coerceToPathList(filesOrPaths) { - if (filesOrPaths is! List) filesOrPaths = [filesOrPaths]; - return filesOrPaths.map((item) { - if (item is String) return item; - if (item is File) return item.path; - return '${item}'; - }).toList(); -} diff --git a/lib/grinder_tools.dart b/lib/grinder_tools.dart index a9a2a6cd..311c30ef 100644 --- a/lib/grinder_tools.dart +++ b/lib/grinder_tools.dart @@ -186,6 +186,9 @@ class TestRunner { /// Run the tests in the current package. See the /// [test package](https://pub.dartlang.org/packages/test). /// + /// [files] - the files or directories to test. This can a path ([String]), + /// [File], or list of paths or files. + /// /// [name] is substring of the name of the test to run. Regular expression /// syntax is supported. [plainName] is a plain-text substring of the name of /// the test to run. [platformSelector] is the platform(s) on which to run the @@ -195,9 +198,11 @@ class TestRunner { /// `firefox`, `safari`. [concurrency] controls the number of concurrent test /// suites run (defaults to 4). [pubServe] is the port of a pub serve instance /// serving `test/`. - void test({String name, String plainName, dynamic platformSelector, - int concurrency, int pubServe, RunOptions runOptions}) { + void test({dynamic files, String name, String plainName, + dynamic platformSelector, int concurrency, int pubServe, + RunOptions runOptions}) { _test.run(_buildArgs( + files: files, name: name, plainName: plainName, selector: platformSelector, @@ -208,6 +213,9 @@ class TestRunner { /// Run the tests in the current package. See the /// [test package](https://pub.dartlang.org/packages/test). /// + /// [files] - the files or directories to test. This can a path ([String]), + /// [File], or list of paths or files. + /// /// [name] is substring of the name of the test to run. Regular expression /// syntax is supported. [plainName] is a plain-text substring of the name of /// the test to run. [platformSelector] is the platform(s) on which to run the @@ -217,9 +225,11 @@ class TestRunner { /// `firefox`, `safari`. [concurrency] controls the number of concurrent test /// suites run (defaults to 4). [pubServe] is the port of a pub serve instance /// serving `test/`. - Future testAsync({String name, String plainName, dynamic platformSelector, - int concurrency, int pubServe, RunOptions runOptions}) { + Future testAsync({dynamic files, String name, String plainName, + dynamic platformSelector, int concurrency, int pubServe, + RunOptions runOptions}) { return _test.runAsync(_buildArgs( + files: files, name: name, plainName: plainName, selector: platformSelector, @@ -227,8 +237,8 @@ class TestRunner { pubServe: pubServe), script: 'test', runOptions: runOptions); } - List _buildArgs({String name, String plainName, dynamic selector, - int concurrency, int pubServe}) { + List _buildArgs({dynamic files, String name, String plainName, + dynamic selector, int concurrency, int pubServe}) { List args = ['--reporter=expanded']; if (name != null) args.add('--name=${name}'); if (plainName != null) args.add('--plain-name=${plainName}'); @@ -238,6 +248,7 @@ class TestRunner { } if (concurrency != null) args.add('--concurrency=${concurrency}'); if (pubServe != null) args.add('--pub-serve=${pubServe}'); + if (files != null) args.addAll(coerceToPathList(files)); // TODO: Pass in --color based on a global property: #243. return args; } diff --git a/lib/src/cli.dart b/lib/src/cli.dart index 3237c0a9..e4a5b481 100644 --- a/lib/src/cli.dart +++ b/lib/src/cli.dart @@ -15,7 +15,7 @@ import 'utils.dart'; import '../grinder.dart'; // This version must be updated in tandem with the pubspec version. -const String APP_VERSION = '0.7.1'; +const String APP_VERSION = '0.7.1+1'; List grinderArgs() => _args; List _args; diff --git a/lib/src/utils.dart b/lib/src/utils.dart index bd714833..42df98b5 100644 --- a/lib/src/utils.dart +++ b/lib/src/utils.dart @@ -125,3 +125,14 @@ class ZonedValue { return v != null ? v : _rootValue; } } + +/// Given a [String], [File], or list of strings or files, coerce the +/// [filesOrPaths] param into a list of strings. +List coerceToPathList(filesOrPaths) { + if (filesOrPaths is! List) filesOrPaths = [filesOrPaths]; + return filesOrPaths.map((item) { + if (item is String) return item; + if (item is File) return item.path; + return '${item}'; + }).toList(); +} diff --git a/pubspec.yaml b/pubspec.yaml index af1c687a..0fff2d10 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -1,6 +1,6 @@ name: grinder # This version must be updated in tandem with the lib/src/cli.dart version. -version: 0.7.1 +version: 0.7.1+1 description: Dart workflows, automated. homepage: https://github.com/google/grinder.dart diff --git a/test/src/utils_test.dart b/test/src/utils_test.dart index 2b0375d5..57da617e 100644 --- a/test/src/utils_test.dart +++ b/test/src/utils_test.dart @@ -3,6 +3,8 @@ library grinder.src.utils_test; +import 'dart:io'; + import 'package:grinder/src/utils.dart'; import 'package:test/test.dart'; @@ -24,5 +26,13 @@ main() { timer.cancel(); expect(timer.isActive, false); }); + + test('coerceToPathList', () { + expect(coerceToPathList([]), isEmpty); + expect(coerceToPathList('foo'), ['foo']); + expect(coerceToPathList(new File('foo')), ['foo']); + expect(coerceToPathList(['a', 'b']), ['a', 'b']); + expect(coerceToPathList([new File('a'), new File('b')]), ['a', 'b']); + }); }); }