]>
git.proxmox.com Git - rustc.git/blob - src/libstd/tests/env.rs
1 // Copyright 2017 The Rust Project Developers. See the COPYRIGHT
2 // file at the top-level directory of this distribution and at
3 // http://rust-lang.org/COPYRIGHT.
5 // Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6 // http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7 // <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8 // option. This file may not be copied, modified, or distributed
9 // except according to those terms.
14 use std
::iter
::repeat
;
15 use std
::ffi
::{OsString, OsStr}
;
19 fn make_rand_name() -> OsString
{
20 let mut rng
= rand
::thread_rng();
21 let n
= format
!("TEST{}", rng
.gen_ascii_chars().take(10)
22 .collect
::<String
>());
23 let n
= OsString
::from(n
);
24 assert
!(var_os(&n
).is_none());
28 fn eq(a
: Option
<OsString
>, b
: Option
<&str>) {
29 assert_eq
!(a
.as_ref().map(|s
| &**s
), b
.map(OsStr
::new
).map(|s
| &*s
));
34 let n
= make_rand_name();
36 eq(var_os(&n
), Some("VALUE"));
40 fn test_remove_var() {
41 let n
= make_rand_name();
48 fn test_set_var_overwrite() {
49 let n
= make_rand_name();
52 eq(var_os(&n
), Some("2"));
54 eq(var_os(&n
), Some(""));
58 #[cfg_attr(target_os = "emscripten", ignore)]
60 let mut s
= "".to_string();
63 s
.push_str("aaaaaaaaaa");
66 let n
= make_rand_name();
68 eq(var_os(&n
), Some(&s
));
72 #[cfg_attr(target_os = "emscripten", ignore)]
73 fn test_env_set_get_huge() {
74 let n
= make_rand_name();
75 let s
= repeat("x").take(10000).collect
::<String
>();
77 eq(var_os(&n
), Some(&s
));
83 fn test_env_set_var() {
84 let n
= make_rand_name();
86 let mut e
= vars_os();
88 assert
!(!e
.any(|(k
, v
)| {
89 &*k
== &*n
&& &*v
== "VALUE"
92 assert
!(vars_os().any(|(k
, v
)| {
93 &*k
== &*n
&& &*v
== "VALUE"