Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: Use relative path instead of absolute when running packages get #919

Merged
merged 13 commits into from
Dec 18, 2023
Merged
8 changes: 7 additions & 1 deletion lib/src/cli/flutter_cli.dart
Original file line number Diff line number Diff line change
Expand Up @@ -84,10 +84,16 @@ class Flutter {
bool recursive = false,
Set<String> ignore = const {},
}) async {
final initialCwd = cwd;

await _runCommand(
cmd: (cwd) async {
final relativePath = p.relative(cwd, from: initialCwd);
final path =
relativePath == '.' ? '.' : '.${p.context.separator}$relativePath';

final installProgress = logger.progress(
'Running "flutter packages get" in $cwd',
'Running "flutter packages get" in $path ',
);

try {
Expand Down
22 changes: 14 additions & 8 deletions test/src/cli/flutter_cli_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -194,6 +194,8 @@ void main() {
File(p.join(ignoredDirectory.path, 'pubspec.yaml'))
.writeAsStringSync(_pubspec);

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

ProcessOverrides.runZoned(
() => expectLater(
Flutter.packagesGet(
Expand All @@ -209,23 +211,29 @@ void main() {
),
runProcess: process.run,
).whenComplete(() {
final nestedRelativePath =
p.relative(nestedDirectory.path, from: tempDirectory.path);

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

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

logger.progress(
any(
that: contains(
'Running "flutter packages get" in '
'${ignoredDirectory.path}',
'''Running "flutter packages get" in $relativePathPrefix$ignoredRelativePath''',
),
),
);
Expand Down Expand Up @@ -1123,8 +1131,7 @@ void main() {
expect(
stdoutLogs,
unorderedEquals([
'Running "flutter test" in '
'$relativePathPrefix$nestedRelativePath ...\n',
'''Running "flutter test" in $relativePathPrefix$nestedRelativePath ...\n''',
contains('All tests passed!'),
'Running "flutter test" in . ...\n',
contains('All tests passed!'),
Expand Down Expand Up @@ -1197,8 +1204,7 @@ void main() {
'Running "flutter test" in '
'. ...\n',
contains('All tests passed!'),
'Running "flutter test" in '
'$relativePathPrefix$nestedRelativePath ...\n',
'''Running "flutter test" in $relativePathPrefix$nestedRelativePath ...\n''',
contains('All tests passed!'),
]),
);
Expand Down
16 changes: 14 additions & 2 deletions test/src/commands/packages/commands/get_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -342,21 +342,33 @@ void main() {
tempDirectory.path,
],
);

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

expect(result, equals(ExitCode.success.code));
verify(() {
final relativePath = path.relative(
directoryA.path,
from: tempDirectory.path,
);
logger.progress(
any(
that: contains(
'Running "flutter packages get" in ${directoryA.path}',
'''Running "flutter packages get" in $relativePathPrefix$relativePath''',
),
),
);
}).called(1);
verifyNever(() {
final relativePath = path.relative(
directoryB.path,
from: tempDirectory.path,
);

logger.progress(
any(
that: contains(
'Running "flutter packages get" in ${directoryB.path}',
'''Running "flutter packages get" in $relativePathPrefix$relativePath''',
),
),
);
Expand Down