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
62 changes: 31 additions & 31 deletions lib/src/cli/flutter_cli.dart
Original file line number Diff line number Diff line change
Expand Up @@ -83,42 +83,42 @@ class CoverageMetrics {
}
}

return records.fold<CoverageMetrics>(
const CoverageMetrics(),
(current, record) {
final found = record.lines?.found ?? 0;
final hit = record.lines?.hit ?? 0;
if (globs.isNotEmpty && record.file != null) {
for (final glob in globs) {
if (glob.matches(record.file!)) return current;
}
return records.fold<CoverageMetrics>(const CoverageMetrics(), (
current,
record,
) {
final found = record.lines?.found ?? 0;
final hit = record.lines?.hit ?? 0;
if (globs.isNotEmpty && record.file != null) {
for (final glob in globs) {
if (glob.matches(record.file!)) return current;
}
}

final file = record.file;
final details = record.lines?.details;
final uncoveredLines = Map<String, List<int>>.from(
current.uncoveredLines,
);

if (file != null && details != null) {
for (final line in details) {
if ((line.hit ?? 1) == 0 && line.line != null) {
uncoveredLines.update(
file,
(lines) => [...lines, line.line!],
ifAbsent: () => [line.line!],
);
}
final file = record.file;
final details = record.lines?.details;
final uncoveredLines = Map<String, List<int>>.from(
current.uncoveredLines,
);

if (file != null && details != null) {
for (final line in details) {
if ((line.hit ?? 1) == 0 && line.line != null) {
uncoveredLines.update(
file,
(lines) => [...lines, line.line!],
ifAbsent: () => [line.line!],
);
}
}
}

return CoverageMetrics(
totalFound: current.totalFound + found,
totalHits: current.totalHits + hit,
uncoveredLines: uncoveredLines,
);
},
);
return CoverageMetrics(
totalFound: current.totalFound + found,
totalHits: current.totalHits + hit,
uncoveredLines: uncoveredLines,
);
});
}

/// Total number of lines hit (covered) across all included files.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,7 @@ Future<bool> installDartPackages(
final isDartInstalled = await Dart.installed(logger: logger);
if (!isDartInstalled) return false;

return Dart.pubGet(
cwd: outputDir.path,
recursive: recursive,
logger: logger,
);
return Dart.pubGet(cwd: outputDir.path, recursive: recursive, logger: logger);
}

/// Runs `flutter pub get` in the [outputDir].
Expand Down
12 changes: 4 additions & 8 deletions lib/src/mcp/mcp_command.dart
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,7 @@ import 'package:very_good_cli/src/mcp/mcp_server.dart';

/// Type definition for a factory that creates a [VeryGoodMCPServer].
typedef ServerFactory =
MCPServer Function({
required StreamChannel<String> channel,
});
MCPServer Function({required StreamChannel<String> channel});

/// Factory function to create a [StreamChannel] from input and output streams.
typedef ChannelFactory = StreamChannel<String> Function();
Expand All @@ -27,11 +25,9 @@ StreamChannel<String> _defaultChannelFactory() {
/// {@endtemplate}
class MCPCommand extends Command<int> {
/// {@macro mcp_command}
MCPCommand({
ChannelFactory? channelFactory,
ServerFactory? serverFactory,
}) : _channelFactory = channelFactory ?? _defaultChannelFactory,
_serverFactory = serverFactory ?? VeryGoodMCPServer.new;
MCPCommand({ChannelFactory? channelFactory, ServerFactory? serverFactory})
: _channelFactory = channelFactory ?? _defaultChannelFactory,
_serverFactory = serverFactory ?? VeryGoodMCPServer.new;

/// The [name] of the command. But static.
static const String commandName = 'mcp';
Expand Down
4 changes: 3 additions & 1 deletion lib/src/pub_license/spdx_license.gen.dart

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 1 addition & 5 deletions test/helpers/test_multi_template_commands.dart
Original file line number Diff line number Diff line change
Expand Up @@ -55,11 +55,7 @@ Future<void> testMultiTemplateCommand({
),
);
verify(
() => generator.generate(
any(),
vars: expectedVars,
logger: logger,
),
() => generator.generate(any(), vars: expectedVars, logger: logger),
).called(1);
verify(() => logger.created(expectedLogSummary)).called(1);
}
168 changes: 76 additions & 92 deletions test/src/cli/dart_cli_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -83,12 +83,7 @@ void main() {
});

test('returns false when dart is not installed', () async {
final processResult = ProcessResult(
42,
ExitCode.software.code,
'',
'',
);
final processResult = ProcessResult(42, ExitCode.software.code, '', '');

when(
() => process.run(
Expand All @@ -100,10 +95,8 @@ void main() {
).thenAnswer((_) async => processResult);

await ProcessOverrides.runZoned(
() => expectLater(
Dart.installed(logger: logger),
completion(isFalse),
),
() =>
expectLater(Dart.installed(logger: logger), completion(isFalse)),
runProcess: process.run,
);
});
Expand Down Expand Up @@ -156,75 +149,69 @@ void main() {
);
});

test(
'completes when there is a pubspec.yaml and '
'directory is ignored (recursive)',
() async {
final tempDirectory = Directory.systemTemp.createTempSync();
addTearDown(() => tempDirectory.deleteSync(recursive: true));

final nestedDirectory = Directory(p.join(tempDirectory.path, 'test'))
..createSync();
final ignoredDirectory = Directory(
p.join(tempDirectory.path, 'test_plugin'),
)..createSync();

File(
p.join(nestedDirectory.path, 'pubspec.yaml'),
).writeAsStringSync(_pubspec);
File(
p.join(ignoredDirectory.path, 'pubspec.yaml'),
).writeAsStringSync(_pubspec);

final relativePathPrefix = '.${p.context.separator}';

await ProcessOverrides.runZoned(
() => expectLater(
Dart.pubGet(
cwd: tempDirectory.path,
recursive: true,
ignore: {
'test_plugin',
'/**/test_plugin_two/**',
},
logger: logger,
),
completes,
test('completes when there is a pubspec.yaml and '
'directory is ignored (recursive)', () async {
final tempDirectory = Directory.systemTemp.createTempSync();
addTearDown(() => tempDirectory.deleteSync(recursive: true));

final nestedDirectory = Directory(p.join(tempDirectory.path, 'test'))
..createSync();
final ignoredDirectory = Directory(
p.join(tempDirectory.path, 'test_plugin'),
)..createSync();

File(
p.join(nestedDirectory.path, 'pubspec.yaml'),
).writeAsStringSync(_pubspec);
File(
p.join(ignoredDirectory.path, 'pubspec.yaml'),
).writeAsStringSync(_pubspec);

final relativePathPrefix = '.${p.context.separator}';

await ProcessOverrides.runZoned(
() => expectLater(
Dart.pubGet(
cwd: tempDirectory.path,
recursive: true,
ignore: {'test_plugin', '/**/test_plugin_two/**'},
logger: logger,
),
runProcess: process.run,
).whenComplete(() {
final nestedRelativePath = p.relative(
nestedDirectory.path,
completes,
),
runProcess: process.run,
).whenComplete(() {
final nestedRelativePath = p.relative(
nestedDirectory.path,
from: tempDirectory.path,
);

verify(() {
logger.progress(
any(
that: contains(
'''Running "dart pub get" in $relativePathPrefix$nestedRelativePath''',
),
),
);
}).called(1);

verifyNever(() {
final ignoredRelativePath = p.relative(
ignoredDirectory.path,
from: tempDirectory.path,
);

verify(() {
logger.progress(
any(
that: contains(
'''Running "dart pub get" in $relativePathPrefix$nestedRelativePath''',
),
),
);
}).called(1);

verifyNever(() {
final ignoredRelativePath = p.relative(
ignoredDirectory.path,
from: tempDirectory.path,
);

logger.progress(
any(
that: contains(
'''Running "dart pub get" in $relativePathPrefix$ignoredRelativePath''',
),
logger.progress(
any(
that: contains(
'''Running "dart pub get" in $relativePathPrefix$ignoredRelativePath''',
),
);
});
),
);
});
},
);
});
});

test('throws when process fails', () async {
when(
Expand Down Expand Up @@ -364,25 +351,22 @@ void main() {
});

test('runs dart with correct args', () async {
await ProcessOverrides.runZoned(
() async {
await Dart.runPigeon(
logger: logger,
cwd: '.',
input: 'pigeons/messages.dart',
);

verify(
() => process.run(
'dart',
['run', 'pigeon', '--input', 'pigeons/messages.dart'],
runInShell: any(named: 'runInShell'),
workingDirectory: any(named: 'workingDirectory'),
),
).called(1);
},
runProcess: process.run,
);
await ProcessOverrides.runZoned(() async {
await Dart.runPigeon(
logger: logger,
cwd: '.',
input: 'pigeons/messages.dart',
);

verify(
() => process.run(
'dart',
['run', 'pigeon', '--input', 'pigeons/messages.dart'],
runInShell: any(named: 'runInShell'),
workingDirectory: any(named: 'workingDirectory'),
),
).called(1);
}, runProcess: process.run);
});
});
});
Expand Down
Loading
Loading