From cae9d2a61afea3948c8dfaf1f7dbc39ebaa71055 Mon Sep 17 00:00:00 2001
From: Brad King <brad.king@kitware.com>
Date: Wed, 16 Jan 2019 14:32:29 -0500
Subject: CTest: Teach --show-only= to reject unknown values

---
 Source/cmCTest.cxx                                         | 3 +++
 Tests/RunCMake/CTestCommandLine/RunCMakeTest.cmake         | 2 ++
 Tests/RunCMake/CTestCommandLine/show-only_bad-result.txt   | 1 +
 Tests/RunCMake/CTestCommandLine/show-only_bad-stderr.txt   | 1 +
 Tests/RunCMake/CTestCommandLine/show-only_human-stdout.txt | 1 +
 5 files changed, 8 insertions(+)
 create mode 100644 Tests/RunCMake/CTestCommandLine/show-only_bad-result.txt
 create mode 100644 Tests/RunCMake/CTestCommandLine/show-only_bad-stderr.txt
 create mode 100644 Tests/RunCMake/CTestCommandLine/show-only_human-stdout.txt

diff --git a/Source/cmCTest.cxx b/Source/cmCTest.cxx
index 65c0d91..ccd74c0 100644
--- a/Source/cmCTest.cxx
+++ b/Source/cmCTest.cxx
@@ -1944,6 +1944,9 @@ bool cmCTest::HandleCommandLineArguments(size_t& i,
       this->Quiet = true;
       this->OutputAsJson = true;
       this->OutputAsJsonVersion = 1;
+    } else if (format != "human") {
+      errormsg = "'--show-only=' given unknown value '" + format + "'";
+      return false;
     }
   }
 
diff --git a/Tests/RunCMake/CTestCommandLine/RunCMakeTest.cmake b/Tests/RunCMake/CTestCommandLine/RunCMakeTest.cmake
index 82bd963..d524f41 100644
--- a/Tests/RunCMake/CTestCommandLine/RunCMakeTest.cmake
+++ b/Tests/RunCMake/CTestCommandLine/RunCMakeTest.cmake
@@ -203,6 +203,8 @@ function(run_ShowOnly)
     set_tests_properties(ShowOnly PROPERTIES WILL_FAIL true _BACKTRACE_TRIPLES \"file1;1;add_test;file0;;\")
     add_test(ShowOnlyNotAvailable NOT_AVAILABLE)
 ")
+  run_cmake_command(show-only_human ${CMAKE_CTEST_COMMAND} --show-only=human)
+  run_cmake_command(show-only_bad ${CMAKE_CTEST_COMMAND} --show-only=bad)
   run_cmake_command(show-only_json-v1 ${CMAKE_CTEST_COMMAND} --show-only=json-v1)
 endfunction()
 run_ShowOnly()
diff --git a/Tests/RunCMake/CTestCommandLine/show-only_bad-result.txt b/Tests/RunCMake/CTestCommandLine/show-only_bad-result.txt
new file mode 100644
index 0000000..d00491f
--- /dev/null
+++ b/Tests/RunCMake/CTestCommandLine/show-only_bad-result.txt
@@ -0,0 +1 @@
+1
diff --git a/Tests/RunCMake/CTestCommandLine/show-only_bad-stderr.txt b/Tests/RunCMake/CTestCommandLine/show-only_bad-stderr.txt
new file mode 100644
index 0000000..cc55ab3
--- /dev/null
+++ b/Tests/RunCMake/CTestCommandLine/show-only_bad-stderr.txt
@@ -0,0 +1 @@
+^CMake Error: '--show-only=' given unknown value 'bad'$
diff --git a/Tests/RunCMake/CTestCommandLine/show-only_human-stdout.txt b/Tests/RunCMake/CTestCommandLine/show-only_human-stdout.txt
new file mode 100644
index 0000000..1332149
--- /dev/null
+++ b/Tests/RunCMake/CTestCommandLine/show-only_human-stdout.txt
@@ -0,0 +1 @@
+Test #1: ShowOnly
-- 
cgit v0.12