From 8b06209bacd5349d11175f66f5c072de7c101e9c Mon Sep 17 00:00:00 2001 From: Jochum van der Ploeg Date: Thu, 8 Dec 2022 17:45:02 +0100 Subject: [PATCH 1/5] fix(test): groups may not be async --- lib/src/commands/test/templates/test_runner_bundle.dart | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/src/commands/test/templates/test_runner_bundle.dart b/lib/src/commands/test/templates/test_runner_bundle.dart index e681eb88..2241f402 100644 --- a/lib/src/commands/test/templates/test_runner_bundle.dart +++ b/lib/src/commands/test/templates/test_runner_bundle.dart @@ -1,5 +1,5 @@ // GENERATED CODE - DO NOT MODIFY BY HAND -// ignore_for_file: prefer_single_quotes, public_member_api_docs, lines_longer_than_80_chars, implicit_dynamic_list_literal, implicit_dynamic_map_literal +// ignore_for_file: type=lint, implicit_dynamic_list_literal, implicit_dynamic_map_literal, inference_failure_on_collection_literal import 'package:mason/mason.dart'; @@ -8,7 +8,7 @@ final testRunnerBundle = MasonBundle.fromJson({ { "path": "test/.test_runner.dart", "data": - "Ly8gR0VORVJBVEVEIENPREUgLSBETyBOT1QgTU9ESUZZIEJZIEhBTkQKLy8gQ29uc2lkZXIgYWRkaW5nIHRoaXMgZmlsZSB0byB5b3VyIC5naXRpZ25vcmUuCgp7eyNpc0ZsdXR0ZXJ9fWltcG9ydCAnZGFydDppbyc7CgppbXBvcnQgJ3BhY2thZ2U6Zmx1dHRlcl90ZXN0L2ZsdXR0ZXJfdGVzdC5kYXJ0JzsKe3svaXNGbHV0dGVyfX17e15pc0ZsdXR0ZXJ9fWltcG9ydCAncGFja2FnZTp0ZXN0L3Rlc3QuZGFydCc7e3svaXNGbHV0dGVyfX0KCnt7I3Rlc3RzfX1pbXBvcnQgJ3t7ey59fX0nIGFzIHt7I3NuYWtlQ2FzZX19e3t7Ln19fXt7L3NuYWtlQ2FzZX19Owp7ey90ZXN0c319CnZvaWQgbWFpbigpIHsKe3sjaXNGbHV0dGVyfX0gIGdvbGRlbkZpbGVD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KQogICAgICAgICAgLndoZXJlKChwYXRoKSA9PiBwYXRoLmVuZHNXaXRoKCcucG5nJykpCiAgICAgICAgICAudG9MaXN0KCk7CgogIEBvdmVycmlkZQogIFVyaSBnZXRUZXN0VXJpKFVyaSBrZXksIGludD8gdmVyc2lvbikgewogICAgZmluYWwga2V5U3RyaW5nID0ga2V5LnBhdGg7CiAgICByZXR1cm4gVXJpLnBhcnNlKGdvbGRlbkZpbGVQYXRocwogICAgICAgIC5zaW5nbGVXaGVyZSgoZ29sZGVuRmlsZVBhdGgpID0+IGdvbGRlbkZpbGVQYXRoLmVuZHNXaXRoKGtleVN0cmluZykpKTsKICB9Cn0Ke3svaXNGbHV0dGVyfX0=", "type": "text" } ], From 52653bbfe72c106976574786261f1035f241da7d Mon Sep 17 00:00:00 2001 From: Jochum van der Ploeg Date: Thu, 8 Dec 2022 19:52:24 +0100 Subject: [PATCH 2/5] fix(test): groups may not be async --- test/e2e_test.dart | 617 ++++++++++-------- test/fixtures/async_main/pubspec.yaml | 10 + .../async_main/test/async_main_test.dart | 10 + 3 files changed, 357 insertions(+), 280 deletions(-) create mode 100644 test/fixtures/async_main/pubspec.yaml create mode 100644 test/fixtures/async_main/test/async_main_test.dart diff --git a/test/e2e_test.dart b/test/e2e_test.dart index cac1ecbb..29e2c3c7 100644 --- a/test/e2e_test.dart +++ b/test/e2e_test.dart @@ -54,290 +54,347 @@ void main() { ); }); - test('create -t dart_pkg', () async { - final directory = Directory(path.join('.tmp', 'very_good_dart')); - - final result = await commandRunner.run( - ['create', 'very_good_dart', '-t', 'dart_pkg', '-o', '.tmp'], - ); - expect(result, equals(ExitCode.success.code)); - - final formatResult = await Process.run( - 'flutter', - ['format', '--set-exit-if-changed', '.'], - workingDirectory: directory.path, - runInShell: true, - ); - expect(formatResult.exitCode, equals(ExitCode.success.code)); - expect(formatResult.stderr, isEmpty); - - final analyzeResult = await Process.run( - 'flutter', - ['analyze', '.'], - workingDirectory: directory.path, - runInShell: true, - ); - expect(analyzeResult.exitCode, equals(ExitCode.success.code)); - expect(analyzeResult.stderr, isEmpty); - expect(analyzeResult.stdout, contains('No issues found!')); - - final testResult = await Process.run( - 'flutter', - ['test', '--no-pub', '--coverage'], - workingDirectory: directory.path, - runInShell: true, - ); - expect(testResult.exitCode, equals(ExitCode.success.code)); - expect(testResult.stderr, isEmpty); - expect(testResult.stdout, contains('All tests passed!')); - - final testCoverageResult = await Process.run( - 'genhtml', - ['coverage/lcov.info', '-o', 'coverage'], - workingDirectory: directory.path, - runInShell: true, - ); - expect(testCoverageResult.exitCode, equals(ExitCode.success.code)); - expect(testCoverageResult.stderr, isEmpty); - expect(testCoverageResult.stdout, contains('lines......: 100.0%')); + group('create', () { + test('-t dart_pkg', () async { + final directory = Directory(path.join('.tmp', 'very_good_dart')); + + final result = await commandRunner.run( + ['create', 'very_good_dart', '-t', 'dart_pkg', '-o', '.tmp'], + ); + expect(result, equals(ExitCode.success.code)); + + final formatResult = await Process.run( + 'flutter', + ['format', '--set-exit-if-changed', '.'], + workingDirectory: directory.path, + runInShell: true, + ); + expect(formatResult.exitCode, equals(ExitCode.success.code)); + expect(formatResult.stderr, isEmpty); + + final analyzeResult = await Process.run( + 'flutter', + ['analyze', '.'], + workingDirectory: directory.path, + runInShell: true, + ); + expect(analyzeResult.exitCode, equals(ExitCode.success.code)); + expect(analyzeResult.stderr, isEmpty); + expect(analyzeResult.stdout, contains('No issues found!')); + + final testResult = await Process.run( + 'flutter', + ['test', '--no-pub', '--coverage'], + workingDirectory: directory.path, + runInShell: true, + ); + expect(testResult.exitCode, equals(ExitCode.success.code)); + expect(testResult.stderr, isEmpty); + expect(testResult.stdout, contains('All tests passed!')); + + final testCoverageResult = await Process.run( + 'genhtml', + ['coverage/lcov.info', '-o', 'coverage'], + workingDirectory: directory.path, + runInShell: true, + ); + expect(testCoverageResult.exitCode, equals(ExitCode.success.code)); + expect(testCoverageResult.stderr, isEmpty); + expect(testCoverageResult.stdout, contains('lines......: 100.0%')); + }); + + test('-t flutter_pkg', () async { + final directory = Directory(path.join('.tmp', 'very_good_flutter')); + + final result = await commandRunner.run( + ['create', 'very_good_flutter', '-t', 'flutter_pkg', '-o', '.tmp'], + ); + expect(result, equals(ExitCode.success.code)); + + final formatResult = await Process.run( + 'flutter', + ['format', '--set-exit-if-changed', '.'], + workingDirectory: directory.path, + runInShell: true, + ); + expect(formatResult.exitCode, equals(ExitCode.success.code)); + expect(formatResult.stderr, isEmpty); + + final analyzeResult = await Process.run( + 'flutter', + ['analyze', '.'], + workingDirectory: directory.path, + runInShell: true, + ); + expect(analyzeResult.exitCode, equals(ExitCode.success.code)); + expect(analyzeResult.stderr, isEmpty); + expect(analyzeResult.stdout, contains('No issues found!')); + + final testResult = await Process.run( + 'flutter', + ['test', '--no-pub', '--coverage'], + workingDirectory: directory.path, + runInShell: true, + ); + expect(testResult.exitCode, equals(ExitCode.success.code)); + expect(testResult.stderr, isEmpty); + expect(testResult.stdout, contains('All tests passed!')); + + final testCoverageResult = await Process.run( + 'genhtml', + ['coverage/lcov.info', '-o', 'coverage'], + workingDirectory: directory.path, + runInShell: true, + ); + expect(testCoverageResult.exitCode, equals(ExitCode.success.code)); + expect(testCoverageResult.stderr, isEmpty); + expect(testCoverageResult.stdout, contains('lines......: 100.0%')); + }); + + test('-t dart_cli', () async { + final directory = Directory(path.join('.tmp', 'very_good_dart_cli')); + + final result = await commandRunner.run( + ['create', 'very_good_dart_cli', '-t', 'dart_cli', '-o', '.tmp'], + ); + expect(result, equals(ExitCode.success.code)); + + final formatResult = await Process.run( + 'flutter', + ['format', '--set-exit-if-changed', '.'], + workingDirectory: directory.path, + runInShell: true, + ); + expect(formatResult.exitCode, equals(ExitCode.success.code)); + expect(formatResult.stderr, isEmpty); + + final analyzeResult = await Process.run( + 'flutter', + ['analyze', '.'], + workingDirectory: directory.path, + runInShell: true, + ); + expect(analyzeResult.exitCode, equals(ExitCode.success.code)); + expect(analyzeResult.stderr, isEmpty); + expect(analyzeResult.stdout, contains('No issues found!')); + + final testResult = await Process.run( + 'flutter', + ['test', '--no-pub', '--coverage'], + workingDirectory: directory.path, + runInShell: true, + ); + expect(testResult.exitCode, equals(ExitCode.success.code)); + expect(testResult.stderr, isEmpty); + expect(testResult.stdout, contains('All tests passed!')); + + final testCoverageResult = await Process.run( + 'genhtml', + ['coverage/lcov.info', '-o', 'coverage'], + workingDirectory: directory.path, + runInShell: true, + ); + expect(testCoverageResult.exitCode, equals(ExitCode.success.code)); + expect(testCoverageResult.stderr, isEmpty); + expect(testCoverageResult.stdout, contains('lines......: 100.0%')); + }); + + test('-t docs_site', () async { + final directory = Directory(path.join('.tmp', 'very_good_docs_site')); + + final result = await commandRunner.run( + ['create', 'very_good_docs_site', '-t', 'docs_site', '-o', '.tmp'], + ); + expect(result, equals(ExitCode.success.code)); + + final installResult = await Process.run( + 'npm', + ['install'], + workingDirectory: directory.path, + runInShell: true, + ); + expect(installResult.exitCode, equals(ExitCode.success.code)); + + final formatResult = await Process.run( + 'npm', + ['run', 'format'], + workingDirectory: directory.path, + runInShell: true, + ); + expect(formatResult.exitCode, equals(ExitCode.success.code)); + expect(formatResult.stderr, isEmpty); + + final lintResult = await Process.run( + 'npm', + ['run', 'lint'], + workingDirectory: directory.path, + runInShell: true, + ); + expect(lintResult.exitCode, equals(ExitCode.success.code)); + expect(lintResult.stderr, isEmpty); + + final buildResult = await Process.run( + 'npm', + ['run', 'build'], + workingDirectory: directory.path, + runInShell: true, + ); + expect(buildResult.exitCode, equals(ExitCode.success.code)); + expect(buildResult.stderr, isEmpty); + }); + + test('-t flame_game', () async { + final directory = + Directory(path.join('.tmp', 'very_good_flame_game')); + + final result = await commandRunner.run( + [ + 'create', + 'very_good_flame_game', + '-t', + 'flame_game', + '-o', + '.tmp' + ], + ); + expect(result, equals(ExitCode.success.code)); + + final formatResult = await Process.run( + 'flutter', + ['format', '--set-exit-if-changed', '.'], + workingDirectory: directory.path, + runInShell: true, + ); + expect(formatResult.exitCode, equals(ExitCode.success.code)); + expect(formatResult.stderr, isEmpty); + + final analyzeResult = await Process.run( + 'flutter', + ['analyze', '.'], + workingDirectory: directory.path, + runInShell: true, + ); + expect(analyzeResult.exitCode, equals(ExitCode.success.code)); + expect(analyzeResult.stderr, isEmpty); + expect(analyzeResult.stdout, contains('No issues found!')); + + final testResult = await Process.run( + 'flutter', + ['test', '--no-pub', '--coverage'], + workingDirectory: directory.path, + runInShell: true, + ); + expect(testResult.exitCode, equals(ExitCode.success.code)); + expect(testResult.stderr, isEmpty); + expect(testResult.stdout, contains('All tests passed!')); + + final testCoverageResult = await Process.run( + 'genhtml', + ['coverage/lcov.info', '-o', 'coverage'], + workingDirectory: directory.path, + runInShell: true, + ); + expect(testCoverageResult.exitCode, equals(ExitCode.success.code)); + expect(testCoverageResult.stderr, isEmpty); + expect(testCoverageResult.stdout, contains('lines......: 97.8%')); + }); + + test('-t core', () async { + final directory = Directory(path.join('.tmp', 'very_good_core')); + + final result = await commandRunner.run( + ['create', 'very_good_core', '-t', 'core', '-o', '.tmp'], + ); + expect(result, equals(ExitCode.success.code)); + + final formatResult = await Process.run( + 'flutter', + ['format', '--set-exit-if-changed', '.'], + workingDirectory: directory.path, + runInShell: true, + ); + expect(formatResult.exitCode, equals(ExitCode.success.code)); + expect(formatResult.stderr, isEmpty); + + final analyzeResult = await Process.run( + 'flutter', + ['analyze', '.'], + workingDirectory: directory.path, + runInShell: true, + ); + expect(analyzeResult.exitCode, equals(ExitCode.success.code)); + expect(analyzeResult.stderr, isEmpty); + expect(analyzeResult.stdout, contains('No issues found!')); + + final testResult = await Process.run( + 'flutter', + ['test', '--no-pub', '--coverage'], + workingDirectory: directory.path, + runInShell: true, + ); + expect(testResult.exitCode, equals(ExitCode.success.code)); + expect(testResult.stderr, isEmpty); + expect(testResult.stdout, contains('All tests passed!')); + + final testCoverageResult = await Process.run( + 'genhtml', + ['coverage/lcov.info', '-o', 'coverage'], + workingDirectory: directory.path, + runInShell: true, + ); + expect(testCoverageResult.exitCode, equals(ExitCode.success.code)); + expect(testCoverageResult.stderr, isEmpty); + expect(testCoverageResult.stdout, contains('lines......: 100.0%')); + }); }); - test('create -t flutter_pkg', () async { - final directory = Directory(path.join('.tmp', 'very_good_flutter')); - - final result = await commandRunner.run( - ['create', 'very_good_flutter', '-t', 'flutter_pkg', '-o', '.tmp'], - ); - expect(result, equals(ExitCode.success.code)); - - final formatResult = await Process.run( - 'flutter', - ['format', '--set-exit-if-changed', '.'], - workingDirectory: directory.path, - runInShell: true, - ); - expect(formatResult.exitCode, equals(ExitCode.success.code)); - expect(formatResult.stderr, isEmpty); - - final analyzeResult = await Process.run( - 'flutter', - ['analyze', '.'], - workingDirectory: directory.path, - runInShell: true, - ); - expect(analyzeResult.exitCode, equals(ExitCode.success.code)); - expect(analyzeResult.stderr, isEmpty); - expect(analyzeResult.stdout, contains('No issues found!')); - - final testResult = await Process.run( - 'flutter', - ['test', '--no-pub', '--coverage'], - workingDirectory: directory.path, - runInShell: true, - ); - expect(testResult.exitCode, equals(ExitCode.success.code)); - expect(testResult.stderr, isEmpty); - expect(testResult.stdout, contains('All tests passed!')); - - final testCoverageResult = await Process.run( - 'genhtml', - ['coverage/lcov.info', '-o', 'coverage'], - workingDirectory: directory.path, - runInShell: true, - ); - expect(testCoverageResult.exitCode, equals(ExitCode.success.code)); - expect(testCoverageResult.stderr, isEmpty); - expect(testCoverageResult.stdout, contains('lines......: 100.0%')); - }); - - test('create -t dart_cli', () async { - final directory = Directory(path.join('.tmp', 'very_good_dart_cli')); - - final result = await commandRunner.run( - ['create', 'very_good_dart_cli', '-t', 'dart_cli', '-o', '.tmp'], - ); - expect(result, equals(ExitCode.success.code)); - - final formatResult = await Process.run( - 'flutter', - ['format', '--set-exit-if-changed', '.'], - workingDirectory: directory.path, - runInShell: true, - ); - expect(formatResult.exitCode, equals(ExitCode.success.code)); - expect(formatResult.stderr, isEmpty); - - final analyzeResult = await Process.run( - 'flutter', - ['analyze', '.'], - workingDirectory: directory.path, - runInShell: true, - ); - expect(analyzeResult.exitCode, equals(ExitCode.success.code)); - expect(analyzeResult.stderr, isEmpty); - expect(analyzeResult.stdout, contains('No issues found!')); - - final testResult = await Process.run( - 'flutter', - ['test', '--no-pub', '--coverage'], - workingDirectory: directory.path, - runInShell: true, - ); - expect(testResult.exitCode, equals(ExitCode.success.code)); - expect(testResult.stderr, isEmpty); - expect(testResult.stdout, contains('All tests passed!')); - - final testCoverageResult = await Process.run( - 'genhtml', - ['coverage/lcov.info', '-o', 'coverage'], - workingDirectory: directory.path, - runInShell: true, - ); - expect(testCoverageResult.exitCode, equals(ExitCode.success.code)); - expect(testCoverageResult.stderr, isEmpty); - expect(testCoverageResult.stdout, contains('lines......: 100.0%')); - }); - - test('create -t docs_site', () async { - final directory = Directory(path.join('.tmp', 'very_good_docs_site')); - - final result = await commandRunner.run( - ['create', 'very_good_docs_site', '-t', 'docs_site', '-o', '.tmp'], - ); - expect(result, equals(ExitCode.success.code)); - - final installResult = await Process.run( - 'npm', - ['install'], - workingDirectory: directory.path, - runInShell: true, - ); - expect(installResult.exitCode, equals(ExitCode.success.code)); - - final formatResult = await Process.run( - 'npm', - ['run', 'format'], - workingDirectory: directory.path, - runInShell: true, - ); - expect(formatResult.exitCode, equals(ExitCode.success.code)); - expect(formatResult.stderr, isEmpty); - - final lintResult = await Process.run( - 'npm', - ['run', 'lint'], - workingDirectory: directory.path, - runInShell: true, - ); - expect(lintResult.exitCode, equals(ExitCode.success.code)); - expect(lintResult.stderr, isEmpty); - - final buildResult = await Process.run( - 'npm', - ['run', 'build'], - workingDirectory: directory.path, - runInShell: true, - ); - expect(buildResult.exitCode, equals(ExitCode.success.code)); - expect(buildResult.stderr, isEmpty); - }); - - test('create -t flame_game', () async { - final directory = Directory(path.join('.tmp', 'very_good_flame_game')); - - final result = await commandRunner.run( - ['create', 'very_good_flame_game', '-t', 'flame_game', '-o', '.tmp'], - ); - expect(result, equals(ExitCode.success.code)); - - final formatResult = await Process.run( - 'flutter', - ['format', '--set-exit-if-changed', '.'], - workingDirectory: directory.path, - runInShell: true, - ); - expect(formatResult.exitCode, equals(ExitCode.success.code)); - expect(formatResult.stderr, isEmpty); - - final analyzeResult = await Process.run( - 'flutter', - ['analyze', '.'], - workingDirectory: directory.path, - runInShell: true, - ); - expect(analyzeResult.exitCode, equals(ExitCode.success.code)); - expect(analyzeResult.stderr, isEmpty); - expect(analyzeResult.stdout, contains('No issues found!')); - - final testResult = await Process.run( - 'flutter', - ['test', '--no-pub', '--coverage'], - workingDirectory: directory.path, - runInShell: true, - ); - expect(testResult.exitCode, equals(ExitCode.success.code)); - expect(testResult.stderr, isEmpty); - expect(testResult.stdout, contains('All tests passed!')); - - final testCoverageResult = await Process.run( - 'genhtml', - ['coverage/lcov.info', '-o', 'coverage'], - workingDirectory: directory.path, - runInShell: true, - ); - expect(testCoverageResult.exitCode, equals(ExitCode.success.code)); - expect(testCoverageResult.stderr, isEmpty); - expect(testCoverageResult.stdout, contains('lines......: 97.8%')); - }); - - test('create -t core', () async { - final directory = Directory(path.join('.tmp', 'very_good_core')); - - final result = await commandRunner.run( - ['create', 'very_good_core', '-t', 'core', '-o', '.tmp'], - ); - expect(result, equals(ExitCode.success.code)); - - final formatResult = await Process.run( - 'flutter', - ['format', '--set-exit-if-changed', '.'], - workingDirectory: directory.path, - runInShell: true, - ); - expect(formatResult.exitCode, equals(ExitCode.success.code)); - expect(formatResult.stderr, isEmpty); - - final analyzeResult = await Process.run( - 'flutter', - ['analyze', '.'], - workingDirectory: directory.path, - runInShell: true, - ); - expect(analyzeResult.exitCode, equals(ExitCode.success.code)); - expect(analyzeResult.stderr, isEmpty); - expect(analyzeResult.stdout, contains('No issues found!')); - - final testResult = await Process.run( - 'flutter', - ['test', '--no-pub', '--coverage'], - workingDirectory: directory.path, - runInShell: true, - ); - expect(testResult.exitCode, equals(ExitCode.success.code)); - expect(testResult.stderr, isEmpty); - expect(testResult.stdout, contains('All tests passed!')); - - final testCoverageResult = await Process.run( - 'genhtml', - ['coverage/lcov.info', '-o', 'coverage'], - workingDirectory: directory.path, - runInShell: true, - ); - expect(testCoverageResult.exitCode, equals(ExitCode.success.code)); - expect(testCoverageResult.stderr, isEmpty); - expect(testCoverageResult.stdout, contains('lines......: 100.0%')); + group('test', () { + test('fails if the project does not exist', () async { + final directory = Directory( + path.join(Directory.current.path, '.tmp', 'not_a_project'), + ); + await directory.create(recursive: true); + + await IOOverrides.runZoned( + () async { + final result = await commandRunner.run(['test']); + expect(result, equals(ExitCode.noInput.code)); + }, + getCurrentDirectory: () => directory, + ); + }); + + test('supports async main methods', () async { + final directory = Directory( + path.join(Directory.current.path, '.tmp', 'async_main'), + ); + await copyDirectory(Directory('test/fixtures/async_main'), directory); + + await IOOverrides.runZoned( + () async { + final result = await commandRunner.run(['test']); + expect(result, equals(ExitCode.success.code)); + }, + getCurrentDirectory: () => directory, + ); + }); }); }, timeout: const Timeout(Duration(minutes: 2)), ); } + +Future copyDirectory(Directory from, Directory to) async { + await to.create(recursive: true); + await for (final entity in from.list(recursive: true)) { + final toPath = path.join( + to.path, + path.relative(entity.path, from: from.path), + ); + if (entity is Directory) { + await Directory(toPath).create(); + } else if (entity is File) { + await entity.copy(toPath); + } + } +} diff --git a/test/fixtures/async_main/pubspec.yaml b/test/fixtures/async_main/pubspec.yaml new file mode 100644 index 00000000..4ece174a --- /dev/null +++ b/test/fixtures/async_main/pubspec.yaml @@ -0,0 +1,10 @@ +name: async_main +description: Fixture for testing async main. +version: 0.1.0+1 +publish_to: none + +environment: + sdk: ">=2.18.0 <3.0.0" + +dev_dependencies: + test: ^1.19.2 diff --git a/test/fixtures/async_main/test/async_main_test.dart b/test/fixtures/async_main/test/async_main_test.dart new file mode 100644 index 00000000..d041c5a1 --- /dev/null +++ b/test/fixtures/async_main/test/async_main_test.dart @@ -0,0 +1,10 @@ +// ignore_for_file: prefer_const_constructors +import 'package:test/test.dart'; + +void main() async { + group('AsyncMain', () { + test('will succeed', () { + expect(true, equals(!false)); + }); + }); +} From 2cf0f9b3b120470c0186da57b91586b9fe4f73d7 Mon Sep 17 00:00:00 2001 From: Jochum van der Ploeg Date: Thu, 8 Dec 2022 19:54:05 +0100 Subject: [PATCH 3/5] fix(test): groups may not be async --- test/e2e_test.dart | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/test/e2e_test.dart b/test/e2e_test.dart index 29e2c3c7..36cab122 100644 --- a/test/e2e_test.dart +++ b/test/e2e_test.dart @@ -370,6 +370,15 @@ void main() { ); await copyDirectory(Directory('test/fixtures/async_main'), directory); + final pubGetResult = await Process.run( + 'flutter', + ['pub', 'get'], + workingDirectory: directory.path, + runInShell: true, + ); + + expect(pubGetResult.exitCode, equals(ExitCode.success.code)); + await IOOverrides.runZoned( () async { final result = await commandRunner.run(['test']); From 3dece185742c574f979a3513dddb8e77717b19f8 Mon Sep 17 00:00:00 2001 From: Jochum van der Ploeg Date: Thu, 8 Dec 2022 20:03:48 +0100 Subject: [PATCH 4/5] fix(test): groups may not be async --- test/e2e_test.dart | 2 ++ 1 file changed, 2 insertions(+) diff --git a/test/e2e_test.dart b/test/e2e_test.dart index 36cab122..923d2f42 100644 --- a/test/e2e_test.dart +++ b/test/e2e_test.dart @@ -349,6 +349,8 @@ void main() { }); group('test', () { + setUp(_removeTemporaryFiles); + test('fails if the project does not exist', () async { final directory = Directory( path.join(Directory.current.path, '.tmp', 'not_a_project'), From b27e16a2a50c38450eb3c7f116ba4a3f0e9d9264 Mon Sep 17 00:00:00 2001 From: Jochum van der Ploeg Date: Fri, 9 Dec 2022 14:01:07 +0100 Subject: [PATCH 5/5] fix(test): groups may not be async --- test/e2e_test.dart | 9 +++------ test/src/commands/packages_test.dart | 2 +- 2 files changed, 4 insertions(+), 7 deletions(-) diff --git a/test/e2e_test.dart b/test/e2e_test.dart index 923d2f42..4fae30ba 100644 --- a/test/e2e_test.dart +++ b/test/e2e_test.dart @@ -352,9 +352,8 @@ void main() { setUp(_removeTemporaryFiles); test('fails if the project does not exist', () async { - final directory = Directory( - path.join(Directory.current.path, '.tmp', 'not_a_project'), - ); + final directory = + Directory.systemTemp.createTempSync('not_a_project'); await directory.create(recursive: true); await IOOverrides.runZoned( @@ -367,9 +366,7 @@ void main() { }); test('supports async main methods', () async { - final directory = Directory( - path.join(Directory.current.path, '.tmp', 'async_main'), - ); + final directory = Directory.systemTemp.createTempSync('async_main'); await copyDirectory(Directory('test/fixtures/async_main'), directory); final pubGetResult = await Process.run( diff --git a/test/src/commands/packages_test.dart b/test/src/commands/packages_test.dart index 995c0691..9db74c14 100644 --- a/test/src/commands/packages_test.dart +++ b/test/src/commands/packages_test.dart @@ -99,7 +99,7 @@ void main() { 'when no pubspec.yaml exists (recursive)', withRunner((commandRunner, logger, pubUpdater, printLogs) async { final result = await commandRunner.run( - ['packages', 'get', '-r', 'test'], + ['packages', 'get', '-r', 'site'], ); expect(result, equals(ExitCode.noInput.code)); verify(() {