From 8c8c268bf2166b9049b51cde89a3330462771249 Mon Sep 17 00:00:00 2001 From: David Robillard Date: Tue, 21 Jan 2025 11:17:32 -0500 Subject: Separate C++ build tests to avoid C/C++ warning clashes --- test/.clang-tidy | 2 - test/cpp/.clang-tidy | 38 +++++++++++++++ test/cpp/meson.build | 106 ++++++++++++++++++++++++++++++++++++++++ test/cpp/test_build.cpp | 20 ++++++++ test/cpp/test_inline_cpp.cpp | 67 +++++++++++++++++++++++++ test/cpp/test_inline_objcpp.mm | 38 +++++++++++++++ test/meson.build | 108 ++--------------------------------------- test/test_build.cpp | 20 -------- test/test_inline_cpp.cpp | 67 ------------------------- test/test_inline_objcpp.mm | 38 --------------- test/test_utils.h | 5 +- 11 files changed, 275 insertions(+), 234 deletions(-) create mode 100644 test/cpp/.clang-tidy create mode 100644 test/cpp/meson.build create mode 100644 test/cpp/test_build.cpp create mode 100644 test/cpp/test_inline_cpp.cpp create mode 100644 test/cpp/test_inline_objcpp.mm delete mode 100644 test/test_build.cpp delete mode 100644 test/test_inline_cpp.cpp delete mode 100644 test/test_inline_objcpp.mm (limited to 'test') diff --git a/test/.clang-tidy b/test/.clang-tidy index c88c7b3..456eb2e 100644 --- a/test/.clang-tidy +++ b/test/.clang-tidy @@ -7,10 +7,8 @@ Checks: > -cert-err33-c, -cert-err34-c, -clang-analyzer-optin.core.EnumCastOutOfRange, - -google-runtime-references, -hicpp-multiway-paths-covered, -hicpp-signed-bitwise, -llvm-header-guard, - -modernize-use-trailing-return-type, -readability-function-cognitive-complexity, InheritParentConfig: true diff --git a/test/cpp/.clang-tidy b/test/cpp/.clang-tidy new file mode 100644 index 0000000..1d936a2 --- /dev/null +++ b/test/cpp/.clang-tidy @@ -0,0 +1,38 @@ +# Copyright 2020-2025 David Robillard +# SPDX-License-Identifier: 0BSD OR ISC + +Checks: > + -*-use-auto, + -*-use-nullptr, + -bugprone-easily-swappable-parameters, + -cert-dcl50-cpp, + -cppcoreguidelines-avoid-c-arrays, + -cppcoreguidelines-avoid-do-while, + -cppcoreguidelines-macro-usage, + -cppcoreguidelines-no-malloc, + -cppcoreguidelines-owning-memory, + -cppcoreguidelines-pro-bounds-array-to-pointer-decay, + -cppcoreguidelines-pro-bounds-constant-array-index, + -cppcoreguidelines-pro-bounds-pointer-arithmetic, + -cppcoreguidelines-pro-type-cstyle-cast, + -cppcoreguidelines-pro-type-member-init, + -cppcoreguidelines-pro-type-union-access, + -cppcoreguidelines-pro-type-vararg, + -google-readability-casting, + -google-runtime-int, + -hicpp-avoid-c-arrays, + -hicpp-member-init, + -hicpp-named-parameter, + -hicpp-no-array-decay, + -hicpp-no-malloc, + -hicpp-vararg, + -misc-use-anonymous-namespace, + -modernize-avoid-c-arrays, + -modernize-loop-convert, + -modernize-loop-convert, + -modernize-redundant-void-arg, + -modernize-use-trailing-return-type, + -modernize-use-using, + -performance-enum-size, + -readability-named-parameter, +InheritParentConfig: true diff --git a/test/cpp/meson.build b/test/cpp/meson.build new file mode 100644 index 0000000..73e2320 --- /dev/null +++ b/test/cpp/meson.build @@ -0,0 +1,106 @@ +# Copyright 2021-2025 David Robillard +# SPDX-License-Identifier: 0BSD OR ISC + +test_cpp_args = [] +if get_option('warning_level') == 'everything' and is_variable('cpp') + if cpp.get_id() == 'clang' + test_cpp_args += [ + '-Wno-documentation', # Cairo + '-Wno-documentation-unknown-command', # Cairo + '-Wno-old-style-cast', + ] + endif + + test_cpp_args = cpp.get_supported_arguments(test_cpp_args) +endif + +unified_args = core_args +unified_deps = [core_deps] +if cairo_dep.found() + unified_args += ['-DWITH_CAIRO'] + unified_deps += [cairo_dep] +endif + +if opengl_dep.found() + unified_args += ['-DWITH_OPENGL'] + unified_deps += [opengl_dep] +endif + +if vulkan_dep.found() + unified_args += ['-DWITH_VULKAN'] + unified_deps += [vulkan_deps] +endif + +if host_machine.system() == 'darwin' + add_languages(['objcpp'], native: false) + + objcpp = meson.get_compiler('objcpp') + + objcpp_unified_args = unified_args + if objcpp.get_id() == 'clang' + objcpp_unified_args += [ + '-Wno-c++98-compat', + '-Wno-c++98-compat-pedantic', + '-Wno-deprecated-declarations', + '-Wno-direct-ivar-access', + ] + endif + + objcpp_unified_args = objcpp.get_supported_arguments(objcpp_unified_args) + + test( + 'inline_objcpp', + executable( + 'test_inline_objcpp', + 'test_inline_objcpp.mm', + dependencies: unified_deps, + include_directories: include_directories('../../include'), + objcpp_args: objcpp_unified_args, + ), + suite: 'unit', + ) + +elif is_variable('cpp') + cpp_unified_args = unified_args + if cpp.get_id() == 'clang' + cpp_unified_args += [ + '-Wno-old-style-cast', + '-Wno-switch-default', + '-Wno-switch-enum', + '-Wno-unused-macros', # Mac + ] + if host_machine.system() == 'windows' + cpp_unified_args += [ + '-Wno-cast-function-type', + '-Wno-deprecated-declarations', + '-Wno-nonportable-system-include-path', + ] + endif + elif cpp.get_id() == 'gcc' + cpp_unified_args += [ + '-Wno-conditionally-supported', + '-Wno-old-style-cast', + '-Wno-switch-default', + '-Wno-switch-enum', + '-Wno-useless-cast', + ] + elif cpp.get_id() == 'msvc' + cpp_unified_args += [ + '/wd4464', # relative include path contains '..' + ] + endif + + cpp_unified_args = cpp.get_supported_arguments(cpp_unified_args) + + test( + 'inline_cpp', + executable( + 'test_inline_cpp', + 'test_inline_cpp.cpp', + cpp_args: cpp_unified_args, + dependencies: unified_deps, + include_directories: include_directories('../../include'), + ), + suite: 'unit', + ) +endif diff --git a/test/cpp/test_build.cpp b/test/cpp/test_build.cpp new file mode 100644 index 0000000..4fd2dac --- /dev/null +++ b/test/cpp/test_build.cpp @@ -0,0 +1,20 @@ +// Copyright 2020 David Robillard +// SPDX-License-Identifier: ISC + +/* + Tests that C++ headers compile without any warnings. +*/ + +#define PUGL_DISABLE_DEPRECATED + +#include "pugl/cairo.hpp" // IWYU pragma: keep +#include "pugl/gl.hpp" // IWYU pragma: keep +#include "pugl/pugl.h" // IWYU pragma: keep +#include "pugl/pugl.hpp" // IWYU pragma: keep +#include "pugl/stub.hpp" // IWYU pragma: keep + +int +main() +{ + return 0; +} diff --git a/test/cpp/test_inline_cpp.cpp b/test/cpp/test_inline_cpp.cpp new file mode 100644 index 0000000..f5694eb --- /dev/null +++ b/test/cpp/test_inline_cpp.cpp @@ -0,0 +1,67 @@ +// Copyright 2021 David Robillard +// SPDX-License-Identifier: ISC + +// Tests that the implementation compiles as included C++ + +#define PUGL_API + +#if defined(__clang__) +# pragma clang diagnostic push +# pragma clang diagnostic ignored "-Wmissing-field-initializers" +# pragma clang diagnostic ignored "-Wold-style-cast" +# pragma clang diagnostic ignored "-Wzero-as-null-pointer-constant" +# if __has_warning("-Wreserved-identifier") +# pragma clang diagnostic ignored "-Wreserved-identifier" +# endif +#elif defined(__GNUC__) +# pragma GCC diagnostic push +# pragma GCC diagnostic ignored "-Wconversion" +# pragma GCC diagnostic ignored "-Wmissing-field-initializers" +# pragma GCC diagnostic ignored "-Wredundant-tags" +# pragma GCC diagnostic ignored "-Wsuggest-attribute=const" +# pragma GCC diagnostic ignored "-Wsuggest-attribute=pure" +# pragma GCC diagnostic ignored "-Wzero-as-null-pointer-constant" +#endif + +#include "../src/common.c" // IWYU pragma: keep +#include "../src/internal.c" // IWYU pragma: keep + +#if defined(_WIN32) +# include "../src/win.c" // IWYU pragma: keep +# include "../src/win.h" // IWYU pragma: keep +# include "../src/win_stub.c" // IWYU pragma: keep +# if defined(WITH_CAIRO) +# include "../src/win_cairo.c" // IWYU pragma: keep +# endif +# if defined(WITH_OPENGL) +# include "../src/win_gl.c" // IWYU pragma: keep +# endif +# if defined(WITH_VULKAN) +# include "../src/win_vulkan.c" // IWYU pragma: keep +# endif + +#else +# include "../src/x11.c" // IWYU pragma: keep +# include "../src/x11_stub.c" // IWYU pragma: keep +# if defined(WITH_CAIRO) +# include "../src/x11_cairo.c" // IWYU pragma: keep +# endif +# if defined(WITH_OPENGL) +# include "../src/x11_gl.c" // IWYU pragma: keep +# endif +# if defined(WITH_VULKAN) +# include "../src/x11_vulkan.c" // IWYU pragma: keep +# endif +#endif + +int +main() +{ + return 0; +} + +#if defined(__clang__) +# pragma clang diagnostic pop +#elif defined(__GNUC__) +# pragma GCC diagnostic pop +#endif diff --git a/test/cpp/test_inline_objcpp.mm b/test/cpp/test_inline_objcpp.mm new file mode 100644 index 0000000..1c9079b --- /dev/null +++ b/test/cpp/test_inline_objcpp.mm @@ -0,0 +1,38 @@ +// Copyright 2021 David Robillard +// SPDX-License-Identifier: ISC + +// Tests that the implementation compiles as included ObjC++ + +#if defined(__clang__) +# pragma clang diagnostic push +# pragma clang diagnostic ignored "-Wzero-as-null-pointer-constant" +# pragma clang diagnostic ignored "-Wold-style-cast" +#endif + +#include "../src/common.c" // IWYU pragma: keep +#include "../src/internal.c" // IWYU pragma: keep +#include "../src/mac.h" // IWYU pragma: keep +#include "../src/mac.m" // IWYU pragma: keep +#include "../src/mac_stub.m" // IWYU pragma: keep + +#if defined(WITH_CAIRO) +# include "../src/mac_cairo.m" // IWYU pragma: keep +#endif + +#if defined(WITH_OPENGL) +# include "../src/mac_gl.m" // IWYU pragma: keep +#endif + +#if defined(WITH_VULKAN) +# include "../src/mac_vulkan.m" // IWYU pragma: keep +#endif + +#if defined(__clang__) +# pragma clang diagnostic pop +#endif + +int +main(void) +{ + return 0; +} diff --git a/test/meson.build b/test/meson.build index c47d3ee..d34763f 100644 --- a/test/meson.build +++ b/test/meson.build @@ -17,20 +17,6 @@ if get_option('warning_level') == 'everything' test_c_args = cc.get_supported_arguments(test_c_args) endif -# Suppress some additional C++ warnings in tests -test_cpp_args = [] -if get_option('warning_level') == 'everything' and is_variable('cpp') - if cpp.get_id() == 'clang' - test_cpp_args += [ - '-Wno-documentation', # Cairo - '-Wno-documentation-unknown-command', # Cairo - '-Wno-old-style-cast', - ] - endif - - test_cpp_args = cpp.get_supported_arguments(test_cpp_args) -endif - # Check licensing metadata if not meson.is_subproject() and get_option('lint') reuse = find_program('reuse', required: false) @@ -144,7 +130,6 @@ if vulkan_dep.found() 'test_' + test, 'test_@0@.c'.format(test), c_args: test_c_args, - cpp_args: test_cpp_args, dependencies: [pugl_dep, pugl_vulkan_dep], include_directories: include_directories(includes), ), @@ -153,93 +138,8 @@ if vulkan_dep.found() endforeach endif -unified_args = core_args -unified_deps = [core_deps] -if cairo_dep.found() - unified_args += ['-DWITH_CAIRO'] - unified_deps += [cairo_dep] -endif - -if opengl_dep.found() - unified_args += ['-DWITH_OPENGL'] - unified_deps += [opengl_dep] -endif - -if vulkan_dep.found() - unified_args += ['-DWITH_VULKAN'] - unified_deps += [vulkan_deps] -endif - -if host_machine.system() == 'darwin' - add_languages(['objcpp'], native: false) - - objcpp = meson.get_compiler('objcpp') +####################### +# C++ / Objective C++ # +####################### - objcpp_unified_args = unified_args - if objcpp.get_id() == 'clang' - objcpp_unified_args += [ - '-Wno-c++98-compat', - '-Wno-c++98-compat-pedantic', - '-Wno-deprecated-declarations', - '-Wno-direct-ivar-access', - ] - endif - - objcpp_unified_args = objcpp.get_supported_arguments(objcpp_unified_args) - - test( - 'inline_objcpp', - executable( - 'test_inline_objcpp', - 'test_inline_objcpp.mm', - dependencies: unified_deps, - include_directories: include_directories(includes), - objcpp_args: objcpp_unified_args, - ), - suite: 'unit', - ) - -elif is_variable('cpp') - cpp_unified_args = unified_args - if cpp.get_id() == 'clang' - cpp_unified_args += [ - '-Wno-old-style-cast', - '-Wno-switch-default', - '-Wno-switch-enum', - '-Wno-unused-macros', # Mac - ] - if host_machine.system() == 'windows' - cpp_unified_args += [ - '-Wno-cast-function-type', - '-Wno-deprecated-declarations', - '-Wno-nonportable-system-include-path', - ] - endif - elif cpp.get_id() == 'gcc' - cpp_unified_args += [ - '-Wno-conditionally-supported', - '-Wno-old-style-cast', - '-Wno-switch-default', - '-Wno-switch-enum', - '-Wno-useless-cast', - ] - elif cpp.get_id() == 'msvc' - cpp_unified_args += [ - '/wd4464', # relative include path contains '..' - ] - endif - - cpp_unified_args = cpp.get_supported_arguments(cpp_unified_args) - - test( - 'inline_cpp', - executable( - 'test_inline_cpp', - 'test_inline_cpp.cpp', - cpp_args: cpp_unified_args, - dependencies: unified_deps, - include_directories: include_directories(includes), - ), - suite: 'unit', - ) -endif +subdir('cpp') diff --git a/test/test_build.cpp b/test/test_build.cpp deleted file mode 100644 index 4fd2dac..0000000 --- a/test/test_build.cpp +++ /dev/null @@ -1,20 +0,0 @@ -// Copyright 2020 David Robillard -// SPDX-License-Identifier: ISC - -/* - Tests that C++ headers compile without any warnings. -*/ - -#define PUGL_DISABLE_DEPRECATED - -#include "pugl/cairo.hpp" // IWYU pragma: keep -#include "pugl/gl.hpp" // IWYU pragma: keep -#include "pugl/pugl.h" // IWYU pragma: keep -#include "pugl/pugl.hpp" // IWYU pragma: keep -#include "pugl/stub.hpp" // IWYU pragma: keep - -int -main() -{ - return 0; -} diff --git a/test/test_inline_cpp.cpp b/test/test_inline_cpp.cpp deleted file mode 100644 index f5694eb..0000000 --- a/test/test_inline_cpp.cpp +++ /dev/null @@ -1,67 +0,0 @@ -// Copyright 2021 David Robillard -// SPDX-License-Identifier: ISC - -// Tests that the implementation compiles as included C++ - -#define PUGL_API - -#if defined(__clang__) -# pragma clang diagnostic push -# pragma clang diagnostic ignored "-Wmissing-field-initializers" -# pragma clang diagnostic ignored "-Wold-style-cast" -# pragma clang diagnostic ignored "-Wzero-as-null-pointer-constant" -# if __has_warning("-Wreserved-identifier") -# pragma clang diagnostic ignored "-Wreserved-identifier" -# endif -#elif defined(__GNUC__) -# pragma GCC diagnostic push -# pragma GCC diagnostic ignored "-Wconversion" -# pragma GCC diagnostic ignored "-Wmissing-field-initializers" -# pragma GCC diagnostic ignored "-Wredundant-tags" -# pragma GCC diagnostic ignored "-Wsuggest-attribute=const" -# pragma GCC diagnostic ignored "-Wsuggest-attribute=pure" -# pragma GCC diagnostic ignored "-Wzero-as-null-pointer-constant" -#endif - -#include "../src/common.c" // IWYU pragma: keep -#include "../src/internal.c" // IWYU pragma: keep - -#if defined(_WIN32) -# include "../src/win.c" // IWYU pragma: keep -# include "../src/win.h" // IWYU pragma: keep -# include "../src/win_stub.c" // IWYU pragma: keep -# if defined(WITH_CAIRO) -# include "../src/win_cairo.c" // IWYU pragma: keep -# endif -# if defined(WITH_OPENGL) -# include "../src/win_gl.c" // IWYU pragma: keep -# endif -# if defined(WITH_VULKAN) -# include "../src/win_vulkan.c" // IWYU pragma: keep -# endif - -#else -# include "../src/x11.c" // IWYU pragma: keep -# include "../src/x11_stub.c" // IWYU pragma: keep -# if defined(WITH_CAIRO) -# include "../src/x11_cairo.c" // IWYU pragma: keep -# endif -# if defined(WITH_OPENGL) -# include "../src/x11_gl.c" // IWYU pragma: keep -# endif -# if defined(WITH_VULKAN) -# include "../src/x11_vulkan.c" // IWYU pragma: keep -# endif -#endif - -int -main() -{ - return 0; -} - -#if defined(__clang__) -# pragma clang diagnostic pop -#elif defined(__GNUC__) -# pragma GCC diagnostic pop -#endif diff --git a/test/test_inline_objcpp.mm b/test/test_inline_objcpp.mm deleted file mode 100644 index 1c9079b..0000000 --- a/test/test_inline_objcpp.mm +++ /dev/null @@ -1,38 +0,0 @@ -// Copyright 2021 David Robillard -// SPDX-License-Identifier: ISC - -// Tests that the implementation compiles as included ObjC++ - -#if defined(__clang__) -# pragma clang diagnostic push -# pragma clang diagnostic ignored "-Wzero-as-null-pointer-constant" -# pragma clang diagnostic ignored "-Wold-style-cast" -#endif - -#include "../src/common.c" // IWYU pragma: keep -#include "../src/internal.c" // IWYU pragma: keep -#include "../src/mac.h" // IWYU pragma: keep -#include "../src/mac.m" // IWYU pragma: keep -#include "../src/mac_stub.m" // IWYU pragma: keep - -#if defined(WITH_CAIRO) -# include "../src/mac_cairo.m" // IWYU pragma: keep -#endif - -#if defined(WITH_OPENGL) -# include "../src/mac_gl.m" // IWYU pragma: keep -#endif - -#if defined(WITH_VULKAN) -# include "../src/mac_vulkan.m" // IWYU pragma: keep -#endif - -#if defined(__clang__) -# pragma clang diagnostic pop -#endif - -int -main(void) -{ - return 0; -} diff --git a/test/test_utils.h b/test/test_utils.h index 214b360..4ebd985 100644 --- a/test/test_utils.h +++ b/test/test_utils.h @@ -471,11 +471,10 @@ static inline void printViewHints(const PuglView* view) { for (unsigned i = 0; i < PUGL_NUM_VIEW_HINTS; ++i) { - const PuglViewHint hint = (PuglViewHint)i; fprintf(stderr, "%s: %d\n", - puglViewHintString(hint), - puglGetViewHint(view, hint)); + puglViewHintString((PuglViewHint)i), + puglGetViewHint(view, (PuglViewHint)i)); } } -- cgit v1.2.1