parent
db8246b3fc
commit
138e0fe984
6 changed files with 97 additions and 0 deletions
@ -0,0 +1,4 @@ |
||||
## New `unset()` method on `environment` objects |
||||
|
||||
[[@env]] now has an [[env.unset]] method to ensure an existing environment |
||||
is *not* defined. |
@ -0,0 +1,50 @@ |
||||
project( |
||||
'environment', |
||||
meson_version: '>=1.4.0', |
||||
) |
||||
|
||||
testenv = find_program(files('testenv.py')) |
||||
|
||||
|
||||
env = environment() |
||||
env.unset('foo') |
||||
test('not set', testenv, args: ['foo'], env: env) |
||||
|
||||
testcase expect_error('You cannot set the already unset variable \'foo\'') |
||||
env.set('foo', 'bar') |
||||
endtestcase |
||||
|
||||
testcase expect_error('You cannot append to unset variable \'foo\'') |
||||
env.append('foo', 'bar') |
||||
endtestcase |
||||
|
||||
testcase expect_error('You cannot prepend to unset variable \'foo\'') |
||||
env.prepend('foo', 'bar') |
||||
endtestcase |
||||
|
||||
|
||||
env1 = environment('foo=bar', method: 'append', separator: ':') |
||||
env1.append('foo', 'baz', separator: ':') |
||||
test('append', testenv, args: ['foo', 'bar:baz'], env: env1) |
||||
|
||||
testcase expect_error('You cannot unset the \'foo\' variable because it is already set') |
||||
env1.unset('foo') |
||||
endtestcase |
||||
|
||||
|
||||
env2 = environment(['foo=baz'], method: 'prepend', separator: ':') |
||||
env2.prepend('foo', 'bar', separator: ':') |
||||
test('prepend', testenv, args: ['foo', 'bar:baz'], env: env2) |
||||
|
||||
testcase expect_error('You cannot unset the \'foo\' variable because it is already set') |
||||
env2.unset('foo') |
||||
endtestcase |
||||
|
||||
|
||||
env3 = environment({'foo': 'foobar'}, method: 'set', separator: ':') |
||||
env3.set('foo', 'qux') |
||||
test('reset', testenv, args: ['foo', 'qux'], env: env3) |
||||
|
||||
testcase expect_error('You cannot unset the \'foo\' variable because it is already set') |
||||
env3.unset('foo') |
||||
endtestcase |
@ -0,0 +1,12 @@ |
||||
#!/usr/bin/env python3 |
||||
|
||||
import os |
||||
import sys |
||||
|
||||
key = sys.argv[1] |
||||
expected = sys.argv[2] if len(sys.argv) > 2 else None |
||||
|
||||
if os.environ.get(key) == expected: |
||||
sys.exit(0) |
||||
|
||||
sys.exit(f'Expected {expected!r}, was {os.environ.get(key)!r}') |
Loading…
Reference in new issue