engine-q merge

This commit is contained in:
Fernando Herrera
2022-02-07 19:11:34 +00:00
1965 changed files with 119062 additions and 20 deletions

View File

@ -84,22 +84,45 @@ impl Director {
impl Executable for Director {
fn execute(&mut self) -> NuResult {
<<<<<<< HEAD
use std::io::Write;
=======
>>>>>>> 9259a56a28f1dd3a4b720ad815aa19c6eaf6adce
use std::process::Stdio;
match self.executable() {
Some(binary) => {
<<<<<<< HEAD
let mut process = match binary
.construct()
.stdout(Stdio::piped())
.stdin(Stdio::piped())
.stderr(Stdio::piped())
=======
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())
.stderr(Stdio::piped())
.arg(format!("-c '{}'", commands))
>>>>>>> 9259a56a28f1dd3a4b720ad815aa19c6eaf6adce
.spawn()
{
Ok(child) => child,
Err(why) => panic!("Can't run test {}", why),
};
<<<<<<< HEAD
if let Some(pipelines) = &self.pipeline {
let child = process.stdin.as_mut().expect("Failed to open stdin");
@ -112,6 +135,8 @@ impl Executable for Director {
child.write_all(b"exit\n").expect("Could not write to");
}
=======
>>>>>>> 9259a56a28f1dd3a4b720ad815aa19c6eaf6adce
process
.wait_with_output()
.map_err(|_| {

View File

@ -1,105 +0,0 @@
use hamcrest2::core::{MatchResult, Matcher};
use std::fmt;
use std::str;
use super::nu_process::Outcome;
use super::{Director, Executable};
#[derive(Clone)]
pub struct Play {
stdout_expectation: Option<String>,
}
impl fmt::Display for Play {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
write!(f, "play")
}
}
impl fmt::Debug for Play {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
write!(f, "play")
}
}
pub fn says() -> Play {
Play {
stdout_expectation: None,
}
}
trait CheckerMatchers {
fn output(&self, actual: &Outcome) -> MatchResult;
fn std(&self, actual: &[u8], expected: Option<&String>, description: &str) -> MatchResult;
fn stdout(&self, actual: &Outcome) -> MatchResult;
}
impl CheckerMatchers for Play {
fn output(&self, actual: &Outcome) -> MatchResult {
self.stdout(actual)
}
fn stdout(&self, actual: &Outcome) -> MatchResult {
self.std(&actual.out, self.stdout_expectation.as_ref(), "stdout")
}
fn std(&self, actual: &[u8], expected: Option<&String>, description: &str) -> MatchResult {
let out = match expected {
Some(out) => out,
None => return Ok(()),
};
let actual = match str::from_utf8(actual) {
Err(..) => return Err(format!("{} was not utf8 encoded", description)),
Ok(actual) => actual,
};
if actual != *out {
return Err(format!(
"not equal:\n actual: {}\n expected: {}\n\n",
actual, out
));
}
Ok(())
}
}
impl Matcher<Outcome> for Play {
fn matches(&self, output: Outcome) -> MatchResult {
self.output(&output)
}
}
impl Matcher<Director> for Play {
fn matches(&self, mut director: Director) -> MatchResult {
self.matches(&mut director)
}
}
impl<'a> Matcher<&'a mut Director> for Play {
fn matches(&self, director: &'a mut Director) -> MatchResult {
if director.executable().is_none() {
return Err(format!("no such process {}", director));
}
let res = director.execute();
match res {
Ok(out) => self.output(&out),
Err(err) => {
if let Some(out) = &err.output {
return self.output(out);
}
Err(format!("could not exec process {}: {:?}", director, err))
}
}
}
}
impl Play {
pub fn stdout(mut self, expected: &str) -> Self {
self.stdout_expectation = Some(expected.to_string());
self
}
}

View File

@ -1,104 +0,0 @@
use super::EnvironmentVariable;
use crate::fs::{binaries as test_bins_path, executable_path};
use std::ffi::{OsStr, OsString};
use std::fmt;
use std::path::Path;
use std::process::{Command, ExitStatus};
pub trait Executable {
fn execute(&mut self) -> NuResult;
}
#[derive(Clone, Debug)]
pub struct Outcome {
pub out: Vec<u8>,
pub err: Vec<u8>,
}
impl Outcome {
pub fn new(out: &[u8], err: &[u8]) -> Outcome {
Outcome {
out: out.to_vec(),
err: err.to_vec(),
}
}
}
pub type NuResult = Result<Outcome, NuError>;
#[derive(Debug)]
pub struct NuError {
pub desc: String,
pub exit: Option<ExitStatus>,
pub output: Option<Outcome>,
}
#[derive(Clone, Debug, Default)]
pub struct NuProcess {
pub arguments: Vec<OsString>,
pub environment_vars: Vec<EnvironmentVariable>,
pub cwd: Option<OsString>,
}
impl fmt::Display for NuProcess {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
write!(f, "`nu")?;
for arg in &self.arguments {
write!(f, " {}", arg.to_string_lossy())?;
}
write!(f, "`")
}
}
impl NuProcess {
pub fn arg<T: AsRef<OsStr>>(&mut self, arg: T) -> &mut Self {
self.arguments.push(arg.as_ref().to_os_string());
self
}
pub fn args<T: AsRef<OsStr>>(&mut self, arguments: &[T]) -> &mut NuProcess {
self.arguments
.extend(arguments.iter().map(|t| t.as_ref().to_os_string()));
self
}
pub fn cwd<T: AsRef<OsStr>>(&mut self, path: T) -> &mut NuProcess {
self.cwd = Some(path.as_ref().to_os_string());
self
}
pub fn get_cwd(&self) -> Option<&Path> {
self.cwd.as_ref().map(Path::new)
}
pub fn construct(&self) -> Command {
let mut command = Command::new(&executable_path());
if let Some(cwd) = self.get_cwd() {
command.current_dir(cwd);
}
command.env_clear();
let paths = vec![test_bins_path()];
let paths_joined = match std::env::join_paths(&paths) {
Ok(all) => all,
Err(_) => panic!("Couldn't join paths for PATH var."),
};
command.env(crate::NATIVE_PATH_ENV_VAR, paths_joined);
for env_var in &self.environment_vars {
command.env(&env_var.name, &env_var.value);
}
for arg in &self.arguments {
command.arg(arg);
}
command
}
}

View File

@ -78,7 +78,12 @@ impl<'a> Playground<'a> {
std::fs::create_dir(PathBuf::from(&nuplay_dir)).expect("can not create directory");
let fixtures = fs::fixtures();
<<<<<<< HEAD
let fixtures = nu_path::canonicalize(fixtures.clone()).unwrap_or_else(|e| {
=======
let cwd = std::env::current_dir().expect("Could not get current working directory.");
let fixtures = nu_path::canonicalize_with(fixtures.clone(), cwd).unwrap_or_else(|e| {
>>>>>>> 9259a56a28f1dd3a4b720ad815aa19c6eaf6adce
panic!(
"Couldn't canonicalize fixtures path {}: {:?}",
fixtures.display(),
@ -97,6 +102,7 @@ impl<'a> Playground<'a> {
let playground_root = playground.root.path();
<<<<<<< HEAD
let test = nu_path::canonicalize(playground_root.join(topic)).unwrap_or_else(|e| {
panic!(
"Couldn't canonicalize test path {}: {:?}",
@ -106,6 +112,20 @@ impl<'a> Playground<'a> {
});
let root = nu_path::canonicalize(playground_root).unwrap_or_else(|e| {
=======
let cwd = std::env::current_dir().expect("Could not get current working directory.");
let test =
nu_path::canonicalize_with(playground_root.join(topic), cwd).unwrap_or_else(|e| {
panic!(
"Couldn't canonicalize test path {}: {:?}",
playground_root.join(topic).display(),
e
)
});
let cwd = std::env::current_dir().expect("Could not get current working directory.");
let root = nu_path::canonicalize_with(playground_root, cwd).unwrap_or_else(|e| {
>>>>>>> 9259a56a28f1dd3a4b720ad815aa19c6eaf6adce
panic!(
"Couldn't canonicalize tests root path {}: {:?}",
playground_root.display(),

View File

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