mirror of
https://github.com/nushell/nushell.git
synced 2025-08-10 12:18:07 +02:00
Add initial nu-test-support port (#913)
* Add initial nu-test-support port * finish changing binary name * Oops, these aren't Windows-safe tests
This commit is contained in:
70
crates/nu-test-support/src/lib.rs
Normal file
70
crates/nu-test-support/src/lib.rs
Normal file
@ -0,0 +1,70 @@
|
||||
pub mod commands;
|
||||
pub mod fs;
|
||||
pub mod macros;
|
||||
pub mod playground;
|
||||
|
||||
pub struct Outcome {
|
||||
pub out: String,
|
||||
pub err: String,
|
||||
}
|
||||
|
||||
#[cfg(windows)]
|
||||
pub const NATIVE_PATH_ENV_VAR: &str = "Path";
|
||||
#[cfg(not(windows))]
|
||||
pub const NATIVE_PATH_ENV_VAR: &str = "PATH";
|
||||
|
||||
#[cfg(windows)]
|
||||
pub const NATIVE_PATH_ENV_SEPARATOR: char = ';';
|
||||
#[cfg(not(windows))]
|
||||
pub const NATIVE_PATH_ENV_SEPARATOR: char = ':';
|
||||
|
||||
impl Outcome {
|
||||
pub fn new(out: String, err: String) -> Outcome {
|
||||
Outcome { out, err }
|
||||
}
|
||||
}
|
||||
|
||||
pub fn pipeline(commands: &str) -> String {
|
||||
commands
|
||||
.lines()
|
||||
.skip(1)
|
||||
.map(|line| line.trim())
|
||||
.collect::<Vec<&str>>()
|
||||
.join(" ")
|
||||
.trim_end()
|
||||
.to_string()
|
||||
}
|
||||
|
||||
pub fn shell_os_paths() -> Vec<std::path::PathBuf> {
|
||||
let mut original_paths = vec![];
|
||||
|
||||
if let Some(paths) = std::env::var_os(NATIVE_PATH_ENV_VAR) {
|
||||
original_paths = std::env::split_paths(&paths).collect::<Vec<_>>();
|
||||
}
|
||||
|
||||
original_paths
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::pipeline;
|
||||
|
||||
#[test]
|
||||
fn constructs_a_pipeline() {
|
||||
let actual = pipeline(
|
||||
r#"
|
||||
open los_tres_amigos.txt
|
||||
| from-csv
|
||||
| get rusty_luck
|
||||
| str to-int
|
||||
| math sum
|
||||
| echo "$it"
|
||||
"#,
|
||||
);
|
||||
|
||||
assert_eq!(
|
||||
actual,
|
||||
r#"open los_tres_amigos.txt | from-csv | get rusty_luck | str to-int | math sum | echo "$it""#
|
||||
);
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user