diff options
author | Xavier Claessens <xavier.claessens@collabora.com> | 2024-04-05 08:55:20 -0700 |
---|---|---|
committer | Jussi Pakkanen <jpakkane@gmail.com> | 2024-04-14 19:40:02 +0300 |
commit | 9f02d0a3e5a5ffc82256391c244b1af38e41ef78 (patch) | |
tree | abd84b53919405a6ea3de5494720e88df7ae23c1 /test cases | |
parent | 1dcffb635f3ba3dae63e6aa1b61d3cf56c9cc49b (diff) | |
download | meson-9f02d0a3e5a5ffc82256391c244b1af38e41ef78.zip meson-9f02d0a3e5a5ffc82256391c244b1af38e41ef78.tar.gz meson-9f02d0a3e5a5ffc82256391c244b1af38e41ef78.tar.bz2 |
Clarify mutable objects usage
Only Environment and ConfigurationData are mutable. However, only
ConfigurationData becomes immutable after first use which is
inconsistent.
This deprecates modification after first use of Environment object and
clarify documentation.
Diffstat (limited to 'test cases')
5 files changed, 40 insertions, 20 deletions
diff --git a/test cases/common/113 interpreter copy mutable var on assignment/check_env.py b/test cases/common/113 interpreter copy mutable var on assignment/check_env.py new file mode 100755 index 0000000..034d292 --- /dev/null +++ b/test cases/common/113 interpreter copy mutable var on assignment/check_env.py @@ -0,0 +1,7 @@ +#!/usr/bin/env python3 + +import os +import sys + +if sys.argv[1] not in os.environ: + exit(42) diff --git a/test cases/common/113 interpreter copy mutable var on assignment/meson.build b/test cases/common/113 interpreter copy mutable var on assignment/meson.build index d414bfc..3d4f3b0 100644 --- a/test cases/common/113 interpreter copy mutable var on assignment/meson.build +++ b/test cases/common/113 interpreter copy mutable var on assignment/meson.build @@ -1,4 +1,4 @@ -project('foo') +project('foo', meson_version: '>=1.5') a = configuration_data() a.set('HELLO', 1) @@ -10,6 +10,15 @@ assert(b.has('HELLO'), 'Original config data should be set on copy') configure_file(output : 'b.h', configuration : b) +testcase expect_error('Can not modify object after it has been used.') + b.set('WORLD', 1) +endtestcase + +# A copy of immutable object is mutable. This should print FeatureNew warning +# if meson_version is lower than 1.5. +c = b +c.set('WORLD', 1) + # This should still work, as we didn't use the original above but a copy! a.set('WORLD', 1) @@ -17,3 +26,26 @@ assert(a.has('WORLD'), 'New config data should have been set') assert(not b.has('WORLD'), 'New config data set should not affect var copied earlier') configure_file(output : 'a.h', configuration : a) + +env1 = environment() +env1.set('FOO', '1') +env2 = env1 +env1.set('BAR', '1') + +# FOO should be in env1 and env2 +run_command('check_env.py', 'FOO', env: env1, check: true) +run_command('check_env.py', 'FOO', env: env2, check: true) + +# BAR should be only in env1 +run_command('check_env.py', 'BAR', env: env1, check: true) +assert(run_command('check_env.py', 'BAR', env: env2, check: false).returncode() == 42) + +# This should print deprecation warning but still work +env1.set('PLOP', '1') +run_command('check_env.py', 'PLOP', env: env1, check: true) + +# A copy of used env should be mutable and not print warning +env3 = env1 +env3.set('BAZ', '1') +run_command('check_env.py', 'PLOP', env: env3, check: true) +run_command('check_env.py', 'BAZ', env: env3, check: true) diff --git a/test cases/failing/70 configuration immutable/input b/test cases/failing/70 configuration immutable/input deleted file mode 100644 index e69de29..0000000 --- a/test cases/failing/70 configuration immutable/input +++ /dev/null diff --git a/test cases/failing/70 configuration immutable/meson.build b/test cases/failing/70 configuration immutable/meson.build deleted file mode 100644 index b6cac41..0000000 --- a/test cases/failing/70 configuration immutable/meson.build +++ /dev/null @@ -1,12 +0,0 @@ -project('configuration_data is immutable') - -a = configuration_data() - -configure_file( - configuration : a, - input : 'input', - output : 'output', -) - -still_immutable = a -still_immutable.set('hello', 'world') diff --git a/test cases/failing/70 configuration immutable/test.json b/test cases/failing/70 configuration immutable/test.json deleted file mode 100644 index fc735fa..0000000 --- a/test cases/failing/70 configuration immutable/test.json +++ /dev/null @@ -1,7 +0,0 @@ -{ - "stdout": [ - { - "line": "test cases/failing/70 configuration immutable/meson.build:12:16: ERROR: Can not set values on configuration object that has been used." - } - ] -} |