diff --git a/CMakeLists.txt b/CMakeLists.txt index f7c157aef..fc5eb7a31 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,4 +1,4 @@ -cmake_minimum_required (VERSION 3.21) +cmake_minimum_required (VERSION 3.22) project (glog VERSION 0.7.0 DESCRIPTION "C++ implementation of the Google logging module" @@ -908,6 +908,51 @@ if (BUILD_TESTING) -DCMAKE_GENERATOR_TOOLSET=${CMAKE_GENERATOR_TOOLSET} -Dglog_DIR=${glog_BINARY_DIR} ) + + add_test (NAME dcheck_on COMMAND ${CMAKE_CTEST_COMMAND} + --build-config Debug + --build-and-test + "${glog_SOURCE_DIR}/src/dcheck_unittest" + "${glog_BINARY_DIR}/Tests/dcheck_on" + --build-generator ${CMAKE_GENERATOR} + --build-generator-platform "${CMAKE_GENERATOR_PLATFORM}" + --build-generator-toolset "${CMAKE_GENERATOR_TOOLSET}" + --build-makeprogram ${CMAKE_MAKE_PROGRAM} + --build-target glog_dcheck + --build-options + -DCMAKE_CXX_COMPILER=${CMAKE_CXX_COMPILER} + -DCMAKE_FIND_PACKAGE_NO_PACKAGE_REGISTRY=ON + -Dglog_DIR=${glog_BINARY_DIR} + --test-command glog_dcheck + ) + set_tests_properties (dcheck_on PROPERTIES + DISABLED $> + ENVIRONMENT_MODIFICATION "PATH=path_list_prepend:$" + PASS_REGULAR_EXPRESSION "Assert failed: false" + ) + + add_test (NAME dcheck_off COMMAND ${CMAKE_CTEST_COMMAND} + --build-config Release + --build-and-test + "${glog_SOURCE_DIR}/src/dcheck_unittest" + "${glog_BINARY_DIR}/Tests/dcheck_off" + --build-generator ${CMAKE_GENERATOR} + --build-generator-platform "${CMAKE_GENERATOR_PLATFORM}" + --build-generator-toolset "${CMAKE_GENERATOR_TOOLSET}" + --build-makeprogram ${CMAKE_MAKE_PROGRAM} + --build-target glog_dcheck + --build-options + -DCMAKE_CXX_COMPILER=${CMAKE_CXX_COMPILER} + -DCMAKE_FIND_PACKAGE_NO_PACKAGE_REGISTRY=ON + -Dglog_DIR=${glog_BINARY_DIR} + --test-command glog_dcheck + ) + # There should be no output + set_tests_properties (dcheck_off PROPERTIES + DISABLED $> + ENVIRONMENT_MODIFICATION "PATH=path_list_prepend:$" + PASS_REGULAR_EXPRESSION "" + ) endif (BUILD_TESTING) install (TARGETS glog diff --git a/src/dcheck_unittest/CMakeLists.txt b/src/dcheck_unittest/CMakeLists.txt new file mode 100644 index 000000000..cd08704f3 --- /dev/null +++ b/src/dcheck_unittest/CMakeLists.txt @@ -0,0 +1,7 @@ +cmake_minimum_required (VERSION 3.16) +project (glog_log_severity LANGUAGES CXX) + +find_package (glog REQUIRED NO_MODULE) + +add_executable (glog_dcheck glog_dcheck.cc) +target_link_libraries (glog_dcheck PRIVATE glog::glog) diff --git a/src/dcheck_unittest/glog_dcheck.cc b/src/dcheck_unittest/glog_dcheck.cc new file mode 100644 index 000000000..bc9f347d0 --- /dev/null +++ b/src/dcheck_unittest/glog_dcheck.cc @@ -0,0 +1,53 @@ +// Copyright (c) 2024, Google Inc. +// All rights reserved. +// +// Redistribution and use in source and binary forms, with or without +// modification, are permitted provided that the following conditions are +// met: +// +// * Redistributions of source code must retain the above copyright +// notice, this list of conditions and the following disclaimer. +// * Redistributions in binary form must reproduce the above +// copyright notice, this list of conditions and the following disclaimer +// in the documentation and/or other materials provided with the +// distribution. +// * Neither the name of Google Inc. nor the names of its +// contributors may be used to endorse or promote products derived from +// this software without specific prior written permission. +// +// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +// +// Author: Sergiu Deitsch + +#include + +int main(int /*argc*/, char** argv) { + google::InitGoogleLogging(argv[0]); + google::InstallFailureSignalHandler(); + +#if defined(_MSC_VER) + // Avoid presenting an interactive dialog that will cause the test to time + // out. + _set_abort_behavior(0, _WRITE_ABORT_MSG | _CALL_REPORTFAULT); +#endif // defined(_MSC_VER) + + DLOG(INFO) << "no output"; + DLOG(WARNING) << "no output"; + DLOG(ERROR) << "no output"; + + // Must not fail in release build + DLOG_ASSERT(false); + + // Must be the last expression + DLOG(FATAL) << "no output"; +} diff --git a/src/glog/logging.h b/src/glog/logging.h index f8cb7884f..db87819d9 100644 --- a/src/glog/logging.h +++ b/src/glog/logging.h @@ -1070,7 +1070,7 @@ constexpr LogSeverity GLOG_0 = GLOG_ERROR; true ? (void)0 : google::LogMessageVoidify() & LOG(severity) # define DLOG_ASSERT(condition) \ - static_cast(0), true ? (void)0 : LOG_ASSERT(condition) + static_cast(0), true ? (void)0 : (LOG_ASSERT(condition)) // MSVC warning C4127: conditional expression is constant # define DCHECK(condition) \