mirror of
https://github.com/nushell/nushell.git
synced 2025-08-09 18:37:42 +02:00
Command tests (#922)
* WIP command tests * Finish marking todo tests * update * update * Windows cd test ignoring
This commit is contained in:
@ -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(|_| {
|
||||
|
@ -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| {
|
||||
|
Reference in New Issue
Block a user