From a0b6aa1fadbeb9adc7ebbd77e2e85f80109e6d4f Mon Sep 17 00:00:00 2001 From: Dustin Lessard Date: Fri, 30 Oct 2015 10:27:49 -0400 Subject: [PATCH 1/4] Allow individual tests to be run --- lib/src/tasks/test/cli.dart | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/lib/src/tasks/test/cli.dart b/lib/src/tasks/test/cli.dart index 79d9d5ef..fd2c6f59 100644 --- a/lib/src/tasks/test/cli.dart +++ b/lib/src/tasks/test/cli.dart @@ -15,6 +15,7 @@ library dart_dev.src.tasks.test.cli; import 'dart:async'; +import 'dart:io'; import 'package:args/args.dart'; @@ -72,6 +73,18 @@ class TestCli extends TaskCli { if (integration) { tests.addAll(config.test.integrationTests); } + + int restLength = parsedArgs.rest.length; + if (restLength > 0) { + //verify this is a test-file and it exists. + for (var i = 0; i < restLength; i++) { + String filePath = parsedArgs.rest[i]; + await new File(filePath).exists().then((bool exists){ + if (exists) tests.add(filePath); + else print("Ignoring unknown argument");}); + } + + } if (tests.isEmpty) { if (unit && config.test.unitTests.isEmpty) { return new CliResult.fail( From 2de73df115b449fc775401e521f1275bb2f2e930 Mon Sep 17 00:00:00 2001 From: Dustin Lessard Date: Fri, 30 Oct 2015 11:46:14 -0400 Subject: [PATCH 2/4] Refactored individual tests change to be more readable --- lib/src/tasks/test/cli.dart | 58 ++++++++++++++++++++++++++++--------- 1 file changed, 44 insertions(+), 14 deletions(-) diff --git a/lib/src/tasks/test/cli.dart b/lib/src/tasks/test/cli.dart index fd2c6f59..7f564bcb 100644 --- a/lib/src/tasks/test/cli.dart +++ b/lib/src/tasks/test/cli.dart @@ -30,7 +30,8 @@ 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.') + defaultsTo: null, + help: 'Includes the unit test suite.') ..addFlag('integration', defaultsTo: defaultIntegration, help: 'Includes the integration test suite.') @@ -46,13 +47,44 @@ class TestCli extends TaskCli { final String command = 'test'; + bool hasRestParams(ArgResults parsedArgs) { + return parsedArgs.rest.length > 0; + } + + Future addToTestsFromRest(List tests, List 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]; + print("filePath:" + filePath); + 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 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 unit = parsedArgs['unit']; print("unit:"+unit.toString()); bool integration = parsedArgs['integration']; + List tests = []; + int individualTests = 0; + var concurrency = TaskCli.valueOf('concurrency', parsedArgs, config.test.concurrency); if (concurrency is String) { @@ -61,12 +93,20 @@ class TestCli extends TaskCli { List 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 tests = []; if (unit) { tests.addAll(config.test.unitTests); } @@ -74,17 +114,7 @@ class TestCli extends TaskCli { tests.addAll(config.test.integrationTests); } - int restLength = parsedArgs.rest.length; - if (restLength > 0) { - //verify this is a test-file and it exists. - for (var i = 0; i < restLength; i++) { - String filePath = parsedArgs.rest[i]; - await new File(filePath).exists().then((bool exists){ - if (exists) tests.add(filePath); - else print("Ignoring unknown argument");}); - } - } if (tests.isEmpty) { if (unit && config.test.unitTests.isEmpty) { return new CliResult.fail( From 5dcb9101a947db976e437eab399e47efe69495bc Mon Sep 17 00:00:00 2001 From: Dustin Lessard Date: Tue, 3 Nov 2015 00:15:51 -0500 Subject: [PATCH 3/4] individual tests : added integration test --- lib/src/tasks/test/cli.dart | 44 ++++++++++++++------------------- test/integration/test_test.dart | 41 +++++++++++++++++++++++++++--- 2 files changed, 56 insertions(+), 29 deletions(-) diff --git a/lib/src/tasks/test/cli.dart b/lib/src/tasks/test/cli.dart index 7f564bcb..8f7bbf9f 100644 --- a/lib/src/tasks/test/cli.dart +++ b/lib/src/tasks/test/cli.dart @@ -29,9 +29,7 @@ import 'package:dart_dev/src/tasks/test/config.dart'; class TestCli extends TaskCli { final ArgParser argParser = new ArgParser() - ..addFlag('unit', - defaultsTo: null, - 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.') @@ -51,23 +49,21 @@ class TestCli extends TaskCli { return parsedArgs.rest.length > 0; } - Future addToTestsFromRest(List tests, List rest) async{ + Future addToTestsFromRest(List tests, List 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]; - print("filePath:" + filePath); - await new File(filePath).exists().then((bool exists) { - if (exists) { - individualTests++; - tests.add(filePath); - } - else { - print("Ignoring unknown argument"); - } - }); - } + 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; } @@ -80,7 +76,7 @@ class TestCli extends TaskCli { .hasImmediateDependency('test')) return new CliResult.fail( 'Package "test" must be an immediate dependency in order to run its executables.'); - bool unit = parsedArgs['unit']; print("unit:"+unit.toString()); + bool unit = parsedArgs['unit']; bool integration = parsedArgs['integration']; List tests = []; int individualTests = 0; @@ -93,20 +89,17 @@ class TestCli extends TaskCli { List platforms = TaskCli.valueOf('platform', parsedArgs, config.test.platforms); - if(hasRestParams(parsedArgs)) { + if (hasRestParams(parsedArgs)) { individualTests = await addToTestsFromRest(tests, parsedArgs.rest); } - if (isExplicitlyFalse(unit) && !integration && individualTests==0) { + 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; + } else { + if (individualTests == 0) unit = true; } - if (unit) { tests.addAll(config.test.unitTests); } @@ -114,7 +107,6 @@ class TestCli extends TaskCli { tests.addAll(config.test.integrationTests); } - if (tests.isEmpty) { if (unit && config.test.unitTests.isEmpty) { return new CliResult.fail( diff --git a/test/integration/test_test.dart b/test/integration/test_test.dart index 6cc5b219..4cb9f340 100644 --- a/test/integration/test_test.dart +++ b/test/integration/test_test.dart @@ -26,12 +26,24 @@ const String projectWithFailingTests = 'test/fixtures/test/failing'; const String projectWithPassingTests = 'test/fixtures/test/passing'; Future runTests(String projectPath, - {bool unit: true, bool integration: false}) async { + {bool unit: true, bool integration: false, List 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); @@ -55,6 +67,22 @@ 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, @@ -62,6 +90,13 @@ void main() { 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, From 7a243c5e06b92c4688d93acfa6aecd277446d77c Mon Sep 17 00:00:00 2001 From: Dustin Lessard Date: Tue, 3 Nov 2015 15:32:51 -0500 Subject: [PATCH 4/4] individual _tests: updated README --- README.md | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/README.md b/README.md index 563be2dc..b7f51ed4 100644 --- a/README.md +++ b/README.md @@ -395,6 +395,11 @@ object. +* 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