Browse Source

cmake: add dedicated error for -E compare_files invalid arguments

Return 2 when user provides invalid arguments

Fixes: #20815
pull/334/head
Asit Dhal 5 years ago
committed by Brad King
parent
commit
b5b6075522
  1. 3
      Help/manual/cmake.1.rst
  2. 2
      Source/cmcmd.cxx
  3. 1
      Tests/RunCMake/CommandLine/E_compare_files-invalid-arguments-result.txt
  4. 1
      Tests/RunCMake/CommandLine/E_compare_files-invalid-arguments-stderr.txt
  5. 1
      Tests/RunCMake/CommandLine/RunCMakeTest.cmake

3
Help/manual/cmake.1.rst

@ -566,7 +566,8 @@ Available commands are:
``compare_files [--ignore-eol] <file1> <file2>``
Check if ``<file1>`` is same as ``<file2>``. If files are the same,
then returns ``0``, if not it returns ``1``. The ``--ignore-eol`` option
then returns ``0``, if not it returns ``1``. In case of invalid
arguments, it retruns 2. The ``--ignore-eol`` option
implies line-wise comparison and ignores LF/CRLF differences.
``copy <file>... <destination>``

2
Source/cmcmd.cxx

@ -582,7 +582,7 @@ int cmcmd::ExecuteCMakeCommand(std::vector<std::string> const& args)
filesDiffer = cmsys::SystemTools::TextFilesDiffer(args[3], args[4]);
} else {
::CMakeCommandUsage(args[0].c_str());
return 1;
return 2;
}
if (filesDiffer) {

1
Tests/RunCMake/CommandLine/E_compare_files-invalid-arguments-result.txt

@ -0,0 +1 @@
2

1
Tests/RunCMake/CommandLine/E_compare_files-invalid-arguments-stderr.txt

@ -0,0 +1 @@
.*

1
Tests/RunCMake/CommandLine/RunCMakeTest.cmake

@ -22,6 +22,7 @@ run_cmake_command(E_compare_files-different-eol ${CMAKE_COMMAND} -E compare_file
run_cmake_command(E_compare_files-ignore-eol-same ${CMAKE_COMMAND} -E compare_files --ignore-eol ${RunCMake_SOURCE_DIR}/compare_files/lf ${RunCMake_SOURCE_DIR}/compare_files/crlf)
run_cmake_command(E_compare_files-ignore-eol-empty ${CMAKE_COMMAND} -E compare_files --ignore-eol ${RunCMake_SOURCE_DIR}/compare_files/empty1 ${RunCMake_SOURCE_DIR}/compare_files/empty2)
run_cmake_command(E_compare_files-ignore-eol-nonexistent ${CMAKE_COMMAND} -E compare_files --ignore-eol nonexistent_a nonexistent_b)
run_cmake_command(E_compare_files-invalid-arguments ${CMAKE_COMMAND} -E compare_files file1.txt file2.txt file3.txt)
run_cmake_command(E_echo_append ${CMAKE_COMMAND} -E echo_append)
run_cmake_command(E_rename-no-arg ${CMAKE_COMMAND} -E rename)
run_cmake_command(E_server-arg ${CMAKE_COMMAND} -E server --extra-arg)

Loading…
Cancel
Save