Skip to content

Commit bceb17f

Browse files
committed
. B updated code: add conditions for path exctractor
1 parent d0a9860 commit bceb17f

File tree

2 files changed

+20
-13
lines changed

2 files changed

+20
-13
lines changed

lib/src/core/file_path_extractor.dart

+16-6
Original file line numberDiff line numberDiff line change
@@ -10,15 +10,19 @@ class FilePathExtractor {
1010
String get filePath {
1111
try {
1212
final stackTraceString = _stackTraceFetcher.currentStackTrace;
13-
// ApprovalLogger.log('Stack trace: $stackTraceString');
14-
//final uriRegExp = RegExp(r'file:\/\/\/([^\s:]+)');
15-
final uriRegExp = RegExp(r'file://(/[a-zA-Z]:[^\s]*)');
13+
14+
final uriRegExp = RegExp(isWindows ? _windowsPattern : _linuxMacOSPattern);
1615
final match = uriRegExp.firstMatch(stackTraceString);
1716

1817
if (match != null) {
19-
final rawPath = match.group(1)!.replaceAll(RegExp(r':\d+:\d+\)$'), '');
20-
final filePath = Uri.parse('file://$rawPath');
21-
return filePath.toFilePath(windows: Platform.isWindows);
18+
if (isWindows) {
19+
final rawPath = match.group(1)!.replaceAll(RegExp(r':\d+:\d+\)$'), '');
20+
final filePath = Uri.parse('file://$rawPath');
21+
return filePath.toFilePath(windows: isWindows);
22+
} else {
23+
final filePath = Uri.tryParse('file:///${match.group(1)!}');
24+
return filePath!.toFilePath();
25+
}
2226
} else {
2327
throw FileNotFoundException(
2428
message: 'File not found in stack trace',
@@ -29,4 +33,10 @@ class FilePathExtractor {
2933
rethrow;
3034
}
3135
}
36+
37+
static bool isWindows = Platform.isWindows;
38+
39+
static const String _windowsPattern = r'file://(/[a-zA-Z]:[^\s]*)';
40+
41+
static const String _linuxMacOSPattern = r'file:\/\/\/([^\s:]+)';
3242
}

lib/src/reporters/diff_tool/diff_tools.dart

+4-7
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,7 @@ part of '../../../../approval_tests.dart';
33
/// `MacDiffTools` contains diff tools available on macOS.
44
final class MacDiffTools {
55
static const DiffInfo visualStudioCode = DiffInfo(
6-
command:
7-
'/Applications/Visual Studio Code.app/Contents/Resources/app/bin/code',
6+
command: '/Applications/Visual Studio Code.app/Contents/Resources/app/bin/code',
87
arg: '-d',
98
name: 'code',
109
);
@@ -28,23 +27,21 @@ final class WindowsDiffTools {
2827
static const DiffInfo androidStudio = DiffInfo(
2928
command: 'C:\\Program Files\\Android\\Android Studio\\bin\\studio64.exe',
3029
arg: 'diff',
31-
name: 'studio',
30+
name: 'studio64',
3231
);
3332
}
3433

3534
/// `LinuxDiffTools` contains diff tools available on Linux.
3635
final class LinuxDiffTools {
37-
// TODO: check correct path for Visual Studio Code on Linux
3836
static const DiffInfo visualStudioCode = DiffInfo(
3937
command: '/snap/bin/code',
4038
arg: '-d',
4139
name: 'code',
4240
);
4341

44-
// TODO: check correct path for Android Studio on Linux
4542
static const DiffInfo androidStudio = DiffInfo(
46-
command: '/snap/bin/studio',
43+
command: '/snap/bin/android-studio',
4744
arg: 'diff',
48-
name: 'studio',
45+
name: 'android-studio',
4946
);
5047
}

0 commit comments

Comments
 (0)