aboutsummaryrefslogtreecommitdiffstats
path: root/test/cpp
diff options
context:
space:
mode:
authorDavid Robillard <d@drobilla.net>2025-01-21 11:17:32 -0500
committerDavid Robillard <d@drobilla.net>2025-01-21 11:17:32 -0500
commit8c8c268bf2166b9049b51cde89a3330462771249 (patch)
treee4a8f33e0dff8989cea934e91ea2cb6ea0f29d8d /test/cpp
parent19b57eae068efd0c56469a1feb4401bc9aa338b8 (diff)
downloadpugl-8c8c268bf2166b9049b51cde89a3330462771249.tar.gz
pugl-8c8c268bf2166b9049b51cde89a3330462771249.tar.bz2
pugl-8c8c268bf2166b9049b51cde89a3330462771249.zip
Separate C++ build tests to avoid C/C++ warning clashes
Diffstat (limited to 'test/cpp')
-rw-r--r--test/cpp/.clang-tidy38
-rw-r--r--test/cpp/meson.build106
-rw-r--r--test/cpp/test_build.cpp20
-rw-r--r--test/cpp/test_inline_cpp.cpp67
-rw-r--r--test/cpp/test_inline_objcpp.mm38
5 files changed, 269 insertions, 0 deletions
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 <d@drobilla.net>
+# 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 <d@drobilla.net>
+# 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 <d@drobilla.net>
+// 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 <d@drobilla.net>
+// 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 <d@drobilla.net>
+// 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;
+}