Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Prev Previous commit
Next Next commit
updated withRunner helper
  • Loading branch information
alestiago committed Oct 5, 2023
commit 4dd84c212667bbcb72edf01812fe9925e76119f2
9 changes: 8 additions & 1 deletion test/helpers/command_helper.dart
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,16 @@ import 'package:mason/mason.dart';
import 'package:mocktail/mocktail.dart';
import 'package:pub_updater/pub_updater.dart';
import 'package:very_good_cli/src/command_runner.dart';
import 'package:very_good_cli/src/pub_license/pub_license.dart';

class MockLogger extends Mock implements Logger {}

class MockProgress extends Mock implements Progress {}

class MockPubUpdater extends Mock implements PubUpdater {}

class _MockPubLicense extends Mock implements PubLicense {}

void Function() _overridePrint(void Function(List<String>) fn) {
return () {
final printLogs = <String>[];
Expand All @@ -31,13 +34,15 @@ void Function() withRunner(
VeryGoodCommandRunner commandRunner,
Logger logger,
PubUpdater pubUpdater,
PubLicense pubLicense,
List<String> printLogs,
) runnerFn,
) {
return _overridePrint((printLogs) async {
final logger = MockLogger();
final progress = MockProgress();
final pubUpdater = MockPubUpdater();
final pubLicense = _MockPubLicense();
final progressLogs = <String>[];
final commandRunner = VeryGoodCommandRunner(
logger: logger,
Expand All @@ -55,7 +60,9 @@ void Function() withRunner(
currentVersion: any(named: 'currentVersion'),
),
).thenAnswer((_) => Future.value(true));
when(() => pubLicense.getLicense(any()))
.thenAnswer((_) => Future.value({'MIT'}));

await runnerFn(commandRunner, logger, pubUpdater, printLogs);
await runnerFn(commandRunner, logger, pubUpdater, pubLicense, printLogs);
});
}
3 changes: 2 additions & 1 deletion test/src/commands/create/commands/dart_cli_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,8 @@ void main() {
group('create dart_cli', () {
test(
'help',
withRunner((commandRunner, logger, pubUpdater, printLogs) async {
withRunner(
(commandRunner, logger, pubUpdater, pubLicense, printLogs) async {
final result =
await commandRunner.run(['create', 'dart_cli', '--help']);
expect(printLogs, equals(expectedUsage));
Expand Down
3 changes: 2 additions & 1 deletion test/src/commands/create/commands/dart_package_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,8 @@ void main() {
group('create dart_package', () {
test(
'help',
withRunner((commandRunner, logger, pubUpdater, printLogs) async {
withRunner(
(commandRunner, logger, pubUpdater, pubLicense, printLogs) async {
final result =
await commandRunner.run(['create', 'dart_package', '--help']);
expect(printLogs, equals(expectedUsage));
Expand Down
3 changes: 2 additions & 1 deletion test/src/commands/create/commands/docs_site_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,8 @@ void main() {
group('create docs_site', () {
test(
'help',
withRunner((commandRunner, logger, pubUpdater, printLogs) async {
withRunner(
(commandRunner, logger, pubUpdater, pubLicense, printLogs) async {
final result =
await commandRunner.run(['create', 'docs_site', '--help']);
expect(printLogs, equals(expectedUsage));
Expand Down
3 changes: 2 additions & 1 deletion test/src/commands/create/commands/flame_game_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,8 @@ void main() {
group('create flame_game', () {
test(
'help',
withRunner((commandRunner, logger, pubUpdater, printLogs) async {
withRunner(
(commandRunner, logger, pubUpdater, pubLicense, printLogs) async {
final result =
await commandRunner.run(['create', 'flame_game', '--help']);
expect(printLogs, equals(expectedUsage));
Expand Down
3 changes: 2 additions & 1 deletion test/src/commands/create/commands/flutter_app_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,8 @@ void main() {
group('create flutter_app', () {
test(
'help',
withRunner((commandRunner, logger, pubUpdater, printLogs) async {
withRunner(
(commandRunner, logger, pubUpdater, pubLicense, printLogs) async {
final result =
await commandRunner.run(['create', 'flutter_app', '--help']);
expect(printLogs, equals(expectedUsage));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,8 @@ void main() {
group('create flutter_package', () {
test(
'help',
withRunner((commandRunner, logger, pubUpdater, printLogs) async {
withRunner(
(commandRunner, logger, pubUpdater, pubLicense, printLogs) async {
final result =
await commandRunner.run(['create', 'flutter_package', '--help']);
expect(printLogs, equals(expectedUsage));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,8 @@ void main() {
group('create flutter_plugin', () {
test(
'help',
withRunner((commandRunner, logger, pubUpdater, printLogs) async {
withRunner(
(commandRunner, logger, pubUpdater, pubLicense, printLogs) async {
final result =
await commandRunner.run(['create', 'flutter_plugin', '--help']);
expect(printLogs, equals(expectedUsage));
Expand Down
3 changes: 2 additions & 1 deletion test/src/commands/create/create_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,8 @@ void main() {
group('create', () {
test(
'help',
withRunner((commandRunner, logger, pubUpdater, printLogs) async {
withRunner(
(commandRunner, logger, pubUpdater, pubLicense, printLogs) async {
final result = await commandRunner.run(['create', '--help']);
expect(printLogs, equals(expectedUsage));
expect(result, equals(ExitCode.success.code));
Expand Down
3 changes: 2 additions & 1 deletion test/src/commands/packages/commands/check/check_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,8 @@ void main() {

test(
'help',
withRunner((commandRunner, logger, pubUpdater, printLogs) async {
withRunner(
(commandRunner, logger, pubUpdater, pubLicense, printLogs) async {
final result = await commandRunner.run(
[...commandArguments, '--help'],
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,8 @@ void main() {

test(
'help',
withRunner((commandRunner, logger, pubUpdater, printLogs) async {
withRunner(
(commandRunner, logger, pubUpdater, pubLicense, printLogs) async {
final result = await commandRunner.run(
[...commandArguments, '--help'],
);
Expand All @@ -41,7 +42,8 @@ void main() {

test(
'returns exit code 0',
withRunner((commandRunner, logger, pubUpdater, printLogs) async {
withRunner(
(commandRunner, logger, pubUpdater, pubLicense, printLogs) async {
final result = await commandRunner.run(commandArguments);
expect(result, equals(ExitCode.success.code));
}),
Expand Down
33 changes: 22 additions & 11 deletions test/src/commands/packages/commands/get_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,8 @@ void main() {
group('packages get', () {
test(
'help',
withRunner((commandRunner, logger, pubUpdater, printLogs) async {
withRunner(
(commandRunner, logger, pubUpdater, pubLicense, printLogs) async {
final result = await commandRunner.run(['packages', 'get', '--help']);
expect(printLogs, equals(_expectedPackagesGetUsage));
expect(result, equals(ExitCode.success.code));
Expand All @@ -38,7 +39,8 @@ void main() {
test(
'throws usage exception '
'when too many arguments are provided',
withRunner((commandRunner, logger, pubUpdater, printLogs) async {
withRunner(
(commandRunner, logger, pubUpdater, pubLicense, printLogs) async {
final result = await commandRunner.run(
['packages', 'get', 'arg1', 'arg2'],
);
Expand All @@ -49,7 +51,8 @@ void main() {
test(
'throws pubspec not found exception '
'when no pubspec.yaml exists',
withRunner((commandRunner, logger, pubUpdater, printLogs) async {
withRunner(
(commandRunner, logger, pubUpdater, pubLicense, printLogs) async {
final result = await commandRunner.run(['packages', 'get', 'test']);
expect(result, equals(ExitCode.noInput.code));
verify(() {
Expand All @@ -61,7 +64,8 @@ void main() {
test(
'throws pubspec not found exception '
'when no pubspec.yaml exists (recursive)',
withRunner((commandRunner, logger, pubUpdater, printLogs) async {
withRunner(
(commandRunner, logger, pubUpdater, pubLicense, printLogs) async {
final result = await commandRunner.run(
['packages', 'get', '-r', 'site'],
);
Expand All @@ -74,7 +78,8 @@ void main() {

test(
'throws when installation fails',
withRunner((commandRunner, logger, pubUpdater, printLogs) async {
withRunner(
(commandRunner, logger, pubUpdater, pubLicense, printLogs) async {
final tempDirectory = Directory.systemTemp.createTempSync();
addTearDown(() => tempDirectory.deleteSync(recursive: true));

Expand All @@ -89,7 +94,8 @@ void main() {

test(
'ignores .fvm directory',
withRunner((commandRunner, logger, pubUpdater, printLogs) async {
withRunner(
(commandRunner, logger, pubUpdater, pubLicense, printLogs) async {
final tempDirectory = Directory.systemTemp.createTempSync();
addTearDown(() => tempDirectory.deleteSync(recursive: true));

Expand Down Expand Up @@ -117,7 +123,8 @@ void main() {
test(
'completes normally '
'when pubspec.yaml exists',
withRunner((commandRunner, logger, pubUpdater, printLogs) async {
withRunner(
(commandRunner, logger, pubUpdater, pubLicense, printLogs) async {
final tempDirectory = Directory.systemTemp.createTempSync();
addTearDown(() => tempDirectory.deleteSync(recursive: true));

Expand Down Expand Up @@ -145,7 +152,8 @@ void main() {
test(
'completes normally '
'when pubspec.yaml exists (recursive)',
withRunner((commandRunner, logger, pubUpdater, printLogs) async {
withRunner(
(commandRunner, logger, pubUpdater, pubLicense, printLogs) async {
final tempDirectory = Directory.systemTemp.createTempSync();
addTearDown(() => tempDirectory.deleteSync(recursive: true));

Expand Down Expand Up @@ -193,7 +201,8 @@ void main() {
test(
'completes normally '
'when pubspec.yaml exists and directory is not ignored (recursive)',
withRunner((commandRunner, logger, pubUpdater, printLogs) async {
withRunner(
(commandRunner, logger, pubUpdater, pubLicense, printLogs) async {
final tempDirectory = Directory.systemTemp.createTempSync();
addTearDown(() => tempDirectory.deleteSync(recursive: true));

Expand Down Expand Up @@ -244,7 +253,8 @@ void main() {
test(
'completes normally '
'''when pubspec.yaml exists and directory is not ignored (recursive) with an empty glob''',
withRunner((commandRunner, logger, pubUpdater, printLogs) async {
withRunner(
(commandRunner, logger, pubUpdater, pubLicense, printLogs) async {
final tempDirectory = Directory.systemTemp.createTempSync();
final directory = Directory(
path.join(tempDirectory.path, 'macos_plugin'),
Expand Down Expand Up @@ -294,7 +304,8 @@ void main() {
test(
'completes normally '
'when pubspec.yaml exists and directory is ignored (recursive)',
withRunner((commandRunner, logger, pubUpdater, printLogs) async {
withRunner(
(commandRunner, logger, pubUpdater, pubLicense, printLogs) async {
final tempDirectory = Directory.systemTemp.createTempSync();
addTearDown(() => tempDirectory.deleteSync(recursive: true));

Expand Down
3 changes: 2 additions & 1 deletion test/src/commands/packages/packages_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,8 @@ void main() {
group('packages', () {
test(
'help',
withRunner((commandRunner, logger, pubUpdater, printLogs) async {
withRunner(
(commandRunner, logger, pubUpdater, pubLicense, printLogs) async {
final result = await commandRunner.run(['packages', '--help']);
expect(printLogs, equals(_expectedPackagesUsage));
expect(result, equals(ExitCode.success.code));
Expand Down
9 changes: 6 additions & 3 deletions test/src/commands/test/test_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,8 @@ void main() {

test(
'help',
withRunner((commandRunner, logger, pubUpdater, printLogs) async {
withRunner(
(commandRunner, logger, pubUpdater, pubLicense, printLogs) async {
final result = await commandRunner.run(['test', '--help']);
expect(printLogs, equals(expectedTestUsage));
expect(result, equals(ExitCode.success.code));
Expand All @@ -127,7 +128,8 @@ void main() {
test(
'throws pubspec not found exception '
'when no pubspec.yaml exists',
withRunner((commandRunner, logger, pubUpdater, printLogs) async {
withRunner(
(commandRunner, logger, pubUpdater, pubLicense, printLogs) async {
final tempDirectory = Directory.systemTemp.createTempSync();
addTearDown(() => tempDirectory.deleteSync(recursive: true));

Expand All @@ -142,7 +144,8 @@ void main() {

test(
'completes normally when no pubspec.yaml exists (recursive)',
withRunner((commandRunner, logger, pubUpdater, printLogs) async {
withRunner(
(commandRunner, logger, pubUpdater, pubLicense, printLogs) async {
final tempDirectory = Directory.systemTemp.createTempSync();
addTearDown(() => tempDirectory.deleteSync(recursive: true));

Expand Down
15 changes: 10 additions & 5 deletions test/src/commands/update_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,8 @@ void main() {

test(
'handles pub latest version query errors',
withRunner((commandRunner, logger, pubUpdater, printLogs) async {
withRunner(
(commandRunner, logger, pubUpdater, pubLicense, printLogs) async {
when(
() => pubUpdater.getLatestVersion(any()),
).thenThrow(Exception('oops'));
Expand All @@ -46,7 +47,8 @@ void main() {

test(
'handles pub update errors',
withRunner((commandRunner, logger, pubUpdater, printLogs) async {
withRunner(
(commandRunner, logger, pubUpdater, pubLicense, printLogs) async {
when(
() => pubUpdater.getLatestVersion(any()),
).thenAnswer((_) async => latestVersion);
Expand All @@ -71,7 +73,8 @@ void main() {

test(
'handles pub update process errors',
withRunner((commandRunner, logger, pubUpdater, printLogs) async {
withRunner(
(commandRunner, logger, pubUpdater, pubLicense, printLogs) async {
final errorProcessResult = ProcessResult(
42,
1,
Expand Down Expand Up @@ -110,7 +113,8 @@ void main() {

test(
'updates when newer version exists',
withRunner((commandRunner, logger, pubUpdater, printLogs) async {
withRunner(
(commandRunner, logger, pubUpdater, pubLicense, printLogs) async {
when(
() => pubUpdater.getLatestVersion(any()),
).thenAnswer((_) async => latestVersion);
Expand All @@ -137,7 +141,8 @@ void main() {

test(
'does not update when already on latest version',
withRunner((commandRunner, logger, pubUpdater, printLogs) async {
withRunner(
(commandRunner, logger, pubUpdater, pubLicense, printLogs) async {
when(
() => pubUpdater.getLatestVersion(any()),
).thenAnswer((_) async => packageVersion);
Expand Down