From b34c739636b9113cc1451be6ce420d7dd5461554 Mon Sep 17 00:00:00 2001 From: Yelaman Yelmuratov Date: Sat, 18 May 2024 02:09:49 +0500 Subject: [PATCH] . r check linux path 1 --- .../command_line/command_line_reporter.dart | 12 +++++--- .../diff_tool/diff_tool_reporter.dart | 7 +++++ lib/src/reporters/diff_tool/diff_tools.dart | 3 +- test/approval_test.dart | 29 +++++++++++++++++++ 4 files changed, 46 insertions(+), 5 deletions(-) diff --git a/lib/src/reporters/command_line/command_line_reporter.dart b/lib/src/reporters/command_line/command_line_reporter.dart index 0054b5b..4c4d6ec 100644 --- a/lib/src/reporters/command_line/command_line_reporter.dart +++ b/lib/src/reporters/command_line/command_line_reporter.dart @@ -9,14 +9,18 @@ class CommandLineReporter implements Reporter { try { final StringBuffer buffer = StringBuffer(message ?? "Differences:\n"); - final List approvedLines = ApprovalUtils.readFile(path: approvedPath).split('\n'); - final List receivedLines = ApprovalUtils.readFile(path: receivedPath).split('\n'); + final List approvedLines = + ApprovalUtils.readFile(path: approvedPath).split('\n'); + final List 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( diff --git a/lib/src/reporters/diff_tool/diff_tool_reporter.dart b/lib/src/reporters/diff_tool/diff_tool_reporter.dart index 1144d0a..7665e4d 100644 --- a/lib/src/reporters/diff_tool/diff_tool_reporter.dart +++ b/lib/src/reporters/diff_tool/diff_tool_reporter.dart @@ -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}.', diff --git a/lib/src/reporters/diff_tool/diff_tools.dart b/lib/src/reporters/diff_tool/diff_tools.dart index 9c80a71..1d1386e 100644 --- a/lib/src/reporters/diff_tool/diff_tools.dart +++ b/lib/src/reporters/diff_tool/diff_tools.dart @@ -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', ); diff --git a/test/approval_test.dart b/test/approval_test.dart index 1d6acca..78cd49d 100644 --- a/test/approval_test.dart +++ b/test/approval_test.dart @@ -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()), + ); + + ApprovalLogger.success( + "Test Passed: Successfully handled a file not found error during comparison.", + ); + }); + } + test('Verify string with scrubber', () { helper.verify( ' Hello World \t\n ',