mirror of
https://github.com/vlang/v.git
synced 2023-08-10 21:13:21 +03:00
add setenv, unsetenv function to os
This commit is contained in:
parent
b464adec43
commit
8c4f7749df
14
os/os.v
14
os/os.v
@ -316,6 +316,20 @@ pub fn getenv(key string) string {
|
|||||||
return string(s)
|
return string(s)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
pub fn setenv(name string, value string, overwrite bool) int {
|
||||||
|
return C.setenv(name.cstr(), value.cstr(), overwrite)
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn unsetenv(name string) int {
|
||||||
|
return C.unsetenv(name.cstr())
|
||||||
|
}
|
||||||
|
|
||||||
|
fn exit(code int) {
|
||||||
|
C.exit(code)
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
// `file_exists` returns true if `path` exists.
|
// `file_exists` returns true if `path` exists.
|
||||||
pub fn file_exists(path string) bool {
|
pub fn file_exists(path string) bool {
|
||||||
res := false
|
res := false
|
||||||
|
21
os/os_test.v
Normal file
21
os/os_test.v
Normal file
@ -0,0 +1,21 @@
|
|||||||
|
import os
|
||||||
|
|
||||||
|
fn test_setenv() {
|
||||||
|
os.setenv('foo', 'bar', true)
|
||||||
|
assert os.getenv('foo') == 'bar'
|
||||||
|
|
||||||
|
// `setenv` should not set if `overwrite` is false
|
||||||
|
os.setenv('foo', 'bar2', false)
|
||||||
|
assert os.getenv('foo') == 'bar'
|
||||||
|
|
||||||
|
// `setenv` should overwrite if `overwrite` is true
|
||||||
|
os.setenv('foo', 'bar2', true)
|
||||||
|
assert os.getenv('foo') == 'bar2'
|
||||||
|
}
|
||||||
|
|
||||||
|
fn test_unsetenv() {
|
||||||
|
os.setenv('foo', 'bar', true)
|
||||||
|
os.unsetenv('foo')
|
||||||
|
assert os.getenv('foo') == ''
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in New Issue
Block a user