2011-07-17 19:11:40 -05:00
|
|
|
import std::generic_os::setenv;
|
|
|
|
import std::generic_os::getenv;
|
|
|
|
import std::option;
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn test_setenv() {
|
2011-07-26 19:18:42 -05:00
|
|
|
// NB: Each test of setenv needs to use different variable names or the
|
|
|
|
// tests will not be threadsafe
|
|
|
|
setenv("NAME1", "VALUE");
|
2011-07-27 07:19:39 -05:00
|
|
|
assert (getenv("NAME1") == option::some("VALUE"));
|
2011-07-17 19:11:40 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn test_setenv_overwrite() {
|
2011-07-26 19:18:42 -05:00
|
|
|
setenv("NAME2", "1");
|
|
|
|
setenv("NAME2", "2");
|
2011-07-27 07:19:39 -05:00
|
|
|
assert (getenv("NAME2") == option::some("2"));
|
2011-07-17 19:11:40 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
// Windows GetEnvironmentVariable requires some extra work to make sure
|
|
|
|
// the buffer the variable is copied into is the right size
|
|
|
|
#[test]
|
|
|
|
fn test_getenv_big() {
|
2011-07-27 07:19:39 -05:00
|
|
|
let s = "";
|
|
|
|
let i = 0;
|
|
|
|
while i < 100 { s += "aaaaaaaaaa"; i += 1; }
|
2011-07-26 19:18:42 -05:00
|
|
|
setenv("NAME3", s);
|
2011-07-27 07:19:39 -05:00
|
|
|
assert (getenv("NAME3") == option::some(s));
|
2011-07-17 19:11:40 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
// Local Variables:
|
|
|
|
// mode: rust;
|
|
|
|
// fill-column: 78;
|
|
|
|
// indent-tabs-mode: nil
|
|
|
|
// c-basic-offset: 4
|
|
|
|
// buffer-file-coding-system: utf-8-unix
|
|
|
|
// compile-command: "make -k -C .. 2>&1 | sed -e 's/\\/x\\//x:\\//g'";
|
|
|
|
// End:
|