Repository: VeryGoodOpenSource/very_good_cli (dart)

Issue:
fix: package name not visible in output when run tests recursive
**Description**

When running all tests recursive the package title is not visible in the output. 

`very_good test --optimization --coverage -r`

Folder structure:

```
packages/name123
packages/name456
packages/name789
```

Output:

```
✓ Optimizing tests (56ms)
00:16 +58: All tests passed!
Running "flutter test" in /Users/danielfelten/Projekte/test/packages...
✓ Optimizing tests (61ms)
00:20 +377: All tests passed!
Running "flutter test" in /Users/danielfelten/Projekte/test/packages...
✓ Optimizing tests (54ms)
00:14 +31: All tests passed!
Running "flutter test" in /Users/danielfelten/Projekte/test/packages...
✓ Optimizing tests (57ms)
```

**Expected Behavior**

Title of each package is visible in the output:

```
✓ Optimizing tests (56ms)
00:16 +58: All tests passed!
Running "flutter test" in /Users/danielfelten/Projekte/test/packages/name123...
✓ Optimizing tests (61ms)
00:20 +377: All tests passed!
Running "flutter test" in /Users/danielfelten/Projekte/test/packages/name456...
✓ Optimizing tests (54ms)
00:14 +31: All tests passed!
Running "flutter test" in /Users/danielfelten/Projekte/test/packages/name789...
✓ Optimizing tests (57ms)
```

Pull request:
<!--
  Thanks for contributing!
  Provide a description of your changes below and a general summary in the title
  Please look at the following checklist to ensure that your PR can be accepted quickly:
-->

Fixes: #754

## Status

**READY**

## Description

<!--- Describe your changes in detail -->
The change introduced in this PR is to clean up the console when the cwd is printed. Specifically when running `very_good test`.
Sometimes the full path of the cwd is too long and would be cut off. If running recursively, this can leave the developer confused as to which directory was tested.

![image](https://github.com/VeryGoodOpenSource/very_good_cli/assets/39742020/a6413b28-7d7f-4eac-8b35-cb38137e7e62)

A solution to the problem is to shorten the path printed to console. Instead of printing the absolute path, the relative path is used.

![image](https://github.com/VeryGoodOpenSource/very_good_cli/assets/39742020/09250cd0-ec9c-4d55-936d-be157d23cff2)

## Type of Change

<!--- Put an `x` in all the boxes that apply: -->

- [ ] ✨ New feature (non-breaking change which adds functionality)
- [ ] 🛠️ Bug fix (non-breaking change which fixes an issue)
- [ ] ❌ Breaking change (fix or feature that would cause existing functionality to change)
- [x] 🧹 Code refactor
- [ ] ✅ Build configuration change
- [ ] 📝 Documentation
- [ ] 🗑️ Chore

Patch:
diff --git a/lib/src/cli/flutter_cli.dart b/lib/src/cli/flutter_cli.dart
index c4afe2697..67ca9fd8b 100644
--- a/lib/src/cli/flutter_cli.dart
+++ b/lib/src/cli/flutter_cli.dart
@@ -153,6 +153,8 @@ class Flutter {
     FlutterTestRunner testRunner = flutterTest,
     GeneratorBuilder buildGenerator = MasonGenerator.fromBundle,
   }) async {
+    final initialCwd = cwd;
+
     return _runCommand<int>(
       cmd: (cwd) async {
         final lcovPath = p.join(cwd, 'coverage', 'lcov.info');
@@ -165,14 +167,17 @@ class Flutter {
         void noop(String? _) {}
         final target = DirectoryGeneratorTarget(Directory(p.normalize(cwd)));
         final workingDirectory = target.dir.absolute.path;
+        final relativePath = p.relative(workingDirectory, from: initialCwd);
+        final path =
+            relativePath == '.' ? '.' : '.${p.context.separator}$relativePath';
 
         stdout?.call(
-          'Running "flutter test" in ${p.dirname(workingDirectory)}...\n',
+          'Running "flutter test" in $path ...\n',
         );
 
         if (!Directory(p.join(target.dir.absolute.path, 'test')).existsSync()) {
           stdout?.call(
-            'No test folder found in ${target.dir.absolute.path}\n',
+            'No test folder found in $path\n',
           );
           return ExitCode.success.code;
         }


Test patch:
diff --git a/test/src/cli/flutter_cli_test.dart b/test/src/cli/flutter_cli_test.dart
index f273bea21..3ae85e25b 100644
--- a/test/src/cli/flutter_cli_test.dart
+++ b/test/src/cli/flutter_cli_test.dart
@@ -394,8 +394,8 @@ void main() {
         expect(
           stdoutLogs,
           equals([
-            'Running "flutter test" in ${p.dirname(tempDirectory.path)}...\n',
-            'No test folder found in ${tempDirectory.absolute.path}\n',
+            'Running "flutter test" in . ...\n',
+            'No test folder found in .\n',
           ]),
         );
       });
@@ -431,7 +431,7 @@ void main() {
         expect(
           stdoutLogs,
           equals([
-            'Running "flutter test" in ${p.dirname(tempDirectory.path)}...\n',
+            'Running "flutter test" in . ...\n',
             '\x1B[2K\r00:00 ...',
             contains('All tests passed!'),
           ]),
@@ -462,7 +462,7 @@ void main() {
         expect(
           stdoutLogs,
           equals([
-            'Running "flutter test" in ${p.dirname(tempDirectory.path)}...\n',
+            'Running "flutter test" in . ...\n',
             '\x1B[2K\r00:02 +1: CounterCubit initial state is 0',
             '''\x1B[2K\r00:02 +2: CounterCubit emits [1] when increment is called''',
             '''\x1B[2K\r00:02 +3: CounterCubit emits [-1] when decrement is called''',
@@ -504,7 +504,7 @@ void main() {
         expect(
           stdoutLogs,
           equals([
-            'Running "flutter test" in ${p.dirname(tempDirectory.path)}...\n',
+            'Running "flutter test" in . ...\n',
             '''\x1B[2K\r\x1B[90m00:02\x1B[0m \x1B[92m+1\x1B[0m: CounterCubit initial state is 0''',
             '''\x1B[2K\r\x1B[90m00:02\x1B[0m \x1B[92m+2\x1B[0m: CounterCubit emits [1] when increment is called''',
             '''\x1B[2K\r\x1B[90m00:02\x1B[0m \x1B[92m+3\x1B[0m: CounterCubit emits [-1] when decrement is called''',
@@ -544,7 +544,7 @@ void main() {
         expect(
           stdoutLogs,
           equals([
-            'Running "flutter test" in ${p.dirname(tempDirectory.path)}...\n',
+            'Running "flutter test" in . ...\n',
             '\x1B[2K\r00:11 -1: CounterCubit initial state is 0',
             '''\x1B[2K\r00:11 +1 -1: CounterCubit emits [1] when increment is called''',
             '''\x1B[2K\r00:11 +2 -1: CounterCubit emits [-1] when decrement is called''',
@@ -599,7 +599,7 @@ void main() {
         expect(
           stdoutLogs,
           equals([
-            'Running "flutter test" in ${p.dirname(tempDirectory.path)}...\n',
+            'Running "flutter test" in . ...\n',
             '\x1B[2K\rSkip: currently failing (see issue 1234)\n',
             '\x1B[2K\r(suite) ${tempDirectory.path}/test/counter/view/other_test.dart (SKIPPED)\n',
             '\x1B[2K\r00:00 ~1: (suite)',
@@ -846,7 +846,7 @@ void main() {
         expect(
           stdoutLogs,
           equals([
-            'Running "flutter test" in ${p.dirname(tempDirectory.path)}...\n',
+            'Running "flutter test" in . ...\n',
             contains('All tests passed!'),
           ]),
         );
@@ -882,7 +882,7 @@ void main() {
         expect(
           stdoutLogs,
           equals([
-            'Running "flutter test" in ${p.dirname(tempDirectory.path)}...\n',
+            'Running "flutter test" in . ...\n',
             'Shuffling test order with --test-randomize-ordering-seed=$seed\n',
             contains('All tests passed!'),
           ]),
@@ -928,7 +928,7 @@ void main() {
         expect(
           stdoutLogs,
           equals([
-            'Running "flutter test" in ${p.dirname(tempDirectory.path)}...\n',
+            'Running "flutter test" in . ...\n',
             contains('All tests passed!'),
           ]),
         );
@@ -969,7 +969,7 @@ void main() {
         expect(
           stdoutLogs,
           equals([
-            'Running "flutter test" in ${p.dirname(tempDirectory.path)}...\n',
+            'Running "flutter test" in . ...\n',
             contains('All tests passed!'),
           ]),
         );
@@ -1016,7 +1016,7 @@ void main() {
         expect(
           stdoutLogs,
           equals([
-            'Running "flutter test" in ${p.dirname(tempDirectory.path)}...\n',
+            'Running "flutter test" in . ...\n',
             contains('All tests passed!'),
           ]),
         );
@@ -1061,7 +1061,7 @@ void main() {
         expect(
           stdoutLogs,
           equals([
-            'Running "flutter test" in ${p.dirname(tempDirectory.path)}...\n',
+            'Running "flutter test" in . ...\n',
             contains('All tests passed!'),
           ]),
         );
@@ -1114,13 +1114,19 @@ void main() {
             completion(equals([ExitCode.success.code, ExitCode.success.code])),
           );
 
+          final nestedRelativePath = p.relative(
+            tempNestedDirectory.path,
+            from: tempDirectory.path,
+          );
+          final relativePathPrefix = '.${p.context.separator}';
+
           expect(
             stdoutLogs,
             unorderedEquals([
               'Running "flutter test" in '
-                  '${p.dirname(tempNestedDirectory.path)}...\n',
+                  '$relativePathPrefix$nestedRelativePath ...\n',
               contains('All tests passed!'),
-              'Running "flutter test" in ${p.dirname(tempDirectory.path)}...\n',
+              'Running "flutter test" in . ...\n',
               contains('All tests passed!'),
             ]),
           );
@@ -1179,14 +1185,20 @@ void main() {
             ),
           );
 
+          final nestedRelativePath = p.relative(
+            tempNestedDirectory.path,
+            from: tempDirectory.path,
+          );
+          final relativePathPrefix = '.${p.context.separator}';
+
           expect(
             stdoutLogs,
             unorderedEquals([
               'Running "flutter test" in '
-                  '${p.dirname(tempDirectory.path)}...\n',
+                  '. ...\n',
               contains('All tests passed!'),
               'Running "flutter test" in '
-                  '${p.dirname(tempNestedDirectory.path)}...\n',
+                  '$relativePathPrefix$nestedRelativePath ...\n',
               contains('All tests passed!'),
             ]),
           );
@@ -1242,7 +1254,7 @@ void main() {
         expect(
           stdoutLogs,
           equals([
-            'Running "flutter test" in ${p.dirname(tempDirectory.path)}...\n',
+            'Running "flutter test" in . ...\n',
             contains('All tests passed!'),
           ]),
         );