summaryrefslogtreecommitdiffstats
path: root/toolkit/crashreporter/client/app/src/std/env.rs
blob: 77d9d4aecc583a9cfd0945192d91464211d4676a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
/* This Source Code Form is subject to the terms of the Mozilla Public
 * License, v. 2.0. If a copy of the MPL was not distributed with this
 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */

use super::mock::{mock_key, MockKey};
pub use std::env::VarError;
use std::ffi::{OsStr, OsString};

mock_key! {
    pub struct MockCurrentExe => std::path::PathBuf
}

pub struct ArgsOs {
    argv0: Option<OsString>,
}

impl Iterator for ArgsOs {
    type Item = OsString;

    fn next(&mut self) -> Option<Self::Item> {
        Some(
            self.argv0
                .take()
                .expect("only argv[0] is available when mocked"),
        )
    }
}

pub fn var<K: AsRef<OsStr>>(_key: K) -> Result<String, VarError> {
    unimplemented!("no var access in tests")
}

pub fn var_os<K: AsRef<OsStr>>(_key: K) -> Option<OsString> {
    unimplemented!("no var access in tests")
}

pub fn args_os() -> ArgsOs {
    MockCurrentExe.get(|r| ArgsOs {
        argv0: Some(r.clone().into()),
    })
}

#[allow(unused)]
pub fn current_exe() -> std::io::Result<super::path::PathBuf> {
    Ok(MockCurrentExe.get(|r| r.clone().into()))
}