From fc4a9c9ce6eebbc472fc2947ae371f5925011545 Mon Sep 17 00:00:00 2001 From: Yu Watanabe Date: Thu, 11 Apr 2024 11:27:18 +0900 Subject: [PATCH] test: PROJECT_FILE macro cannot be used in generated code MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit If the build directory is outside of the source tree, ASSERT_XYZ() triggers the following warning: === [20/569] Compiling C object test-hashmap.p/meson-generated_.._src_test_test-hashmap-ordered.c.o In file included from ../../home/watanabe/git/systemd/src/basic/macro.h:399, from ../../home/watanabe/git/systemd/src/basic/alloc-util.h:10, from src/test/test-hashmap-ordered.c:5: src/test/test-hashmap-ordered.c: In function ‘test_ordered_hashmap_get’: ../../home/watanabe/git/systemd/src/basic/log.h:216:27: warning: offset ‘32’ outside bounds of constant string [-Warray-bounds=] 216 | ? log_internal(_level, _e, PROJECT_FILE, __LINE__, __func__, __VA_ARGS__) \ | ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ../../home/watanabe/git/systemd/src/basic/log.h:238:24: note: in expansion of macro ‘log_full_errno_zerook’ 238 | (void) log_full_errno_zerook(level, 0, fmt, ##__VA_ARGS__); \ | ^~~~~~~~~~~~~~~~~~~~~ ../../home/watanabe/git/systemd/src/basic/log.h:248:28: note: in expansion of macro ‘log_full’ 248 | #define log_error(...) log_full(LOG_ERR, __VA_ARGS__) | ^~~~~~~~ ../../home/watanabe/git/systemd/src/shared/tests.h:251:25: note: in expansion of macro ‘log_error’ 251 | log_error("%s:%i: Assertion failed: expected \"%s\" to be NULL, but \"%p\" != NULL", \ | ^~~~~~~~~ src/test/test-hashmap-ordered.c:614:9: note: in expansion of macro ‘ASSERT_NULL’ 614 | ASSERT_NULL(r); | ^~~~~~~~~~~ === --- src/test/test-hashmap-plain.c | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/src/test/test-hashmap-plain.c b/src/test/test-hashmap-plain.c index 75195887ff..c343acb8a4 100644 --- a/src/test/test-hashmap-plain.c +++ b/src/test/test-hashmap-plain.c @@ -10,6 +10,13 @@ #include "tests.h" #include "time-util.h" +/* PROJECT_FILE, which is used by ASSERT_XYZ(), cannot be used in generated files, as the build directory + * may be outside of the source directory. */ +#ifdef ORDERED +# undef PROJECT_FILE +# define PROJECT_FILE __FILE__ +#endif + TEST(hashmap_replace) { _cleanup_hashmap_free_ Hashmap *m = NULL; _cleanup_free_ char *val1 = NULL, *val2 = NULL, *val3 = NULL, *val4 = NULL, *val5 = NULL;