diff options
author | Xavier Claessens <xavier.claessens@collabora.com> | 2023-05-30 09:27:42 -0400 |
---|---|---|
committer | Xavier Claessens <xclaesse@gmail.com> | 2023-08-02 13:35:29 -0400 |
commit | cec3edc08a6cd6a89761c49292ba6a3bace8b3c1 (patch) | |
tree | ca8f4504ead8fe875ef582299b2cbb9f07d85688 /test cases | |
parent | 465ad6d261e2733c60c3a066eebabee72f14346a (diff) | |
download | meson-cec3edc08a6cd6a89761c49292ba6a3bace8b3c1.zip meson-cec3edc08a6cd6a89761c49292ba6a3bace8b3c1.tar.gz meson-cec3edc08a6cd6a89761c49292ba6a3bace8b3c1.tar.bz2 |
Unify message(), format() and fstring formatting
Share a common function to convert objects to display strings for
consistency.
While at it, also add support for formatting user options.
Diffstat (limited to 'test cases')
-rw-r--r-- | test cases/common/264 format string/meson.build | 20 | ||||
-rw-r--r-- | test cases/common/264 format string/meson_options.txt | 1 | ||||
-rw-r--r-- | test cases/common/264 format string/test.json | 28 |
3 files changed, 49 insertions, 0 deletions
diff --git a/test cases/common/264 format string/meson.build b/test cases/common/264 format string/meson.build new file mode 100644 index 0000000..200cfac --- /dev/null +++ b/test cases/common/264 format string/meson.build @@ -0,0 +1,20 @@ +project('test format string') + +# Test all supported types in message(), format(), f-string. +foreach t : [get_option('opt'), 42, true, false, 'str', ['list'], {'dict': 'value'}] + message(t, '@0@'.format(t), f'@t@', [t], {'key': t}) +endforeach + +# Deprecated but should work with str.format(). +env = environment() +message('@0@'.format(env)) + +# Should fail with f-string and message() +error_msg = 'Value other than strings, integers, bools, options, dictionaries and lists thereof.' +testcase expect_error('message(): ' + error_msg) + message(env) +endtestcase + +testcase expect_error('f-string: ' + error_msg) + message(f'@env@') +endtestcase diff --git a/test cases/common/264 format string/meson_options.txt b/test cases/common/264 format string/meson_options.txt new file mode 100644 index 0000000..2e39176 --- /dev/null +++ b/test cases/common/264 format string/meson_options.txt @@ -0,0 +1 @@ +option('opt', type: 'feature') diff --git a/test cases/common/264 format string/test.json b/test cases/common/264 format string/test.json new file mode 100644 index 0000000..2369864 --- /dev/null +++ b/test cases/common/264 format string/test.json @@ -0,0 +1,28 @@ +{ + "stdout": [ + { + "line": "Message: auto auto auto [auto] {'key' : auto}" + }, + { + "line": "Message: 42 42 42 [42] {'key' : 42}" + }, + { + "line": "Message: true true true [true] {'key' : true}" + }, + { + "line": "Message: false false false [false] {'key' : false}" + }, + { + "line": "Message: str str str ['str'] {'key' : 'str'}" + }, + { + "line": "Message: ['list'] ['list'] ['list'] [['list']] {'key' : ['list']}" + }, + { + "line": "Message: {'dict' : 'value'} {'dict' : 'value'} {'dict' : 'value'} [{'dict' : 'value'}] {'key' : {'dict' : 'value'}}" + }, + { + "line": "Message: <EnvironmentVariables: []>" + } + ] + } |