nu_test_support/
lib.rs

1#![doc = include_str!("../README.md")]
2pub mod commands;
3pub mod fs;
4pub mod locale_override;
5pub mod macros;
6pub mod playground;
7use std::process::ExitStatus;
8
9// Needs to be reexported for `nu!` macro
10pub use nu_path;
11
12#[derive(Debug)]
13pub struct Outcome {
14    pub out: String,
15    pub err: String,
16    pub status: ExitStatus,
17}
18
19#[cfg(windows)]
20pub const NATIVE_PATH_ENV_VAR: &str = "Path";
21#[cfg(not(windows))]
22pub const NATIVE_PATH_ENV_VAR: &str = "PATH";
23
24#[cfg(windows)]
25pub const NATIVE_PATH_ENV_SEPARATOR: char = ';';
26#[cfg(not(windows))]
27pub const NATIVE_PATH_ENV_SEPARATOR: char = ':';
28
29impl Outcome {
30    pub fn new(out: String, err: String, status: ExitStatus) -> Outcome {
31        Outcome { out, err, status }
32    }
33}
34
35pub fn nu_repl_code(source_lines: &[&str]) -> String {
36    let mut out = String::from("nu --testbin=nu_repl ...[ ");
37
38    for line in source_lines.iter() {
39        out.push('`');
40        out.push_str(line);
41        out.push('`');
42        out.push(' ');
43    }
44
45    out.push(']');
46
47    out
48}
49
50pub fn shell_os_paths() -> Vec<std::path::PathBuf> {
51    let mut original_paths = vec![];
52
53    if let Some(paths) = std::env::var_os(NATIVE_PATH_ENV_VAR) {
54        original_paths = std::env::split_paths(&paths).collect::<Vec<_>>();
55    }
56
57    original_paths
58}