aboutsummaryrefslogtreecommitdiff
path: root/test cases/common
diff options
context:
space:
mode:
authorXavier Claessens <xavier.claessens@collabora.com>2023-03-02 11:59:28 -0500
committerXavier Claessens <xclaesse@gmail.com>2023-08-05 07:14:08 -0400
commite01d53b816c9fba25a068039e62d8ac9e5e2a971 (patch)
tree7905b8adc6c81750daa160cccbe7738e636e59a5 /test cases/common
parent50baf3c626267252a2d943a49d8e7c0402e23218 (diff)
downloadmeson-e01d53b816c9fba25a068039e62d8ac9e5e2a971.zip
meson-e01d53b816c9fba25a068039e62d8ac9e5e2a971.tar.gz
meson-e01d53b816c9fba25a068039e62d8ac9e5e2a971.tar.bz2
compiler: Add required keyword to has_* methods
add the "required" keyword to the functions has_function has_type has_member has_members has_argument has_multi_arguments has_link_argument has_multi_link_argument has_function_attribute Co-authored-by: Milan Hauth <milahu@gmail.com>
Diffstat (limited to 'test cases/common')
-rw-r--r--test cases/common/262 required keyword in has functions/meson.build67
-rw-r--r--test cases/common/262 required keyword in has functions/meson_options.txt1
2 files changed, 68 insertions, 0 deletions
diff --git a/test cases/common/262 required keyword in has functions/meson.build b/test cases/common/262 required keyword in has functions/meson.build
new file mode 100644
index 0000000..afd07ea
--- /dev/null
+++ b/test cases/common/262 required keyword in has functions/meson.build
@@ -0,0 +1,67 @@
+project('required keyword in has functions', 'c')
+
+cc = meson.get_compiler('c')
+opt = get_option('opt')
+
+cc.has_function('printf', prefix : '#include<stdio.h>', required : true)
+cc.has_type('time_t', prefix : '#include<time.h>', required : true)
+cc.has_member('struct tm', 'tm_sec', prefix : '#include<time.h>', required : true)
+cc.has_members('struct tm', ['tm_sec', 'tm_min'], prefix : '#include<time.h>', required : true)
+cc.has_header('time.h', required : true)
+cc.has_header_symbol('time.h', 'time', required : true)
+
+assert(not cc.has_function('printf', prefix : '#include<stdio.h>', required : opt))
+assert(not cc.has_type('time_t', prefix : '#include<time.h>', required : opt))
+assert(not cc.has_member('struct tm', 'tm_sec', prefix : '#include<time.h>', required : opt))
+assert(not cc.has_members('struct tm', ['tm_sec', 'tm_min'], prefix : '#include<time.h>', required : opt))
+assert(not cc.has_header('time.h', required : opt))
+assert(not cc.has_header_symbol('time.h', 'time', required : opt))
+
+# compiler.has_argument
+if cc.get_id() == 'msvc'
+ is_arg = '/O2'
+else
+ is_arg = '-O2'
+endif
+cc.has_argument(is_arg, required: true)
+assert(not cc.has_argument(is_arg, required: opt))
+
+# compiler.has_multi_arguments
+if cc.get_id() == 'gcc'
+ pre_arg = '-Wformat'
+ arg = '-Werror=format-security'
+ cc.has_multi_arguments([pre_arg, arg], required: true)
+ assert(not cc.has_multi_arguments(pre_arg, arg, required: opt))
+endif
+
+# compiler.has_link_argument
+if cc.get_argument_syntax() == 'msvc'
+ is_arg = '/OPT:REF'
+else
+ is_arg = '-Wl,-L/tmp'
+endif
+cc.has_link_argument(is_arg, required: true)
+assert(not cc.has_link_argument(is_arg, required: opt))
+
+# compiler.has_function_attribute
+if not ['pgi', 'msvc', 'clang-cl', 'intel-cl'].contains(cc.get_id())
+ a = 'aligned'
+ cc.has_function_attribute(a, required: true)
+ assert(not cc.has_function_attribute(a, required: opt))
+endif
+
+testcase expect_error('''compiler.has_function keyword argument 'required' was of type str but should have been one of: bool, UserFeatureOption''')
+ cc.has_function('printf', required : 'not a bool')
+endtestcase
+
+testcase expect_error('''C function 'asdfkawlegsdiovapfjhkr' not usable''')
+ cc.has_function('asdfkawlegsdiovapfjhkr', required : true)
+endtestcase
+
+testcase expect_error('''C header 'asdfkawlegsdiovapfjhkr.h' not found''')
+ cc.has_header('asdfkawlegsdiovapfjhkr.h', required : true)
+endtestcase
+
+testcase expect_error('''C symbol time_not_found not found in header time.h''')
+ cc.has_header_symbol('time.h', 'time_not_found', required : true)
+endtestcase
diff --git a/test cases/common/262 required keyword in has functions/meson_options.txt b/test cases/common/262 required keyword in has functions/meson_options.txt
new file mode 100644
index 0000000..53175af
--- /dev/null
+++ b/test cases/common/262 required keyword in has functions/meson_options.txt
@@ -0,0 +1 @@
+option('opt', type: 'feature', value: 'disabled')