From 286292235981a3d8393defaf983c3d153046578f Mon Sep 17 00:00:00 2001 From: Jian Zhang Date: Thu, 6 Feb 2025 16:44:03 +0100 Subject: [PATCH] test: check the namespace is not cluttered with min/max MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit libnvme defined a min/max macro before and exposed to all users. This has been removed but let's sure it doesn't come back, thus add a test for this. Before renaming the macro, the cpp's std::min will fail to compile. ``` ./test/cpp.cc: In function β€˜int min_compile_test()’: ../src/nvme/util.h:563:19: error: expected unqualified-id before β€˜(’ token 563 | #define min(x, y) ((x) > (y) ? (y) : (x)) ``` Signed-off-by: Jian Zhang [wagi: move the test to a seperate file] Signed-off-by: Daniel Wagner --- test/meson.build | 11 +++++++++++ test/misc.cc | 22 ++++++++++++++++++++++ 2 files changed, 33 insertions(+) create mode 100644 test/misc.cc diff --git a/test/meson.build b/test/meson.build index 2ab7e312a..d3d64562f 100644 --- a/test/meson.build +++ b/test/meson.build @@ -23,6 +23,17 @@ if cxx_available dependencies: libnvme_dep, include_directories: [incdir, internal_incdir] ) + + test('cpp-dump', cpp) + + misc = executable( + 'test-misc', + ['misc.cc'], + dependencies: libnvme_dep, + include_directories: [incdir, internal_incdir] + ) + test('cpp-misc', misc) + endif register = executable( diff --git a/test/misc.cc b/test/misc.cc new file mode 100644 index 000000000..3613beb09 --- /dev/null +++ b/test/misc.cc @@ -0,0 +1,22 @@ +// SPDX-License-Identifier: LGPL-2.1-or-later +/** + * This file is part of libnvme. + * Copyright (c) 2025 Daniel Wagner, SUSE LLC + */ + +#include +#include + +static int minmax_test() +{ + /* + * Ensure libnvme doesn't spoil the namespace, e.g. by exposing a + * min/max macro. + */ + return !(std::min(1, 2) == 1 && std::max(1, 2) == 2); +} + +int main(int argc, char *argv[]) +{ + return minmax_test(); +}