Skip to content

Commit

Permalink
. r check linux path 1
Browse files Browse the repository at this point in the history
  • Loading branch information
yelmuratoff committed May 17, 2024
1 parent 715de19 commit b34c739
Show file tree
Hide file tree
Showing 4 changed files with 46 additions and 5 deletions.
12 changes: 8 additions & 4 deletions lib/src/reporters/command_line/command_line_reporter.dart
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,18 @@ class CommandLineReporter implements Reporter {
try {
final StringBuffer buffer = StringBuffer(message ?? "Differences:\n");

final List<String> approvedLines = ApprovalUtils.readFile(path: approvedPath).split('\n');
final List<String> receivedLines = ApprovalUtils.readFile(path: receivedPath).split('\n');
final List<String> approvedLines =
ApprovalUtils.readFile(path: approvedPath).split('\n');
final List<String> receivedLines =
ApprovalUtils.readFile(path: receivedPath).split('\n');

final int maxLines = max(approvedLines.length, receivedLines.length);

for (int i = 0; i < maxLines; i++) {
final String approvedLine = i < approvedLines.length ? approvedLines[i] : "";
final String receivedLine = i < receivedLines.length ? receivedLines[i] : "";
final String approvedLine =
i < approvedLines.length ? approvedLines[i] : "";
final String receivedLine =
i < receivedLines.length ? receivedLines[i] : "";

if (approvedLine != receivedLine) {
buffer.writeln(
Expand Down
7 changes: 7 additions & 0 deletions lib/src/reporters/diff_tool/diff_tool_reporter.dart
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,13 @@ class DiffReporter implements Reporter {
if (e is PathNotFoundException) {
rethrow;
}
if (e is ProcessException) {
ApprovalLogger.exception(e, stackTrace: st);
throw ProcessException(
'Error during comparison via ${ide.name}. Please try check path to IDE. \n Current path: ${diffInfo.command}.',
[diffInfo.arg],
);
}
throw IDEComparatorException(
message:
'Error during comparison via ${ide.name}. Please try check path to IDE. \n Current path: ${diffInfo.command}.',
Expand Down
3 changes: 2 additions & 1 deletion lib/src/reporters/diff_tool/diff_tools.dart
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@ part of '../../../../approval_tests.dart';
/// `MacDiffTools` contains diff tools available on macOS.
final class MacDiffTools {
static const DiffInfo visualStudioCode = DiffInfo(
command: '/Applications/Visual Studio Code.app/Contents/Resources/app/bin/code',
command:
'/Applications/Visual Studio Code.app/Contents/Resources/app/bin/code',
arg: '-d',
);

Expand Down
29 changes: 29 additions & 0 deletions test/approval_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -178,6 +178,35 @@ void main() {
);
});

if (Platform.isLinux) {
test(
'Verify string with DiffReporter. Must throw IDEComparatorException.',
() async {
const reporter = DiffReporter(
customDiffInfo: LinuxDiffTools.visualStudioCode,
);

// Setup: paths to non-existent files
const nonExistentApprovedPath =
'test/approved_files/approval_test.verify.approved.txt';
const nonExistentReceivedPath =
'test/approved_files/approval_test.verify.received.txt';

// Expect an exception to be thrown
expect(
() => reporter.report(
nonExistentApprovedPath,
nonExistentReceivedPath,
),
throwsA(isA<ProcessException>()),
);

ApprovalLogger.success(
"Test Passed: Successfully handled a file not found error during comparison.",
);
});
}

test('Verify string with scrubber', () {
helper.verify(
' Hello World \t\n ',
Expand Down

0 comments on commit b34c739

Please sign in to comment.