Command tests (#922)

* WIP command tests

* Finish marking todo tests

* update

* update

* Windows cd test ignoring
This commit is contained in:
JT
2022-02-03 21:01:45 -05:00
committed by GitHub
parent ac0b331f00
commit a008f1aa80
139 changed files with 10298 additions and 348 deletions

View File

@ -56,7 +56,7 @@ mod tests {
open los_tres_amigos.txt
| from-csv
| get rusty_luck
| str to-int
| into int
| math sum
| echo "$it"
"#,
@ -64,7 +64,7 @@ mod tests {
assert_eq!(
actual,
r#"open los_tres_amigos.txt | from-csv | get rusty_luck | str to-int | math sum | echo "$it""#
r#"open los_tres_amigos.txt | from-csv | get rusty_luck | into int | math sum | echo "$it""#
);
}
}

View File

@ -84,34 +84,32 @@ impl Director {
impl Executable for Director {
fn execute(&mut self) -> NuResult {
use std::io::Write;
use std::process::Stdio;
match self.executable() {
Some(binary) => {
let mut process = match binary
let mut commands = String::new();
if let Some(pipelines) = &self.pipeline {
for pipeline in pipelines {
if !commands.is_empty() {
commands.push_str("| ");
}
commands.push_str(&format!("{}\n", pipeline));
}
}
let process = match binary
.construct()
.stdout(Stdio::piped())
.stdin(Stdio::piped())
// .stdin(Stdio::piped())
.stderr(Stdio::piped())
.arg(format!("-c '{}'", commands))
.spawn()
{
Ok(child) => child,
Err(why) => panic!("Can't run test {}", why),
};
if let Some(pipelines) = &self.pipeline {
let child = process.stdin.as_mut().expect("Failed to open stdin");
for pipeline in pipelines {
child
.write_all(format!("{}\n", pipeline).as_bytes())
.expect("Could not write to");
}
child.write_all(b"exit\n").expect("Could not write to");
}
process
.wait_with_output()
.map_err(|_| {

View File

@ -1,23 +1,12 @@
use crate::playground::Playground;
use std::path::{Path, PathBuf};
use super::matchers::says;
use hamcrest2::assert_that;
use hamcrest2::prelude::*;
fn path(p: &Path) -> PathBuf {
let cwd = std::env::current_dir().expect("Could not get current working directory.");
nu_path::canonicalize_with(p, cwd)
.unwrap_or_else(|e| panic!("Couldn't canonicalize path {}: {:?}", p.display(), e))
}
#[test]
fn asserts_standard_out_expectation_from_nu_executable() {
Playground::setup("topic", |_, nu| {
assert_that!(nu.cococo("andres"), says().stdout("andres"));
})
}
#[test]
fn current_working_directory_in_sandbox_directory_created() {
Playground::setup("topic", |dirs, nu| {