From 9dce965f85f6713abe6ecb24db0f5242a82064a1 Mon Sep 17 00:00:00 2001 From: Morgan Date: Wed, 13 Dec 2023 09:53:24 -0700 Subject: [PATCH 1/5] feat: use relative path when printing to console for flutter test --- lib/src/cli/flutter_cli.dart | 7 +++-- test/src/cli/flutter_cli_test.dart | 46 ++++++++++++++++++------------ 2 files changed, 33 insertions(+), 20 deletions(-) diff --git a/lib/src/cli/flutter_cli.dart b/lib/src/cli/flutter_cli.dart index c4afe269..2b329a03 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( cmd: (cwd) async { final lcovPath = p.join(cwd, 'coverage', 'lcov.info'); @@ -165,14 +167,15 @@ class Flutter { void noop(String? _) {} final target = DirectoryGeneratorTarget(Directory(p.normalize(cwd))); final workingDirectory = target.dir.absolute.path; + final diff = p.relative(workingDirectory, from: initialCwd); stdout?.call( - 'Running "flutter test" in ${p.dirname(workingDirectory)}...\n', + 'Running "flutter test" in .${p.context.separator}$diff...\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 .${p.context.separator}$diff\n', ); return ExitCode.success.code; } diff --git a/test/src/cli/flutter_cli_test.dart b/test/src/cli/flutter_cli_test.dart index f273bea2..ac1cc581 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 .${p.context.separator}...\n', + 'No test folder found in .${p.context.separator}\n', ]), ); }); @@ -431,7 +431,7 @@ void main() { expect( stdoutLogs, equals([ - 'Running "flutter test" in ${p.dirname(tempDirectory.path)}...\n', + 'Running "flutter test" in .${p.context.separator}...\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 .${p.context.separator}...\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 .${p.context.separator}...\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 .${p.context.separator}...\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 .${p.context.separator}...\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 .${p.context.separator}...\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 .${p.context.separator}...\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 .${p.context.separator}...\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 .${p.context.separator}...\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 .${p.context.separator}...\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 .${p.context.separator}...\n', contains('All tests passed!'), ]), ); @@ -1114,13 +1114,18 @@ void main() { completion(equals([ExitCode.success.code, ExitCode.success.code])), ); + final nestedRelativePath = p.relative( + tempNestedDirectory.path, + from: tempDirectory.path, + ); + expect( stdoutLogs, unorderedEquals([ 'Running "flutter test" in ' - '${p.dirname(tempNestedDirectory.path)}...\n', + '.${p.context.separator}$nestedRelativePath...\n', contains('All tests passed!'), - 'Running "flutter test" in ${p.dirname(tempDirectory.path)}...\n', + 'Running "flutter test" in .${p.context.separator}...\n', contains('All tests passed!'), ]), ); @@ -1179,14 +1184,19 @@ void main() { ), ); + final nestedRelativePath = p.relative( + tempNestedDirectory.path, + from: tempDirectory.path, + ); + expect( stdoutLogs, unorderedEquals([ 'Running "flutter test" in ' - '${p.dirname(tempDirectory.path)}...\n', + '.${p.context.separator}...\n', contains('All tests passed!'), 'Running "flutter test" in ' - '${p.dirname(tempNestedDirectory.path)}...\n', + '.${p.context.separator}$nestedRelativePath...\n', contains('All tests passed!'), ]), ); @@ -1242,7 +1252,7 @@ void main() { expect( stdoutLogs, equals([ - 'Running "flutter test" in ${p.dirname(tempDirectory.path)}...\n', + 'Running "flutter test" in .${p.context.separator}...\n', contains('All tests passed!'), ]), ); From bce66750bdb3bda8fcbb20a65195695548fc9205 Mon Sep 17 00:00:00 2001 From: Morgan Date: Wed, 13 Dec 2023 10:06:37 -0700 Subject: [PATCH 2/5] fix: add . for current directory --- test/src/cli/flutter_cli_test.dart | 32 +++++++++++++++--------------- 1 file changed, 16 insertions(+), 16 deletions(-) diff --git a/test/src/cli/flutter_cli_test.dart b/test/src/cli/flutter_cli_test.dart index ac1cc581..52e5dee3 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.context.separator}...\n', - 'No test folder found in .${p.context.separator}\n', + 'Running "flutter test" in .${p.context.separator}....\n', + 'No test folder found in .${p.context.separator}.\n', ]), ); }); @@ -431,7 +431,7 @@ void main() { expect( stdoutLogs, equals([ - 'Running "flutter test" in .${p.context.separator}...\n', + 'Running "flutter test" in .${p.context.separator}....\n', '\x1B[2K\r00:00 ...', contains('All tests passed!'), ]), @@ -462,7 +462,7 @@ void main() { expect( stdoutLogs, equals([ - 'Running "flutter test" in .${p.context.separator}...\n', + 'Running "flutter test" in .${p.context.separator}....\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.context.separator}...\n', + 'Running "flutter test" in .${p.context.separator}....\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.context.separator}...\n', + 'Running "flutter test" in .${p.context.separator}....\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.context.separator}...\n', + 'Running "flutter test" in .${p.context.separator}....\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.context.separator}...\n', + 'Running "flutter test" in .${p.context.separator}....\n', contains('All tests passed!'), ]), ); @@ -882,7 +882,7 @@ void main() { expect( stdoutLogs, equals([ - 'Running "flutter test" in .${p.context.separator}...\n', + 'Running "flutter test" in .${p.context.separator}....\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.context.separator}...\n', + 'Running "flutter test" in .${p.context.separator}....\n', contains('All tests passed!'), ]), ); @@ -969,7 +969,7 @@ void main() { expect( stdoutLogs, equals([ - 'Running "flutter test" in .${p.context.separator}...\n', + 'Running "flutter test" in .${p.context.separator}....\n', contains('All tests passed!'), ]), ); @@ -1016,7 +1016,7 @@ void main() { expect( stdoutLogs, equals([ - 'Running "flutter test" in .${p.context.separator}...\n', + 'Running "flutter test" in .${p.context.separator}....\n', contains('All tests passed!'), ]), ); @@ -1061,7 +1061,7 @@ void main() { expect( stdoutLogs, equals([ - 'Running "flutter test" in .${p.context.separator}...\n', + 'Running "flutter test" in .${p.context.separator}....\n', contains('All tests passed!'), ]), ); @@ -1125,7 +1125,7 @@ void main() { 'Running "flutter test" in ' '.${p.context.separator}$nestedRelativePath...\n', contains('All tests passed!'), - 'Running "flutter test" in .${p.context.separator}...\n', + 'Running "flutter test" in .${p.context.separator}....\n', contains('All tests passed!'), ]), ); @@ -1193,7 +1193,7 @@ void main() { stdoutLogs, unorderedEquals([ 'Running "flutter test" in ' - '.${p.context.separator}...\n', + '.${p.context.separator}....\n', contains('All tests passed!'), 'Running "flutter test" in ' '.${p.context.separator}$nestedRelativePath...\n', @@ -1252,7 +1252,7 @@ void main() { expect( stdoutLogs, equals([ - 'Running "flutter test" in .${p.context.separator}...\n', + 'Running "flutter test" in .${p.context.separator}....\n', contains('All tests passed!'), ]), ); From fe6b50c22dc38fc51e15f2bac1965cb692f6fb9d Mon Sep 17 00:00:00 2001 From: Morgan Date: Wed, 13 Dec 2023 10:10:38 -0700 Subject: [PATCH 3/5] feat: update variable name to be more meaningful --- lib/src/cli/flutter_cli.dart | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/lib/src/cli/flutter_cli.dart b/lib/src/cli/flutter_cli.dart index 2b329a03..230e8c37 100644 --- a/lib/src/cli/flutter_cli.dart +++ b/lib/src/cli/flutter_cli.dart @@ -167,15 +167,15 @@ class Flutter { void noop(String? _) {} final target = DirectoryGeneratorTarget(Directory(p.normalize(cwd))); final workingDirectory = target.dir.absolute.path; - final diff = p.relative(workingDirectory, from: initialCwd); + final relativePath = p.relative(workingDirectory, from: initialCwd); stdout?.call( - 'Running "flutter test" in .${p.context.separator}$diff...\n', + 'Running "flutter test" in .${p.context.separator}$relativePath...\n', ); if (!Directory(p.join(target.dir.absolute.path, 'test')).existsSync()) { stdout?.call( - 'No test folder found in .${p.context.separator}$diff\n', + 'No test folder found in .${p.context.separator}$relativePath\n', ); return ExitCode.success.code; } From 3e4029a084f6460c44f54ac16dd0a841bdee880e Mon Sep 17 00:00:00 2001 From: Morgan Date: Thu, 14 Dec 2023 09:26:09 -0700 Subject: [PATCH 4/5] feat: add space between progress dots. Add check for root to display only . --- lib/src/cli/flutter_cli.dart | 7 ++++-- test/src/cli/flutter_cli_test.dart | 38 ++++++++++++++++-------------- 2 files changed, 25 insertions(+), 20 deletions(-) diff --git a/lib/src/cli/flutter_cli.dart b/lib/src/cli/flutter_cli.dart index 230e8c37..b4d7e7b8 100644 --- a/lib/src/cli/flutter_cli.dart +++ b/lib/src/cli/flutter_cli.dart @@ -168,14 +168,17 @@ class Flutter { final target = DirectoryGeneratorTarget(Directory(p.normalize(cwd))); final workingDirectory = target.dir.absolute.path; final relativePath = p.relative(workingDirectory, from: initialCwd); + final relativePathPrefix = '.${p.context.separator}'; + final path = + relativePath == '.' ? '.' : '$relativePathPrefix$relativePath'; stdout?.call( - 'Running "flutter test" in .${p.context.separator}$relativePath...\n', + 'Running "flutter test" in $path ...\n', ); if (!Directory(p.join(target.dir.absolute.path, 'test')).existsSync()) { stdout?.call( - 'No test folder found in .${p.context.separator}$relativePath\n', + 'No test folder found in $path\n', ); return ExitCode.success.code; } diff --git a/test/src/cli/flutter_cli_test.dart b/test/src/cli/flutter_cli_test.dart index 52e5dee3..3ae85e25 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.context.separator}....\n', - 'No test folder found in .${p.context.separator}.\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.context.separator}....\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.context.separator}....\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.context.separator}....\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.context.separator}....\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.context.separator}....\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.context.separator}....\n', + 'Running "flutter test" in . ...\n', contains('All tests passed!'), ]), ); @@ -882,7 +882,7 @@ void main() { expect( stdoutLogs, equals([ - 'Running "flutter test" in .${p.context.separator}....\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.context.separator}....\n', + 'Running "flutter test" in . ...\n', contains('All tests passed!'), ]), ); @@ -969,7 +969,7 @@ void main() { expect( stdoutLogs, equals([ - 'Running "flutter test" in .${p.context.separator}....\n', + 'Running "flutter test" in . ...\n', contains('All tests passed!'), ]), ); @@ -1016,7 +1016,7 @@ void main() { expect( stdoutLogs, equals([ - 'Running "flutter test" in .${p.context.separator}....\n', + 'Running "flutter test" in . ...\n', contains('All tests passed!'), ]), ); @@ -1061,7 +1061,7 @@ void main() { expect( stdoutLogs, equals([ - 'Running "flutter test" in .${p.context.separator}....\n', + 'Running "flutter test" in . ...\n', contains('All tests passed!'), ]), ); @@ -1118,14 +1118,15 @@ void main() { tempNestedDirectory.path, from: tempDirectory.path, ); + final relativePathPrefix = '.${p.context.separator}'; expect( stdoutLogs, unorderedEquals([ 'Running "flutter test" in ' - '.${p.context.separator}$nestedRelativePath...\n', + '$relativePathPrefix$nestedRelativePath ...\n', contains('All tests passed!'), - 'Running "flutter test" in .${p.context.separator}....\n', + 'Running "flutter test" in . ...\n', contains('All tests passed!'), ]), ); @@ -1188,15 +1189,16 @@ void main() { tempNestedDirectory.path, from: tempDirectory.path, ); + final relativePathPrefix = '.${p.context.separator}'; expect( stdoutLogs, unorderedEquals([ 'Running "flutter test" in ' - '.${p.context.separator}....\n', + '. ...\n', contains('All tests passed!'), 'Running "flutter test" in ' - '.${p.context.separator}$nestedRelativePath...\n', + '$relativePathPrefix$nestedRelativePath ...\n', contains('All tests passed!'), ]), ); @@ -1252,7 +1254,7 @@ void main() { expect( stdoutLogs, equals([ - 'Running "flutter test" in .${p.context.separator}....\n', + 'Running "flutter test" in . ...\n', contains('All tests passed!'), ]), ); From af197e80ab49f03af7f089dd730dafca3ef5c6f7 Mon Sep 17 00:00:00 2001 From: Morgan Date: Thu, 14 Dec 2023 10:59:40 -0700 Subject: [PATCH 5/5] refactor: remove uncessary variable declaration --- lib/src/cli/flutter_cli.dart | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/lib/src/cli/flutter_cli.dart b/lib/src/cli/flutter_cli.dart index b4d7e7b8..67ca9fd8 100644 --- a/lib/src/cli/flutter_cli.dart +++ b/lib/src/cli/flutter_cli.dart @@ -168,9 +168,8 @@ class Flutter { final target = DirectoryGeneratorTarget(Directory(p.normalize(cwd))); final workingDirectory = target.dir.absolute.path; final relativePath = p.relative(workingDirectory, from: initialCwd); - final relativePathPrefix = '.${p.context.separator}'; final path = - relativePath == '.' ? '.' : '$relativePathPrefix$relativePath'; + relativePath == '.' ? '.' : '.${p.context.separator}$relativePath'; stdout?.call( 'Running "flutter test" in $path ...\n',