From 470b3a76b363951c343d5523bb9de77c9ba4bf16 Mon Sep 17 00:00:00 2001 From: Asit Dhal Date: Thu, 18 Jun 2020 08:26:32 +0200 Subject: get_filename_component: make errors fatal Make all errors in `get_filename_component` fatal. Fixes: #20015 --- Source/cmGetFilenameComponentCommand.cxx | 2 ++ Tests/RunCMake/get_filename_component/IncorrectArguments-result.txt | 1 + Tests/RunCMake/get_filename_component/IncorrectArguments-stderr.txt | 4 ++++ Tests/RunCMake/get_filename_component/IncorrectArguments.cmake | 2 ++ Tests/RunCMake/get_filename_component/RunCMakeTest.cmake | 1 + Tests/RunCMake/get_filename_component/UnknownComponent-stderr.txt | 4 ++-- Tests/RunCMake/get_filename_component/UnknownComponent.cmake | 1 + 7 files changed, 13 insertions(+), 2 deletions(-) create mode 100644 Tests/RunCMake/get_filename_component/IncorrectArguments-result.txt create mode 100644 Tests/RunCMake/get_filename_component/IncorrectArguments-stderr.txt create mode 100644 Tests/RunCMake/get_filename_component/IncorrectArguments.cmake diff --git a/Source/cmGetFilenameComponentCommand.cxx b/Source/cmGetFilenameComponentCommand.cxx index 811421a..38bffbf 100644 --- a/Source/cmGetFilenameComponentCommand.cxx +++ b/Source/cmGetFilenameComponentCommand.cxx @@ -14,6 +14,7 @@ bool cmGetFilenameComponentCommand(std::vector const& args, { if (args.size() < 3) { status.SetError("called with incorrect number of arguments"); + cmSystemTools::SetFatalErrorOccured(); return false; } @@ -114,6 +115,7 @@ bool cmGetFilenameComponentCommand(std::vector const& args, } else { std::string err = "unknown component " + args[2]; status.SetError(err); + cmSystemTools::SetFatalErrorOccured(); return false; } diff --git a/Tests/RunCMake/get_filename_component/IncorrectArguments-result.txt b/Tests/RunCMake/get_filename_component/IncorrectArguments-result.txt new file mode 100644 index 0000000..d00491f --- /dev/null +++ b/Tests/RunCMake/get_filename_component/IncorrectArguments-result.txt @@ -0,0 +1 @@ +1 diff --git a/Tests/RunCMake/get_filename_component/IncorrectArguments-stderr.txt b/Tests/RunCMake/get_filename_component/IncorrectArguments-stderr.txt new file mode 100644 index 0000000..af08afa --- /dev/null +++ b/Tests/RunCMake/get_filename_component/IncorrectArguments-stderr.txt @@ -0,0 +1,4 @@ +^CMake Error at IncorrectArguments.cmake:1 \(get_filename_component\): + get_filename_component called with incorrect number of arguments +Call Stack \(most recent call first\): + CMakeLists.txt:[0-9]+ \(include\)$ diff --git a/Tests/RunCMake/get_filename_component/IncorrectArguments.cmake b/Tests/RunCMake/get_filename_component/IncorrectArguments.cmake new file mode 100644 index 0000000..e329e29 --- /dev/null +++ b/Tests/RunCMake/get_filename_component/IncorrectArguments.cmake @@ -0,0 +1,2 @@ +get_filename_component(var) +message("The error is fatal, so this should not print") diff --git a/Tests/RunCMake/get_filename_component/RunCMakeTest.cmake b/Tests/RunCMake/get_filename_component/RunCMakeTest.cmake index 156fc8f..a7820a0 100644 --- a/Tests/RunCMake/get_filename_component/RunCMakeTest.cmake +++ b/Tests/RunCMake/get_filename_component/RunCMakeTest.cmake @@ -1,4 +1,5 @@ include(RunCMake) +run_cmake(IncorrectArguments) run_cmake(KnownComponents) run_cmake(UnknownComponent) diff --git a/Tests/RunCMake/get_filename_component/UnknownComponent-stderr.txt b/Tests/RunCMake/get_filename_component/UnknownComponent-stderr.txt index b146e5b..f86a688 100644 --- a/Tests/RunCMake/get_filename_component/UnknownComponent-stderr.txt +++ b/Tests/RunCMake/get_filename_component/UnknownComponent-stderr.txt @@ -1,4 +1,4 @@ -CMake Error at UnknownComponent.cmake:1 \(get_filename_component\): +^CMake Error at UnknownComponent.cmake:1 \(get_filename_component\): get_filename_component unknown component BOGUS Call Stack \(most recent call first\): - CMakeLists.txt:[0-9]+ \(include\) + CMakeLists.txt:[0-9]+ \(include\)$ diff --git a/Tests/RunCMake/get_filename_component/UnknownComponent.cmake b/Tests/RunCMake/get_filename_component/UnknownComponent.cmake index 06abc51..19521ba 100644 --- a/Tests/RunCMake/get_filename_component/UnknownComponent.cmake +++ b/Tests/RunCMake/get_filename_component/UnknownComponent.cmake @@ -1 +1,2 @@ get_filename_component(var "/path/to/filename.ext.in" BOGUS) +message("The error is fatal, so this should not print") -- cgit v0.12