Skip to content
Merged
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
5 changes: 5 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -395,6 +395,11 @@ object.
</tr>
</tbody>
</table>
* Individual test files can be executed by appending their path to the end of the command.

```
ddev test path/to/test_name path/to/another/test_name
```


## CLI Usage
Expand Down
43 changes: 39 additions & 4 deletions lib/src/tasks/test/cli.dart
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
library dart_dev.src.tasks.test.cli;

import 'dart:async';
import 'dart:io';

import 'package:args/args.dart';

Expand All @@ -28,8 +29,7 @@ import 'package:dart_dev/src/tasks/test/config.dart';

class TestCli extends TaskCli {
final ArgParser argParser = new ArgParser()
..addFlag('unit',
defaultsTo: defaultUnit, help: 'Includes the unit test suite.')
..addFlag('unit', defaultsTo: null, help: 'Includes the unit test suite.')
..addFlag('integration',
defaultsTo: defaultIntegration,
help: 'Includes the integration test suite.')
Expand All @@ -45,13 +45,42 @@ class TestCli extends TaskCli {

final String command = 'test';

bool hasRestParams(ArgResults parsedArgs) {
return parsedArgs.rest.length > 0;
}

Future addToTestsFromRest(List<String> tests, List<String> rest) async {
int restLength = rest.length;
int individualTests = 0;
//verify this is a test-file and it exists.
for (var i = 0; i < restLength; i++) {
String filePath = rest[i];
await new File(filePath).exists().then((bool exists) {
if (exists) {
individualTests++;
tests.add(filePath);
} else {
print("Ignoring unknown argument");
}
});
}
return individualTests;
}

bool isExplicitlyFalse(bool value) {
return value != null && value == false;
}

Future<CliResult> run(ArgResults parsedArgs) async {
if (!platform_util
.hasImmediateDependency('test')) return new CliResult.fail(
'Package "test" must be an immediate dependency in order to run its executables.');

bool unit = parsedArgs['unit'];
bool integration = parsedArgs['integration'];
List<String> tests = [];
int individualTests = 0;

var concurrency =
TaskCli.valueOf('concurrency', parsedArgs, config.test.concurrency);
if (concurrency is String) {
Expand All @@ -60,18 +89,24 @@ class TestCli extends TaskCli {
List<String> platforms =
TaskCli.valueOf('platform', parsedArgs, config.test.platforms);

if (!unit && !integration) {
if (hasRestParams(parsedArgs)) {
individualTests = await addToTestsFromRest(tests, parsedArgs.rest);
}

if (isExplicitlyFalse(unit) && !integration && individualTests == 0) {
return new CliResult.fail(
'No tests were selected. Include at least one of --unit or --integration.');
} else {
if (individualTests == 0) unit = true;
}

List<String> tests = [];
if (unit) {
tests.addAll(config.test.unitTests);
}
if (integration) {
tests.addAll(config.test.integrationTests);
}

if (tests.isEmpty) {
if (unit && config.test.unitTests.isEmpty) {
return new CliResult.fail(
Expand Down
41 changes: 38 additions & 3 deletions test/integration/test_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,24 @@ const String projectWithFailingTests = 'test/fixtures/test/failing';
const String projectWithPassingTests = 'test/fixtures/test/passing';

Future<bool> runTests(String projectPath,
{bool unit: true, bool integration: false}) async {
{bool unit: true, bool integration: false, List<String> files}) async {
await Process.run('pub', ['get'], workingDirectory: projectPath);

List args = ['run', 'dart_dev', 'test'];
args.add(unit ? '--unit' : '--no-unit');
args.add(integration ? '--integration' : '--no-integration');
if (unit != null) args.add(unit ? '--unit' : '--no-unit');
if (integration != null) args
.add(integration ? '--integration' : '--no-integration');
int i;

if (files != null) {
int filesLength = files.length;
if (filesLength > 0) {
for (i = 0; i < filesLength; i++) {
args.add(files[i]);
}
}
}

TaskProcess process =
new TaskProcess('pub', args, workingDirectory: projectPath);

Expand All @@ -55,13 +67,36 @@ void main() {
isFalse);
});

test('should run individual unit test', () async {
expect(
await runTests(projectWithPassingTests, files:
['test/fixtures/test/passing/test/passing_unit_test.dart']),
isTrue);
});

test('should run individual unit tests', () async {
expect(
await runTests(projectWithPassingTests, files: [
'test/fixtures/test/passing/test/passing_unit_test.dart',
'test/fixtures/test/passing/test/passing_unit_integration.dart'
]),
isTrue);
});

test('should run unit tests', () async {
expect(
await runTests(projectWithPassingTests,
unit: true, integration: false),
isTrue);
});

test('should run unit tests by default', () async {
expect(
await runTests(projectWithPassingTests,
unit: null, integration: null),
isTrue);
});

test('should run integration tests', () async {
expect(
await runTests(projectWithPassingTests,
Expand Down