From b5b60755228e3b1489d5cd43622c08d0d8d77bc9 Mon Sep 17 00:00:00 2001 From: Asit Dhal Date: Fri, 12 Jun 2020 04:59:32 +0200 Subject: cmake: add dedicated error for -E compare_files invalid arguments Return 2 when user provides invalid arguments Fixes: #20815 --- Help/manual/cmake.1.rst | 3 ++- Source/cmcmd.cxx | 2 +- .../RunCMake/CommandLine/E_compare_files-invalid-arguments-result.txt | 1 + .../RunCMake/CommandLine/E_compare_files-invalid-arguments-stderr.txt | 1 + Tests/RunCMake/CommandLine/RunCMakeTest.cmake | 1 + 5 files changed, 6 insertions(+), 2 deletions(-) create mode 100644 Tests/RunCMake/CommandLine/E_compare_files-invalid-arguments-result.txt create mode 100644 Tests/RunCMake/CommandLine/E_compare_files-invalid-arguments-stderr.txt diff --git a/Help/manual/cmake.1.rst b/Help/manual/cmake.1.rst index 9becfc6..e4c662e 100644 --- a/Help/manual/cmake.1.rst +++ b/Help/manual/cmake.1.rst @@ -566,7 +566,8 @@ Available commands are: ``compare_files [--ignore-eol] `` Check if ```` is same as ````. 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 ... `` diff --git a/Source/cmcmd.cxx b/Source/cmcmd.cxx index cbc8e8f..6882fdd 100644 --- a/Source/cmcmd.cxx +++ b/Source/cmcmd.cxx @@ -582,7 +582,7 @@ int cmcmd::ExecuteCMakeCommand(std::vector const& args) filesDiffer = cmsys::SystemTools::TextFilesDiffer(args[3], args[4]); } else { ::CMakeCommandUsage(args[0].c_str()); - return 1; + return 2; } if (filesDiffer) { diff --git a/Tests/RunCMake/CommandLine/E_compare_files-invalid-arguments-result.txt b/Tests/RunCMake/CommandLine/E_compare_files-invalid-arguments-result.txt new file mode 100644 index 0000000..0cfbf08 --- /dev/null +++ b/Tests/RunCMake/CommandLine/E_compare_files-invalid-arguments-result.txt @@ -0,0 +1 @@ +2 diff --git a/Tests/RunCMake/CommandLine/E_compare_files-invalid-arguments-stderr.txt b/Tests/RunCMake/CommandLine/E_compare_files-invalid-arguments-stderr.txt new file mode 100644 index 0000000..8d98f9d --- /dev/null +++ b/Tests/RunCMake/CommandLine/E_compare_files-invalid-arguments-stderr.txt @@ -0,0 +1 @@ +.* diff --git a/Tests/RunCMake/CommandLine/RunCMakeTest.cmake b/Tests/RunCMake/CommandLine/RunCMakeTest.cmake index 16fdeef..f291f15 100644 --- a/Tests/RunCMake/CommandLine/RunCMakeTest.cmake +++ b/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) -- cgit v0.12