diff --git a/vlib/v/util/diff/diff.v b/vlib/v/util/diff/diff.v index f509fb1b6a795d..64b41c3feb85be 100644 --- a/vlib/v/util/diff/diff.v +++ b/vlib/v/util/diff/diff.v @@ -49,19 +49,22 @@ pub fn find_working_diff_command() !string { return error('No working "diff" command found') } -pub fn color_compare_files(diff_cmd string, path1 string, path2 string) string { - os.find_abs_path_of_executable(diff_cmd) or { - return 'comparison command: `${diff_cmd}` not found' - } - flags := $if openbsd { - ['-d', '-a', '-U', '2'] - } $else $if freebsd { - ['--minimal', '--text', '--unified=2'] - } $else { - ['--minimal', '--text', '--unified=2', '--show-function-line="fn "'] +pub fn color_compare_files(diff_cmd string, file1 string, file2 string) string { + if diff_cmd != '' { + mut full_cmd := '${diff_cmd} --minimal --text --unified=2 --show-function-line="fn " ${os.quoted_path(file1)} ${os.quoted_path(file2)} ' + $if freebsd { + full_cmd = '${diff_cmd} --minimal --text --unified=2 ${os.quoted_path(file1)} ${os.quoted_path(file2)} ' + } + $if openbsd { + full_cmd = '${diff_cmd} -d -a -U 2 ${os.quoted_path(file1)} ${os.quoted_path(file2)} ' + } + x := os.execute(full_cmd) + if x.exit_code < 0 { + return 'comparison command: `${full_cmd}` not found' + } + return x.output.trim_right('\r\n') } - full_cmd := '${diff_cmd} ${flags.join(' ')} ${os.quoted_path(path1)} ${os.quoted_path(path2)}' - return os.execute(full_cmd).output.trim_right('\r\n') + return '' } pub fn color_compare_strings(diff_cmd string, unique_prefix string, expected string, found string) string {