Skip to content

Commit

Permalink
Merge pull request #246 from google/devoncarew_add_testrunner_param
Browse files Browse the repository at this point in the history
add a files param to TestRunner.test
  • Loading branch information
devoncarew committed May 20, 2015
2 parents 4659175 + acab6a7 commit 072bae4
Show file tree
Hide file tree
Showing 7 changed files with 48 additions and 21 deletions.
3 changes: 3 additions & 0 deletions changelog.md
Original file line number Diff line number Diff line change
@@ -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`.
Expand Down
18 changes: 5 additions & 13 deletions lib/grinder_sdk.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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);
}

Expand All @@ -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);
}
Expand All @@ -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;
}

Expand Down Expand Up @@ -535,12 +536,3 @@ class _PubLocalApp extends PubApp {
script: script, arguments: arguments, runOptions: runOptions);
}
}

List<String> _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();
}
23 changes: 17 additions & 6 deletions lib/grinder_tools.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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,
Expand All @@ -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
Expand All @@ -217,18 +225,20 @@ 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,
concurrency: concurrency,
pubServe: pubServe), script: 'test', runOptions: runOptions);
}

List<String> _buildArgs({String name, String plainName, dynamic selector,
int concurrency, int pubServe}) {
List<String> _buildArgs({dynamic files, String name, String plainName,
dynamic selector, int concurrency, int pubServe}) {
List<String> args = ['--reporter=expanded'];
if (name != null) args.add('--name=${name}');
if (plainName != null) args.add('--plain-name=${plainName}');
Expand All @@ -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;
}
Expand Down
2 changes: 1 addition & 1 deletion lib/src/cli.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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<String> grinderArgs() => _args;
List<String> _args;
Expand Down
11 changes: 11 additions & 0 deletions lib/src/utils.dart
Original file line number Diff line number Diff line change
Expand Up @@ -125,3 +125,14 @@ class ZonedValue<T> {
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<String> 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();
}
2 changes: 1 addition & 1 deletion pubspec.yaml
Original file line number Diff line number Diff line change
@@ -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
Expand Down
10 changes: 10 additions & 0 deletions test/src/utils_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@

library grinder.src.utils_test;

import 'dart:io';

import 'package:grinder/src/utils.dart';
import 'package:test/test.dart';

Expand All @@ -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']);
});
});
}

0 comments on commit 072bae4

Please sign in to comment.