mirror of
https://github.com/vlang/v.git
synced 2023-08-10 21:13:21 +03:00
os: ensure that setenv creates the key on windows (#6560)
This commit is contained in:
parent
0c174104fc
commit
2622070f14
@ -35,6 +35,12 @@ pub fn setenv(name string, value string, overwrite bool) int {
|
||||
unsafe {
|
||||
return C._putenv(format.str)
|
||||
}
|
||||
} else {
|
||||
if getenv(name).len == 0 {
|
||||
unsafe {
|
||||
return C._putenv(format.str)
|
||||
}
|
||||
}
|
||||
}
|
||||
return -1
|
||||
} $else {
|
||||
|
@ -1,4 +1,5 @@
|
||||
import os
|
||||
import time
|
||||
|
||||
fn test_getenv() {
|
||||
// VEXE is set by the V builtin test runner
|
||||
@ -34,3 +35,15 @@ fn test_environ() {
|
||||
assert all['myvar2'] == 'bar2'
|
||||
assert all['myvar_not_defined'] == ''
|
||||
}
|
||||
|
||||
fn test_setenv_var_not_exists(){
|
||||
key := time.new_time(time.now()).unix
|
||||
os.setenv('foo$key', 'bar', false)
|
||||
assert os.getenv('foo$key') == 'bar'
|
||||
}
|
||||
|
||||
fn test_getenv_empty_var(){
|
||||
key := time.new_time(time.now()).unix
|
||||
os.setenv('empty$key', '""', false)
|
||||
assert os.getenv('empty$key') == '""'
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user